You can also do something like this to get each character as an integer... 
you'll need to convert each integer to Int64 as Stefan noted when doing the 
multiplication.

julia> z = reinterpret(Int32,collect(numb_strg[1:12])) .- 48
12-element Array{Int32,1}: 
 8 
 2 
 1 
 6 
 6 
 3 
 7 
 0 
 4 
 8 
 4 
 4


On Monday, June 15, 2015 at 12:39:14 PM UTC-4, James Byars wrote:
>
> Hey all,
>
> I am working through some Project Euler problem (#008) about searching 
> through a number to determine the greatest product of 
> thirteen adjacent numbers. Here is a code snippet:
>
> n = 12
> numb_strg = "82166370484403199890008895243450658541227588666881"
> string_post = length(numb_strg) - n
> string_post = 0
>
> When I run this command: *collect(numb_strg[(string_post+1):(string_post*
> *+n)])*
>
> I get a character vector.
>
> 12-element Array{Char,1}:
>  '8'
>  '2'
>  '1'
>  '6'
>  '6'
>  '3'
>  '7'
>  '0'
>  '4'
>  '8'
>  '4'
>  '4'
>
>
> However, if I attempt to convert it to a integer array. I get the 
> following array.
>
> 12-element Array{Int64,1}:
>  56
>  50
>  49
>  54
>  54
>  51
>  55
>  48
>  52
>  56
>  52
>  52
>
>
> If I subtract 48 from the each element in the array, I get the correct 
> number. Is there any reason for the odd conversion from character to integer 
> (or float)? My primary language is R and I am using Project Euler to learn 
> Julia.
>
>
> Thanks,
>
>
> James
>
>

Reply via email to