http://www.perlmonks.org?node_id=734447


in reply to Christmas Tree

some perl golfing for xmas-trees! 8 )
DB<2> printf"%20d%d\n",(4**$_)x2for 1..17 44 1616 6464 256256 10241024 40964096 1638416384 6553665536 262144262144 10485761048576 41943044194304 1677721616777216 6710886467108864 268435456268435456 10737418241073741824 -1-1 -1-1 DB<3> printf'%20d%1$d'.$/,4**$_ for 1..17 44 1616 6464 256256 10241024 40964096 1638416384 6553665536 262144262144 10485761048576 41943044194304 1677721616777216 6710886467108864 268435456268435456 10737418241073741824 -1-1 -1-1 DB<4> ($x=4**$_)=~y/1-9/"/,printf"%22s%s\n",($x)x2for 1..20,0,0 "" """" """" """""" "0"""0"" "0"""0"" """""""""" """""""""" """""""""""" "0""""""0""""" """""0""""""0" """""""""""""""" """0"""""""0"""" """""""""""""""""" "0"""""""""0"""""""" """""""""""""""""""" """""""""""""""""""""" """""""""""""""""""""" """""""0"""""""""""0"""" "0""""""""""""0""""""""""" "" ""

UPDATE: Maybe someone knows how to further shorten the last, decorated example!

Replies are listed 'Best First'.
Re^2: Christmas Tree
by mtve (Deacon) on Jan 11, 2009 at 11:56 UTC
    printf"%22s%s\n",$_%=21,$_=4**$_,y/0/"/cfor 1..22

    Happy New Year! :)

      Thanx, and a happy new year for you too! 8 )

      I have to admit I was confused by your example, it's important to understand that printf takes his parameters by reference and not by value!

      So it's possible to still influence $_ in the last parameter with effect for the first!

      Very insightful, thanx a lot!

      Cheers Rolf

        Well, it's a bit complicated, but yes, all perl functions take parameters by reference.
Re^2: Christmas Tree
by LanX (Saint) on Dec 23, 2013 at 22:11 UTC
    ♪..♫ Last Christmas I gave you my code ... But the very next day you golfed it away...♩..♬

    DB<99> ($x=4**$_)=~y/1-9/"/,printf"%22s%s\n",($x)x2for 1..20,0,0 "" """" """" """""" "0"""0"" "0"""0"" """""""""" """""""""" """""""""""" "0""""""0""""" """""0""""""0" """""""""""""""" """0"""""""0"""" """""""""""""""""" "0"""""""""0"""""""" """""""""""""""""""" """""""""""""""""""""" """""""""""""""""""""" """""""0"""""""""""0"""" "0""""""""""""0""""""""""" "" ""

    Merry Xmas, Monks and Morlocks! =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^2: Christmas Tree
by LanX (Saint) on Dec 17, 2012 at 22:59 UTC
    Merry Christmas honorable monks! (push! =)

    DB<103> printf"%20d%d\n",(4**$_)x2for 1..17 44 1616 6464 256256 10241024 40964096 1638416384 6553665536 262144262144 10485761048576 41943044194304 1677721616777216 6710886467108864 268435456268435456 10737418241073741824 -1-1 -1-1

    Cheers Rolf

Re^2: Christmas Tree
by LanX (Saint) on Dec 22, 2010 at 13:59 UTC
    Merry Christmas honorable monks! (push! =)

    Cheers Rolf