From: Sebastian Hungerecker Date: 2008-09-21T19:15:33+09:00 Subject: Re: One-Liners Mashup (#177 again) James Coglan wrote: > > def per(n, b = 10) > >  i=1;x=b;h={};loop {x=x%n*b;break 0 if x==0;h[x]?(break i-h[x]):h[x]=i; > > i+=1} > > end > > Would be interested to see if you could produce a version with no > assignments or semicolons. def per(n, b=10) (1..1.0/0).inject([b,{}]) { |(x,h),i| if x==0 then break 0 elsif h[x%n*b] then break i-h[x%n*b] else [x%n*b, h.merge(x%n*b=>i)] end} end But frankly, I like my first solution better. And this one clearly does not fit in one line. -- NP: Disbelief - Spill The Blood (Bonus Track) Jabber: sepp2k@jabber.org ICQ: 205544826