[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Smallest FizzBuzz program

Alexey Kalmykov

3/2/2007 7:51:00 PM


>>> On Mar 2, 2:21 pm, "Kyle Schmitt" <kyleaschm...@gmail.com> wrote:
>>> Ummm..... funny.... I see 9 and 12 in the output when I ran this :)
>>
>> it is my fault, last second optimization is always wrong
>> (my lunch is too short and I can't use ruby in the office :( ),
>> best I can get if 58 chars:
>>
>> 1.upto(?d){|i,x|i%3<1&&x=:Fizz;puts i%5<1?"#{x}Buzz":x||i}
>>
>> hope it works OK :)
>>

>Nice work. I removed ,x from |i,x| on a whim and it still works - 57
>bytes! (you have to count file size which as an EOF char)

I think you don't have to. Otherwise you have to count hard disk drive
sector size (a file cannot have it's size < sector size, which is
usually 512 byte) :)

5 Answers

Brian Adkins

3/2/2007 8:00:00 PM

0

Alexey Kalmykov wrote:
>>>> On Mar 2, 2:21 pm, "Kyle Schmitt" <kyleaschm...@gmail.com> wrote:
>>>> Ummm..... funny.... I see 9 and 12 in the output when I ran this :)
>>> it is my fault, last second optimization is always wrong
>>> (my lunch is too short and I can't use ruby in the office :( ),
>>> best I can get if 58 chars:
>>>
>>> 1.upto(?d){|i,x|i%3<1&&x=:Fizz;puts i%5<1?"#{x}Buzz":x||i}
>>>
>>> hope it works OK :)
>>>
>
>> Nice work. I removed ,x from |i,x| on a whim and it still works - 57
>> bytes! (you have to count file size which as an EOF char)
>
> I think you don't have to. Otherwise you have to count hard disk drive
> sector size (a file cannot have it's size < sector size, which is
> usually 512 byte) :)
>

Well, I didn't make the rules. When you upload a file to the following
site (if it wasn't down):

http://golf.shinh.org/p.r...

The site saves the uploaded file and computes the file size. Regarding
your sector size, that's a separate issue. Save the code to a file and do:

ls -l fizzbuzz.rb

Surely we can knock one measly byte off of this sucker :)

Brian

Mat Schaffer

3/2/2007 8:37:00 PM

0


On Mar 2, 2007, at 3:00 PM, Brian Adkins wrote:
> Well, I didn't make the rules. When you upload a file to the
> following site (if it wasn't down):
>
> http://golf.shinh.org/p.r...
>
> The site saves the uploaded file and computes the file size.
> Regarding your sector size, that's a separate issue. Save the code
> to a file and do:
>
> ls -l fizzbuzz.rb
>
> Surely we can knock one measly byte off of this sucker :)


Omit the new line:

-rw-r--r-- 1 schapht schapht 56 Mar 2 15:35 fizzbuzz.rb

-Mat

Brian Adkins

3/2/2007 9:46:00 PM

0

Mat Schaffer wrote:
>
> On Mar 2, 2007, at 3:00 PM, Brian Adkins wrote:
>> Well, I didn't make the rules. When you upload a file to the following
>> site (if it wasn't down):
>>
>> http://golf.shinh.org/p.r...
>>
>> The site saves the uploaded file and computes the file size. Regarding
>> your sector size, that's a separate issue. Save the code to a file and
>> do:
>>
>> ls -l fizzbuzz.rb
>>
>> Surely we can knock one measly byte off of this sucker :)
>
>
> Omit the new line:
>
> -rw-r--r-- 1 schapht schapht 56 Mar 2 15:35 fizzbuzz.rb

Interesting. For me, vim shows 56 bytes of actual code, but ls shows 57
bytes, so I assumed that included an EOF character. There is no newline
in my file.

>
> -Mat
>

Mat Schaffer

3/3/2007 3:05:00 AM

0


On Mar 2, 2007, at 4:50 PM, Brian Adkins wrote:
> Interesting. For me, vim shows 56 bytes of actual code, but ls
> shows 57
> bytes, so I assumed that included an EOF character. There is no
> newline
> in my file.

You sure? If you do File.read(filename) in irb is there a \n at the
end?
-Mat

Brian Adkins

3/3/2007 3:35:00 AM

0

Mat Schaffer wrote:
>
> On Mar 2, 2007, at 4:50 PM, Brian Adkins wrote:
>> Interesting. For me, vim shows 56 bytes of actual code, but ls shows 57
>> bytes, so I assumed that included an EOF character. There is no newline
>> in my file.
>
> You sure? If you do File.read(filename) in irb is there a \n at the end?
> -Mat
>

My bad - dude, you're a genius. Little did I know that Vim was sneaking
in an extra newline on me :(

So it's official, we're tied for 1st now - checkout comp.lang.ruby on:

http://golf.shinh.org/p.r...

I don't think I'll ever do a golf challenge again - what a time sync!