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

Commonmark migration
Source Link

Minkolang, 32 bytes

0$nI1-[1=?v0g1+1R]N.
 .Ng0<

Try it online!

###Explanation

Explanation

0 pushes 0 (this is the number that will keep track of the number of 1s)
 $n pushes all of input as numbers (pushes -1 if there is no input)
 I1- pushes stack minus 1 (to exclude the 0)
 [ ] for loop with the previous number as the number of iterations
 1=? check equality with 1 (this is for the empty input testcase)
 where -1 will be pushed by the interpreter

If number is not 1 (ie 0 or -1[-1 will be pushed if there is no input]):

 < start going left
 g0 gets the first element in stack
 .N output it as number and stop program

If number is 1:

 v gets jumped over by ? since true has been evaluated
 0g1+ gets the first element and adds 1 to it
 1R rotates stack once clockwise
 N. outputs as number and stops program

Minkolang, 32 bytes

0$nI1-[1=?v0g1+1R]N.
 .Ng0<

Try it online!

###Explanation

0 pushes 0 (this is the number that will keep track of the number of 1s)
 $n pushes all of input as numbers (pushes -1 if there is no input)
 I1- pushes stack minus 1 (to exclude the 0)
 [ ] for loop with the previous number as the number of iterations
 1=? check equality with 1 (this is for the empty input testcase)
 where -1 will be pushed by the interpreter

If number is not 1 (ie 0 or -1[-1 will be pushed if there is no input]):

 < start going left
 g0 gets the first element in stack
 .N output it as number and stop program

If number is 1:

 v gets jumped over by ? since true has been evaluated
 0g1+ gets the first element and adds 1 to it
 1R rotates stack once clockwise
 N. outputs as number and stops program

Minkolang, 32 bytes

0$nI1-[1=?v0g1+1R]N.
 .Ng0<

Try it online!

Explanation

0 pushes 0 (this is the number that will keep track of the number of 1s)
 $n pushes all of input as numbers (pushes -1 if there is no input)
 I1- pushes stack minus 1 (to exclude the 0)
 [ ] for loop with the previous number as the number of iterations
 1=? check equality with 1 (this is for the empty input testcase)
 where -1 will be pushed by the interpreter

If number is not 1 (ie 0 or -1[-1 will be pushed if there is no input]):

 < start going left
 g0 gets the first element in stack
 .N output it as number and stop program

If number is 1:

 v gets jumped over by ? since true has been evaluated
 0g1+ gets the first element and adds 1 to it
 1R rotates stack once clockwise
 N. outputs as number and stops program
Source Link
user41805
  • 13.4k
  • 6
  • 43
  • 88

Minkolang, 32 bytes

0$nI1-[1=?v0g1+1R]N.
 .Ng0<

Try it online!

###Explanation

0 pushes 0 (this is the number that will keep track of the number of 1s)
 $n pushes all of input as numbers (pushes -1 if there is no input)
 I1- pushes stack minus 1 (to exclude the 0)
 [ ] for loop with the previous number as the number of iterations
 1=? check equality with 1 (this is for the empty input testcase)
 where -1 will be pushed by the interpreter

If number is not 1 (ie 0 or -1[-1 will be pushed if there is no input]):

 < start going left
 g0 gets the first element in stack
 .N output it as number and stop program

If number is 1:

 v gets jumped over by ? since true has been evaluated
 0g1+ gets the first element and adds 1 to it
 1R rotates stack once clockwise
 N. outputs as number and stops program

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