06-04-2013 10:56 PM - edited 06-04-2013 10:58 PM
I've recently been left with no choice but to modify some legacy code. Two things keep going through my head:
1) this thread
2) this dilbert comic
http://dilbert.com/strips/comic/2013-02-24/
I have no code examples to post, my nightmare is not contained in any single block diagram. It spirals in countless interdependancies and circular references of variants coerced to multitudinous data types with no comments or descriptions.
I feel like Copernicus must have felt trying to simplify the Ptolemaic model of planitary motion. Epicycles on epicycles.
I know I've coded my own fair share of Rube Goldberg code over the years but I think this time the code may win.
06-11-2013 08:58 AM
I knew that I could simplify, but sometimes the daily hurry catches you and you produce a Rube! 😄
OP asked, besides another functions, a simple program that generate a number between 0-100 and to check if this number is Odd or Even.
Here is what I did:
But user apok, improved it.
Also, RavensFan pointed out a important detail:
"RavensFan wrote:
You do not want round to nearest. When you multiply by 100, you'll get a number between 0 and 99.99999..... Round to nearest will give you an integer between 0 and 100. but the values of 0 and 100 will only occur half as often as the values in between.
You should round down. Now you will have a number between 0 and 99 that all have equal chances of occurring. If you want 1 to 100, then add 1. If you want 0 to 100, then multiply by 101."
This is referred to this thread.
Regards
06-11-2013 10:17 AM
@joaopam wrote:
I knew that I could simplify, but sometimes the daily hurry catches you and you produce a Rube! 😄
Also, RavensFan pointed out a important detail:
@"RavensFan wrote:
You should round down.
The round down trick is important, for example if you need to do a "fair" dice (1..6). If unsure, you should always test using a historgram.
Of course the above quoted example still used twice as may bits as needed. For 0..100, U8 would have been perfectly fine. 😄
The quotient&remainder technique is useful for more general problems, e.g. to check divisibility by 3 or higher.
06-11-2013 11:42 AM
Thanks for the tips, Christian!
Yeah, U8 would be perfectly fine. Another flaw in my code! 🙂
Regards
[off-topic: I found insteresting your new signature phrase. It serves as inspiration to avoid Rubes. I wrote it down in our office board, in the motivational phrase section 😄 ]
06-11-2013 03:09 PM - edited 06-11-2013 03:15 PM
It could have been worse. Seen Here
Although, the first two offers are not QUITE and RG'd its best to remember you do have the type def.
06-11-2013 03:32 PM
Well, I'm speachless.
All I can say is that this remembered me of some message altenbach posted once, years ago in this very thread (yes, I read the entire thread :))
This looks like an aztec pyramid! 😄
Nice spot!
06-11-2013 06:23 PM
If you show ALL of the False cases it resembles an Egyptian pyramid
06-12-2013 01:45 AM
Looks a bit like this:
06-19-2013 07:34 AM
i have seen a nice example on the idee exchange.
hire
06-19-2013 07:57 AM
@LordNobady wrote:
i have seen a nice example on the idee exchange.
hire
Agreed, he should have used a case structure to keep everything nice and centre-aligned.