Register Stats Arcade Portal Forum FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read
 Zelaron Gaming Forum [C#,Math] Anyone think they can do this better?

 [C#,Math] Anyone think they can do this better?
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.

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
#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
#15 Gunslinger Girl

Anime List
 Profile PM WWW Search
Goodlookinguy

Posted 2010-12-14, 06:56 AM in reply to Goodlookinguy's post "[C#,Math] Anyone think they can do this..."
Code:
 if(intNumber==0)return 0; int mag; for(mag=7;mag>=0;mag--){ if((1<

Last edited by WetWired; 2010-12-14 at 07:12 AM.
 Profile PM WWW Search
 WetWired

 Posted 2010-12-14, 10:48 AM in reply to WetWired's post starting "if(intNumber==0)return 0; int mag;..." Really, you could use a log 2 operation then take the integer part instead of using the for loop, but then you may have to deal with floating point precision issues. That, along with swapping the left shift with an exponent operation would make the solution entirely mathmatical
 Profile PM WWW Search
 WetWired

Posted 2010-12-14, 01:59 PM in reply to WetWired's post starting "Really, you could use a log 2 operation..."
WetWired said: [Goto]
 Really, you could use a log 2 operation then take the integer part instead of using the for loop, but then you may have to deal with floating point precision issues. That, along with swapping the left shift with an exponent operation would make the solution entirely mathematical
I don't know enough math to go into dealing with a semi-complex algorithm like that.

The solution you gave was more than enough. Took me a good 45-minutes to an hour to understand how your solution works. I had previously tried to figure out a solution using binary shifting and such, but failed. You nailed it though. So really, thank you so much. I really thought there was no better way to pull this off. I think I may have gotten a bit rusty from not being able to write code as often as I used to.

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
#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
#15 Gunslinger Girl

Anime List
 Profile PM WWW Search
Goodlookinguy

 Posted 2010-12-14, 02:44 PM in reply to Goodlookinguy's post starting "I don't know enough math to go into..." Is this for something?
 Profile PM WWW Search
 WetWired

Posted 2010-12-14, 04:03 PM in reply to WetWired's post starting "Is this for something?"
WetWired said: [Goto]
 Is this for something?
It is indeed. I like to play around with my own private server of Perfect World, among other games. Because I have more fun editing, designing, and figuring out how these things work than I do the game themselves. So I'm in the process of making a hex item data generator. One of the patterns I caught onto was one that started with a base number of 16000, then did the pattern I described. I then made what I had previously written. However, I felt it was too many loops, which is why I thought it could be done better.

I'm making the program freeware, so that's why I didn't want it to be too heavy when it generates data. Considering it could be a very wide-range of users; And all of the other things it has to calculate before the output. That's all.

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
#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
#15 Gunslinger Girl

Anime List
 Profile PM WWW Search
Goodlookinguy

Posted 2010-12-15, 07:01 AM in reply to Goodlookinguy's post "[C#,Math] Anyone think they can do this..."
goodlookinGuy said:
 I'm trying to see if there's an easier way, mathematically [...]

Not enough math in this "math" thread. Anyway, I found you a closed-form function for your problem:

$\reverse
\mathbf{f}(n) = \sum_{p=0}^7 $$\sum_{k=\frac{2^p + H[p-1] +1}{2}}^{2^p} \(2^{(8-p) H[n-k]} + H[n-2k] + H[n-2k+1] -1$$ \)
$

where $\reverse H[t]$ is the discrete Heaviside step function defined as

$\reverse H[t]=\begin{cases} 0, & t < 0, \\ 1, & t \ge 0. \end{cases}$

Last edited by Knight Sir Rick; 2010-12-15 at 07:07 AM.
 Profile PM WWW Search
Knight Sir Rick

Posted 2010-12-16, 01:25 AM in reply to Knight Sir Rick's post starting "Not enough math in this "math" thread...."
knight sir Rick said: [Goto]
 Not enough math in this "math" thread. Anyway, I found you a closed-form function for your problem: $\reverse \mathbf{f}(n) = \sum_{p=0}^7 $$\sum_{k=\frac{2^p + H[p-1] +1}{2}}^{2^p} \(2^{(8-p) H[n-k]} + H[n-2k] + H[n-2k+1] -1$$ \)$ where $\reverse H[t]$ is the discrete Heaviside step function defined as $\reverse H[t]=\begin{cases} 0, & t < 0, \\ 1, & t \ge 0. \end{cases}$

While I understand what you wrote. Converting it to code it seems like it would take longer to compute than WW's answer. Considering for each sigma, there's a for loop that must be run. As well as calls to the function H.

For a completely math based, non-linear, answer though, very impressive. You compressed it into two functions worth. Still much better than my original way of doing it.

------------
Also, what I meant by the "[Math...]" and "...mathematically..." was just because it isn't just some regular programming stuff. It requires a bit of math knowledge to try and make something that works.

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
#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
#15 Gunslinger Girl

Anime List
 Profile PM WWW Search
Goodlookinguy

 Posted 2010-12-18, 08:11 PM in reply to Goodlookinguy's post "[C#,Math] Anyone think they can do this..." Holy shit, math is fucking hard.
 Profile PM WWW Search
Skurai

 Posted 2010-12-19, 09:05 PM in reply to Skurai's post starting "Holy shit, math is fucking hard." just think about this ... most if not all of us on this forum have taken or is taking algebra atm Tim I know you said not to deal w/ them I didn't think I'm lost and I'm sorry﻿ They Know Run
 Profile PM WWW Search
jamer123

 Posted 2010-12-19, 09:27 PM in reply to jamer123's post starting "just think about this ... most if not..." Algebra is srs bsns D3V: I need to get on zelaron more. I'm having withdrawls. Skurai: You should be used to withdrawls by now, D3V. !King_Amazon!: It's "withdrawals" you illiterate douchebags
 Profile PM WWW Search
 !King_Amazon!

 Posted 2010-12-20, 11:09 AM in reply to !King_Amazon!'s post starting "Algebra is srs bsns" Algebra is a myth.
 Profile PM WWW Search
Skurai

 Bookmarks

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

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home The Zelaron Nexus     Forum News, Suggestions and Discussion         Test Forum             RSS News     Member Introductions     The Lounge         World Record Thread     General Discussion         News and Events         Life Discussion         Opinion and Debate     Science and Art         Tech Help         Science and Technology News         Principia Mathematica     The Anime Corner Zelaron Gaming     General Gaming         Deus Ex: Human Revolution     DayZ     Diablo III         Diablo I & II             Diablo Cube             D2 PvP             D2 Marketplace     RPGMaker

All times are GMT -6. The time now is 04:32 PM.
 -- Synthesis 2 (Original Blue) -- Synthesis 2 (Lava Ashes) -- Synthesis 2 (Liquid Violet) -- Ocean -- Zephios -- HUD Revision 'Synthesis 2' vBulletin 3.x styles and 'x79' derivative by WetWired the Unbound and Chruser Copyright ©2002-2008 zelaron.com