[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] fun with numbers





On Tue, 6 Jun 2000, Perl lover wrote:
> write a program as short as possible(i made one, less than 70
> characters) to print numbers derived from (x+y) ** n (n is 1 to 14)
> in the following format:

 [Pascal's triangle snipped]

Shorter entries have already been posted, but just for fun I'd like to add
one that doesn't use an array:

  perl -e 'for($_="\n";s/\d+(?= (\d+))/$&+$1/eg<14;print){s/^/1 /}'

This was derived from my one-line ASCII Sierpinski triangle generator by
applying the fact that a "discrete Sirpinski triangle" is nothing more
than a Pascal's triangle modulo 2: 

  perl -e 'for($_="db\n";print;s/..(?=d)/$&^"DB"/eg){s/^/ /}' | less

(How's that for obfuscated Perl? I really like that bitwise xor..)

-- 
Ilmari Karonen
http://www.sci.fi/~iltzu/


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe