an easier version if you are checking whether y is odd instead of n
(-&1`(-&2)@.(2&|))^:(<5) ] 100
100 99 97 95 93
this doesn't match your output, but does handle a calculation based on n
pD =: 1!:2&2
(<:@:{. (, pD) ((1 -~ {:)`(2 -~ {:))@.(2 | {:))^:(0 < {.)^:_ ] 20 100
----- Original Message -----
From: Brian Schott <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Monday, July 13, 2015 12:39 PM
Subject: [Jprogramming] Powerize a while.
I have the following verb t and wonder if anyone would like to show how it
could be more elegantly defined (using the Power conjunction?) I would
enjoy learning your result.
The intent of t is to alternatively subtract 1 or 2 from a positive number
showing the intermediate results of say n=20 subtractions.
e =. -&2
o =. -&1
t =. monad define
n =. 20
while. n =. n - 1 do.
if. 2|n do. smoutput y =. e y
else. smoutput y =. o y
end.
end.
)
t 100
98
97
95
94
92
91
89
88
86
85
83
82
80
79
77
76
74
73
71
--
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm