|
|
|
| Non-WTF Job: IT Applications Manager at Questex Media Group (Auburndale, Ma) |
| « Prev | Page 1 | Page 2 | Next » |
isn't that supposed to be int(N)? |
|
|
Presumably, the coder didn't trust the obvious N mod 2 solution.
Perhaps he thought that odd and even don't work when the number is binary. No, I've worked it out. This is the result of a genetically determined algorithm - random code was generated until the output from the function was always correct. |
|
I also like the fact he has 2 functions: idOdd() and isEven().
I wonder if he will call isOdd() when isEven() returns false :P |
|
Another likely solution: n And 1 ' Remember, Folks, Bit 0 makes an odd number [;)]
|
|
He could have converted the number to a string to get the last digit.
|
|
I'm a little confused... Since N isn't specified as an int, as far as I can see, what will these functions return for, say, IsEven(4.2)? [:|] Scary stuff. |
|
Simply amazing... he understands how mod works, but can't figure out how to use it to determine if a number is even? Having two functions is SOMEWHAT understandable for readability... it doesn't really hurt anything, except maybe maintainability if the definition of odd and even changes (or if they figure out what they're doing with floats :)) |
|
|
In case it wasn't obvious, the bolded part was meant to be sarcastic. [:)] |
lol - same thing I thought...WhyTF is he/she using mod 10?!?[:|] |
It will return True, since he/she's casting N to an int 4.2 will become 4. |
|
I see the WTF! For isOdd(N) he should have returned !isEven(N), right ?!? right?!?!
|
Re: IsOdd()? Yes, Is Very Odd.
2005-03-21 14:20
•
by
misses the point
|
Why not use mod 6? The even numbers would then be 0,2 and 4. Odd numbers: 1,3 and 5. It will work with mod by any even number... |
Ah, duh, me brain not go work-work yet today huh huh. Of course that just raises new questions, since he's casting his input then returning information about the (possibly changed) input number [:^)] |
Re: IsOdd()? Yes, Is Very Odd.
2005-03-21 14:23
•
by
Jimmy James
|
|
"Presumably, the coder didn't trust the obvious N mod 2 solution." Maybe the developer didn't realize understand the concept of even vs. odd and only knew this rule by rote. I know lots of developers who are unable to |
|
IF NOT IsEven(N) AND NOT IsOdd(N) THEN
Call IM_AN_IDIOT() End if |
I know that mod will work with any even number, but didn't you learn in school to get the lowest common denominator? [;)] LastDigit = int(N) mod 666 [6] |
|
Open that link and do a search for "Figure: dictionarydb". A bonus WTF for today! |
|
Sorry, I didn't do that post right - I meant to reply to Tom Mathews's post with link to http://www.15seconds.com/issue/040202.htm. |
|
Oh boy, thanks for the laugh, was feeling a bit tired today but that perked me up. Made me realize that my 4 years of university was worth something after all.
|
I do not see what you are referring to. Was there an error on the page that you saw? Maybe the error has been fixed already. |
|
>Made me realize that my 4 years of university was worth something after all. So at the end of 4 years of university study you can reliably and efficiently tell if a number if odd or even? Congratulations! You are doing better than most [:)] |
I couldn't find the text "Figure: dictionarydb", but just under the text: "Pictures below demonstrate CAPTCHAs generated by gimpy" check out the top right image and they word they say it is [*-)] Cheers, evnafets |
|
eh, it basically what everybody was taught in gradeschool. I wouldn't be surprised if this was a typical example of somebody coming up with a solution and asking somebody more knowledgeable for the piece they needed to get the solution to work (how do I find the last digit in a number). If they had mentioned what they were really trying to do they would have gottena better answer. It could easily be worse. He could have converted N to a string and used string ops to find the lsat digit. |
|
As you can see, their word "space" is in red, because they should have
typed "spade". The rest of the captions are in green, meaning their a bit human after all. |
|
What? doesnt this code work? At least he didnt convert it to a string first. What else can you ask for?
|
Is there a function IsEvenOdder() ? |
|
I've seen worse:
DEFSNG A-Z Disclaimer: This was posted on Usenet, so it doesn't meet the requirements for a WTF submission. |
|
Nope, it can still get worse...
<?php function IsEven($num) |
|
Recursive odd/even is the best ever. =D Impress professors and colleagues alike!
I like the new forum look a lot, except the main page is too slim (I can't find whatever css is doing it) and the lack of a reply button on the bottom. (Quickpost would be even nicer, hint to CommunityServer folks.) Otherwise, [Y] here's to (hopefully) the end of the forum wtfs! |
Sorry guys... If you scroll to the bottom of the above page you will see "Writing Your Own CAPTCHA Application." Following that link takes you to, http://www.15seconds.com/issue/040203.htm. On that page you will see the "Figure: dictionarydb" I was talking about. This table is in what I like to call "26th Normal Form." |
|
Good that he did it with 10, iimagine what should have happened if it was 100.
|
|
Hmmm, and what about negatives?
|
|
Another solution: Find all prime factors of N and check if 2 is one of them. |
Haha... wtf would they do that? |
|
I realize it isn't required in VB, but for god's christ please try to add some declarations in your code. Two functions there, are they private or public? We'll just let it use whatever the default is. Is that parameter being passed by reference or by value? Who cares, it's not like the function is modifying the value! Not yet, at least. And speaking of which, what kind of variable is that coming in? VB's catch-all Variant type, no doubt. Finally, why bother even declaring variables if you're not going to give them a type? Just get rid of that "Option Explicit" at the top of your form (if you even bothered) and let the compiler do all the work for you. After all, you have to get back to writing Excel macros to calculate your cell phone bill. I know I'm anal retentive about it. Oh yeah, and the functions suck. |
|
Perhaps the real WTF is that a swiss-army-knife language like VB6
doesn't already have these functions. While I've always favored minimalist core languages in general, it seems to me that if you're going to go the 'bigger is better' route, you should at least cover all the reasonable cases, and this is one that comes up quite often. In VB if you don't declare types, it uses Variants for everything, which is pretty inefficient; also, you end up with typing holes like you won't believe. I guess this person hasn't heard of Option Explicit, either. There are some languages where dynamic typing is the standard idiom, but VB isn't one of them. Anyway, as has already been beaten to death here, the most reasonable approaches for this function are either Function IsOdd(n as Integer) as Boolean or Function IsOdd(N as Integer) as Boolean either of which would be easier to code and understand than this. And of course, the obvious way to write IsEven() would be Function IsEven(n as Integer) as Boolean Was this too hard to figure out? Pedantic aside: in priniciple, the bitwise version should be slightly faster than the modulo version on most systems; in practice, the difference is probably not measurable. Also, the bitwise approach assumes 2's-complement arithmetic; while this is always true with VB, as well as on virtually all current hardware, it would technically be a portability WTF in languages such as C. (BTW, what's the preferred method of posting code examples in a message? The [ code ] tags seem to have problems with indentation, at least in preview mode. I'm using the Formatted text type here, but it doesn't look quite right.) |
Or indeed, mod 2... |
Re: IsOdd()? Yes, Is Very Odd.
2005-03-22 13:01
•
by
GalacticCmdr
|
|
Bah, you heretics and your mod 2. Why back in my day we had to make use
of nothing but OR gates because AND gates were more expensive. The sad part is that I am semi-serious. I had to hard-code (meaning pluggable module sets) using nothing but OR gates and the last 3 AND gates we had in stock. Since the stock would not be replenished until after quarterly cutoff and this machine (meaning high-profit contact) had to be on the train before quarterly ended. |
Re: IsOdd()? Yes, Is Very Odd.
2005-03-22 17:15
•
by
Stan Rogers
|
|
OR gates? And three ANDs? Bloody luxury, that. We had nothing but NAND
gates -- nothing at all but, mind you, on 4-bys -- then our fathers would beat us to death with a herring. |
|
No, ! isEven() is the same as isUnEven(), for lumpy
numbers. Likewise, ! isOdd() is actually the same as isUnOdd(), otherwise known as isNormal(). Sheesh. What are those math professors teaching these days? |
Now that takes the cake! It's a little hard to believe someone who can think recursively would write this as serious code, though. |
|
That just makes me shudder [:|]
|
|
That only works for numbers stored as 2's-complement which I admit is the vast majority of circumstances, but is in no means mandated by any standard.
|
|
"if the definition of odd and even changes" ????? Reminds me of the following snippet of code: #define PI 3.14159 /* In case value of PI ever changes */ Regards, Pax. PS: Hey, I can't even read that captcha box - I'll have to repost.
Aaah, that's better.
|
|
Oh joy, the joy of that code! Oh that is so beautiful, I think I will start using that same brilliant method in my code. You know, most programming can be done without much understanding of math, but understanding just a little bit of math now and then wouldn't hurt.
|
I don't see why it would lead to portability problems? Both the C and C++ standards definition od operator & should ensure that the following will return 1 if the number is odd:
Maybe I'm missing something though. What system would that not port to? |
|
Wow that code tag really jacked up my formatting. That should be(second try):
int isOdd(int i){ return i & 1; } |
|
Perhapse I should clarify. In both the C and C++ standards & is a
binary operator. The word binary by definition is two's compliment is it not? I could be wrong but I thought the two were identical. If I am correct then any integer &'d by 1 should return 1. Is this not correct? |
| « Prev | Page 1 | Page 2 | Next » |