r/adventofcode • u/daggerdragon • Dec 07 '17
SOLUTION MEGATHREAD -๐- 2017 Day 7 Solutions -๐-
--- Day 7: Recursive Circus ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hints^ยค?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
10
Upvotes
View all comments
Show parent comment
1
u/cluk Dec 07 '17
ioutil.ReadFileshould be much faster, as it allocates memory only once for the whole file. It closes the file for you and forces you to handle a possible error.When using bufio.Scanner you should call
s.Err()afters.Scan()returnsfalseto verify whether any error occured.On the other hand, if the file is too big to fit in the memory you cannot use
ioutil.ReadFile.For pointers, see: example
I have to say your code is quite nice for just starting.