I got a message in WhatsApp from Adam, one of the other Ride Ambassadors in the club.

Thought you might like this site. https://adventofcode.com

We rode a Zwift ride a week or so ago where he and I were the only ones on Discord, and we started talking about programming. He is a programmer by profession as was I. It sounds like we have a fair bit in common there.

It took me a couple of days to follow up, and it turns out it was something I liked.

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other. You don’t need a computer science background to participate – just a little programming knowledge and some problem solving skills will get you pretty far. Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.

https://adventofcode.com/2020/about

I started four days late: there were already four days of puzzles already out there, but I caught up by the next day, and did today’s puzzle this morning before my bike ride. Tammy asked me if they were difficult problems and I didn’t know how to answer that right away. They aren’t difficult from a computer science point of view. More like problem solving. Most of my solutions are about 75 lines of code or so, some shorter, some longer. I like a good problem and I like coding. It beats getting a little piece of chocolate every day. I mean, who wouldn’t want to hack away and make code like this? Gotta decode that seat information on your plane ticket!

let binary = code.replacingOccurrences(of: "F", with: "0")
		 .replacingOccurrences(of: "B", with: "1")
		 .replacingOccurrences(of: "L", with: "0")
		 .replacingOccurrences(of: "R", with: "1")
let splitIndex = binary.index(binary.startIndex, offsetBy: 7)
let rowBinary = binary[binary.startIndex..<splitIndex]
let seatBinary = binary[splitIndex..<binary.endIndex]
		
self.row = Int(rowBinary, radix: 2) ?? -1
self.seat = Int(seatBinary, radix: 2) ?? -1

Turns out the code “FBFBBFFRLR” on the ticket is row 44, seat 5.

It also gave me a chance to learn and be hands-on with GitHub. When I finished the first puzzle and asked Adam about his solution, he sent me a link to his code repository on GitHub as an answer. Well, that’s a challenge if there ever was one. And in about 15 minutes, I had my code uploaded as well.

https://github.com/sbiickert/SwiftAdventOfCode2020

I chose to write my code in Swift. It’s the language that Apple created for the iPhone and other platforms. I could have done it in Python or Perl, or even PHP. They might have been better choices, based on the puzzles so far. There’s a fair bit of text munging and Swift can do it, but with more code.

I hope I’ll continue for the whole 25 days. After all, Christmas must be saved! 🎄

Updated December 26th

I’m going to link here to my ReadMe on GitHub.

I finished it, and it was an exciting 25 days, never knowing if I would have trouble the next day or not.

All done! 50 stars.

One Comment

Comments are closed.