Arxcis / adventofcode2020

Community-project solving https://adventofcode.com/ - problems, with Github CI, Docker and support for many languages.
6 stars 8 forks source link

Solution for Day01 in Kotlin upon new input/output data #134

Closed Stektpotet closed 2 years ago

Stektpotet commented 2 years ago

image

Kotlin solution seems to be off by one on solving the puzzle using the input I was given for day01.

Stektpotet commented 2 years ago

Side note on this: the test.sh should log which solution caused its crash as well, to clearly indicate which solution fails, even though it also can be inferred from the list of already completed tests.

Arxcis commented 2 years ago

Woow. Off by one error in both directions :roll_eyes: :confused: ....

Arxcis commented 2 years ago

I have some results from my investigation into this issue :thinking: When using the readLine()in Kotlin I don't get the entire input - I get the input in chunks - looks like the first 4096 bytes.

These chunks may split a number in half, if I try to insert newline characters between chunks:

2031
2036
2037
2038
2037
2036
20         // <<----- End of chunk 1 
38         // <<----- Beginning of chunk 2
2031
2043
2044
2047
2050

Or it may join two numbers together, because newline characters between chunks are discarded: (ref: https://stackoverflow.com/questions/4758525/carriage-return-and-new-line-with-java-and-readline)

< 9055
< 9056
< 9059
< 9076
< 9075
< 90819092   // <<--- Last number from chunk1 contatinated with first number from chunk 2.....
< 9100
< 9101
< 9123
< 9124
< 9147
< 9143
< 9146