From: Christian Neukirchen Date: 2007-04-09T21:52:20+09:00 Subject: Re: [QUIZ] Getting to 100 (#119) "Ryan Leavengood" writes: > On 4/8/07, Christian Neukirchen wrote: >> >> (00000000..'22222222'.to_i(3)).map { |x| x.to_s(3).rjust(8, "0"). >> tr('012', '-+ ') }. >> find_all { |x| x.count("-") == 2 and x.count("+") == 1 }. >> map { |x| >> t = "1" + x.split(//).zip((2..9).to_a).join.delete(" ") >> [eval(t), t] >> }.sort.each { |s, x| >> puts "*****************" if s == 100 >> puts "#{x}: #{s}" >> puts "*****************" if s == 100 >> } > > That's brilliant. It took me a minute to figure out how it worked, but I like. > > I started working on a generalized solution using this algorithm, but > it gets tricky. It isn't too hard to generalize the number sequence, > but generalizing the operators really makes it messy. The number sequence is easy, and the operators are easy too (just change the base), as you have shown. The real problem is to allow the numbers in any order. > Ryan P.S: The code was not written deliberately in a cryptic style (but admittedly unfactored). This is how I code one-shot things. -- Christian Neukirchen http://chneukirchen.org