September 16, 2014 at 11:49 am
Carlo Romagnano (9/16/2014)
WOW64, I learned something new!😀
+1 (<== As luck would have it, an Armstrong number!)
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
September 16, 2014 at 1:59 pm
Carlo Romagnano (9/16/2014)
WOW64, I learned something new!😀
Actually you didn't :). You'll forget about this. He'd better posted it on a forum for maths.
However, interesting ...
Igor Micev,My blog: www.igormicev.com
September 16, 2014 at 3:01 pm
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.
I agree. Though I do like maths lessons, I'm not sure what I was supposed to be learning.
September 16, 2014 at 4:51 pm
Fun question. Utterly horrible code for people to understand, which is always interesting. And a few lessons to be learnt here.
Sean Lange (9/16/2014)
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.It isn't even really math. From the wiki page.
These are odd facts, very suitable for puzzle columns and likely to amuse amateurs, but there is nothing in them which appeals to the mathematician.
I too found it strange to have to research what the name of this was. Still I thought was an interesting question.
The Wiki page got that wrong, didn't it? Obviously Michael Armstrong found them interesting, so did Dik Winter, Joseph Madachy, Martin Gardner, Lionel Deimel (although some people might argue about whether he is a mathematician) and rather a lot of others. Of course there are four different types of Armstrong number, this question is about one particular type, and is of course about base 10 representations (different bases lead to different Armstrong numbers).
I was briefly confused by the question; it obviously wasn't generating the set of base 10 Armstrong between 0 and 1000, because it misses out 2,3,4,5,6,7,8, and 9 (single digits in any base are trivially Armstong numbers of this type; so numbers base X have X trivial Armstong numbers) so at first I discounted the Armstrong number option, but that meant there was no correct option so I decided that omitting trivial Armstrong numbers didn't matter and that must be the answer.
Someone suggested there's nothing to learn from a question like this. I think that's pure bunk. Reading the code and seeing what for example POWER(ISNULL(SUBSTRING(CAST(value AS VARCHAR), 2, 1), 0), 3) means is pretty good mental excercise and will help people to understand how these functions mesh together. and will probably teach some people something about CAST. For those who notice that it doesn't do the right thing for numbers less than 100 or greater than 999 it's a nice demonstration that working some of the time may be good enough some of the time but is unlikely to be good enough all the time: don't expect to get the next base 10 Armstrong number, 1634, by changing the recusion limit from 1000 to 10000: although you may get some numbers between 1000 and 10000 none of them will be Armstrong numbers. The code covers the range 0 to 9, but only detects 2 or the 10 Armstrong numbers in that range; it does the wrong thing for numers from 10 to 99 inclusive too, and gets the right answer (none of them are Armstrong numbers) by accident.
edit: Just so that no-one mistakes my comment about the code doing the correct thing only for 3-digit numbers as criticism, I think the odd behavour of the code was intentional; the question doesn't ask "which numbers" and offer "the Armstrong numbers" as an answer, it asks "which type of number" and offers the answer "Armstrong numbers" which suggests that not generating all the Armstrong numbers in the range was intentional - a good way of making people think a bit harder about exactly what the question meant (it certainly had that effect on me, anyway). Also seeing code that does what is required to recognise Armstrong numbers in the range 100 to 999 but not in the range 0 to 99 or from 1000 upwards provides a nice example of code which may look good when tested but doesn't really work outside of a narrow range of data - and that such code is easy to write is something which some developers never learn, despite writing far too much of it, so it's good to show people examples of it. This is great code for teaching some useful lessons, which is what QotD is about.
Tom
September 16, 2014 at 5:12 pm
Shiva N (9/15/2014)
Which type of Numbers?
Shiva,
No matter what has been said about the value of the question and all this noise and chatter, keep the questions coming. We may argue and gripe about stuff but at the end of the day we do appreciate those who offer questions.
Thanks, you are doing a good thing! and keep it up
edited because I got the quote messed up the first time.
Not all gray hairs are Dinosaurs!
September 17, 2014 at 12:36 am
Hany Helmy (9/16/2014)
Koen Verbeeck (9/16/2014)
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.It's an exercise in reading T-SQL 🙂
Still not convinced it`s important to us SQL users.
When Steve has a fun-question for 7 points about the names of Santa's reindeers or a Thanksgiving question for 10 points, I hear nobody complaining it's no use for SQL users 😉
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
September 17, 2014 at 12:58 am
Koen Verbeeck (9/17/2014)
Hany Helmy (9/16/2014)
Koen Verbeeck (9/16/2014)
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.It's an exercise in reading T-SQL 🙂
Still not convinced it`s important to us SQL users.
When Steve has a fun-question for 7 points about the names of Santa's reindeers or a Thanksgiving question for 10 points, I hear nobody complaining it's no use for SQL users 😉
+10
very nice question, i did learn something new today. 🙂
September 17, 2014 at 4:55 am
I told someone that these numbers are real and they laughed. Excellent post.
Jamie
September 17, 2014 at 6:04 am
I learned something about math today from this question, but I won't use it and will probably forget it.
September 17, 2014 at 1:02 pm
Fun question. Thank you Shiva.
A nice example of the capabilities for using SQL Server to recreate interesting calculations. While I am positive I will never have to know what Armstrong numbers are in my professional career, I personally don't consider this question as a complete waste of time. I can see this number sequence coming up in a puzzle book or trivia game, so there is a slight chance that I will need to recall this sometime in my life. So, thanks in advance for that!
September 17, 2014 at 2:02 pm
Thanks Shiva for an amusing question.
I like the simplicity of the brute force approach although of course it doesn't scale beyond 3 digits. The only criticism I have is the use of a recursive Tally table, in this case that would be at least 5 times quicker. Never the less an excellent question. BTW have you tried the Project Euler[/url]?
😎
September 18, 2014 at 1:06 am
That was a lovely exercise, thank you Shiva.
Iulian
September 18, 2014 at 6:01 am
Koen Verbeeck (9/16/2014)
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.It's an exercise in reading T-SQL 🙂
No, it's not. It's a math lesson!
The only troublesome part of the T-SQL code is a WHERE clause, which is utterly without any relevance to any job I can ever imagine putting a SQL Server to do in any company in any part of the world!!
If you want to handle data sets, use SQL Server (or whatever your choice of data base machine).
If you want to construct algebraic objects, use a calculator! SQL Server is NOT a calculator - even though it can perform a range of operations.
"Just because something is possible, doesn't mean it is smart" 😉
September 18, 2014 at 8:03 am
hjp (9/18/2014)
Koen Verbeeck (9/16/2014)
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.It's an exercise in reading T-SQL 🙂
No, it's not. It's a math lesson!
The only troublesome part of the T-SQL code is a WHERE clause, which is utterly without any relevance to any job I can ever imagine putting a SQL Server to do in any company in any part of the world!!
If you want to handle data sets, use SQL Server (or whatever your choice of data base machine).
If you want to construct algebraic objects, use a calculator! SQL Server is NOT a calculator - even though it can perform a range of operations.
"Just because something is possible, doesn't mean it is smart" 😉
I still find it a good question , it is nice, a little bit unusual and very funny.
Also I understand your point in that SQL is not necessary a calculator for arithmetic challenges;
though someone has to challenge this aspect of SQL too, how to know what SQL streghts are if not challenging it ?
but what is this question missing to be a good one ?
What I am thinking is: SQL Server tends to go very much in the area of BI, Analysis and these sort of things which is true needs statistical background, and not arithmetic , but who knows what formula / indicator are you asked to make for a promotional campaign ?
That is one aspect there might be others too.
Cheers,
Iulian
October 9, 2014 at 1:01 am
Sean Pearce (9/16/2014)
And this relates to SQL Server how? I am not here for maths lessons.
I thought it would be a frienfly question, so I picked Amicable numbers...
Viewing 15 posts - 31 through 45 (of 46 total)
You must be logged in to reply to this topic. Login to reply