This happens because the character '0' is encoded in ASCII <https://en.wikipedia.org/wiki/ASCII#ASCII_printable_code_chart> (or UTF-8) as the byte value 48 – i.e. the Uint8 vale 0x30 – and the other digits are the following ASCII byte values, 48-57. If you know that your string is pure ASCII and that it only contains decimal digits, then pulling out each character and subtracting '0' from it is the best way to get individual digits:
julia> numb_strg = "82166370484403199890008895243450658541227588666881" "82166370484403199890008895243450658541227588666881" julia> numb_dgts = Int64[c-'0' for c in numb_strg] 50-element Array{Int64,1}: 8 2 1 ⋮ 8 8 1 Once you have an array of decoded individual digits as Int64 values, you can find the starting offset where that digits multiplied with the following 12 digits has the greatest value. The product is guaranteed not to overflow since 9^13 = 2541865828329 which is less than typemax(Int64) = 9223372036854775807. If one used 32-bit integers, however, there may well be overflow since typemax(Int32) = 2147483647, which is much smaller than 9^13. If you were looking for 20-digit products, you'd need to use Int128 since 9^20 > typemax(Int). On Mon, Jun 15, 2015 at 1:02 PM, Huda Nassar <nassar.h...@gmail.com> wrote: > You can use the parseint function: > > *julia> **a = '3'* > > *'3'* > > *julia> **typeof(a)* > > *Char* > > *julia> **b = parseint(a)* > > *3* > > *julia> **typeof(b)* > > *Int64* > > > > 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 >> >>