|
| 1 | +// |
| 2 | +// Trebuchet.swift |
| 3 | +// |
| 4 | +// Created by Matthew Judy on 2023-12-04. |
| 5 | +// |
| 6 | + |
| 7 | + |
| 8 | +import ArgumentParser |
| 9 | +import Foundation |
| 10 | +import Shared |
| 11 | + |
| 12 | + |
| 13 | +/** |
| 14 | + Day 1 : Trebuchet?! |
| 15 | + |
| 16 | + # Part One |
| 17 | + |
| 18 | + Something is wrong with global snow production, and you've been selected to |
| 19 | + take a look. The Elves have even given you a map; on it, they've used stars |
| 20 | + to mark the top fifty locations that are likely to be having problems. |
| 21 | + |
| 22 | + You've been doing this long enough to know that to restore snow operations, |
| 23 | + you need to check all **fifty stars** by December 25th. |
| 24 | + |
| 25 | + Collect stars by solving puzzles. Two puzzles will be made available on each |
| 26 | + day in the Advent calendar; the second puzzle is unlocked when you complete |
| 27 | + the first. Each puzzle grants **one star**. Good luck! |
| 28 | + |
| 29 | + You try to ask why they can't just use a weather machine ("not powerful |
| 30 | + enough") and where they're even sending you ("the sky") and why your map looks |
| 31 | + mostly blank ("you sure ask a lot of questions") and hang on did you just say |
| 32 | + the sky ("of course, where do you think snow comes from") when you realize |
| 33 | + that the Elves are already loading you into a trebuchet ("please hold still, |
| 34 | + we need to strap you in"). |
| 35 | + |
| 36 | + As they're making the final adjustments, they discover that their calibration |
| 37 | + document (your puzzle input) has been **amended** by a very young Elf who was |
| 38 | + apparently just excited to show off her art skills. Consequently, the Elves |
| 39 | + are having trouble reading the values on the document. |
| 40 | + |
| 41 | + The newly-improved calibration document consists of lines of text; each line |
| 42 | + originally contained a specific **calibration value** that the Elves now need |
| 43 | + to recover. On each line, the calibration value can be found by combining |
| 44 | + the **first digit** and the **last digit** (in that order) to form a single |
| 45 | + **two-digit number**. |
| 46 | + |
| 47 | + For example: |
| 48 | + |
| 49 | + ``` |
| 50 | + 1abc2 |
| 51 | + pqr3stu8vwx |
| 52 | + a1b2c3d4e5f |
| 53 | + treb7uchet |
| 54 | + ``` |
| 55 | + |
| 56 | + In this example, the calibration values of these four lines are `12`, `38`, |
| 57 | + `15`, and `77`. Adding these together produces `142`. |
| 58 | + |
| 59 | + Consider your entire calibration document. **What is the sum of all of the |
| 60 | + calibration values?** |
| 61 | + */ |
| 62 | +@main |
| 63 | +struct Trebuchet: AsyncParsableCommand |
| 64 | +{ |
| 65 | + /// Enumeration for argument which activates "Part Two" behavior |
| 66 | + enum Mode: String, ExpressibleByArgument, CaseIterable |
| 67 | + { |
| 68 | + case modeA |
| 69 | + case modeB |
| 70 | + } |
| 71 | + |
| 72 | + @Option(help: "<#Argument used to activate “Part Two” behavior.#>") |
| 73 | + var mode: Mode |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +// MARK: - Command Execution |
| 78 | + |
| 79 | +extension Trebuchet |
| 80 | +{ |
| 81 | + mutating func run() async throws |
| 82 | + { |
| 83 | + while let inputLine = readLine() |
| 84 | + { |
| 85 | + print("\(inputLine)") |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | + |
0 commit comments