Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next

 
[C#,Math] Anyone think they can do this better?
Reply
Posted 2010-12-13, 04:36 PM
I tried for an answer at Yahoo! answers and figured no one would answer. Which was exactly what happened. So I'm here because I know that some of the most brilliant mathematical minds I've met are here. Anyways, here's me quoting, well, me. For the most part anyway.

Quote:
I'm trying to see if there's an easier way, mathematically, to take in a number, and then get it's output based on an adding system of what I have written below. Going in order, adding each time.

256, add 1 time
128, add 1 time
64, add 2 times
32, add 4 times
16, add 8 times
8, add 16 times
4, add 32 times
2, add 64 times
1, add 128 times

Examples
1 would be 256 + 256
2 would be 384 + 128
3 would be 448 + 64
4 would be 512 + 64
5 would be 544 + 32
...
50 would be 968

Here's the code I made in C# to do it. But I feel having to run through the loops for bigger numbers, for instance, would take a bit of strain on certain computers.

Code:
private int Generate(int intNumber)
{
    int intAddTo2 = 0;
    int intOutput = 0;

    if (intNumber != 0) {
        for (int intAddTo = 256, cnt = 0; intNumber > cnt; cnt++) {
            intOutput += intAddTo;
            if (intAddTo2 % 128 == 0) {
                intAddTo /= 2;
                intAddTo2 = 0;
            }
            intAddTo2 += intAddTo;
        }
    }
    else {
        intOutput = 0;
    }
    return intOutput;
}
I'll accept an answer in any language someone writes an answer in, within the boundaries of a high level programming language, and not Brain Fuck or anything like it. That is, if there is a better way to do this. In my head, I always believe there's a better way to do something. For this though, I think I may have hit the pinnacle of a way to do this.
 
Work List
疲れていますから 寝むってありますね。 むずかしいです。 また、ケーキ屋で ケーキを食べていました。

I've considered being a translator, but I dunno. It feels like a lot of work. If someone gets angry then I have to deal with it, you know? I'd rather just relax.

 
Speed Test
 
Favorite Anime/Manga
#01 Clannad ~After Story~
#02 Trigun {Maximum}
#03 Koi Kaze
#04 Berserk
#05 Outlaw Star
#06 Slayers
#07 Desert Punk
#08 Spirited Away
#09 Fullmetal Alchemist
#10 Shakugan no Shana
#11 Death Note
#12 FLCL
#13 Tokyo Magnitude 8.0
#14 Toradora
#15 Gunslinger Girl

 
Anime List
Old
Profile PM WWW Search
Goodlookinguy seldom sees opportunities until they cease to beGoodlookinguy seldom sees opportunities until they cease to beGoodlookinguy seldom sees opportunities until they cease to beGoodlookinguy seldom sees opportunities until they cease to be
 
 
Goodlookinguy
 



 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 03:45 PM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.