Skip to content

Commit 1dcfbef

Browse files
author
Matthew Judy
committed
Create stubs for challenge 2023-03. Improve template (mode switching).
1 parent d638e84 commit 1dcfbef

File tree

3 files changed

+113
-9
lines changed

3 files changed

+113
-9
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ let package: Package = Package(
4343
// 2023
4444
.executableTarget(name: "trebuchet", dependencies: commonDependencies, path: "Sources/2023/01", swiftSettings: commonSettings),
4545
.executableTarget(name: "cube-conundrum", dependencies: commonDependencies, path: "Sources/2023/02", swiftSettings: commonSettings),
46+
.executableTarget(name: "gear-ratios", dependencies: commonDependencies, path: "Sources/2023/03", swiftSettings: commonSettings),
4647
]
4748
)

Sources/2023/03/GearRatios.swift

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// GearRatios.swift
3+
//
4+
// Created by Matthew Judy on 2023-12-14.
5+
//
6+
7+
8+
import ArgumentParser
9+
import Foundation
10+
import Shared
11+
12+
13+
/// Day 3 : Gear Ratios
14+
///
15+
/// # Part One
16+
///
17+
/// You and the Elf eventually reach a gondola lift station; he says the
18+
/// gondola lift will take you up to the **water source**, but this is as far
19+
/// as he can bring you. You go inside.
20+
///
21+
/// It doesn't take long to find the gondolas, but there seems to be a problem:
22+
/// they're not moving.
23+
///
24+
/// "Aaah!"
25+
///
26+
/// You turn around to see a slightly-greasy Elf with a wrench and a look of
27+
/// surprise. "Sorry, I wasn't expecting anyone! The gondola lift isn't working
28+
/// right now; it'll still be a while before I can fix it." You offer to help.
29+
///
30+
/// The engineer explains that an engine part seems to be missing from the
31+
/// engine, but nobody can figure out which one. If you can **add up all the
32+
/// part numbers** in the engine schematic, it should be easy to work out which
33+
/// part is missing.
34+
///
35+
/// The engine schematic (your puzzle input) consists of a visual
36+
/// representation of the engine. There are lots of numbers and symbols you
37+
/// don't really understand, but apparently **any number adjacent to a
38+
/// symbol**, even diagonally, is a "part number" and should be included in
39+
/// your sum. Periods (`.`) do not count as a symbol.
40+
///
41+
/// Here is an example engine schematic:
42+
///
43+
///```
44+
/// 467..114..
45+
/// ...*......
46+
/// ..35..633.
47+
/// ......#...
48+
/// 617*......
49+
/// .....+.58.
50+
/// ..592.....
51+
/// ......755.
52+
/// ...$.*....
53+
/// .664.598..
54+
/// ```
55+
///
56+
/// In this schematic, two numbers are **not** part numbers because they are
57+
/// not adjacent to a symbol: `114` (top right) and `58` (middle right). All
58+
/// other numbers are adjacent to a symbol and so are part numbers; their sum
59+
/// is **`4361`**.
60+
///
61+
/// Of course, the actual engine schematic is much larger. **What is the sum of
62+
/// all of the part numbers in the engine schematic?**
63+
///
64+
@main
65+
struct GearRatios: AsyncParsableCommand
66+
{
67+
// /// Adds a `--mode` option to the command, which allows the command's logic
68+
// /// to branch and handle requirements of either "Part One" or "Part Two".
69+
// /// The option must be followed by a value from this enumeration.
70+
// enum Mode: String, ExpressibleByArgument, CaseIterable
71+
// {
72+
// case <#modeA#>
73+
// case <#modeB#>
74+
// }
75+
// @Option(help: "'<#modeA#>' or '<#modeB#>'")
76+
// var mode: Mode
77+
78+
// /// Adds a flag to the command, named for the behavioral difference in
79+
// /// "Part Two." This allows the command's logic to branch and handle the
80+
// /// requirements of either "Part One" or "Part Two".
81+
// @Flag(help: "Search for both cardinal values ('one', 'two', ...) and integers.")
82+
// var <#partTwoDifference#>: Bool = false
83+
}
84+
85+
86+
// MARK: - Command Execution
87+
88+
extension GearRatios
89+
{
90+
mutating func run() async throws
91+
{
92+
let input: AsyncLineSequence = FileHandle.standardInput.bytes.lines // URL.homeDirectory.appending(path: "Desktop/input.txt").lines
93+
try await input.reduce(into: []) { $0.append($1) }.forEach { print($0) }
94+
}
95+
}
96+

Template/ChallengeName.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ import Shared
1818
@main
1919
struct <#ChallengeName#>: AsyncParsableCommand
2020
{
21-
/// <#Enumeration for argument which activates "Part Two" behavior#>
22-
enum Mode: String, ExpressibleByArgument, CaseIterable
23-
{
24-
case modeA
25-
case modeB
26-
}
27-
28-
@Option(help: "<#Argument used to activate “Part Two” behavior.#>")
29-
var mode: Mode
21+
// /// Adds a `--mode` option to the command, which allows the command's logic
22+
// /// to branch and handle requirements of either "Part One" or "Part Two".
23+
// /// The option must be followed by a value from this enumeration.
24+
// enum Mode: String, ExpressibleByArgument, CaseIterable
25+
// {
26+
// case <#modeA#>
27+
// case <#modeB#>
28+
// }
29+
// @Option(help: "'<#modeA#>' or '<#modeB#>'")
30+
// var mode: Mode
31+
32+
// /// Adds a flag to the command, named for the behavioral difference in
33+
// /// "Part Two." This allows the command's logic to branch and handle the
34+
// /// requirements of either "Part One" or "Part Two".
35+
// @Flag(help: "Search for both cardinal values ('one', 'two', ...) and integers.")
36+
// var <#partTwoDifference#>: Bool = false
3037
}
3138

3239

0 commit comments

Comments
 (0)