Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Chess Board Single Loop

by aaron_baugher (Deacon)
on Oct 04, 2013 at 01:57 UTC ( #1056829=note: print w/ replies, xml ) Need Help??


in reply to Chess Board Single Loop

If one loop is better than two, zero loops must be better than one!

#!/usr/bin/env perl use strict; use warnings; sub add { my $n = shift; return add($n-1) . sprintf( "%3d",$n) . ($n%8?'':"\n") if $n > 0; } print add(64); # output 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

Aaron B.
Available for small or large Perl jobs; see my home node.


Comment on Re: Chess Board Single Loop
Download Code
Re^2: Chess Board Single Loop
by davido (Archbishop) on Oct 04, 2013 at 03:17 UTC

    I wish I could ++ this more. Who ever would think of using recursion for this?! Beautiful? Ugly? Fun! (I think that's 2nd term CS in most community college Comp Sci programs.)


    Dave

      Heh, thanks. The funny thing is, I've almost never used recursion in a serious project. But it comes in handy for those "My solution is more obscure than yours" competitions.

      Aaron B.
      Available for small or large Perl jobs; see my home node.

      > Who ever would think of using recursion for this?

      LISPing people with recursing tails? ;-)

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-08-22 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (158 votes), past polls