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

Re: Telephone - Nested Loops

by ozone (Friar)
on Jun 22, 2007 at 15:14 UTC ( #622810=note: print w/replies, xml ) Need Help??


in reply to Telephone - Nested Loops

sounds like a great candidate for recursion:

getPhoneNumbers(7); sub getPhoneNumbers { my $maxLength = shift; my $curPhoneNumber = shift || '0'; if($maxLength - 1) { for(my $i = 0; $i < 10; $i++) { getPhoneNumbers($maxLength - 1, $curPhoneNumber.$i); } } else { print $curPhoneNumber, "\n"; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2022-05-28 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?