Skip to content

Commit bd0dc59

Browse files
committed
yayyyyyyyyyyyy only had to cheat a tiny bit
1 parent 0a3586a commit bd0dc59

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

2025/day03/p1.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
FILE="$1"
4+
5+
function find_two() {
6+
while read line; do
7+
len=${#line}
8+
max_v=0
9+
max_i=0
10+
for ((i=0; i<len-1; ++i)); do
11+
c=${line:i:1}
12+
if [[ c -gt max_v ]]; then
13+
max_v=$c
14+
max_i=$i
15+
fi
16+
done
17+
max_v2=0
18+
for ((i=max_i+1; i<len; ++i)); do
19+
c=${line:i:1}
20+
if [[ c -gt max_v2 ]]; then
21+
max_v2=$c
22+
fi
23+
done
24+
echo "$max_v$max_v2"
25+
done
26+
}
27+
28+
cat "$FILE" \
29+
| find_two \
30+
| paste -sd+ \
31+
| bc

2025/day03/p2-2.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
FILE="$1"
4+
5+
function find_ninety_seven() {
6+
while read line; do
7+
len=${#line}
8+
max_v=0
9+
for ((i=0; i<len-2; ++i)); do
10+
for ((j=i+1; j<len-1; ++j)); do
11+
for ((k=j+1; k<len; ++k)); do
12+
[[ k -eq j ]] && continue
13+
[[ k -eq i ]] && continue
14+
c="${line:0:i}${line:$((i+1)):$((j-i-1))}${line:$((j+1)):$((k-j-1))}${line:$((k+1)):$((len-k))}"
15+
# echo $i $j $k "$c" ${#c}
16+
if [[ c -gt max_v ]]; then
17+
max_v=$c
18+
fi
19+
done
20+
done
21+
done
22+
echo $max_v
23+
done
24+
}
25+
26+
head -n1 "$FILE" |
27+
find_ninety_seven
28+
# gotta go fast
29+
# if [[ -n "$DONT_FORK_BOMB_ME_BRO" ]]; then
30+
# find_twelve
31+
# else
32+
# export DONT_FORK_BOMB_ME_BRO=true
33+
# <$FILE parallel --pipe -N 4 $0 \
34+
# | paste -sd+ \
35+
# | bc
36+
# fi

2025/day03/p2-bad.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
FILE="$1"
4+
5+
function find_ninety_seven() {
6+
while read line; do
7+
len=${#line}
8+
max_v=0
9+
for ((i=0; i<len-2; ++i)); do
10+
for ((j=i+1; j<len-1; ++j)); do
11+
for ((k=j+1; k<len; ++k)); do
12+
[[ k -eq j ]] && continue
13+
[[ k -eq i ]] && continue
14+
c="${line:0:i}${line:$((i+1)):$((j-i-1))}${line:$((j+1)):$((k-j-1))}${line:$((k+1)):$((len-k))}"
15+
# echo $i $j $k "$c" ${#c}
16+
if [[ c -gt max_v ]]; then
17+
max_v=$c
18+
fi
19+
done
20+
done
21+
done
22+
echo $max_v
23+
done
24+
}
25+
26+
cat "$FILE" \
27+
| find_ninety_seven \
28+
| paste -sd+ \
29+
| bc

2025/day03/p2.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
FILE="$1"
4+
5+
function find_twelve() {
6+
local input=$1
7+
local acc=$2
8+
local first=$3
9+
local search=9
10+
local len=${#input}
11+
RVAL=
12+
local needed=${#acc}
13+
needed=$((12-needed))
14+
if [[ needed -eq 0 ]]; then
15+
RVAL=$acc
16+
return
17+
fi
18+
if [[ len -lt needed ]]; then
19+
RVAL=
20+
return
21+
fi
22+
if [[ len -eq 1 ]]; then
23+
RVAL=$acc$input
24+
return
25+
fi
26+
# max_i=-1
27+
for ((search=9; search>0; --search)); do
28+
for ((i=0; i<len-needed+1; ++i)); do
29+
local c=${input:i:1}
30+
if [[ c -eq search ]]; then
31+
find_twelve ${input:((i+1))} $acc$c
32+
if [[ ${#RVAL} -eq 12 ]]; then
33+
[[ -n $first ]] && echo $RVAL
34+
return
35+
fi
36+
break
37+
fi
38+
done
39+
done
40+
[[ -n $first ]] && echo $RVAL
41+
RVAL=$acc
42+
}
43+
44+
function find_ninety_seven() {
45+
while read -r line; do
46+
# echo -n "$line -> "
47+
find_twelve $line '' 1
48+
done
49+
}
50+
51+
cat "$FILE" |
52+
find_ninety_seven \
53+
| paste -sd+ | bc
54+
# | paste -sd+ | bc
55+
# | paste -sd+ | bc
56+
# gotta go fast
57+
# if [[ -n "$DONT_FORK_BOMB_ME_BRO" ]]; then
58+
# find_twelve
59+
# else
60+
# export DONT_FORK_BOMB_ME_BRO=true
61+
# <$FILE parallel --pipe -N 4 $0 \
62+
# | paste -sd+ \
63+
# | bc
64+
#

0 commit comments

Comments
 (0)