× Register Login What's New! Contact us
Results 1 to 7 of 7 visibility 1996

Anybody good with programming?

  1. #1
    Skywalker's Avatar Full Member
    brightness_1
    Full Member
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Nov 2006
    Location
    Canada
    Gender
    Male
    Religion
    Islam
    Posts
    443
    Threads
    25
    Rep Power
    107
    Rep Ratio
    45
    Likes Ratio
    0

    Anybody good with programming?

    Report bad ads?



    I have this project to do in C, and I'm working on this one function that's driving me crazy.

    If anybody here has programming knowledge in any language, I'm trying to make a function that prints all possible combinations of a set of numbers.

    For example if you have, 3 5 3 7, it would print:

    3
    35
    33
    37
    353
    357
    337
    3537
    5
    53
    57
    537
    3
    37
    7

    Anybody got an idea how to do this?
    Anybody good with programming?

    I have the best signature on this forum!
    chat Quote

  2. Report bad ads?
  3. #2
    lolwatever's Avatar Full Member
    brightness_1
    IB Oldtimer
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Feb 2006
    Location
    Solar System
    Gender
    Male
    Religion
    Islam
    Posts
    4,063
    Threads
    57
    Rep Power
    121
    Rep Ratio
    35
    Likes Ratio
    1

    Re: Anybody good with programming?

    i done C last year and i've 4gotten most of it, but basically the idea is to create an Array containing the 4 digits.

    and then print Array[i] where i = rand(1-4)

    thet rick is to check if previous numbers are the same as teh randomly generated combination, to do that you'd store each generated random number in a new array and compare the current combination with previous combinatons.

    i'd love to translate that into actual code 4u.. but i've just4goten alot of it! maybe if i get a sec i'll look into it insh

    tc salams!
    Anybody good with programming?

    commenthere:



    ليس بعلم ما حواه القمطر، ماالعلم إلا ما وعاه الصدر
    animationPop 1 - Anybody good with programming?
    .::.....sabr Ayyoub.....::.
    chat Quote

  4. #3
    Skywalker's Avatar Full Member
    brightness_1
    Full Member
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Nov 2006
    Location
    Canada
    Gender
    Male
    Religion
    Islam
    Posts
    443
    Threads
    25
    Rep Power
    107
    Rep Ratio
    45
    Likes Ratio
    0

    Re: Anybody good with programming?

    The thing is, random numbers are not a guaranteed way of getting those results, and even so, it could take an infinite number of tries to get it right.

    I'm sure this can be done with either a recursive function or with several nested loops, but the complexity of this problem is just too much for my mind.

    What I have is an array, int arr[]={3,5,3,7}, and I want to print all combinations somehow...
    Anybody good with programming?

    I have the best signature on this forum!
    chat Quote

  5. #4
    lolwatever's Avatar Full Member
    brightness_1
    IB Oldtimer
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Feb 2006
    Location
    Solar System
    Gender
    Male
    Religion
    Islam
    Posts
    4,063
    Threads
    57
    Rep Power
    121
    Rep Ratio
    35
    Likes Ratio
    1

    Re: Anybody good with programming?

    salams

    skywalker yeh ur right, i know its a lazy way but hey... theoretically ti works, plus when ur dealin with 2,3 or possibly 4 digits.. you could *possibly* get away with it.

    but... i have done a few things b4 with numbers that may be of help?

    Here's a combination program i wrote last year.. The issue is, this one tells you how many combinations you can make, but it won't spit out the combinations themselves..


    Code:
    
    #include <stdio.h>
    int
    n_choose_k(int n, int k);
    int
    recursion(int n);
    int
    recursionk(int k);
    int
    recursionnk(int n,int k);
    int
    recursionb(int b);
    int
    main(int argc, char **argv) {
    int n, k;
    
    scanf("%d %d", &n, &k);
    printf("There are %d ways to choose %d items from %d distinct items", n_choose_k(n, k), k, n);
    return 0;
    }
     
    int
    n_choose_k(int n, int k) {
    return (recursion(n) / (recursionnk(n,k) * recursionk(k)));
    }
    int
    recursion(int n) {
    if(n == 1) {
    return n;
    }
    return (n * recursion(n-1));
    }
    int
    recursionk(int k) {
    int n=k;
    return recursion(n);
    }
    int
    recursionnk(int n, int k) {
    int b=n-k;
    return recursionb(b);
    }
    int
    recursionb(int b) {
    int n=b;
    return recursion(n);
    }
    
    Also this one.. basically you insert a number and it will do an arithmetic and tell you which number generated the longest cycle... i dont think this is too helpful but... dunno.. lol

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    int
    main(int argc, char **argv) {
    int i=0, n=0, o=0, cycle=0, maxcyc=0, maxcycn=0;
    printf("Enter a number:");
    scanf("%d", &n);
    for(i=1; i<=n; i++) {
    o = i;
    cycle = 0;
    while(o>1) {
    if(o%2==0) {
    o /= 2;
    } else {
    o = (o * 3) +1;
    }
    cycle++;
    }
    if(cycle>maxcyc) {
    maxcyc = cycle;
    maxcycn = i;
    }
    }
    printf("Longest cycle was generated by %d which caused %d cycles to occur", maxcycn, maxcyc);
    return 0;
    }
    
    Anybody good with programming?

    commenthere:



    ليس بعلم ما حواه القمطر، ماالعلم إلا ما وعاه الصدر
    animationPop 1 - Anybody good with programming?
    .::.....sabr Ayyoub.....::.
    chat Quote

  6. Report bad ads?
  7. #5
    lolwatever's Avatar Full Member
    brightness_1
    IB Oldtimer
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Feb 2006
    Location
    Solar System
    Gender
    Male
    Religion
    Islam
    Posts
    4,063
    Threads
    57
    Rep Power
    121
    Rep Ratio
    35
    Likes Ratio
    1

    Re: Anybody good with programming?

    I think i figured it!!!

    perhaps get the numbers into an array, and then sort that array (i.e. from lowest to highest)... and then for example print it this way:

    e.g. user puts in a c b

    Sort it into: a b c

    (i've made a function that does that..)

    Code:
    void
    order(int A[], int usedup){
        int j, temp, didswap;
        while(didswap){
           didswap=0;
           for(j=0; j<(usedup-1); j++){
               if(A[j] >= A[j+1]){
                   temp = A[j];
                   A[j] = A[j+1];
                   A[j+1] = temp;
                   didswap=1;
               }
           }
        }
        return;
    }

    then decrement the position of 'c

    a b c
    a c b
    c a b

    Then the psoition fo b..

    c b a
    b c a

    Then the position of a..
    c a b (but notice that c a b is already done... so you'd make a checker against all previous entries to insure there's no repition)




    I'm using letters just for clarity.. but obviously same goes for numbers. The function i made is designed for numbers... (simple bubblesort algorithm)

    all the best
    Anybody good with programming?

    commenthere:



    ليس بعلم ما حواه القمطر، ماالعلم إلا ما وعاه الصدر
    animationPop 1 - Anybody good with programming?
    .::.....sabr Ayyoub.....::.
    chat Quote

  8. #6
    Skywalker's Avatar Full Member
    brightness_1
    Full Member
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Nov 2006
    Location
    Canada
    Gender
    Male
    Religion
    Islam
    Posts
    443
    Threads
    25
    Rep Power
    107
    Rep Ratio
    45
    Likes Ratio
    0

    Re: Anybody good with programming?

    Great idea, I'm gonna see how I can implement it. Also, to avoid repetition, don't make the 'a' decrement (it's at the beginning anyway).

    I hope I'll be able to use this function the way I need to. The funny thing is, this is probably one of the easier functions that I'll have to make in one huge program that I have to do.

    Thanks for the sugg. bro!

    Anybody good with programming?

    I have the best signature on this forum!
    chat Quote

  9. #7
    lolwatever's Avatar Full Member
    brightness_1
    IB Oldtimer
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Feb 2006
    Location
    Solar System
    Gender
    Male
    Religion
    Islam
    Posts
    4,063
    Threads
    57
    Rep Power
    121
    Rep Ratio
    35
    Likes Ratio
    1

    Re: Anybody good with programming?

    hehe np bro all the best

    salamz
    Anybody good with programming?

    commenthere:



    ليس بعلم ما حواه القمطر، ماالعلم إلا ما وعاه الصدر
    animationPop 1 - Anybody good with programming?
    .::.....sabr Ayyoub.....::.
    chat Quote


  10. Hide
Hey there! Anybody good with programming? Looks like you're enjoying the discussion, but you're not signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. And you can like posts and share your thoughts. Anybody good with programming?
Sign Up

Similar Threads

  1. Do you know programming?
    By MMohammed in forum General
    Replies: 9
    Last Post: 03-03-2010, 12:40 PM
  2. Programming solution help ?
    By Al-Hanbali in forum Education Issues
    Replies: 9
    Last Post: 09-15-2008, 07:13 PM
  3. Programming for beginners?
    By FBI in forum General
    Replies: 2
    Last Post: 01-24-2007, 06:51 PM
  4. Java Programming. helppppppp
    By Falafel Eater in forum Education Issues
    Replies: 6
    Last Post: 02-17-2006, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
create