This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Ive been trying to get into the programming grove with java, but wasnt having much opertunity to practise what Ive learnt, and then I thought I had found the perfect solution - The uni of auckland posts assignments from previous years on its website. I thought if I could do these, ill get plenty of the right kinda practise, i mean, these guys teach people how to code for a living, right?
One small problem, and its not with Java per se.
Im stuck trying to figure the algorythm for the 3rd (yes, the 3rd) excerise.
It sounds simple enough. Given 3 numbers, put them in order, smallest to bigest. Just one complication: no conditional statements of any kind. Use on Math.max() and Math.min().
Now, im sure its possible, but I cant figure it. Neither can the various members of the family ive posed it as a simple puzzle too. Ive spend a good 2 hours on this away from the computer with 3 cards and a notebook.
I think I got finding the smallest and biggest, like this:
But, whatever i do, it seems without conditional statments (which I take to be if, while, and for) I can not get the middle number.
Im sure its possible, probley very obvious, but the way my brain is wired, I can't figure.
Any pointers, tips and/or peusdocode would enable me to sleep tonight. Thanks.
Now that you have the max and the min number. Add all the three orignal numbers together. Then subtract the sum of the maximum and the minimum from the sum of the three numbers. [ May 08, 2007: Message edited by: Anupam Sinha ]