I am trying to generate the least common multiple for all numbers from 1 to n as described in OEIS-A003418. In the DrRacket REPL I'm using the following code:
(lcm (apply values (build-list 256 add1)))
Which gives me a "result arity mismatch" error (expected 1, received 256). When I omit lcm
I get a sequence from 1 to 256 output to the console. I'm uncertain as to the cause of the arity mismatch, since lcm
is supposed to be able to take arbitrarily many arguments (according to the docs), and apply
seems to be doing what I would expect when it is the outermost function and not an input to lcm
. What am I missing? Also, if there is an easier way to write the LCM from 1 to n please feel free to share.