r/adventofcode • • Dec 02 '15

Spoilers Day 2 solutions

Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.

15 Upvotes

161 comments sorted by

View all comments

Show parent comment

1

u/Hoi_A Dec 02 '15

I just found out what was wrong with my program, and im sure your solution wouldnt have fixed it. So I think ill leave my code as is now.

The problem was that I was adding the extra paper 2 times instead of once.

1

u/Serialloser Dec 02 '15
  1. I would read the input from a file instead of a string
  2. There's a method called split on the String class, it splits (doh) your String into a String[] using a delimiter that you pass to the method.

You can find a solution here http://pastebin.com/Sg66jaea It's over engineered but it uses the technique presented above. It needs the latest jdk to run I think (used an online compiler to test) and it expects a file called "input" next to your app.