I read the puzzle as "keep the numbers that are multiples of both 3 AND 5", as opposed to "keep any multiple of 3 OR 5", but I should've paid closer attentio to your code.
In my version, change *. (LCM) to +. (GCD). Note that the results of 0= |/ are boolean (any result of = is boolean). And that for booleans, LCM and GCD are just "and" and "or" respectively. 99% of the time you see these symbols in J code, they just mean plain old and an or. A good mnemonic to remember which is which is that *. looks like * which is multiply, which has the same result on booleans, and +. looks like + , plus whose definiton on bools is also related (for booleans, +. = 2 | +). > Right now I don't feel like I'm being tripped up by the > composition but rather my lack > of experience using the many > operators/functions. Everyone learns differently, and I don't kno what comes naturally to a Clojuerer - do what works for you. I guess what I'm suggesting is if you *do* get bogged down composing functions, just skip it, strip out ecverything but nouns and verbs, and focus on learning the verbs (as you say). -Dan Please excuse typos; composed on a handheld device. -----Original Message----- From: "Lau B. Jensen" <[email protected]> Date: Sat, 05 Dec 2009 23:47:11 To: Programming forum<[email protected]> Subject: Re: [Jprogramming] Code review / Euler > Mr. Bron wrote: > 3 5 (0 *./@:= |/) i. 20 > 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 > > 3 5 (] #~ 0 *./@:= |/) i. 20 > 0 15 > > Thank you very much for that step-by-step approach Mr. Bron, it really made it quite easy to follow. Just for the sake of correctness your program however produces an incorrect result, I think because of your application of LCM, so the correct result would come from +/~., 3 5 (] #~ 0 ~.@:= |/) i. 20 78 Where yours returned 15, or +/~., 3 5 (] #~ 0 ~.@:= |/) i. 1000 233168 I think I would be able to write something like that up myself now, because its analogous to how I visualize it mentally, I'm a bit surprised that the compiler knows where to apply the zero... > You might be interested in the Fibonacci sequence essay on our Wiki [2]. > > I think it was the frontpage of the essays which said "More text than code", but I find the relationship between the amounts very uneven. Reading through the examples in Fibonacci sequences, I came out more lost than I was going in. > To break this down, right-to-left (as J verbs are read): > > "0 NB. For every number individually, > @:": NB. get its decimal string representation > -:|. NB. and tell whether it matches (-:) its own reverse (|.) > Aha. I almost makes a lot of sense. :) > However, for the beginning, I suggest you eschew tacit programming and > function composition (@: &: etc). Is it not just a matter of learning the order of evaluation, composition of trains, etc and adding that to your knowledge of functions? Right now I don't feel like I'm being tripped up by the composition but rather my lack of experience using the many operators/functions. Personally I would hate to have to take a step 'back' and learn it in those two phases - do you feel strongly about it? Many thanks (once again), Lau ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
