Thread: Output all 1024 number sequences, need help

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    3

    Output all 1024 number sequences, need help

    A function in my program is supposed to output all of the possible number sequences for the numbers 0-3. So, 4*4*4*4 = 1024 possible sequences. I'm not looking for someone to hand me the code just a general idea for how to start. Thanks in advance for any help

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Recursion is a way.

    Write a function that prints all combinations of length n, using f(n-1).

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by longhorn View Post
    So, 4*4*4*4 = 1024 possible sequences.
    4^4 = 256


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    For all combinations of four numbers he'll need four for loops for sure.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Or just one.

    Recursion is a way.

    Write a function that prints all combinations of length n, using f(n-1).

  6. #6
    Registered User
    Join Date
    May 2011
    Posts
    3
    Sorry for the lack of detail in my first post. This function will be called and it will return either a 0, 1, 2 or 3. It needs to return all possible 5 number sequences 1 digit at a time (so 4x4x4x4x4 = 1024). For example: it is called and returns a 1, then called again and returns a 0, then 0, then, 0 and 0. That would be 1 of the possible sequences.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by longhorn View Post
    Sorry for the lack of detail in my first post. This function will be called and it will return either a 0, 1, 2 or 3. It needs to return all possible 5 number sequences 1 digit at a time (so 4x4x4x4x4 = 1024). For example: it is called and returns a 1, then called again and returns a 0, then 0, then, 0 and 0. That would be 1 of the possible sequences.
    What's the fifth number in a range of zero to three?

    As to lack of detail, you still haven't actually shown us your attempt or that you even have an attempt. If you are just wondering what it is called so you can research it on your own, look up Permutations. Oh wait, I just did that for you.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    May 2011
    Posts
    3
    I didn't know that there couldn't be 5 number sequences made of #'s 0-3? What about 10013 or 12312 or 00023? And no, I haven't made an attempt yet that is why I posted here looking for some guidance to get me started.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by longhorn View Post
    I didn't know that there couldn't be 5 number sequences made of #'s 0-3?
    That's my whole point, there isn't one. I was trying to decide why you thought you would have five numbers there when there were only four in that. But I see that you actually mean that you have five digits in each number, rather than what you indicated in your first post.

    Anyway, I've provided you a link you should read, then post your attempt.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    All numbers from 00000 to 33333? Sounds like a simple base-4 counter that goes from base-10 0 to 1023, Then treat the binary value as base-4 and extract 2 bits at a time for the digits.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Huge number output
    By mushroom_ in forum C Programming
    Replies: 2
    Last Post: 08-06-2009, 02:04 PM
  2. Input a Hex number and output hex number to a text field
    By zoobaby in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2009, 11:26 AM
  3. Saving number Output
    By Apocalyptic_end in forum C++ Programming
    Replies: 37
    Last Post: 01-26-2008, 05:16 PM
  4. i don't want number on output
    By Kirdra in forum C++ Programming
    Replies: 6
    Last Post: 09-15-2007, 01:09 PM
  5. Funny output on hex value of number
    By shav in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 08:19 AM