Timeline for Ruby-ize for loop - counting all the n-digit numbers that contain the digit 5 anywhere
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 13, 2017 at 12:19 | history | edited | CommunityBot |
replaced http://math.stackexchange.com/ with https://math.stackexchange.com/
|
|
Jun 7, 2014 at 3:12 | comment | added | Cary Swoveland | The reason this works is straightforward: there are 10^n numbers with n or fewer digits when the digits are drawn from the 10 digits 0-9, whereas there are 9^n numbers with n or fewer digits when the digits are drawn from the 9 digits 0,1,2,3,4,6,7,8,9. The difference is therefore the number of numbers with n or fewer digits that contain one or more 5's. | |
Jun 6, 2014 at 15:34 | history | edited | RubberDuck | CC BY-SA 3.0 |
deleted 21 characters in body
|
Jun 4, 2014 at 18:32 | comment | added | 200_success |
10 ** n - 9 ** n is a good solution for Ruby, where integers are unbounded. Be careful, though, with languages where ints can overflow, where the recursive solution may be better.
|
|
Jun 4, 2014 at 17:03 | history | answered | RubberDuck | CC BY-SA 3.0 |