Hello,
I am new to programming. I am learning Julia through online resources. I tried to implement a code in dynamic programming to find Longest common sub sequence. But I get some error, that I do not understand.
All sorts of helps are highly appreciated.
Welcome to discourse. Please avoid posting screenshots of your code: it will be easier for us to help you if we can copy-paste your buggy code to try and improve it.
See below for some instructions about how to correctly quote source code here:
As for your problem, I can’t see very well (yet another problem with screenshots), but isn’t the x in your 5th line lowercase when it should be uppercase?
Note also that your code is not correct for general Unicode (non-ASCII) strings.
-
Use
lastindex
and notlength
to get the last index in a string. -
Use
prevind(X, a)
instead ofa-1
to get the previous index inX
, and similarly forb
.
Hey @diwas07!
It seem like you have a typo in the elseif, you probably need capitalize the x.
Because x is not the string you are inputting (but probably some other variable in your environment), Julia doesn’t know how to access it as an array.
Another bug seems to be the final println. In the line above you probably want to assign that to a variable and then print the variable. Instead printing the function itself which doesn’t have the result you have (see below).
julia> function sum(a,b)
return a+b
end
sum (generic function with 1 method)
julia> sum(1,2)
3
julia> println("$sum")
sum
Hope this helps and good luck!