Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [QUIZ] Symbolify (#169)

Reply
Thread Tools

[QUIZ] Symbolify (#169)

 
 
ara.t.howard
Guest
Posts: n/a
 
      07-11-2008

On Jul 11, 2008, at 1:25 PM, Alex LeDonne wrote:

> After clearing a "duh" moment, I've improved these encoded lengths...
> symbolify(999).length == 127
> symbolify(9999).length == 127
> symbolify(999999).length == 337
> symbolify(12345678901234567890).length == 1112
> symbolify(("9"*2100).to_i).length == 350265




mine are all zero length


a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




 
Reply With Quote
 
 
 
 
ara.t.howard
Guest
Posts: n/a
 
      07-11-2008

On Jul 11, 2008, at 12:57 PM, Matthew Moss wrote:

> Anyway, here's another test:
>
> nums = (0...1000).sort_by { rand }
> strs = nums.map { |n| symbolify(n) }
>
> strs.zip(nums).sort_by { rand }.each do |str, num|
> res = eval(str)
> raise "Not a string!" unless str.is_a? String
> raise "Invalid chars!" unless str.delete("?*()-").empty?
> raise "Decode failed!" unless res == num
> end
>
> puts "Passed!"


52 chars for this attm

a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




 
Reply With Quote
 
 
 
 
Alex LeDonne
Guest
Posts: n/a
 
      07-11-2008
On Fri, Jul 11, 2008 at 3:27 PM, Wouter Smeenk <(E-Mail Removed)> wrote:
> 2008/7/11 James Gray <(E-Mail Removed)>:
>> On Jul 11, 2008, at 12:16 PM, ara.t.howard wrote:
>>
>>>
>>> On Jul 11, 2008, at 11:07 AM, Dana Merrick wrote:
>>>
>>>> Haha, I just did it and my solution just happened to be 42 characters.
>>>
>>>
>>> damn - i've usurped!

>>
>> Mine was 28 characters, with normal whitespace usage.
>>
>> James Edward Gray II
>>
>>

>
> I managed to squeeze my solution in 19 characters and 23 with normal
> whitespace usage.
>
> Wouter Smeenk
>


I found a 19-character, 23-with-whitespace solution as well, thanks to
your inspiring post, Wouter.

My golfed solution which also handles negative numbers is 39
characters, 51 with whitespace.

These both pass both of the provided tests - they really build
strings, as James indicated his does. No cheating here...

-A

 
Reply With Quote
 
Matthew Moss
Guest
Posts: n/a
 
      07-12-2008
On Jul 11, 3:21=A0pm, "ara.t.howard" <(E-Mail Removed)> wrote:
> On Jul 11, 2008, at 1:25 PM, Alex LeDonne wrote:
>
> > After clearing a "duh" moment, I've improved these encoded lengths...
> > symbolify(999).length =3D=3D 127
> > symbolify(9999).length =3D=3D 127
> > symbolify(999999).length =3D=3D 337
> > symbolify(12345678901234567890).length =3D=3D 1112
> > symbolify(("9"*2100).to_i).length =3D=3D 350265

>
> mine are all zero length


Yeah, my ugly solution has zero length strings as well.

 
Reply With Quote
 
Glen F. Pankow
Guest
Posts: n/a
 
      07-12-2008
James Gray wrote:
> On Jul 11, 2008, at 12:23 PM, James Gray wrote:
>
>> On Jul 11, 2008, at 12:16 PM, ara.t.howard wrote:
>>
>>>
>>> On Jul 11, 2008, at 11:07 AM, Dana Merrick wrote:
>>>
>>>> Haha, I just did it and my solution just happened to be 42 characters.
>>>
>>>
>>> damn - i've usurped!

>>
>> Mine was 28 characters, with normal whitespace usage.

>
> Of course, using my solution, the following code causes Ruby to Segfault:
>
> eval(symbolify(1200))
>
> James Edward Gray II
>


One line; 38 chars (uses no whitespace); no cheating; 1200 OK;
output doesn't use the '*' character.

Glen Pankow


 
Reply With Quote
 
Bill Kelly
Guest
Posts: n/a
 
      07-12-2008

From: "Alex LeDonne" <(E-Mail Removed)>
> On Fri, Jul 11, 2008 at 3:27 PM, Wouter Smeenk <(E-Mail Removed)> wrote:
>> 2008/7/11 James Gray <(E-Mail Removed)>:
>>> On Jul 11, 2008, at 12:16 PM, ara.t.howard wrote:
>>>> On Jul 11, 2008, at 11:07 AM, Dana Merrick wrote:
>>>>
>>>>> Haha, I just did it and my solution just happened to be 42 characters.
>>>>
>>>> damn - i've usurped!
>>>
>>> Mine was 28 characters, with normal whitespace usage.
>>>
>>> James Edward Gray II

>>
>> I managed to squeeze my solution in 19 characters and 23 with normal
>> whitespace usage.
>>
>> Wouter Smeenk

>
> I found a 19-character, 23-with-whitespace solution as well, thanks to
> your inspiring post, Wouter.
>
> My golfed solution which also handles negative numbers is 39
> characters, 51 with whitespace.
>
> These both pass both of the provided tests - they really build
> strings, as James indicated his does. No cheating here...


Wow... Nice...

My ultra cheezy cheat version is 18 characters... I'm amazed
people are coming up with such short non-cheat versions


Regards,

Bill



 
Reply With Quote
 
Alex LeDonne
Guest
Posts: n/a
 
      07-12-2008
On Fri, Jul 11, 2008 at 9:57 PM, Bill Kelly <(E-Mail Removed)> wrote:
>
> From: "Alex LeDonne" <(E-Mail Removed)>
>>
>> On Fri, Jul 11, 2008 at 3:27 PM, Wouter Smeenk <(E-Mail Removed)>
>> wrote:
>>>
>>> I managed to squeeze my solution in 19 characters and 23 with normal
>>> whitespace usage.
>>>
>>> Wouter Smeenk

>>
>> I found a 19-character, 23-with-whitespace solution as well, thanks to
>> your inspiring post, Wouter.
>>
>> My golfed solution which also handles negative numbers is 39
>> characters, 51 with whitespace.
>>
>> These both pass both of the provided tests - they really build
>> strings, as James indicated his does. No cheating here...

>
> Wow... Nice...
>
> My ultra cheezy cheat version is 18 characters... I'm amazed
> people are coming up with such short non-cheat versions
>
>
> Regards,
>
> Bill
>


I, on the other hand, am looking forward to the various "cheating"
solutions. I re-learned some operator precedence rules solving this
the old fashioned way, but I expect I'll learn more from solutions
that produce, for example, zero-length strings, but still pass the
tests.

But then I've come to expect such wizardry from some of the submitters
to this quiz...

-A

 
Reply With Quote
 
Frederick Cheung
Guest
Posts: n/a
 
      07-12-2008

On 11 Jul 2008, at 20:25, Alex LeDonne wrote:
>>
>> I also have a longer solution that produces relatively compact
>> representations relatively quickly such that
>>
>> symbolify(999).length == 145
>> symbolify(9999).length == 145
>> symbolify(999999).length == 389
>> symbolify(12345678901234567890).length == 1290
>> symbolify(("9"*2100).to_i).length == 402035
>>

>
> After clearing a "duh" moment, I've improved these encoded lengths...
> symbolify(999).length == 127
> symbolify(9999).length == 127
> symbolify(999999).length == 337
> symbolify(12345678901234567890).length == 1112
> symbolify(("9"*2100).to_i).length == 350265


I've been trying the short representations that are just plain old
strings thing too. I've got it down to

symbolify(9999).length == 48
symbolify(999999).length == 87
symbolify(12345678901234567890).length == 221
symbolify
(1234567899999999999999999999999999999999999901234 567890).length ==796
symbolify(("9"*2100).to_i).length == 33219

not quite the prettiest code you've ever seen though

Fred

 
Reply With Quote
 
Bill Kelly
Guest
Posts: n/a
 
      07-12-2008

From: "Alex LeDonne" <(E-Mail Removed)>
> On Fri, Jul 11, 2008 at 9:57 PM, Bill Kelly <(E-Mail Removed)> wrote:
>>
>> My ultra cheezy cheat version is 18 characters... I'm amazed
>> people are coming up with such short non-cheat versions

>
> I, on the other hand, am looking forward to the various "cheating"
> solutions. I re-learned some operator precedence rules solving this
> the old fashioned way, but I expect I'll learn more from solutions
> that produce, for example, zero-length strings, but still pass the
> tests.
>
> But then I've come to expect such wizardry from some of the submitters
> to this quiz...


Although I'd mulled over a slightly more clever cheat, I went
with a totally unclever, groan-inducing approach. It's a
Kobayashi Maru solution... <grin>

(c.f. http://echosphere.net/star_trek_insp/insp_kobayashi.jpg )


On the other hand, my non-cheat solution is currently 70
characters, with whitespace squeezed out... :/

And it has to run with `ulimit -s unlimited` or it will die with
(eval):1: stack level too deep (SystemStackError) before it even
gets to 1000.... lol

Oh well . . .


Regards,

Bill



 
Reply With Quote
 
Frederick Cheung
Guest
Posts: n/a
 
      07-12-2008

>
> I've been trying the short representations that are just plain old
> strings thing too. I've got it down to
>
> symbolify(9999).length == 48
> symbolify(999999).length == 87
> symbolify(12345678901234567890).length == 221
> symbolify
> (1234567899999999999999999999999999999999999901234 567890).length ==796
> symbolify(("9"*2100).to_i).length == 33219
>
> not quite the prettiest code you've ever seen though


Or even
symbolify(9999).length == 37
symbolify(999999).length == 48
symbolify(12345678901234567890).length == 275
symbolify
(1234567899999999999999999999999999999999999901234 567890).length ==640
symbolify(("9"*2100).to_i).length == 26762

Enough from me!
Fred

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SUMMARY] Symbolify (#169) Matthew Moss Ruby 1 07-17-2008 08:31 PM



Advertisments