3.1.2 - Never use return in the middle of a method
return is to be used at the end of a method only.
Reasoning: Using return in the middle of a method makes it difficult to later break the method into smaller methods. It also forces the developer to consider more than one exit point to a method.
3.1.4 - Never use break other than in a switch statement
break is used only for switch statement control.
Reasoning: Using break, other than for switch statement control, makes it difficult to later break a construct into smaller constructs or methods. It also forces the developer to consider more than one end point for a construct.
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.
Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:
d2d3d4=406 is divisible by 2
d3d4d5=063 is divisible by 3
d4d5d6=635 is divisible by 5
d5d6d7=357 is divisible by 7
d6d7d8=572 is divisible by 11
d7d8d9=728 is divisible by 13
d8d9d10=289 is divisible by 17
Find the sum of all 0 to 9 pandigital numbers with this property.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Personally, I would approach this in an entirely different manner where dividing a number up into sub-digits isn't needed...Luigi Plinge wrote:So would you go for the Strings option, Fred?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie wrote:What you can do is have divisors, and divide the divisors by 10 every time.
Do they really expect you to go through all pandigital numbers? Assuming you don't start with 0, there are 9 × 9! of them.
Don't get me started about those stupid light bulbs. |