Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Chess Board Single Loop

by aaron_baugher (Curate)
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.

Replies are listed 'Best First'.
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?
[Corion]: Meh. Some Open Source people get bought out by advertising firms to change their projects to include advertising. But nobody has approached me to buy out WWW::Mechanize ::$browser from me, to make the browsers launch an ad page ...
[Corion]: ... instead of about:blank, which the modules currently do at startup.
[Corion]: Maybe I'm too pricey. But I haven't received any offers at all ;-)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2017-07-24 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (354 votes). Check out past polls.