this is the error : LoadError(“main.jl”, 5, ErrorException(“syntax: invalid iteration specification”))
function makeAnagram(a::String,b::String)
lettercounts = zeros(Int,27)
for i in a
a1 = a[i]
lettercounts[Int(a1) - Int('a')] += 1
end
for i in b
b1 = b[i]
lettercounts[Int(b1) - Int('a')] -= 1
end
result = 0
for i in lettercounts
result += abs(i)
end
return result
end
a="abcd"
b = "abcd"
println("Total " , makeAnagram( a,b))
yes i see, but i still dont know how to fix it and i can’t find the solution in any file in julia.
i need to convert the first letter in the word to int in for loop
example :
for letter in word , word = dog
the letter ‘d’ convert to number
and o and g
This is the second topic from you that looks like homework.
It is fine to ask about homework here, but please check our (currently informal) homework policy, and invest some time in learning the basics of the language first, otherwise your experience with Julia may be needlessly frustrating. If your course has a TA, that person could also be a valuable resource.
this code stil with error
LoadError(“main.jl”, 22, MethodError(getindex, (“abcd”, ‘a’), 0x00000000000063e2))
i try to fix it, its work fine
i think the error is in a1 = a[i] any one can help me ? this is not homework or some thing i just learn the language endividually and i try to solve some qestions alone
doesn’t give you an index i, it gives you already the single characters of string a:
julia> a="abcd"
"abcd"
julia> for i in a
println(i)
end
a
b
c
d
so try
for i in a
lettercounts[Int(i) - Int('a')] += 1
end
By the way, don’t edit your code in the OP, just paste new code in your new answer. In this way the thread has some meaning in the answers before and others can see how it evolves.
This is good advice, but it would be nice for you to edit the title to something more descriptive of the error so that future people searching can find the answer.