Re: Cleaner solution, anyone?

2014-05-02 Thread Divyansh Prakash
I've been trying out my code in both Clojure and ClojureScript REPLs. 1. Ratio not being a type in js might cause inconsistencies if not used carefully. (for eg in a web app that uses both clj and cljscript) 2. Lazy sequences in Clojure are lazy in

Re: Cleaner solution, anyone?

2014-05-02 Thread Divyansh Prakash
Exactly! By the way, I posted the same questionto stackoverflow. A. Webb seems to agree with Steve, showing a version using reduced. Thank you for the response, guys! On Friday, May 2, 2014 1:38:09 AM UTC+5:30, Guru De

Re: Cleaner solution, anyone?

2014-05-01 Thread Stephen Gilardi
> I wrote a blog post discussing Thomson's Paradox, and simulated it in Clojure- > http://pizzaforthought.blogspot.in/2014/05/and-infinity-beyond.html > > The state function defined towards the end is not very functional. > Could someone guide me towards a cleaner approach? Here's an option:

Re: Cleaner solution, anyone?

2014-05-01 Thread James Reeves
Yes, sorry, I didn't mean reduce, I meant reductions. - James On 1 May 2014 21:35, Guru Devanla wrote: > Reduce is not lazy, correct? Will it ever return for drop-while to > execute. The problem here is not knowing how many iterations make up the > sum, isnt? > > > On Thu, May 1, 2014 at 1:13

Re: Cleaner solution, anyone?

2014-05-01 Thread Guru Devanla
Reduce is not lazy, correct? Will it ever return for drop-while to execute. The problem here is not knowing how many iterations make up the sum, isnt? On Thu, May 1, 2014 at 1:13 PM, James Reeves wrote: > I'd suggest generating an intermediate seq with the summed time: > > (defn state [time] >

Re: Cleaner solution, anyone?

2014-05-01 Thread James Reeves
I'd suggest generating an intermediate seq with the summed time: (defn state [time] (->> (thomsons-lamp) (reduce (fn [[_ t] [onoff dur]] [onoff (+ t dur)])) (drop-while (fn [[_ t]] (< t time))) first second)) - James On 1 May 2014 20:06, Divyansh Prakash wrote: > Hey!

Re: Cleaner solution, anyone?

2014-05-01 Thread Guru Devanla
Neat, so in your last solution are you trying to get rid of recur and solve 1 - (1/2)^x = ? On Thu, May 1, 2014 at 12:06 PM, Divyansh Prakash < divyanshprakas...@gmail.com> wrote: > Hey! > I wrote a blog post discussing Thomson's Paradox, and simulated it in > Clojure- > http://pizzaforthou