Dead Men Walking

dMw Chit Chat => The Beer Bar => It's my Birthday! => Topic started by: Bob on January 31, 2007, 01:05:57 PM

Title: Code quizz
Post by: Bob on January 31, 2007, 01:05:57 PM
Here is a little something for those of you that fancy some cool coding:
int magic(int i) {
               int j = 1337, k = 0;
               do k -= i += (i<0 ? 1 : 0) + i;
               while ((j *= 42) != 0);
               return k;
       }
What does the function magic do?

You will for sure know when you find the right answer, so please don't post it here and ruin the fun for somebody else :)
I will later today, or some other day, post some hints if you have problems with it (or you could send me a PM if you're impatient), and finally the solution as well I guess.

Good luck :flirty:
Title: Code quizz
Post by: Jamoe on January 31, 2007, 02:08:54 PM
crash my laptop is what it did lol

doesn't really like php hehe
Title: Code quizz
Post by: Bob on January 31, 2007, 03:00:54 PM
Haha :lmfao:

Try using a real programming language Jamoe, like Java or C :narnar:
Title: Code quizz
Post by: Jamoe on January 31, 2007, 03:25:00 PM
hehe, I did convert it to php befor running it lol :flirty:

anyway, as I can't set apache to not ever time out and php runs out of numbers after 10 seconds I guess thats a clue. lol

Anyway, I cans see what its doing, just can't see the point lol.
Title: Code quizz
Post by: Anonymous on January 31, 2007, 03:25:21 PM
Quote from: Bob;175349Haha :lmfao:

Try using a real programming language Jamoe, like Java or C :narnar:


what's wrong with Fortran?
Title: Code quizz
Post by: Bob on January 31, 2007, 03:45:22 PM
Quote from: BlueBall;175353what's wrong with Fortran?
Nothing at all, but I couldn't list all the "real" programming languages I know about, just took the first two that came to mind :)

Of course I could also have mentioned Fortran, Cobol, Pascal, Prolog, Lisp, Python, Assembly etc, but I didn't see the point :rolleyes:
Title: Code quizz
Post by: Bob on January 31, 2007, 03:49:17 PM
Quote from: Jamoe;175351Anyway, I cans see what its doing, just can't see the point lol.
Seriously, can you really see what it's doing, just by looking at the code :blink:

Either you're exceptionally bright, or you don't see what it actually does (meaning, what the "general" result of the function is) :g:
Title: Code quizz
Post by: Jamoe on January 31, 2007, 03:49:51 PM
ADA, Eiffel, C# nice

Prolog = Evil
Title: Code quizz
Post by: Gandalf on January 31, 2007, 03:50:23 PM
You need to run it to work that out?

For shame. Easy, NEXT.
Title: Code quizz
Post by: Jamoe on January 31, 2007, 03:50:56 PM
Quote from: Bob;175356Seriously, can you really see what it's doing, just by looking at the code :blink:

Either you're exceptionally bright, or you don't see what it actually does (meaning, what the "general" result of the function is) :g:

the result of the function? u mean it actually has one?
Title: Code quizz
Post by: Bob on January 31, 2007, 03:55:44 PM
Quote from: Jamoe;175359the result of the function? u mean it actually has one?
Yes indeed :rolleyes:
And a quite sensible result as well...
And the whole point for you is to figure out what (which Gandy obviously thinks is quite easy :blink:)...
Title: Code quizz
Post by: Jamoe on January 31, 2007, 04:17:53 PM
lol so much for php, weakly typed languages ftl
Title: Code quizz
Post by: Gandalf on January 31, 2007, 04:23:41 PM
I may have it wrong, but.... PM'ed
Title: Code quizz
Post by: Jamoe on January 31, 2007, 05:00:55 PM
yea, i had forgotten that php will automaticaly convert ints to floats when they go over certain sizes.

thanks to Bob for the int tip, it finally makes sense. lol
Title: Code quizz
Post by: Gandalf on February 01, 2007, 08:05:36 AM
:devil:
Title: Code quizz
Post by: suicidal_monkey on February 01, 2007, 10:48:52 AM
actually now that I got a little hint the output does fit a pattern ... though why you'd want that particular information is another matter...? :)
Title: Code quizz
Post by: Luminance on February 01, 2007, 11:10:16 AM
pm me the outcome i give up :P
Title: Code quizz
Post by: Bob on February 01, 2007, 11:13:20 AM
Quote from: suicidal_monkey;175401actually now that I got a little hint the output does fit a pattern ... though why you'd want that particular information is another matter...? :)
And we can congratulate SM with the first correct answer :toast:
(At least the first one that PMed it to me...)

For those of you that are still struggling (and haven't already given up :narnar:), here is a good hint: think binary :flirty:
Title: Code quizz
Post by: DuVeL on February 01, 2007, 11:16:26 AM
Here's my answer:
(http://www.thinkgeek.com/images/products/zoom/binary-people.jpg)
Title: Code quizz
Post by: Bob on February 01, 2007, 11:18:01 AM
You're just grumpy cause you can't figure it out Duvel - I bet you probably belong to those that don't :norty:
Title: Code quizz
Post by: DuVeL on February 01, 2007, 11:21:23 AM
Quote from: Bob;175409You're just grumpy cause you can't figure it out Duvel - I bet you probably belong to those that don't :norty:

I made the higher education with a 5 on my exam and was proud of it.
Me and maths: :doh:
I was hoping that I could win with my original answer...
Title: Code quizz
Post by: Luminance on February 01, 2007, 11:37:34 AM
it was very origional, i had to read the tshirt a 2nd time before i saw that 10 was really 2 so i probly won't find the answer of bob :(
Title: Code quizz
Post by: delanvital on February 01, 2007, 12:20:46 PM
Easy. The answer is: 42!
Title: Code quizz
Post by: Luminance on February 01, 2007, 01:52:53 PM
42? nah its 7!
Title: Code quizz
Post by: delanvital on February 02, 2007, 10:10:07 AM
Quote from: Luminance;17542542? nah its 7!

A poor Douglas Adams attempt... :rolleyes:
Title: Code quizz
Post by: Bob on February 02, 2007, 10:40:38 AM
For you that still haven't figured it out, here comes the answer:


















The function counts the number of 1s in the binary representation of the number you put into it :learn:
A quite weird way to do so if you ask me (and not sure if I can see too much practical use of it), but it's kinda cool :flirty: