After 7 days, let's see how my Advent of Code 2017 is going.
- Web framework: I made a standard web console, which I then copy forward to the next day. I could just as easily have put all the buttons on a single page, but it'd get too long by day 31.
Unit testing: As seen in stdlib.js, my test framework is very simple: On page load, setup, run some asserts, finish to get stats and redbar/greenbar the test console. This has been a great win, even though several of the days had only one or two examples.
"The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list."
- So this is nice and easy, linear problem for JS string processing. On the second variant I turned the inner function to pick the next char into a function, which I pass in. No external state.
"The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences."
- Needed to write more utils, this time to process strings into a table of numbers. My first solution kept it as a table of strings, and then I had problems with JS type coercion. Same strategy of finding a pure functional inner loop and extracting that as a function. Actually, subtotalFunc1 mutates cols, but you'll never use it again so it doesn't matter.
"Each square on the grid is allocated in a spiral pattern starting at a location marked 1 and then counting up while spiraling outward. For example, the first few squares are allocated like this:
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23---> ...
While this is very space-efficient (no squares are skipped), requested data must be carried back to square 1 (the location of the only access port for this memory system) by programs that can only move up, down, left, or right. They always take the shortest path: the Manhattan Distance between the location of the data and square 1."
- This was a little insane. There's apparently a pure math solution, but I am not a mathematician, I am a turtle; also song; also Lewis Carroll; also Gödel Escher Bach. So I solved it by moving a turtle around the spiral, turning left whenever there's an open space, and then I could just examine the spiral for values.
- Yes, I store points as a vector-2 of numbers, rather than making a "Point" class with x,y. In C using a struct makes more sense (since it only takes 8 bytes intead of the 40+ in any object system!), but in anything else, the vector requires the least memory, least work, and is easiest to serialize, use as a hashtable key, and so on.
- I just copy-pasted and modified for the second task, instead of making a nice inner function to pass in. It's not incredibly hard to parameterize, but I would need to break out of that inner function to return early, so probably using an exception for flow control?
"A passphrase consists of a series of words (lowercase letters) separated by spaces.
To ensure security, a valid passphrase must contain no duplicate words."
- Super simple, a histogram that only counts to 1. The second part only requires sorting the chars in each word, so you can check they aren't anagrams. I was worried that day 3 was the start of an exponential curve in difficulty, so by the end it'd take to the end of the Earth to finish.
"The message includes a list of the offsets for each jump. Jumps are relative: -1 moves to the previous instruction, and 2 skips the next one. Start at the first instruction in the list. The goal is to follow the jumps until one leads outside the list.
In addition, these instructions are a little strange; after each jump, the offset of that instruction increases by 1. So, if you come across an offset of 3, you would move three instructions forward, but change it to a 4 for the next time it is encountered.
How many steps does it take to reach the exit?"
- I returned the program counter at first, and that passes the sample data test, so I "guessed" wrong the first time, but then reread and found my bug. Having only one example is a problem. Both parts are as usual solved by passing in a function to determine the next state of the instruction. Trivial one aside from my stupid bug.
- I'm building up a good library of tools by now.
"In each cycle, it finds the memory bank with the most blocks (ties won by the lowest-numbered memory bank) and redistributes those blocks among the banks. To do this, it removes all of the blocks from the selected bank, then moves to the next (by index) memory bank and inserts one of the blocks. It continues doing this until it runs out of blocks; if it reaches the last memory bank, it wraps around to the first one.
The debugger would like to know how many redistributions can be done before a blocks-in-banks configuration is produced that has been seen before."
- Making the balancer was straightforward, I stored each state as a string in a history array, and a parallel histogram to catch the duplicate; I could get rid of hist but it turned out to make the second task easier.
- 07: (Don't read this or the code until tomorrow if you don't want a spoiler)
"You offer to help, but first you need to understand the structure of these towers. You ask each program to yell out their name, their weight, and (if they're holding a disc) the names of the programs immediately above them balancing on that disc. You write this information down (your puzzle input). Unfortunately, in their panic, they don't do this in an orderly fashion; by the time you're done, you're not sure which program gave which information.
Before you're ready to help them, you need to make sure your information is correct. What is the name of the bottom program?"
- Building the tree was a good puzzle, but not hard: Parse the text into nodes, keep them in a dictionary, then build the structure, and return the only parentless node (the root). Making a recursive toString so I could debug it was important…
- Second task looked to be tedious (depth-first search and pass the result all the way up), but then I just looked at my output and saw the unbalanced numbers, so entered it by hand. I am a computer, too.
I've got both gold stars each day. I'm completely incapable of reliably checking in at exactly 21:00 PST, and I'm too fussy about my code to ever be "the fastest", so my rankings are awful; maybe it ought to count from when you read the problem set, but then everyone would cheat on at least the first task.
- In Search of Space, by Hawkwind: 1970
- Into the Woods, by Hawkwind: 2017
- Black Swans and Wormhole Wizards, by Joe Satriani: 2010
- Surfing with the Alien, by Joe Satriani: 1987
- Are You Experienced, by Jimi Hendrix: 1967
- The Cry of Love, by Jimi Hendrix: 1971
- Chronicle of the Black Sword, by Hawkwind: 1986
New animals and furniture just got added: Bluebear, Antonio, Phoebe, and Raddle! And a ton of new furniture, noticeably tiki torches, campfires, some new rugs, medical machines that go Bing!. I had all 40 animals unlocked, and 37/40 befriended, so this is just in time.
Rather than wait for the new ones to appear in random rotation, I'm starting to call them up with the Calling Cards I got from levelling other animals to Level 10 or 15. Never waste leaf tickets on anything temporary, only on inventory, market boxes, and maybe camper paint jobs.
If you visit my.nintendo at least once a week, you can click on your Mii wandering around, sometimes it'll give you coins (Club Nintendo points). Then hit Redeem, and you can redeem both AC-only points and Club Nintendo points for materials, like the ever-scarce cotton; in the app, you can only redeem AC points. I wish I could trade over some Miitomo points, too.
You can mark craftable furnishings as Favorites (star icon) on the order screen, without finishing the order. Do this for all the items you need to summon each animal, and for their special request items, and then they'll be on the star tab, without having to go hunt for the item or look thru contacts again. When you actually craft it, un-favorite it so you don't have to see it in the list again.
After crafting 4 levels of the Cool street scene instantly (but had to wait for materials), for the 5th I'm now back to a giant 48-hour construction box and the endless sound of hammering and sawing. UGH. I'm at 240-something CC now, so I'll finish the holiday items tomorrow, a day ahead of prediction.
"Give me all your candy canes, little piggy, and nobody has to go on the grill."
- sketchbook vol #1: 12-17, by Slime Girls - then listen to everything else by Slime Girls on Bandcamp.
- The first few holiday items went quick, and doing the ones with CC (Candy Cane) rewards in the Timed Goals, they're free or even generate a profit. The rest are a little pricey. Every day between the quarry and a few rounds of animal requests I make about 100 CC, so I should have all the holiday items by the 6th. Someone playing more casually should still get there by the end of the month.
Feature requests filed with Nintendo (More->Misc->Customer Support->Feedback): Market Box Search: Search all friends' market boxes for a specific item, and see a list sorted by unit price ascending. Sort Inventory: A button to sort clothes and furnishings A-Z instead of date-added. Breezy Hollow, the orchard area, has no reason to revisit it except when fruit resets every 3 hours. The other 3 harvest areas all have 2 fruit trees and fish/bugs, so Breezy Hollow should have 2 bug spots. Who knows if some English feature requests are even going to make it to the dev staff, but better than just complaining to the blog.
I've been thinking about the need for chat. It'd be nice to give feedback on camps beyond a Kudo (which for the daily goals is often just "first in the friend list"). Ideally we could just see our friends' Miitomo accounts and go chat there, it's been dead quiet for a year.
But then I think of Nintendo's Disney-like purity goals and remember Randy Farmer's BlockChat post. So I'm pondering ways to share a URL with items, say with letter/number shirts in the camper.
These animals are crazy:
But not always wrong:
And sometimes full of wisdom:
I've joined the Advent of Code, and I'll be doing it in JS. Got my 2 stars for the day.
For good discipline (or as a handicap), I'm building a halfway-decent set of pages, unit testing framework, and sort of doing things right (good ES6 practices) instead of easy (hack some inline JS in compatibility mode). I'll link it in the sidebar tomorrow, when challenge 1 expires: My Advent of Code
Go on and do it yourself! I say "easy mode is for babies" and make it hard on myself, but really you can do this in anything. There's a perfectly nice Chipmunk BASIC or FreePascal if you're old-school.
Note: The leaderboard reset time is ridiculous, and I don't care about speed-coding or leaderboards. Don't stress about competing for first 100 completions, just do the thing.
- Halloween, by Mannheim Steamroller
- Fresh Aire IV: Winter, by Mannheim Steamroller
- Halloween 2 Creatures Collection, by Mannheim Steamroller
I'm just gonna dump these here, but listen in like 3 weeks, not right now: