Kotlin Day 2

I Was Told There Would Be No Math

Fang Jin
2 min readSep 19, 2020

--

I Was Told There Would Be No Math

From Advent of Code 2015, Day 2

3x11x24
13x5x19
1x9x27
24x8x21
6x8x17

Modal

Model the Box as a list of integer sizes which can be extracted via regular expression.

If you are not sure why we build a model (object) first, please check Day 0 and you can find out how to get a list of models from string (or file) as well.

Part 1

Given a list of box dimensions in string, find out the total wrapping paper required.

Calculate all wrapping paper required.

For each line in order to calculate the paper, we outsource it to a function that takes geometric sizes and output wrapping paper .

Part 2

For same list of box dimensions in string, find out the total wrapping paper following another wrapping method.

If you happen to have quite a bit different wrapping method, it might be worthwhile to come up a function that accepts the wrapping method as one of the input variables.

Highlights

  • How to extract info using regular expression?
  • How to swap a method with another method?

Now, ready for the next day? Day 3 — Perfectly Spherical Houses in a Vaccum

Or, revisit the previous day? Day 1 — Not Quite Lisp

For Complete source code, please visit AoC 2015 Kotlin.

--

--

Fang Jin

#OpenToWork Front-end Engineer, book author of “Designing React Hooks the Right Way” sold at Amazon.