[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Codegolf - Pascals Triangle

Michael Ulm

8/11/2006 8:24:00 AM

My take on the latest problem from http://www.co...

a=[]
34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}


56 bytes.

Best regards,

Michael

--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-219, fax: +43 2236 21081
e-mail: michael.ulm@isis-papyrus.com
Visit our Website: www.isis-papyrus.com

---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------


13 Answers

benjohn

8/11/2006 8:59:00 AM

0

> My take on the latest problem from http://www.co...
>
> a=[]
> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}

:) That's very impressive - I like the way you've implemented the filter
like box kernel (summing adjacent array entries) - I wouldn't have
imagined the k=i would bind tighter than the k+k.



Kev Jackson

8/11/2006 9:27:00 AM

0


On 11 Aug 2006, at 15:58, benjohn@fysh.org wrote:

>> My take on the latest problem from http://www.co...
>>
>> a=[]
>> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
>
> :) That's very impressive - I like the way you've implemented the
> filter
> like box kernel (summing adjacent array entries) - I wouldn't have
> imagined the k=i would bind tighter than the k+k.

how about

a=[]
34.times{k=0;p (a.map!{|i|k+k=i}<<1).join(" ")}

I *never* use puts, and in this case using p saves you 3 characters -
yay for micro-tuning :)

Kev

--
"That government is best which governs not at all" - Henry Thoreau


Harold Hausman

8/11/2006 9:37:00 AM

0

On 8/11/06, Kev Jackson <foamdino@gmail.com> wrote:
>
> On 11 Aug 2006, at 15:58, benjohn@fysh.org wrote:
>
> >> My take on the latest problem from http://www.co...
> >>
> >> a=[]
> >> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
> >
> > :) That's very impressive - I like the way you've implemented the
> > filter
> > like box kernel (summing adjacent array entries) - I wouldn't have
> > imagined the k=i would bind tighter than the k+k.
>
> how about
>
> a=[]
> 34.times{k=0;p (a.map!{|i|k+k=i}<<1).join(" ")}
>
> I *never* use puts, and in this case using p saves you 3 characters -
> yay for micro-tuning :)
>
> Kev
>

Unfortunately, the p method puts things in "" on stdout, which would
cause your code to fail the acceptance test. :(

-Harold

Michael Ulm

8/11/2006 9:38:00 AM

0

Kev Jackson wrote:

>
> On 11 Aug 2006, at 15:58, benjohn@fysh.org wrote:
>
>>> My take on the latest problem from http://www.co...
>>>
>>> a=[]
>>> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
>>
>>
>> :) That's very impressive - I like the way you've implemented the filter
>> like box kernel (summing adjacent array entries) - I wouldn't have
>> imagined the k=i would bind tighter than the k+k.
>
>
> how about
>
> a=[]
> 34.times{k=0;p (a.map!{|i|k+k=i}<<1).join(" ")}
>
> I *never* use puts, and in this case using p saves you 3 characters -
> yay for micro-tuning :)
>

This does not produce the same output on my system;
your version gives lines like

"1 2 1"

instead of

1 2 1

Since the output format is fixed in codegolf.com, unfortunately
this is not a solution.

Best regards,

Michael

--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-219, fax: +43 2236 21081
e-mail: michael.ulm@isis-papyrus.com
Visit our Website: www.isis-papyrus.com

---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------

Sander Land

8/11/2006 9:50:00 AM

0

You can make it even shorter by using *' ' over .join(' '), Array#*
is an alias for Array#join :)

Christian Neukirchen

8/11/2006 11:21:00 AM

0

Michael Ulm <michael.ulm@isis-papyrus.com> writes:

> a=[]
> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}

a=[]
34.times{k=0;puts (a.map!{|i|k+k=i}<<1)*" "}

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Carlos

8/11/2006 11:57:00 AM

0

Christian Neukirchen wrote:
> Michael Ulm <michael.ulm@isis-papyrus.com> writes:
>
>
>>a=[]
>>34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
>
>
> a=[]
> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1)*" "}

Let's reuse a not needed array and save 4 bytes :) (doesn't work if you
set RUBY_OPT to always require some module...)

34.times{k=0;puts ($".map!{|i|k+k=i}<<1)*" "}

--


benjohn

8/11/2006 1:52:00 PM

0

> Michael Ulm <michael.ulm@isis-papyrus.com> writes:
>
>> a=[]
>> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
>
> a=[]
> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1)*" "}

a=[]
9.times{k=0;puts (a.map!{|i|k+k=i}<<1)*" "}

:)


Daniel Martin

8/11/2006 2:17:00 PM

0

Michael Ulm <michael.ulm@isis-papyrus.com> writes:

> My take on the latest problem from http://www.co...
>
> a=[]
> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
>
>
> 56 bytes.

I think this may be very close to minimal - no approaches I tried got
this small. Note that you can slightly improve readability (but with
no change in character count) with:

a=[]
34.times{k=0;a.map!{|i|k+k=i}<<1;puts a.join(" ")}

Then there's removing the parentheses around the argument to join, but
that generates a warning that probably means you fail their test.

Stefan Lang

8/11/2006 3:51:00 PM

0


On Friday, August 11, 2006, at 11:16 PM, Daniel Martin wrote:
>Michael Ulm <michael.ulm@isis-papyrus.com> writes:
>
>> My take on the latest problem from http://www.co...
>>
>> a=[]
>> 34.times{k=0;puts (a.map!{|i|k+k=i}<<1).join(" ")}
>>
>>
>> 56 bytes.
>
>I think this may be very close to minimal - no approaches I tried got
>this small. Note that you can slightly improve readability (but with
>no change in character count) with:
>
>a=[]
>34.times{k=0;a.map!{|i|k+k=i}<<1;puts a.join(" ")}
>
>Then there's removing the parentheses around the argument to join, but
>that generates a warning that probably means you fail their test.
>



How about:

a=[]
34.times{k=0;puts (a.map!{|i|k+k=i}<<1)*' '}

--
Posted with http://De.... Sign up and save your mailbox.