Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 196 characters in body
Source Link
Leo
  • 12.9k
  • 1
  • 33
  • 63

Alice, 12(削除) 12 (削除ここまで) 10 bytes

2 bytes saved thanks to Martin Ender

i.h$#@h%.7%$io

Try it online! Try it online!

Explanation

This is a 1-D code operating in cardinal mode, so it's easy to follow its flow:

i Read a byte from input (pushes -1 on EOF)
 .h Duplicate it and add 1 to the copy
 $#@% If the resultCompute isn%(n+1). 0,This terminate.will exit with an error on n==-1
 and return n for any non-negative n.
 .7% Duplicate the input again and compute its value modulo 7
 This returns 6 for '0' (unicode value 48) and 0 for '1'
 (unicode value 49)
 $i $i If this last result was not 0, input another number.
 This ignores every other '0' in the input
 and moves to the following number (another '0')
 o o Output the last byte read
 At the end, wrap back to the beginning of the line

Alice, 12 bytes

i.h$#@.7%$io

Try it online!

Explanation

This is a 1-D code operating in cardinal mode, so it's easy to follow its flow:

i Read a byte from input (pushes -1 on EOF)
 .h Duplicate it and add 1 to the copy
 $#@ If the result is 0, terminate.
 .7% Duplicate the input again and compute its value modulo 7
 This returns 6 for '0' (unicode value 48) and 0 for '1'
 (unicode value 49)
 $i If this last result was not 0, input another number.
 This ignores every other '0' in the input
 and moves to the following number (another '0')
 o Output the last byte read
 At the end, wrap back to the beginning of the line

Alice, (削除) 12 (削除ここまで) 10 bytes

2 bytes saved thanks to Martin Ender

i.h%.7%$io

Try it online!

Explanation

This is a 1-D code operating in cardinal mode, so it's easy to follow its flow:

i Read a byte from input (pushes -1 on EOF)
 .h Duplicate it and add 1 to the copy
 % Compute n%(n+1). This will exit with an error on n==-1
 and return n for any non-negative n.
 .7% Duplicate the input again and compute its value modulo 7
 This returns 6 for '0' (unicode value 48) and 0 for '1'
 (unicode value 49)
 $i If this last result was not 0, input another number.
 This ignores every other '0' in the input
 and moves to the following number (another '0')
 o Output the last byte read
 At the end, wrap back to the beginning of the line
Added explanation
Source Link
Leo
  • 12.9k
  • 1
  • 33
  • 63

Alice, 12 bytes

i.h$#@.7%$io

Try it online!

Explanation

Explanation coming tomorrowThis is a 1-D code operating in cardinal mode, so it's easy to follow its flow:

i Read a byte from input (pushes -1 on EOF)
 .h Duplicate it and add 1 to the copy
 $#@ If the result is 0, terminate.
 .7% Duplicate the input again and compute its value modulo 7
 This returns 6 for '0' (unicode value 48) and 0 for '1'
 (unicode value 49)
 $i If this last result was not 0, input another number.
 This ignores every other '0' in the input
 and moves to the following number (another '0')
 o Output the last byte read
 At the end, wrap back to the beginning of the line

Alice, 12 bytes

i.h$#@.7%$io

Try it online!

Explanation coming tomorrow

Alice, 12 bytes

i.h$#@.7%$io

Try it online!

Explanation

This is a 1-D code operating in cardinal mode, so it's easy to follow its flow:

i Read a byte from input (pushes -1 on EOF)
 .h Duplicate it and add 1 to the copy
 $#@ If the result is 0, terminate.
 .7% Duplicate the input again and compute its value modulo 7
 This returns 6 for '0' (unicode value 48) and 0 for '1'
 (unicode value 49)
 $i If this last result was not 0, input another number.
 This ignores every other '0' in the input
 and moves to the following number (another '0')
 o Output the last byte read
 At the end, wrap back to the beginning of the line
Source Link
Leo
  • 12.9k
  • 1
  • 33
  • 63

Alice, 12 bytes

i.h$#@.7%$io

Try it online!

Explanation coming tomorrow

AltStyle によって変換されたページ (->オリジナル) /