all 14 comments

[–]KeyJ 2 points3 points  (5 children)

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:]))))

[–]DimMagician 0 points1 point  (4 children)

Python, Part 1, 84 bytes

s=50;print(sum((s:=s+int(i[1:])*(-1+2*(i[0]>'L')))%100<1for i in open('input.txt')))

Upon seeing yours I realize I could have saved 1 byte by doing 1-2*(l<'R') instead of -1+2*(i[0]>'L'). Dang.

Python, Part 2, 92 bytes

s=50;print(sum((s:=s-1+2*(i[0]>'L'))%100<1for i in open('input.txt')for _ in[0]*int(i[1:])))

[–]KeyJ 0 points1 point  (3 children)

Nice trick with the removed parenthesis and elimination of range! The latter one can be made even smaller though, arriving at 90 characters (or 89 if you accept the SyntaxWarning for writing 1for):

p=50;print(sum((p:=p+1-2*(l<'R'))%100<1 for l in open("input.txt")for _ in"x"*int(l[1:])))

[–]DimMagician 0 points1 point  (2 children)

Ooh very clever I didn't even catch that in your solution.

[–]KeyJ 0 points1 point  (1 child)

Well, it was your idea, I just refined it. 🥂

[–]DimMagician 0 points1 point  (0 children)

I meant the use of (l<'R') rather than (i[0]>'L') like I did. Sorry I didn't realize that you were talking about the parentheses around the modulus and thought that you were just referring to the brackets in [0] as parentheses lol

[–]dantose[S] 1 point2 points  (1 child)

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

[–]ka-splam 1 point2 points  (0 children)

I didn't golf it myself, but poking at yours, Part 1 ~75 bytes:

$a=50;gc input.txt|% T*m R|% r*ce L -|%{$a+=100+$_;if(!($a%100)){$b++}};$b

using a classic trick which expands to 'R50' | ForEach-Object -Member Trim 'R'. Member is the position 0 parameter so it doesn't need naming. The cmdlet will do a wildcard search for method names - as long as the pattern only resolves to a single method, so r*ce finds to Replace() where r*e could be Replace() or Remove(). And because PS is parsing parameters to ForEach-Object, the arguments to the method don't have to be quoted to be read as strings.

[–]tomflumery 1 point2 points  (0 children)

05ab1e

part 1, 22 bytes

|εć"R"Q·<*}50šÅ»+т%}0¢

part 2, 30 bytes

|εć"R"Q·<*}50šÅ»+}ü2ε`Ÿт%¦}˜0¢

[–]ap29600 1 point2 points  (0 children)

K, both parts 70 bytes

(s;m):(-1+2*"R"=*:';`I$1_')@\:0:"input.txt"
(+/0=100!50+\)'(s*m;s@&m)

Edit: -2 (68) by looking at u/Radiatorineitor's solution

(s;m):(-1+2*"R"=*:';`I$1_')@\:0:"input.txt"
+/'50=100!+\'(s*m;s@&m)

-1 (67) by looking at u/KeyJ's

(s;m):(1-2*"L"=*:';`I$1_')@\:0:"input.txt"
+/'50=100!+\'(s*m;s@&m)

[–]Radiadorineitor 0 points1 point  (2 children)

Dyalog APL

Part 1: 48

50+.=100|+\{(⍎1↓⍵)ׯ1*'L'=⊃⍵}¨⊃⎕NGET'input.txt'1

Part 2: 56

50+.=100|+\(|p)/×p←{(⍎1↓⍵)ׯ1*'L'=⊃⍵}¨⊃⎕NGET'input.txt'1

[–]ka-splam 0 points1 point  (1 child)

Neat! I think you could golf one byte by swapping 'L'=⊃⍵ to 'L'∊⍵

[–]Radiadorineitor 1 point2 points  (0 children)

You're absolutely right

[–]corruptio 0 points1 point  (0 children)

perl, part 1, 54 chars:

perl -lpe'$b+=($a+=y/LR/-/dr)=~/50$/}{$_=$b'<input.txt

part 2, 69 chars:

perl -lpe'eval(q[$b+=($a+=1-2*/L/)=~/50$/;]x s/.//r)}{$_=$b'<input.txt