At the risk of asking a question with an obvious solution: if I have a function in J that takes two arguments and returns two arguments and I want to accumulate the answer's second argument and to use the first argument for the next calculation and to stop once the first argument equals 0, how do I do it without using a loop?
For instance, I have a function that calculates simultaneously the modulo as well as the integer division of a number in J:
f=:([<.@%]),(]|[) Following the example in https://en.wikipedia.org/wiki/Factorial_number_system#Definition ;
f/463 1 463 0 f/463 2 231 1 f/231 3 77 0 f/77 4 19 1 f/19 5 3 4 f/3 6 0 3 How can I accumulate the sequence 3:4:1:0:1:0 without an explicit accumulator
How do I keep the first argument from the answer as well as the second from the previous step to calculate the arguments for the next step?
Just to show and make clear what I'm not looking for is a solution like this in Clojure:
(defn ->factorialBase [n] (loop [counter 1 toRet [] num n] (if (zero? num) toRet (recur (inc counter) (conj toRet (mod num counter)) (quot num counter))))) I remember reading about something called windowing where you select a portion of an array, use the portion as arguments to your function and move along. Perhaps there is a solution with that?
Thanks in advance