From: Wouter Smeenk Date: 2008-07-12T17:39:49+09:00 Subject: Re: Symbolify (#169) 2008/7/12 Frederick Cheung : > > On 12 Jul 2008, at 08:40, ThoML wrote: > >>> Or even >>> symbolify(9999).length == 37 >>> symbolify(999999).length == 48 >>> symbolify(12345678901234567890).length == 275 >>> symbolify >>> (1234567899999999999999999999999999999999999901234567890).length ==640 >>> symbolify(("9"*2100).to_i).length == 26762 >> >> Well, well. >> >> I tried the following: >> >> p (0..10000).to_a.inject(0) {|a, i| >> s = symbolify(i) >> x = eval(s) >> raise "Decode failed! #{i} != #{x} : #{s}" unless i == x >> a + s.size >> } >> >> For my current solution, this prints: 556136 >> > > 419100 for me. I'm pretty sure I've got the odd extra set of parentheses I > don't really need so it should be possible to shave it down a little. > > Fred > > My results for the short encoding: symbolify(9999).length == 43 symbolify(999999).length == 52 symbolify(12345678901234567890).length == 224 symbolify(1234567899999999999999999999999999999999999901234567890).length == 636 symbolify(('9'*2100).to_i).length == 25724 (0..10000).to_a.inject(0) {|a, i| a + symbolify(i).length} == 400312 Only after the second test it begins to catchup. This also has allot of extra parentheses so expect better result! :) I wrote some simple testcode that might be useful: [ "symbolify(9999).length", "symbolify(999999).length", "symbolify(12345678901234567890).length", "symbolify(1234567899999999999999999999999999999999999901234567890).length", "symbolify(('9'*2100).to_i).length", "(0..10000).to_a.inject(0) {|a, i| a + symbolify(i).length}" ].each do |test| print test + " == " $stdout.flush puts (eval test).to_s end Wouter