r/codegolf • u/dantose • Dec 01 '25
Advent of Code, Day 1
Post your best golfs.
Assume input is saved as input.txt.
8
Upvotes
r/codegolf • u/dantose • Dec 01 '25
Post your best golfs.
Assume input is saved as input.txt.
2
u/dantose Dec 01 '25
Powershell. There's definitely improvements to be made here
Part 1: 88
$a=50;$(gc input.txt).Trim('R') -replace "L","-"|%{$a=$a+100+$_;if(!($a%100)){$b++}};$b
Part 2: 189
$a=50;$(gc input.txt).Trim('R') -replace "L","-"|%{if($a -eq 0 -and $a+$_ -lt 0){$a=$a+100};$a=$a+$_;while($a -lt 0){$a=$a+100;$b++};if($a -eq 0){$b++};while($a -gt 99){$a=$a-100;$b++}};$b
3
u/KeyJ Dec 01 '25
Python, Part 1, 83 bytes:
p=50;print(sum(1>(p:=(p+int(l[1:])*(1-2*(l<'R')))%100)for l in open("input.txt")))Python, Part 2, 96 bytes:
p=50;print(sum(1>(p:=(p+1-2*(l<'R'))%100)for l in open("input.txt")for _ in range(int(l[1:]))))2
u/tomflumery Dec 02 '25 edited Dec 02 '25
05ab1e
part 1, 22 bytes
part 2, 30 bytes
2
u/ap29600 Dec 03 '25 edited Dec 04 '25
K, both parts 70 bytes
Edit: -2 (68) by looking at u/Radiatorineitor's solution
-1 (67) by looking at u/KeyJ's
1
u/Radiadorineitor Dec 02 '25
Dyalog APL
Part 1: 48
50+.=100|+\{(⍎1↓⍵)ׯ1*'L'=⊃⍵}¨⊃⎕NGET'input.txt'1Part 2: 56
50+.=100|+\(|p)/×p←{(⍎1↓⍵)ׯ1*'L'=⊃⍵}¨⊃⎕NGET'input.txt'11
u/corruptio Dec 05 '25 edited Dec 05 '25
perl, part 1, 54 chars:
part 2, 69 chars: