Skip to main content
6 of 6
added 526 characters in body
Wheat Wizard
  • 98.8k
  • 21
  • 278
  • 652

1.

The portion 2+(_[0]+_[1]>=10) could be rewritten as 2+(_[0]+_[1]>9) to save two bytes. In a similar vein 2-(_[0]==10) can be rewritten as 2-(_[0]>9), since 10 is the only possible value greater than 9.

a=map(ord,raw_input());a=[10if y==88else 0if y==45else 58-a[x-1]if y==47else y-48for x,y in enumerate(a)]
t=0;exec('t+=sum(a[:2+(a[0]+a[1]>9)]);a=a[2-(a[0]>9):];'*10);print t

Try it online!

(I also renamed _ to a, because even though it's code-golf we don't have to make it unreadable)

2.

You can also use a dictionary instead of conditionals to saves some bytes.

a=raw_input();a=[{y:ord(y)-48,'X':10,'-':0,'/':58-ord(a[x-1])}[y]for x,y in enumerate(a)]
t=0;exec('t+=sum(a[:2+(a[0]+a[1]>9)]);a=a[2-(a[0]>9):];'*10);print t

Try it online!

3.

Don't enumerate. enumerate tends to be too long for it's own good. Here you want to get the last character, which can better be acheived with a zip.

a=raw_input();a=[{y:ord(y)-48,'X':10,'-':0,'/':58-ord(x)}[y]for x,y in zip('-'+a,a)]
t=0;exec('t+=sum(a[:2+(a[0]+a[1]>9)]);a=a[2-(a[0]>9):];'*10);print t

Try it online!


If you combine this with @user202729's two tips you get 149 bytes.

a=raw_input();a=[[10,0,58-ord(x),ord(y)-48]['X-/'.find(y)]for x,y in zip('-'+a,a)]
t=0;exec't+=sum(a[:2+(a[0]+a[1]>9)]);a=a[2-(a[0]>9):];'*10;print t

Try it online!


Here's another version that is also 149 bytes:

a=raw_input();a=[['-123456789X'.find(y),58-ord(x)][y=='/']for x,y in zip('-'+a,a)]
t=0;exec't+=sum(a[:2+(a[0]+a[1]>9)]);a=a[2-(a[0]>9):];'*10;print t

Try it online!

Wheat Wizard
  • 98.8k
  • 21
  • 278
  • 652