Skip to content

Commit 4131d19

Browse files
committed
more sols
1 parent da4ff09 commit 4131d19

File tree

12 files changed

+1011
-39
lines changed

12 files changed

+1011
-39
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Stars: 500](https://img.shields.io/badge/Stars-500⭐-blue)
44
![Rust: 250](https://img.shields.io/badge/Rust-250-cyan?logo=Rust)
5-
![Python: 123](https://img.shields.io/badge/Python-123-cyan?logo=Python)
5+
![Python: 122](https://img.shields.io/badge/Python-122-cyan?logo=Python)
66

77
<img src="./scripts/assets/christmas_ferris_2015_2024.png" alt="Christmas Ferris" width="164" />
88

@@ -26,28 +26,28 @@ Puzzle | Stars |
2626
[Day 10: Hoof It](https://adventofcode.com/2024/day/10) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day10/day10.rs) [![Go](./scripts/assets/go.png)](src/year2024/day10/day10.go)
2727
[Day 11: Plutonian Pebbles](https://adventofcode.com/2024/day/11) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day11/day11.rs) [![Go](./scripts/assets/go.png)](src/year2024/day11/day11.go)
2828
[Day 12: Garden Groups](https://adventofcode.com/2024/day/12) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day12/day12.rs) [![Go](./scripts/assets/go.png)](src/year2024/day12/day12.go)
29-
[Day 13: Claw Contraption](https://adventofcode.com/2024/day/13) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day13/day13.rs) [![Rust](./scripts/assets/rust.png)](src/year2024/day13_z3/day13_z3.rs) [![Python](./scripts/assets/python.png)](src/year2024/day13_z3/day13.py) [![Go](./scripts/assets/go.png)](src/year2024/day13/day13.go)
29+
[Day 13: Claw Contraption](https://adventofcode.com/2024/day/13) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day13/day13.rs) [![Rust](./scripts/assets/rust.png)](src/year2024/day13_z3/day13_z3.rs) [![Python](./scripts/assets/python.png)](src/year2024/day13_z3/day13_z3.py) [![Go](./scripts/assets/go.png)](src/year2024/day13/day13.go)
3030
[Day 14: Restroom Redoubt](https://adventofcode.com/2024/day/14) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day14/day14.rs) [![Python](./scripts/assets/python.png)](src/year2024/day14/day14.py) [![Go](./scripts/assets/go.png)](src/year2024/day14/day14.go) [🎁](src/year2024/day14/README.md)
3131
[Day 15: Warehouse Woes](https://adventofcode.com/2024/day/15) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day15/day15.rs) [![Go](./scripts/assets/go.png)](src/year2024/day15/day15.go) [🎁](src/year2024/day15/README.md)
3232
[Day 16: Reindeer Maze](https://adventofcode.com/2024/day/16) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day16/day16.rs) [🎁](src/year2024/day16/README.md)
3333
[Day 17: Chronospatial Computer](https://adventofcode.com/2024/day/17) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day17/day17.rs)
3434
[Day 18: RAM Run](https://adventofcode.com/2024/day/18) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day18/day18.rs) [![C++](./scripts/assets/cpp.png)](src/year2024/day18/day18.cpp) [![Go](./scripts/assets/go.png)](src/year2024/day18/day18.go)
35-
[Day 19: Linen Layout](https://adventofcode.com/2024/day/19) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day19/day19.rs)
35+
[Day 19: Linen Layout](https://adventofcode.com/2024/day/19) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day19/day19.rs) [![Python](./scripts/assets/python.png)](src/year2024/day19/day19.py) [![Go](./scripts/assets/go.png)](src/year2024/day19/day19.go)
3636
[Day 20: Race Condition](https://adventofcode.com/2024/day/20) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day20/day20.rs)
3737
[Day 21: Keypad Conundrum](https://adventofcode.com/2024/day/21) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day21/day21.rs)
38-
[Day 22: Monkey Market](https://adventofcode.com/2024/day/22) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day22/day22.rs)
39-
[Day 23: LAN Party](https://adventofcode.com/2024/day/23) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day23/day23.rs) [![Python](./scripts/assets/python.png)](src/year2024/day23/day23.py)
40-
[Day 24: Crossed Wires](https://adventofcode.com/2024/day/24) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day24/day24.rs)
38+
[Day 22: Monkey Market](https://adventofcode.com/2024/day/22) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day22/day22.rs) [![Go](./scripts/assets/go.png)](src/year2024/day22/day22.go)
39+
[Day 23: LAN Party](https://adventofcode.com/2024/day/23) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day23/day23.rs) [![Python](./scripts/assets/python.png)](src/year2024/day23/day23.py) [![Go](./scripts/assets/go.png)](src/year2024/day23/day23.go)
40+
[Day 24: Crossed Wires](https://adventofcode.com/2024/day/24) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day24/day24.rs) [![Go](./scripts/assets/go.png)](src/year2024/day24/day24.go)
4141
[Day 25: Code Chronicle](https://adventofcode.com/2024/day/25) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2024/day25/day25.rs) [![Python](./scripts/assets/python.png)](src/year2024/day25/day25.py) [![Go](./scripts/assets/go.png)](src/year2024/day25/day25.go)
4242

4343
## All years
4444

4545
Calendar | Solutions | Stars | Rust | Python | 🎁
4646
-------- | --------- | ----- | ---- | ------ | --
47-
[Advent of Code 2024](https://adventofcode.com/2024) | [Solutions](src/year2024/README.md) | 50⭐ | 25 | 10 | 3
48-
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 11 | 2
47+
[Advent of Code 2024](https://adventofcode.com/2024) | [Solutions](src/year2024/README.md) | 50⭐ | 25 | 11 | 3
48+
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 10 | 2
4949
[Advent of Code 2022](https://adventofcode.com/2022) | [Solutions](src/year2022/README.md) | 50⭐ | 25 | 18 | 1
50-
[Advent of Code 2021](https://adventofcode.com/2021) | [Solutions](src/year2021/README.md) | 50⭐ | 25 | 12 |
50+
[Advent of Code 2021](https://adventofcode.com/2021) | [Solutions](src/year2021/README.md) | 50⭐ | 25 | 11 |
5151
[Advent of Code 2020](https://adventofcode.com/2020) | [Solutions](src/year2020/README.md) | 50⭐ | 25 | 23 |
5252
[Advent of Code 2019](https://adventofcode.com/2019) | [Solutions](src/year2019/README.md) | 50⭐ | 25 | 23 | 2
5353
[Advent of Code 2018](https://adventofcode.com/2018) | [Solutions](src/year2018/README.md) | 50⭐ | 25 | 4 | 1

scripts/answers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,13 @@ def parse(self, year, _day):
610610
bonus = defaultdict(list)
611611

612612
for year, day, stars, title, sols in puzzles:
613-
if any(f.suffix == ".rs" for f in sols):
613+
614+
if any(f.suffix == ".rs" and f.parent.name == f.stem for f in sols):
614615
rust[year] += 1
615-
if any(f.suffix == ".py" for f in sols):
616+
617+
if any(f.suffix == ".py" and f.parent.name == f.stem for f in sols):
616618
python[year] += 1
619+
617620
all_stars[year] += stars
618621

619622
if sols:

scripts/runall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def aoc_available_puzzles(
8787
"Go": "{AOC_TARGET_DIR}/build/year{year}/day{day}_go",
8888
"C#": "{AOC_TARGET_DIR}/build/year{year}/day{day}_cs.exe",
8989
"Swift": "{AOC_TARGET_DIR}/build/year{year}/day{day}_swift",
90+
"Tcl": "src/year{year}/day{day}/day{day}.tcl",
9091
}
9192

9293
INTERPRETERS = {
@@ -111,6 +112,7 @@ def aoc_available_puzzles(
111112
"Lua": {"Lua": "lua5.4"},
112113
"Ruby": {"Ruby": "ruby"},
113114
"Perl": {"Perl": "perl"},
115+
"Tcl": {"Tcl": "tclsh"},
114116
}
115117

116118

src/year2024/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
![AoC2024](https://img.shields.io/badge/Advent_of_Code-2024-8A2BE2)
44
![Stars: 50](https://img.shields.io/badge/Stars-50⭐-blue)
55
![Rust: 26](https://img.shields.io/badge/Rust-26-cyan?logo=Rust)
6-
![Python: 10](https://img.shields.io/badge/Python-10-cyan?logo=Python)
6+
![Python: 11](https://img.shields.io/badge/Python-11-cyan?logo=Python)
77

88
## 2024 ([Calendar](https://adventofcode.com/2024)) ([Solutions](./)) : 50⭐
99

@@ -21,16 +21,16 @@ Puzzle | Stars |
2121
[Day 10: Hoof It](https://adventofcode.com/2024/day/10) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day10/day10.rs) [![Go](../../scripts/assets/go.png)](day10/day10.go)
2222
[Day 11: Plutonian Pebbles](https://adventofcode.com/2024/day/11) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day11/day11.rs) [![Go](../../scripts/assets/go.png)](day11/day11.go)
2323
[Day 12: Garden Groups](https://adventofcode.com/2024/day/12) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day12/day12.rs) [![Go](../../scripts/assets/go.png)](day12/day12.go)
24-
[Day 13: Claw Contraption](https://adventofcode.com/2024/day/13) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day13/day13.rs) [![Rust](../../scripts/assets/rust.png)](day13_z3/day13_z3.rs) [![Python](../../scripts/assets/python.png)](day13_z3/day13.py) [![Go](../../scripts/assets/go.png)](day13/day13.go)
24+
[Day 13: Claw Contraption](https://adventofcode.com/2024/day/13) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day13/day13.rs) [![Rust](../../scripts/assets/rust.png)](day13_z3/day13_z3.rs) [![Python](../../scripts/assets/python.png)](day13_z3/day13_z3.py) [![Go](../../scripts/assets/go.png)](day13/day13.go)
2525
[Day 14: Restroom Redoubt](https://adventofcode.com/2024/day/14) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day14/day14.rs) [![Python](../../scripts/assets/python.png)](day14/day14.py) [![Go](../../scripts/assets/go.png)](day14/day14.go) [🎁](day14/README.md)
2626
[Day 15: Warehouse Woes](https://adventofcode.com/2024/day/15) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day15/day15.rs) [![Go](../../scripts/assets/go.png)](day15/day15.go) [🎁](day15/README.md)
2727
[Day 16: Reindeer Maze](https://adventofcode.com/2024/day/16) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day16/day16.rs) [🎁](day16/README.md)
2828
[Day 17: Chronospatial Computer](https://adventofcode.com/2024/day/17) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day17/day17.rs)
2929
[Day 18: RAM Run](https://adventofcode.com/2024/day/18) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day18/day18.rs) [![C++](../../scripts/assets/cpp.png)](day18/day18.cpp) [![Go](../../scripts/assets/go.png)](day18/day18.go)
30-
[Day 19: Linen Layout](https://adventofcode.com/2024/day/19) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day19/day19.rs)
30+
[Day 19: Linen Layout](https://adventofcode.com/2024/day/19) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day19/day19.rs) [![Python](../../scripts/assets/python.png)](day19/day19.py) [![Go](../../scripts/assets/go.png)](day19/day19.go)
3131
[Day 20: Race Condition](https://adventofcode.com/2024/day/20) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day20/day20.rs)
3232
[Day 21: Keypad Conundrum](https://adventofcode.com/2024/day/21) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day21/day21.rs)
33-
[Day 22: Monkey Market](https://adventofcode.com/2024/day/22) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day22/day22.rs)
34-
[Day 23: LAN Party](https://adventofcode.com/2024/day/23) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day23/day23.rs) [![Python](../../scripts/assets/python.png)](day23/day23.py)
35-
[Day 24: Crossed Wires](https://adventofcode.com/2024/day/24) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day24/day24.rs)
33+
[Day 22: Monkey Market](https://adventofcode.com/2024/day/22) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day22/day22.rs) [![Go](../../scripts/assets/go.png)](day22/day22.go)
34+
[Day 23: LAN Party](https://adventofcode.com/2024/day/23) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day23/day23.rs) [![Python](../../scripts/assets/python.png)](day23/day23.py) [![Go](../../scripts/assets/go.png)](day23/day23.go)
35+
[Day 24: Crossed Wires](https://adventofcode.com/2024/day/24) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day24/day24.rs) [![Go](../../scripts/assets/go.png)](day24/day24.go)
3636
[Day 25: Code Chronicle](https://adventofcode.com/2024/day/25) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day25/day25.rs) [![Python](../../scripts/assets/python.png)](day25/day25.py) [![Go](../../scripts/assets/go.png)](day25/day25.go)

src/year2024/day1/day1.c

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
#include <stdlib.h>
55
#include <string.h>
66
#include <inttypes.h>
7-
#include <stdbool.h>
87
#include <time.h>
9-
#include <stdarg.h>
10-
#include <unistd.h>
11-
#include <signal.h>
12-
#include <sys/time.h>
13-
#include <sys/types.h>
14-
#include <sys/stat.h>
158

169
static int int_cmp(const void *a, const void *b)
1710
{
@@ -21,21 +14,53 @@ static int int_cmp(const void *a, const void *b)
2114
int main(int argc, char *argv[])
2215
{
2316
FILE *f;
17+
long data_size;
18+
char *data;
2419
int a, b;
2520
int *left = NULL, *right = NULL;
2621
size_t size = 0;
2722
size_t n = 0;
23+
int *right_count;
24+
struct timespec ts_start, ts_end;
2825

29-
if (argc >= 2)
30-
f = fopen(argv[1], "r");
31-
else
32-
f = fopen("input.txt", "r");
26+
f = fopen((argc >= 2) ? argv[1] : "input.txt", "r");
27+
if (f == NULL)
28+
{
29+
perror("fopen");
30+
exit(1);
31+
}
32+
fseek(f, 0, SEEK_END);
33+
data_size = ftell(f);
34+
data = (char *)malloc(data_size + 1);
35+
fseek(f, 0, SEEK_SET);
36+
fread(data, 1, data_size, f);
37+
data[data_size] = '\0';
38+
fclose(f);
39+
40+
clock_gettime(CLOCK_MONOTONIC, &ts_start);
3341

34-
while (fscanf(f, "%d %d", &a, &b) == 2)
42+
// beginning of puzzle solution
43+
44+
right_count = (int *)calloc(100000, sizeof(int));
45+
46+
const char *p = data;
47+
int consumed = 0;
48+
while (p < (data + data_size) && sscanf(p, "%d %d%n", &a, &b, &consumed) == 2)
3549
{
50+
if (consumed <= 0)
51+
break;
52+
p += consumed;
53+
54+
if (b >= 100000)
55+
{
56+
fprintf(stderr, "Error: b value %d exceeds right_count size\n", b);
57+
exit(1);
58+
}
59+
right_count[b] += 1;
60+
3661
if (n >= size)
3762
{
38-
size += 16;
63+
size += 128;
3964
left = (int *)realloc(left, size * sizeof(int));
4065
right = (int *)realloc(right, size * sizeof(int));
4166
}
@@ -53,25 +78,37 @@ int main(int argc, char *argv[])
5378
{
5479
part1 += abs(left[i] - right[i]);
5580
}
56-
printf("%d\n", part1);
5781

5882
// part 2
5983
int part2 = 0;
6084
for (size_t i = 0; i < n; ++i)
6185
{
6286
int a = left[i];
63-
for (size_t j = 0; j < n; ++j)
64-
{
65-
if (right[j] == a)
66-
{
67-
part2 += a;
68-
}
69-
}
87+
part2 += right_count[a] * a;
7088
}
71-
printf("%d\n", part2);
7289

7390
free(left);
7491
free(right);
92+
free(right_count);
93+
94+
// end of puzzle solution
95+
96+
clock_gettime(CLOCK_MONOTONIC, &ts_end);
97+
98+
free(data);
99+
100+
printf("%d\n", part1);
101+
printf("%d\n", part2);
102+
103+
for (int i = 2; i < argc; ++i)
104+
{
105+
if (strcmp(argv[i], "--elapsed") == 0)
106+
{
107+
double elapsed = (ts_end.tv_sec - ts_start.tv_sec) + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9;
108+
printf("elapsed: %.6f ms\n", elapsed * 1000.);
109+
break;
110+
}
111+
}
75112

76113
return 0;
77114
}

src/year2024/day1/day1.tcl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env tclsh
2+
# [Day 1: Historian Hysteria](https://adventofcode.com/2024/day/1)
3+
4+
# Usage: ./day1.tcl [input.txt]
5+
6+
if {![info exists env(PATH)]} {
7+
# noop, ensure tclsh has access to env if needed
8+
}
9+
10+
set filename "input.txt"
11+
if {$argc >= 1} {
12+
set filename [lindex $argv 0]
13+
}
14+
15+
set left {}
16+
set right {}
17+
18+
set fp [open $filename r]
19+
while {[gets $fp line] >= 0} {
20+
set line [string trim $line]
21+
if {$line eq ""} continue
22+
# parse exactly two integers from the line; skip if not present
23+
set a 0
24+
set b 0
25+
if {[scan $line "%d %d" a b] != 2} {
26+
continue
27+
}
28+
lappend left $a
29+
lappend right $b
30+
}
31+
close $fp
32+
33+
set left_sorted [lsort -integer $left]
34+
set right_sorted [lsort -integer $right]
35+
36+
# part 1: sum of absolute differences of paired elements
37+
set n [llength $left_sorted]
38+
set sum1 0
39+
for {set i 0} {$i < $n} {incr i} {
40+
set a [lindex $left_sorted $i]
41+
set b [lindex $right_sorted $i]
42+
set diff [expr {abs($a - $b)}]
43+
incr sum1 $diff
44+
}
45+
puts $sum1
46+
47+
# part 2: sum over left values of (value * count_of_same_value_in_right)
48+
array unset right_counts
49+
foreach b $right_sorted {
50+
incr right_counts($b)
51+
}
52+
53+
set sum2 0
54+
foreach a $left_sorted {
55+
if {[info exists right_counts($a)]} {
56+
set cnt $right_counts($a)
57+
} else {
58+
set cnt 0
59+
}
60+
incr sum2 [expr {$a * $cnt}]
61+
}
62+
puts $sum2
File renamed without changes.

0 commit comments

Comments
 (0)