How about

Code:`(a>b)-(a<b)+(a==b)-(a==b)`

Printable View

- 03-27-2009PINGRiddle #4: if-statement considered harmful
How about

Code:`(a>b)-(a<b)+(a==b)-(a==b)`

- 03-27-2009SnafuistRiddle #3: three dwarfs, two paths, one life
I love this solution. My little brother suggested killing the dwarves until one of them decides to tell the truth anyway, but this solution suffers in a similar way.

And after all, a 50% chance is not too bad, so simply asking for food and a cold beer is probably ok.

Greets,

Philip

PS: ok, I looked it up and will use "dwarves" from now on. Funny language... - 03-27-2009SnafuistRiddle #4: if-statement considered harmfulQuote:

I presume that includes ternary operator, and that this is either C or C++?

Code:`return (a >b)?1:(a<b)?-1:0;`

Quote:

(a>b)-(a<b)+(a==b)-(a==b)

Greets,

Philip - 03-27-2009laserlightRiddle #3: three dwarfs, two paths, one life
I was inspired by this: Security.

- 03-27-2009SnafuistRiddle #3: three dwarfs, two paths, one life
And I was inspired by this: Labyrinth Puzzle.

- 03-27-2009laserlightRiddle #4: if-statement considered harmful
Oh, this is good. Every since iMalc pointed out that a simple return a - b; is vulnerable to arithmetic overflow, I have been rather depressed over having to use the more verbose ternary operator version, or resort to an if-else chain. So, return (a > b) - (a < b); is good enough :)

- 03-27-2009SnafuistRiddle #5: more dwarfs
Right!

Can someone else explain it?

Greets,

Philip - 03-27-2009PerspectiveRiddle #4: if-statement considered harmful
They are not equivalent if I remember correctly. (a < b) will return 0 if false and something non-zero otherwise (but not necessarily 1). The original program returned 1.

- 03-27-2009laserlightRiddle #4: if-statement considered harmfulQuote:

Originally Posted by**Perspective**

- 03-27-2009SnafuistRiddle #6: natural languages
I introduce two new adjectives fooish and barish.

A word is fooish if it denotes a property that it has itself.

A word is barish if it doesn't.

Examples for fooish words:

- "short" is a short word.

- "English" is an English word.

- "unfrequent" is an unfrequent word.

Examples for barish words:

- "long" is not a long word.

- "German" is not a German word.

- "rife" is not a rife word.

I claim that every adjective is either fooish or barish.

Is "barish" fooish or barish?

Greets,

Philip - 03-27-2009abachlerNumber theory in 21 minutes
Yes I'm sure, no I won't elaborate. Well, maybe a little. Specifically, any prime number P modulo a primorial X such that P=> primorial X will have a prime remainder. Obviously it also works for P< X btu then you just check it agaisnt he known primes. This is not a guarantee that the number tested is prime, but it will guarantee it is composite if it fails. It will nto however give you any of the factors of the composite number. The greater the value of X the stronger the evidence for being prime. This method of checking very large primes is an embarrisingly parallelizable method. Since as X grows, it increases teh number of independant checks very quickly. It does however require a very large and comprehensive database of known primes for values of X larger than ~31. The size of the database approaches (X primorial / ln(X primorial)) * sizeof(N) where N is the type of teh storage unit for a single prime. For X = 23 and N is a DWORD its about 46MB, while for 29 its over 1GB, and it grows more rapidly after that.

- 03-27-2009brewbuckRiddle #4: if-statement considered harmful
This would be more fun if you also banned '<' and '>'

- 03-27-2009whiteflagsRiddle #4: if-statement considered harmful
This reminds me when I listened to Steve Gibson talk about a version of assembly that had no OR. You had to implement your own.

- 03-27-2009SnafuistRiddle #4: if-statement considered harmfulQuote:

This would be more fun if you also banned '<' and '>'

Quote:

This reminds me when I listened to Steve Gibson talk about a version of assembly that had no OR. You had to implement your own.

a OR b == !(!a AND !b)

I once had to show that AND and NOT form a logical basis, i.e. that one can express every boolean formula by only using AND and NOT (and variables, of course). An even smaller logical basis is NOR. Sounds like a good riddle...

A far more intriguing example of simplicity is the "One Instruction Set Computer", which only has a single instruction. One possible solution is the SBN instruction, subtract-and-branch-if-negative. It has three operands a, b and c. It works by subtracting the contents of memory location a from those at address b, storing the result at address b and jumping to c if *a > *b. Of course, this machine can be proven to be Turing-complete.

This takes the meaning of RISC to a higher level.

Greets,

Philip - 03-27-2009laserlightRiddle #4: if-statement considered harmfulQuote:

Originally Posted by**Snafuist**