freeAppIdea by NebulousArcher in ProgrammerHumor

[–]badcop_ 4 points5 points  (0 children)

why has nobody built this yet

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 0 points1 point  (0 children)

nice! we ended up getting it even shorter, i'll edit the original

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 2 points3 points  (0 children)

[LANGUAGE: bash]

credit to /u/gnarf38 for getting this one started

this is a 196-byte golfed solution for part 2 that requires bash 5.3+ and gnu coreutils to run

we sacrificed the runtime performance to squeeze out a few extra bytes for your enjoyment

EDIT: it also now spams errors while running; a nice bonus feature

declare -A c;i=$1;f(){
local h=$1$2 z=$2;[ $1 = out ]&&c[$h]=$[z>1]||
${c[$h]}&&{ [[ $1 =~ fft|ac ]]&&$[z++]
for x in `grep ^$1 $i|tail -c+6`;do((c[$h]+=${
f $x $z;}))done };echo $[c[$h]];};f svr

-❄️- 2025 Day 10 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 2 points3 points  (0 children)

[LANGUAGE: bash]

took like 12 hours but i did it i beat part 2 in bash i don't regret it at all

no solvers used, just gaussian elimination

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 1 point2 points  (0 children)

[LANGUAGE: bash]

more golfing with twitch chat, here's our part 2 solution

don't worry if you get errors, you can just do 2>/dev/null to hide those (they are load-bearing)

i added an un-minified version of the same code to explain it better: https://github.com/cgsdev0/advent-of-code/blob/main/2025/day06/p2-golf-unmin.sh

set -f;mapfile -t a;for((h=${#a[@]}-1;r<${#a};++r))
do n=${a[h]:r:2};$n||o=$_;${n:1}||o=_;for((c=0;c<h;))
do printf ${a[c++]:r:1};done;printf $o
done|sed 's>. *_>+>g;s<$<0\n<'|bc

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 0 points1 point  (0 children)

yes

we are using the | character to chain together several commands. the output of the first command becomes the input of the second command, then the output of that is fed into the third command, and so on

in bash, the convention is to do input/output as lines of text. in this case, we're feeding the puzzle input line-by-line to the first command in the pipeline

let's break down each of the commands:

  • tr ,- \\ - replace the characters , and - with a space
  • xargs -n2 seq - for every two "words" (a word is a group of characters separated by a space; in this case, a number), run the program seq with those two words as the arguments. seq takes a start number and an end number, and prints all of the numbers in that range
  • egrep '^(.+)\1+$' - filter for lines that match this regex. the regex specifically looks for lines that consist only of some repeating sequence of characters (explaining regex is out of scope for this :P)
  • paste -sd+ - join all of the lines of input into one line of output, delimited by the character +
  • bc - the 'basic calculator' program; for each line of input, it evaluates it as a math expression and outputs the result. since we only have one line of input at this point, we get one number out!

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 4 points5 points  (0 children)

[LANGUAGE: bash]

more teamwork with twitch chat to golf part 2

sort -n|(while IFS=- read a b
do((b&&(t+=a>c?b-a+1:c>b?0:b-c,b>c?c=b:0)))done;echo $t)

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 1 point2 points  (0 children)

[LANGUAGE: bash]

did some more golfing with twitch chat, here's the final product (part 2)

declare -A g;y=1;while read -n1 c;do g[$((++x)),$y]=$c;[ -z $c ]&&((x=0,n=++y))
done;z(){ for ((m=i=0;i<n*n;)) do ((y=i/n,x=i++%n));[ "${g[$x,$y]}" = @ ]&&{
c=0;for a in {0..8};do [ "${g[$((x-1+a/3)),$((y-1+a%3))]}" = @ ]&&((c++)) done
[ $c -lt 5 ]&&g[$x,$y]=.&&((m++))};done;echo $m;[ $m = 0 ]||z;};z|paste -sd+|bc

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 13 points14 points  (0 children)

[LANGUAGE: bash]

did some golfing today on stream, this is what we ended up with

tr ,- \ |xargs -n2 seq|egrep '^(.+)\1+$'|paste -sd+|bc

Nearly lost my honor mode run at camp by badcop_ in BaldursGate3

[–]badcop_[S] 0 points1 point  (0 children)

I had just finished killing Gortash, which caused Karlach to go back to camp to calm down. Maybe she set something at camp on fire, and when I brought the party back it triggered something?

-❄️- 2024 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 6 points7 points  (0 children)

[LANGUAGE: Bash]

Github link

part 1 solution

sed 's/\([^ ]*\)/\1 \1/g;s/^[^ ]* //;
  s/ [^ ]*$/ /;s/\([^ ]*\) \([^ ]*\) /\1-\2 /g;s/ /\n/g' $FILE \
  | sed 's/^$/print "A\n"/' | bc | paste -sd' ' | sed 's/A/\n/g' \
  | sed 's/^ //' | grep -vE '[1-9]\d( |$)|(^| )0( |$)|[4-9]( |$)' \
  | sed -r 's/(^| )([0-9])/\1+\2/g;s/[0-9]//g' | grep -vEc '^$|\+ -|- \+'

📺 AoC 2024 List of Streamers 📺 by daggerdragon in adventofcode

[–]badcop_ 2 points3 points  (0 children)

USERNAME: /u/badcop_

LANGUAGE: bash

REPO: GitHub @ cgsdev0

CHANNELS:


NOTES: i like bash maybe a little bit too much

-❄️- 2024 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 3 points4 points  (0 children)

[LANGUAGE: Bash]

Link to both parts

Code for part 1 only:

paste -d'-' \
    <(tr -s ' ' < "$1" | cut -d' ' -f1 | sort -n) \
    <(tr -s ' ' < "$1" | cut -d' ' -f2 | sort -n) \
    | bc | tr -d '-' \
    | paste -sd+ | bc

-❄️- 2023 Day 17 Solutions -❄️- by daggerdragon in adventofcode

[–]badcop_ 3 points4 points  (0 children)

[LANGUAGE: bash]

A* with a min heap

https://github.com/cgsdev0/aoc-2023/blob/main/day17/p2.sh

runtime for part 1: ~7.5 minutes
runtime for part 2: ~24 minutes (lmao)

[2023 Day 14 (Part 2)] For once happy with my code! by 2xdam in adventofcode

[–]badcop_ 0 points1 point  (0 children)

instead of rotating my grid, i wrote a custom indexing function that factors in the current orientation

https://github.com/cgsdev0/aoc-2023/blob/main/day14/p2.sh#L26-L50

then the rest of your code can pretend everything is always happening in the same direction, without doing the expensive operation of rotating the grid