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 explanation
Source Link
Wheat Wizard
  • 102.8k
  • 23
  • 299
  • 697

Brain-Flak, 30 bytes

(()){{}({}{{}}<><{}>)<>([])}<>

Try it online!

Explanation

(()) #{ Start Loop. Used instead of ([]) so that the loop will run at least once on empty input. }
{{} #{Remove the stack height. }
 (
 {}{{}} #{ Add the TOS with any 1s below it (until a zero). }
 <><{}> #{ Remove a value on the other stack if there. }
 ) #{ Push the result (# of 1s just removed) to the other stack. } 
 <> #{ Switch stacks back. }
 ([]) #{ Push stack height for the loop. }
} #{ Once the loop is done (stack is empty)... }
<> #{ Switch stacks to the most recent # of 1s removed. }

Brain-Flak, 30 bytes

(()){{}({}{{}}<><{}>)<>([])}<>

Try it online!

Brain-Flak, 30 bytes

(()){{}({}{{}}<><{}>)<>([])}<>

Try it online!

Explanation

(()) #{ Start Loop. Used instead of ([]) so that the loop will run at least once on empty input. }
{{} #{Remove the stack height. }
 (
 {}{{}} #{ Add the TOS with any 1s below it (until a zero). }
 <><{}> #{ Remove a value on the other stack if there. }
 ) #{ Push the result (# of 1s just removed) to the other stack. } 
 <> #{ Switch stacks back. }
 ([]) #{ Push stack height for the loop. }
} #{ Once the loop is done (stack is empty)... }
<> #{ Switch stacks to the most recent # of 1s removed. }
Source Link
Wheat Wizard
  • 102.8k
  • 23
  • 299
  • 697

Brain-Flak, 30 bytes

(()){{}({}{{}}<><{}>)<>([])}<>

Try it online!

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