6 kyu
Simple Fun #151: Rocks
190 of 632myjinxin2015
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
The code doesn't work with large numbers. I used for loop. Suggestions ?
Well, you are saving each digits to an array. If you look at the sample tests,
36123011
will results in277872985
(277 million) digits. Array cannot store that many items. You need to look for alternative way to count them.You've got to find an optimal approach mathematically and logically speaking to not go through all numbers one by one
Ruby 3.0 version in this fork
Approved, keep those updates coming!
nice little kata, took some time and scribbling on actual paper to work it out the first time...
I can't get it:
//1..9 = (9 * 1) = 9
//10..99 = (100 * 2) = 200
//100..999 = (1_000 * 3) = 3_000
//1000..9999 = (10_000 * 4) = 40_000
//10_000..99_999 = (100_000 * 5) = 500_000
//100_000..999_999 = (1_000_000 * 4) = 6_000_000
//1_000_000..9_999_999 = (10_000_000 * 7) = 70_000_000
//10_000_000..36_123_011 = (26123011 * 8) = 208_984_088
//sum: 208_984_088 + 70_000_000 + 6_000_000 + 500_000 + 40_000 + 3_000 + 200 + 9 = 285_527_297
//And solution is telling 277_872_985
What am I doing wrong?
This comment has been hidden.
python new test framework is required. updated in this fork
Approved
Duplicate of https://www.codewars.com/kata/55905b7597175ffc1a00005a ? (Just a difference of performance?)
Ruby translation should be updated 3.0, see relevent information here: https://github.com/codewars/content-issues/wiki/List-of-Ruby-Kata-to-Update
Done in latest fork
I'm not a great connoisseur of C#, but is there a good reason for the input and output to be double and not merely integers? It does not make much sense at first glance.
changed to
long
, existing solutions will not be invalidatedfunction rocks(int $n): int { $result = 0; for ($i=1;$i<$n+1;$i++) { $result += strlen($i); } return $result; }
works but times out lol
Brute-force solution can not deal with large number
This comment has been hidden.
Your solution is s(l)m(a)a(z)r(y)t, but I think it can not deal with the large numbers such as 1000000000. Try to find the law, make a O(1) solution ;-)
Beta Status:Awaiting smile67 approval
^_^
approved;-)
The instructions were quite confusing. However the actual task was great.
Can you point out where is
quite confusing
? Thanks.Maybe add some example to description would be better.
OK, good idea ;-)
example added:
For
n = 13
, the result should be17
.你好
jinxin
,一如既往 PHP 和 Coffee :-)好的,已批准。 谢谢!
:D Nice!