Thread: Comparing Digits!!!

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    195

    Comparing Digits!!!

    Ok, lets say i have the number 13112. How do i compare the digits of this number to see if one number (in this case the number "1") appears in over 50% of the number. In this case the number "1" appears 3/5 digits so it appears over 50%. Anyone know how to do this tastk thanks

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I'd transform it into a string and check the digit occurance 1 by 1.
    Code:
    char TempChar;
    int Number = 13112
    std::stringstream Stream(Number);
    int Occurance[10] = {0};
    
    while(!Stream.eof())
    {
      Stream >> TempChar;
      Occurance[TempChar - '0']++;
    }
    Note: Code has not been tested.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Magos
    I'd transform it into a string and check the digit occurance 1 by 1.
    Or leave it as an int and check each digit:
    Code:
    int TempChar;
    int Number = 13112
    int Occurance[10] = {0};
    
    while(Number > 0)
    {
        TempChar = Number % 10;
        Number /= 10;
        Occurance[TempChar]++;
    }
    Note: Code has not been tested, but I've done it before. It should be fine.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How do i compare the digits of this number to see if one number (in this case the number "1") appears in over 50% of the number.
    Numeric profiling can result in riots if you aren't tactful. I suggest starting a fight between the 1's and the other digits. If there are any 1's at the end then they probably had superior numbers.

    >In this case the number "1" appears 3/5 digits so it appears over 50%.
    Be careful though. 7's can hide pretty well behind 2's. A cursory glance isn't always enough.
    My best code is written with the delete key.

  5. #5
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Originally posted by Prelude
    suggest starting a fight between the 1's and the other digits. If there are any 1's at the end then they probably had superior numbers.
    That's abserd! This gives a huge disadvantage to the slow and sluggish 8's. And we all know that 6's and 9's tend to team up.

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Prelude
    >How do i compare the digits of this number to see if one number (in this case the number "1") appears in over 50% of the number.
    Numeric profiling can result in riots if you aren't tactful. I suggest starting a fight between the 1's and the other digits. If there are any 1's at the end then they probably had superior numbers.
    I don't know about that. Every fight between the "others" and either Hercules, Xena, or Arnold resulted in the superior numbers being soundly trounced. You need to keep track of the realities of the world, Prelude.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Every fight between the "others" and either Hercules, Xena, or Arnold resulted in the superior numbers being soundly trounced.
    Well, I didn't mention digit placement because it adds quite a bit of complexity. You see, 10110 is considerably more powerful than 3002. By assuming that greater numbers means greater power you can save yourself the trouble of measuring total value of the hoards. Besides, 2 and 3 aren't heroic at all, unlike 5, who has some m4d l33t sk1llz. And of course 9 is god-like; the Hercules of the decimal system. But don't forget 1 and 0 when they join forces, whooo.

    >You need to keep track of the realities of the world, Prelude.
    That's something I don't hear much.
    My best code is written with the delete key.

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Prelude
    And of course 9 is god-like; the Hercules of the decimal system.
    But don't forget it's omnipotence over the octal system, where he's unimaginably powerful! God-like isn't even close!
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >But don't forget it's omnipotence over the octal system, where he's unimaginably powerful!
    Unfortunately, 9 causes spacial anomalies with his very existence in the octal system, so any estimates of his power are mere speculation.
    My best code is written with the delete key.

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Prelude
    And of course 9 is god-like; the Hercules of the decimal system. But don't forget 1 and 0 when they join forces, whooo.
    bah, you're so wrong... when 1 and 0 join forces, they're weaker than 1 alone... the 1 tries to fight, but the 0 does absolutely nothing... and the 9 just comes along and only destroys the 1 because the 0 couldn't be any worse off...

    -and-

    Originally posted by WaltP
    You need to keep track of the realities of the world, Prelude.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Bah, if I were a mod I would've closed this thread for off-topic spam
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  12. #12
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    lol!

    i dunno, personally i think 6 is the strongest, with all that arm training and weight training. i mean he's been walking on his hands for ages...
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

  13. #13
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Magos
    Bah, if I were a mod I would've closed this thread for off-topic spam
    you must not mod many forums... it's hard to stop threads when they get offtopic, because most threads would be closed within a few posts...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    Registered User
    Join Date
    Jan 2003
    Posts
    311

    Re: lol!

    Originally posted by heat511
    i dunno, personally i think 6 is the strongest, with all that arm training and weight training. i mean he's been walking on his hands for ages...
    sure 6 usually teems up with 9 but now 6 is upset with seven because 7 8 9.

  15. #15
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: Re: lol!

    Originally posted by grib
    sure 6 usually teems up with 9 but now 6 is upset with seven because 7 8 9.
    That cannibal!! This wouldn't happen in binary!! A much more civilized system.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. decimal to number if digits in different bases
    By jorgejags in forum C Programming
    Replies: 21
    Last Post: 09-24-2008, 12:55 PM
  2. reverse a number digits
    By tootoo in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2007, 11:24 AM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 11:39 AM
  4. Hex digits stored in char array.
    By Kevinmun in forum C Programming
    Replies: 8
    Last Post: 11-18-2005, 04:05 PM
  5. Odd/Even Digits in a Number-Help!
    By ProgrammingDlux in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2002, 10:39 PM