File tree Expand file tree Collapse file tree 2 files changed +62
-1
lines changed
Expand file tree Collapse file tree 2 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 1010| ---| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
1111| python3 | [ ✓] ( src/main/python/AoC2025_01.py ) | [ ✓] ( src/main/python/AoC2025_02.py ) | [ ✓] ( src/main/python/AoC2025_03.py ) | | | | | | | | | |
1212| java | [ ✓] ( src/main/java/AoC2025_01.java ) | [ ✓] ( src/main/java/AoC2025_02.java ) | | | | | | | | | | |
13- | bash | [ ✓] ( src/main/bash/AoC2025_01.sh ) | [ ✓] ( src/main/bash/AoC2025_02.sh ) | | | | | | | | | | |
13+ | bash | [ ✓] ( src/main/bash/AoC2025_01.sh ) | [ ✓] ( src/main/bash/AoC2025_02.sh ) | [ ✓ ] ( src/main/bash/AoC2025_03.sh ) | | | | | | | | | |
1414<!-- @END:ImplementationsTable:2025@ -->
1515
1616## 2024
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ #
3+ # Advent of Code 2025 Day 3
4+ #
5+
6+ year=2025
7+ day=03
8+
9+ solve_line () {
10+ local line=" $1 "
11+ local -i digits=" $2 "
12+ local -i pos=0
13+
14+ for (( i = digits; i > 0 ; i-- )) ; do
15+ best=0
16+ for (( j = pos; j < ${# line} - i + 1 ; j++ )) ; do
17+ if (( ${line: j: 1} > best)) ; then
18+ best=${line: j: 1}
19+ (( pos = j + 1 ))
20+ fi
21+ done
22+ echo -n " $best "
23+ done
24+ return 0
25+ }
26+
27+ solve () {
28+ local -i ans=0
29+ while read -r line || [ -n " $line " ]; do
30+ (( ans += $(solve_line "$line " "$2 ")) )
31+ done < " $1 "
32+ echo " $ans "
33+ return 0
34+ }
35+
36+ part1 () {
37+ solve " $1 " 2
38+ return 0
39+ }
40+
41+ part2 () {
42+ solve " $1 " 12
43+ return 0
44+ }
45+
46+ tests () {
47+ # shellcheck disable=SC2034
48+ {
49+ sample=(
50+ " 987654321111111"
51+ " 811111111111119"
52+ " 234234234234278"
53+ " 818181911112111"
54+ )
55+ }
56+
57+ TEST part1 sample 357
58+ TEST part2 sample 3121910778619
59+ }
60+
61+ source " $( dirname " $0 " ) /aoc_main.sh"
You can’t perform that action at this time.
0 commit comments