Stair-climbing puzzle: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: simplify step)
(→‎{{header|J}}: use and explain 0:)
Line 162: Line 162:
'''Solution (Tacit):'''
'''Solution (Tacit):'''
<lang j>step =: 0.6 > ?@0:
<lang j>step =: 0.6 > ?@0:
attemptClimb =: [: <:`>:@.step #@(''"_)
attemptClimb =: [: <:`>:@.step 0:
isNotUpOne =: -.@(+/@])
isNotUpOne =: -.@(+/@])


step_up=: (] , attemptClimb)^:isNotUpOne^:_ NB. no variables or numbers</lang>
step_up=: (] , attemptClimb)^:isNotUpOne^:_</lang>
Note that J's verbs (functions) must always take an argument i.e. there is no such thing as a niladic verb. Verbs that ignore their arguments (e.g. <code>step</code>) achieve the same effect.
Note that <code>0:</code> is not a number but a verb (function) that returns the number zero irrespective of its argument(s). Therefore the above solution for <code>step_up</code> meets the restrictions of no variables or numbers.

J's verbs (functions) always take an argument i.e. there is no such thing as a niladic verb. Verbs that ignore their arguments (e.g. <code>step</code> and <code>attemptClimb</code>) achieve the same effect.


'''Solution (Explicit):'''
'''Solution (Explicit):'''