Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Diamonds for fun

by hbm (Hermit)
on Mar 07, 2011 at 20:38 UTC ( #891907=note: print w/replies, xml ) Need Help??

in reply to Re: Diamonds for fun
in thread Diamonds for fun

Squaring a string of ones ((1x$_)**2) is very clever! This works for me up to 8, but 9 fails (because 111111111**2 = 1.23456789876543e+16). (Same for toolic's solution below...)

You can save one more character with $" instead of " ".

Replies are listed 'Best First'.
Re^3: Diamonds for fun
by ambrus (Abbot) on Mar 07, 2011 at 21:14 UTC

    It works for 9 on a 64 bit system, which is why I didn't notice it's broken, but it is indeed broken on 64 bit systems.

    You could try to fix it with something like this, but as is that's too long and I don't feel much like golfing it now.

    perl -e 'printf"%*.0f\n",$t+abs,(1x abs)**2for 1..($t=pop),1-$t..-1' 9

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://891907]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-07-17 02:23 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (353 votes). Check out past polls.