I decided to use f # as my functional language.
My problem: give a bunch of 50digits in the file, get the first 10 digits of the sum of each line. (Euler's problem for those who know)
e.g. (simplified): 1234567890
The sum is 45
The first "ten" digits or in our case the "first" digit is 4.
Here is my problem, I read my numbers file, I can split it with "\ n", and now I have each line, and then I try to convert it to a char array, but the problem is here. I cannot access every element of this array.
let total =
lines.Split([|'\n'|])
|> Seq.map (fun line -> line.ToCharArray())
|> Seq.take 1
|> Seq.to_list
|> Seq.length
I get each line, convert it to an array, I take the first array (for testing only), and I try to convert it to a list, and then get the length of the list. But this length is the length of the number of arrays (i.e. 1). This should be 50, because the number of elements in the array.
Does anyone know how to bind it to access each char?
source
share