How about
Code:(a>b)-(a<b)+(a==b)-(a==b)
How about
Code:(a>b)-(a<b)+(a==b)-(a==b)
Last edited by CornedBee; 03-28-2009 at 11:45 AM.
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
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...
Last edited by CornedBee; 03-28-2009 at 11:46 AM.
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
Yes.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.(a>b)-(a<b)+(a==b)-(a==b)
Greets,
Philip
Last edited by CornedBee; 03-28-2009 at 11:46 AM.
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
I was inspired by this: Security.
Last edited by CornedBee; 03-28-2009 at 11:47 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
And I was inspired by this: Labyrinth Puzzle.
Last edited by CornedBee; 03-28-2009 at 11:47 AM.
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
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
Last edited by CornedBee; 03-28-2009 at 11:48 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Right!
Can someone else explain it?
Greets,
Philip
Last edited by CornedBee; 03-28-2009 at 11:50 AM.
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
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.
Last edited by CornedBee; 03-28-2009 at 11:48 AM.
No, it will return 1 for non-zero (or true, in the case of C++, which will be converted to 1).Originally Posted by Perspective
Last edited by CornedBee; 03-28-2009 at 11:48 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
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.
Last edited by CornedBee; 03-28-2009 at 11:48 AM.
This would be more fun if you also banned '<' and '>'
Last edited by CornedBee; 03-28-2009 at 11:50 AM.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
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.
Last edited by CornedBee; 03-28-2009 at 11:50 AM.
I can see some ugly bit twiddling here. Any volunteers? )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: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
Last edited by CornedBee; 03-28-2009 at 11:51 AM.
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
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.Originally Posted by Snafuist
Last edited by CornedBee; 03-28-2009 at 11:51 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)