Skip to content

Commit

Permalink
update to Swift 6 / AoCTools 0.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gereons committed Oct 4, 2024
1 parent ab6c3e3 commit 2872a46
Show file tree
Hide file tree
Showing 31 changed files with 69 additions and 14 deletions.
38 changes: 33 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
{
"originHash" : "491a32c3af53ada53c6e874e2a142c02f10d9d27fc923e31fb6e1fee3b5726b8",
"pins" : [
{
"identity" : "aoctools",
"kind" : "remoteSourceControl",
"location" : "https://github.com/gereons/AoCTools",
"state" : {
"revision" : "19b8a7f6845c9fc89d26c52f09a14f1d7f46b81a",
"version" : "0.0.45"
"revision" : "d7971984089e4724cee928895176db6e81939491",
"version" : "0.1.0"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms",
"state" : {
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics.git",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swiftlintplugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/lukepistrol/SwiftLintPlugin",
"state" : {
"revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e",
"version" : "0.54.0"
"revision" : "bea71d23db993c58934ee704f798a66d7b8cb626",
"version" : "0.57.0"
}
}
],
"version" : 2
"version" : 3
}
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.9
// swift-tools-version:6.0

import PackageDescription

let package = Package(
name: "AdventOfCode",
platforms: [ .macOS(.v14) ],
platforms: [ .macOS(.v15) ],
dependencies: [
.package(url: "https://github.com/gereons/AoCTools", from: "0.0.45"),
.package(url: "https://github.com/gereons/AoCTools", from: "0.1.0"),
// .package(path: "../AoCTools"),
],
targets: [
Expand Down
1 change: 1 addition & 0 deletions Sources/AoC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AoCTools
import Foundation

@main
@MainActor
struct AdventOfCode {
// assign to eg `.day(1)`, leave as nil to run the puzzle for the current calendar day
static var defaultDay: Day? // = .day(1)
Expand Down
9 changes: 5 additions & 4 deletions Sources/Day05/Day05.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

import AoCTools
import Algorithms

private struct Almanac {
let seeds: [Int]
Expand Down Expand Up @@ -78,8 +79,8 @@ final class Day05: AOCDay {

func part2() -> Int {
var ranges = almanac.seeds
.chunked(2)
.compactMap { Range(from: $0[0], to: $0[0] + $0[1] - 1) }
.chunks(ofCount: 2)
.map { Range(from: $0.first!, to: $0.first! + $0.last! - 1) }

for map in almanac.maps {
var newRanges = [Range]()
Expand Down Expand Up @@ -115,8 +116,8 @@ final class Day05: AOCDay {

func part2_bruteForce() -> Int {
let seedRanges = almanac.seeds
.chunked(2)
.map { $0[0] ..< $0[0]+$0[1] }
.chunks(ofCount: 2)
.map { $0.first! ..< $0.first! + $0.last! }

var minLocation = Int.max
for range in seedRanges {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Day11/Day11.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Day11: AOCDay {
let galaxies = expand(galaxies, growth: growth)

return galaxies
.combinations(of: 2)
.combinations(ofCount: 2)
.map { pair in
pair[0].distance(to: pair[1])
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Day24/Day24.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class Day24: AOCDay {
func part1() -> Int {
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
var total = 0
for pair in stones.combinations(of: 2) {
for pair in stones.combinations(ofCount: 2) {
let s1 = pair[0]
let s2 = pair[1]
let (slope1, intercept1) = slopeIntercept(for: s1)
Expand Down
1 change: 1 addition & 0 deletions Tests/Day01Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day01Tests: XCTestCase {
let testInput = """
1abc2
Expand Down
1 change: 1 addition & 0 deletions Tests/Day02Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day02Tests: XCTestCase {
let testInput = """
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Expand Down
1 change: 1 addition & 0 deletions Tests/Day03Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day03Tests: XCTestCase {
let testInput = """
467..114..
Expand Down
1 change: 1 addition & 0 deletions Tests/Day04Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day04Tests: XCTestCase {
let testInput = """
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Expand Down
1 change: 1 addition & 0 deletions Tests/Day05Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day05Tests: XCTestCase {
let testInput = """
seeds: 79 14 55 13
Expand Down
1 change: 1 addition & 0 deletions Tests/Day06Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day06Tests: XCTestCase {
let testInput = """
Time: 7 15 30
Expand Down
1 change: 1 addition & 0 deletions Tests/Day07Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day07Tests: XCTestCase {
let testInput = """
32T3K 765
Expand Down
1 change: 1 addition & 0 deletions Tests/Day08Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day08Tests: XCTestCase {
let testInput1a = """
RL
Expand Down
1 change: 1 addition & 0 deletions Tests/Day09Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day09Tests: XCTestCase {
let testInput = """
0 3 6 9 12 15
Expand Down
1 change: 1 addition & 0 deletions Tests/Day10Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day10Tests: XCTestCase {
let testInput1a = """
-L|F7
Expand Down
1 change: 1 addition & 0 deletions Tests/Day11Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day11Tests: XCTestCase {
let testInput = """
...#......
Expand Down
1 change: 1 addition & 0 deletions Tests/Day12Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day12Tests: XCTestCase {
let testInput = """
???.### 1,1,3
Expand Down
1 change: 1 addition & 0 deletions Tests/Day13Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day13Tests: XCTestCase {
let testInput = """
#.##..##.
Expand Down
1 change: 1 addition & 0 deletions Tests/Day14Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day14Tests: XCTestCase {
let testInput = """
O....#....
Expand Down
1 change: 1 addition & 0 deletions Tests/Day15Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day15Tests: XCTestCase {
let testInput = """
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
Expand Down
1 change: 1 addition & 0 deletions Tests/Day16Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day16Tests: XCTestCase {
let testInput = #"""
.|...\....
Expand Down
1 change: 1 addition & 0 deletions Tests/Day17Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day17Tests: XCTestCase {
let testInput = """
2413432311323
Expand Down
1 change: 1 addition & 0 deletions Tests/Day18Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day18Tests: XCTestCase {
let testInput = """
R 6 (#70c710)
Expand Down
1 change: 1 addition & 0 deletions Tests/Day19Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day19Tests: XCTestCase {
let testInput = """
px{a<2006:qkq,m>2090:A,rfg}
Expand Down
1 change: 1 addition & 0 deletions Tests/Day20Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day20Tests: XCTestCase {
let testInput1 = """
broadcaster -> a, b, c
Expand Down
1 change: 1 addition & 0 deletions Tests/Day21Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day21Tests: XCTestCase {
let testInput = """
...........
Expand Down
1 change: 1 addition & 0 deletions Tests/Day22Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day22Tests: XCTestCase {
let testInput = """
1,0,1~1,2,1
Expand Down
1 change: 1 addition & 0 deletions Tests/Day23Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day23Tests: XCTestCase {
let testInput = """
#.#####################
Expand Down
1 change: 1 addition & 0 deletions Tests/Day24Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day24Tests: XCTestCase {
let testInput = """
19, 13, 30 @ -2, 1, -2
Expand Down
1 change: 1 addition & 0 deletions Tests/Day25Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XCTest
@testable import AdventOfCode

@MainActor
final class Day25Tests: XCTestCase {
func testDay25_part1_solution() throws {
let day = Day25(input: Day25.input)
Expand Down

0 comments on commit 2872a46

Please sign in to comment.