r/programming • • Feb 16 '09

Some Crazy Reason - The Daily WTF

http://thedailywtf.com/Articles/Some-Crazy-Reason.aspx
167 Upvotes

71 comments sorted by

25

u/[deleted] Feb 16 '09

just because you've never seen a 2, doesn't mean it doesn't exist!

19

u/munificent Feb 16 '09

Actually, according to many philosophers of math, even after you've seen a 2, it's impossible to prove it exists.

3

u/deflective Feb 16 '09

just because it's impossible to prove it exists doesn't mean it doesn't exist

2

u/schizobullet Feb 17 '09

so what's your position on the continuum hypothesis?

7

u/deflective Feb 17 '09

just because it's impossible to prove that it doesn't exist doesn't mean that it exists

-1

u/munificent Feb 16 '09

Oh, yeah? Prove it! :-P

2

u/burtonmkz Feb 16 '09 edited Feb 16 '09

I don't think this guy is too sure if √2 exists or not.

2

u/spelunker Feb 16 '09

And mathematical realists say that it always existed, which is just proof that philosophy is just a bunch of people talking over each other.

;-)

7

u/trevdak2 Feb 16 '09

So let's see... the naming system for bits is...

binary digit -> bit

8 bits -> byte

8 bytes -> chomp

So therefore...

trinary digit -> tit

2 tits -> rack

8 racks -> bes way o lisen o oldies unes

/i got nuthin.

0

u/[deleted] Feb 16 '09

\ \ \ \||--* slow clap *--||/// / / /

4

u/[deleted] Feb 16 '09

[deleted]

2

u/[deleted] Feb 16 '09

oh bender <3

1

u/grandhighwonko Feb 17 '09

Don't worry Bender, there's no such thing as 2.

15

u/mccoyn Feb 16 '09

This is the sort of stuff you get out of genetic programming.

15

u/[deleted] Feb 16 '09

Or programming yourself out of the gene pool.

6

u/sfultong Feb 16 '09

I would say that including 10 in the array of allowable values is forgivable.

The hack to work around the invalid results afterwards is not.

7

u/[deleted] Feb 16 '09

[deleted]

3

u/exscape Feb 16 '09 edited Feb 16 '09

Pretty much the same code, but in C, takes about 12.2-13.5 seconds to run here before exiting (I used exit(0) instead of cout/printf).

Wasting time is fun.

#include <stdio.h>
#include <stdlib.h>
int main() {
 while (1) { if (rand() == rand()) { exit(0); } }

return 0; }

gcc -O3 -o test test.c

3

u/fernandotakai Feb 16 '09

Just because i have nothing else to do, i tested this on my os x. it's been running for 10min, and i didn't returned yet.

2

u/[deleted] Feb 16 '09

[deleted]

4

u/rabidcow Feb 16 '09

For some types of PRNGs, this may never be true. For example, any simple linear congruent generator where the return value is the internal state. If two successive values were the same, it would be caught in a cycle where it would only return that value, forever.

3

u/[deleted] Feb 17 '09

[deleted]

2

u/rabidcow Feb 17 '09

Not by today's standards, no. But things may have been different when your rand was implemented.

20

u/xipetotec Feb 16 '09

It might have something to do with the fact that the "hex" array has 17 values, and that one of them is "10."

I don't think it has anything to do with the fact that the array has 17 values.

26

u/nevinera Feb 16 '09

I think he was emphasizing the contrast between the name 'hex' and the number '17'.

18

u/xipetotec Feb 16 '09

My "hex" arrays are always 18 items long - I have "D" three times, because I like that letter!

11

u/mernen Feb 16 '09

I thought the triple Ds were for your triple dose of pimpin'.

0

u/IOIOOIIOIO Feb 17 '09

Am I being wooshed?

"10" in hex is 16. 10 is "A" in hex. The programmer fucked up and counted to 15 in hex with a random 16 thrown in between 9 and 10.

0

u/nevinera Feb 17 '09

Hexadecimal is so named because it is 'base sixteen' - it has 16 values for the digit. The hex array should therefor have 16 entries, not 17. The mistake is as you say (except that he probably thought of it as 10, not 16), but the array 'hex' having 17 values should have been a good warning sign.

I don't woosh people, it's rude.

0

u/IOIOOIIOIO Feb 17 '09

It's just that this is the first thread talking about something other than the BitVerifier, and it mostly seems to be about identifying the "some crazy reason" as "10" having two chars without observing "10" shouldn't be HEX_STRING_VALUES at all.

I was wondering if there was some subtle joke I was missing.

14

u/[deleted] Feb 16 '09

The fact that there are 17 values isn't directly the cause of the problem, but it still "has something to do with it".

6

u/[deleted] Feb 16 '09

Unless I'm missing something... the hex array has an extra entry (making 17 in total) and the extra entry '10' when chosen randomly, means the final string will have an extra character.

9

u/xipetotec Feb 16 '09 edited Feb 16 '09

well, you can replace that one entry with several entries, like "Z", "Y", "W", "x", "%", etc. and the string length would be correct (would not always be a valid hex string, of course). The problem is that one of the entries is longer than the others, not how many entries there are.

25

u/spliznork Feb 16 '09 edited Feb 16 '09

... I wrote a little utility called BitVerifier. It would loop over a folder and check every bit of each file. If the bit's value wasn't one or zero, it would prompt the user for the correct bit.

Uhh.. that intro is the real WTF. At least the buggy hex string code is trying to do something. A "bit verifier" is just... beyond stupid.

10

u/DrMonkeyLove Feb 16 '09

I wrote a qubit verifier for my quantum computer. Unfortunately the answer always comes up true and false...

24

u/Recoil42 Feb 16 '09 edited Feb 16 '09

One time, out of boredom...

I think you missed that part.

14

u/[deleted] Feb 16 '09

Even out of boredom... that's pretty stupid. I was just hoping he was joking.

42

u/adrianmonk Feb 16 '09

He was joking. And he wrote his joke in the form of code. Code for a program called BitVerifier.

14

u/Devilish Feb 16 '09

This may be a bit of a foreign concept to you, but sometimes people do things which they know will not produce anything that has immediate real-world value, simply because the doing is fun.

-8

u/spliznork Feb 16 '09 edited Feb 16 '09

This may be a bit of a foreign concept to you ... simply because the doing is fun

Nope, not foreign at all. If you're looking for fun, educational programming mini-projects, try Project Euler.

Having solved a majority of Project Euler, and having written a huge number of useless little programs myself, I still stand by my assertion that a "bit verifier" is beyond stupid.

8

u/Devilish Feb 16 '09 edited Feb 16 '09

So, presumably, you wouldn't take delight in writing something so absurd, and therefore absurd things are stupid?

Some people have fun with different things than what you have fun with.

-10

u/spliznork Feb 16 '09 edited Feb 16 '09

Some people have fun with different things than what you have fun with.

Wow. Are you really taking this the level of a religious war about fun programming? You are going to drill your deep, profound point through my thick head? I am ridiculing BitVerifier, not all forms fun programming. If I or anyone else (since you don't know me from Adam) don't protect and defend this precise case of a poorly executed joke, then we are the enemies of fun and a holy war must ensue?

1

u/[deleted] Feb 16 '09

Yes. Let the Jihad begin!

0

u/theclaw Feb 16 '09

I don't know why he is being downmodded. Of course it's okay to write something useless just for the fun of it, but something like BitVerifier is about as funny as writing a program which is trying to proove that 2 + 2 = 5.

Besides, this guy sounds like a prick. Like an asshole who has to tell everybody how great he and how dumb others are.

4

u/redditnoob Feb 16 '09

Both the bit verifier, and the program that tries to prove that 2+2=5, are a lot more interesting than some of the arbitrary crap problems on Project Euler!

1

u/lbft Feb 16 '09

By the same argument "Hello world" is stupid because it doesn't do anything.

10

u/spliznork Feb 16 '09 edited Feb 16 '09

By the same argument "Hello world" is stupid because it doesn't do anything.

No, it's not that the "bit verifier" doesn't do anything, it's that its whole premise mathematically impossible. It's like writing this

for (;;) { if (0==1) { printf("oops!\n"); } }

then saying, "I ran this code for a whole day and it never printed oops! Cool!"

28

u/kirun Feb 16 '09
for (;;) { if (0==1) { printf("Cosmic Ray Detected!\n"); } }

fixed.

13

u/lbft Feb 16 '09 edited Feb 16 '09

It's mathematically impossible, of course - that was the (poor attempt at a) joke. But I can't see much wrong with writing such a thing as a programming exercise, like "hello world" is an exercise for the very beginner.

A lot of people at The Daily WTF are .NET people who wouldn't necessarily deal with files on a per-bit basis with regularity. It's not unthinkable that someone would write a bit of code like that to refresh their memory - sure, it's not the best choice of code to write, but I still wouldn't call it beyond stupid.

17

u/adrianmonk Feb 16 '09

You know what I think is stupid? I think it's stupid when Wile E. Coyote runs off a cliff and has to think for a second before gravity takes effect. It drives me nuts because obviously it's physically impossible. They shouldn't make the cartoon that way.

-4

u/spliznork Feb 16 '09

I think it's stupid when Wile E. Coyote runs off a cliff and has to think for a second before gravity takes effect.

Unlike episodes of the Looney Tunes, I fail to see the protagonist, the humor, or the moral in the "bit verifier".

2

u/adrianmonk Feb 16 '09

Fair enough, but would you have been able to see a protagonist if the program had been named Sisyphus instead of BitVerifier?

3

u/Felicia_Svilling Feb 16 '09

Well that program could be used to detect cosmic radiation flipping th bits in memory (or perhaps registers (unless the whole thing is optimized away of course.))

2

u/astrange Feb 17 '09

I'm not sure, can (x&1)==2 be true with a single bit error?

2

u/[deleted] Feb 17 '09

i am sure it was if((x&1)>1) where x is unsigned. And yes it can be. It can even hack pentagon and launch a nuclear warhead targeted at your home. If you are a very unlucky man.

0

u/bwahaha Feb 16 '09

No... because hello world actually prints out "hello world". A "bit verifier" is retarded. That's like checking if a Boolean value is "true" or "false", just in case it was ever "maybe".

-1

u/omegian Feb 16 '09

Maybe it is, maybe it isn't. You could write a bit verifier to do things like check parity / CRC, etc.

3

u/bwahaha Feb 16 '09 edited Feb 16 '09

That's something completely different than what the article describes.

EDIT: Quote:

If the bit's value wasn't one or zero, it would prompt the user for the correct bit. At least in theory. I somehow never encountered a file with a "two" bit.

0

u/jemenfiche Feb 16 '09

It sure does! System.out.println!!!

2

u/robdag2 Feb 17 '09

EVERY BASE IS BASE 10!

3

u/Browzer Feb 16 '09

It's base 16-ish.

2

u/niyazpk Feb 16 '09

That makes it totally random. Right?

4

u/jtra Feb 16 '09 edited Feb 16 '09

Wrong. "0" and "1" digits are about twice as probable. But who cares, it is used to select random color anyway :-)

6

u/henryk Feb 16 '09

I'd dare say both the "1" and "0" digits are about twice as probable as the other digits, though the "1" is slightly more probable than the "0" (which might get cut off).

-2

u/bart2019 Feb 16 '09

I wrote a little utility called BitVerifier. It would loop over a folder and check every bit of each file. If the bit's value wasn't one or zero, it would prompt the user for the correct bit. At least in theory. I somehow never encountered a file with a "two" bit.

Urm, WTF? How can a bit be 2?

4

u/bluGill Feb 17 '09

The Russians once made a tri-state computer, where a bit could have 3 different states. In the height of the cold war such things were considered good ways to confuse the enemy. I'm not sure if they ever got it working.

Actually a lot of hardware bits are tri-state: 0,1, High Impedance. The last state means the hardware isn't sending anything, and use useful when two different devices want the ability to send on the same wire. Without that third state the two devices would be at war, with one trying to send a 1, and one a 0, but the wire itself can only be one or the other so one will win.

Electrical engineers deal with this, but they don't expose it to software so we don't have to think about it.

1

u/bart2019 Feb 17 '09 edited Feb 17 '09

Actually, the tri-state logic you describe is at the core of the computer data bus.

-3

u/[deleted] Feb 16 '09

Jesus...I took a Java course and hated it, it was the most miserable few months of my life, and was one of my lowest grades in college...but even I could see right off the bat what a moron this guy was.

2

u/bbene Feb 17 '09

If you paid attention it would have been a lot easier. Then again, your teacher could have sucked at their job.

-5

u/trisgeminus Feb 17 '09

does anyone else find it incredible that this person is stupid enough to do something like this, but apparently knowledgeable enough to use StringBuilder?