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 730 characters in body
Source Link
manatwork
  • 20.9k
  • 5
  • 53
  • 82

Keg, (削除) 19 (削除ここまで) 17 characters

?{!1<|=[|0.(_)]}1

Explanation:

? # read input
{ # while
 !1< # stack length greater than 1?
| # end of while condition and beginning of while block
 = # compare the 2 top values in the stack
 [ # if (the condition is the top of stack)
 | # end of then block and beginning of else block
 0. # output 0
 (_) # clear stack (discard top of stack in for loop stack length times)
 ] # end if
} # end while
1 # stack is already empty, push a truthy value
 # implicitly output the stack content if there was no explicit output

Try it online!

Keg, (削除) 19 (削除ここまで) 17 characters

?{!1<|=[|0.(_)]}1

Try it online!

Keg, (削除) 19 (削除ここまで) 17 characters

?{!1<|=[|0.(_)]}1

Explanation:

? # read input
{ # while
 !1< # stack length greater than 1?
| # end of while condition and beginning of while block
 = # compare the 2 top values in the stack
 [ # if (the condition is the top of stack)
 | # end of then block and beginning of else block
 0. # output 0
 (_) # clear stack (discard top of stack in for loop stack length times)
 ] # end if
} # end while
1 # stack is already empty, push a truthy value
 # implicitly output the stack content if there was no explicit output

Try it online!

deleted 228 characters in body
Source Link
manatwork
  • 20.9k
  • 5
  • 53
  • 82

Keg, 19(削除) 19 (削除ここまで) 17 characters

?({!2/|=[|01-1<|=[|0.(_)])}1

I found no way to break a for loop, so I clear the stack to avoid getting a "-1" for each non-matching pair. This has the drawback of occasionally getting error message on STDERR, after displaying the correct result on STDOUT.

Try it online! Try it online!

Keg, 19 characters

?(!2/|=[|01-.(_)])1

I found no way to break a for loop, so I clear the stack to avoid getting a "-1" for each non-matching pair. This has the drawback of occasionally getting error message on STDERR, after displaying the correct result on STDOUT.

Try it online!

Keg, (削除) 19 (削除ここまで) 17 characters

?{!1<|=[|0.(_)]}1

Try it online!

Source Link
manatwork
  • 20.9k
  • 5
  • 53
  • 82

Keg, 19 characters

?(!2/|=[|01-.(_)])1

I found no way to break a for loop, so I clear the stack to avoid getting a "-1" for each non-matching pair. This has the drawback of occasionally getting error message on STDERR, after displaying the correct result on STDOUT.

Try it online!

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