How about
Code:(a>b)-(a<b)+(a==b)-(a==b)
Printable View
How about
Code:(a>b)-(a<b)+(a==b)-(a==b)
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...
Yes.Quote:
I presume that includes ternary operator, and that this is either C or C++?
Nice try.Code:return (a >b)?1:(a<b)?-1:0;
Right! But you may safely skip the "+(a==b)-(a==b)" part.Quote:
(a>b)-(a<b)+(a==b)-(a==b)
Greets,
Philip
I was inspired by this: Security.
And I was inspired by this: Labyrinth Puzzle.
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 :)
Right!
Can someone else explain it?
Greets,
Philip
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.
No, it will return 1 for non-zero (or true, in the case of C++, which will be converted to 1).Quote:
Originally Posted by Perspective
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
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.
This would be more fun if you also banned '<' and '>'
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.
I can see some ugly bit twiddling here. Any volunteers? :))Quote:
This would be more fun if you also banned '<' and '>'
Nothing easier than that if you know that double negation doesn't change the value: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
I had the impression that proving that NAND and NOR are universal gates is a pretty common assignment for first or second year computing and engineering students.Quote:
Originally Posted by Snafuist