Sep 16, 2010 at 12:21pm UTC
I get:
5537376230
with:
(io.Source fromFile "euler13.txt" getLines).map(BigInt(_)).sum.toString.substring(0, 10)
Have you tested if your code adds numbers correctly? E.g. try it for some simple numbers first and check manually where the error is.
BTW: This can be simplified:
1 2 3 4 5
while (wynik[i] >= 10)
{
wynik[i+1] += wynik[i]/10;
wynik[i] = wynik[i]%10;
}
To:
1 2 3 4 5
if (wynik[i] >= 10)
{
wynik[i+1] += 1;
wynik[i] -= 10;
}
BTW2: Don't you read the digits in the wrong order? (reversed)? The algorithm assumes wynik[0] is the least significant position, while in the file, the first character is the most significant.
Last edited on Sep 16, 2010 at 12:32pm UTC
Sep 16, 2010 at 12:40pm UTC
You were right.
It was adding digits of these numbers in reversed order.
I've correct it. Thanks.