Much Like A Fist, It Is Entirely Pointless
- 2 minutes read - 259 wordsSo, as I was washing up earlier tonight, my mind wandered somewhat. As it does. And, as usual, I decided to follow.
Because of reasons, during my school career, I did just one term of Computer Science at school. I was third in the class, beating the lad who was fourth by one mark. Only after our exam papers were returned did I notice that the teacher had failed to mark the last page of my exam, meaning that I could have been top of the class. It matters not now.
The only assignment I can remember from those long-ago days seems to be something of a classic:
Identify the four three-digit numbers which are equal to the sum of the cubes of their digits.
I don’t think I worked out the answer in the limited time available, mainly because we were programming on paper. I have clearly worked it out since, any number of times, not least when Red Demigod was asked the same question.
The challenge now is to do this in the least likely way possible. So here’s a solution to the problem, coded in Microsoft SQL:
WITH Nums(N) AS
(
SELECT 100 UNION ALL
SELECT 1 + N FROM Nums WHERE N < 999
)
SELECT N AS [Results]
FROM Nums
WHERE N = (POWER((N / 100),3)) + POWER(((N / 10) % 10),3) + POWER((N % 10), 3) OPTION(MAXRECURSION 0);
GOInterpreting the title is left as an exercise for you, gentle reader. Writing a comment, likewise, is up to you (but greatly appreciated).