7 kyu
Katastrophe!
1,479 of 3,510jackcarlisle
Loading description...
Mathematics
Fundamentals
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.
Based on the author's solution, there seems to be an implicit assumption that whatever the size of the outer array, is also the size of each of the inner arrays. If this is the case, it needs to be explictized (and will probably invalidate some answers). All the current tests hardcode a length of 3, and the random tests of the Python translation hardcode the inner array size as 3. The description should be cleaned up to sort this out, as it makes adapting this Kata awkward into languages that support tuples or compile-time sized arrays because each person who adapts this Kata seems to make a different set of assumptions.
From what I can tell, none of the translations use fixed-length arrays or tuples, and none of the reference solutions make any assumptions of outer/inner array length. The phrasing in the description may be brief, but it is sufficiently language-agnostic and it is very clear what is being asked for.
Regarding the test inputs all being 3x3, why not? The kata description makes no statements regarding input size other than the single example earthquake which is 3x3. Also, if a particular language's tests show the input upon failure (which they really should for a 7 kyu), having a smaller array will make it easier to debug your failing solution.
This comment has been hidden.
Haskell fork
Ruby should be updated to v3 (new test framework) + needs random tests
Python fork
Actually a complete rework of the actual test, please review carefully :)
modified your fork a bit
Approved, although sample tests should include the example in the description.
nice kata
Excellent kata, became 1111 my solved kata. I had to think about it, but it was fun.
This one was fun!
Some languages do not have random tests.
The most popular solution tests for greater than or equal to instead of greater than.
You should either update the description or invalidate older solutions by adding a test case that has the magnitude equal to the strength of the building.
Javascript version of Kata should include more test cases, better if are random
Alr raised as issue
I think there may be an issue with one of these test cases: strongEnough([[ 5, 1, 7 ], [ 1, 1, 1 ], [ 4, 1, 2 ] ], 100).
[ 5 + 1 + 7 ],* [ 1 + 1 + 1 ] * [ 4 + 1 + 2 ] returns 273
Building Age is 100 and 1000 - 1% one hundred times returns 0.
0 is less than 273, which would require "Needs Reinforcements!" but it is expecting "Safe!".
That's were you are wrong. No issue, the test is correct.
Python 3 please? Congrats for the Kata BTW!
This comment has been hidden.
Javascript version of Kata should ideally include random test cases; keep that in mind when authoring future Kata :)
Alr raised as issue
This comment has been hidden.
You cannot debug with
alert
instead useconsole.log
but also you need toreturn
the values'looks like u solved it'
This comment has been hidden.
Hi,
My script works fine on IDLE but when I run it using the "Submit" button it will give an error and won't accept my solution.
Despite the fact that the "Output" window shows the correct answer ("Safe!" or "Needs Reinforcement!"), it says "None should equal 'Safe!'"
This is my first try and I'm stuck. Am I doing anything wrong?
Should I post my code here?
Thanks in advance
EDIT: I just noticed I was printing instead of returning!
This comment has been hidden.
This kata is more difficult than 7kyu
Absolutely.
I really liked this one! I had to look up how exponential decay works and I see a lot of different implementations here. Gonna read up a bit more :) Thanks for a practical approach with a good story line.
I published a CoffeeScript translation.
What's supposed to happen if the strength of the earthquake equals the strength of the building? I'd assume that it means it needs reinforcement.
'alr approved some time ago'
Really good kata! Taught me a lot
Thanks! Glad you enjoyed it
Fantastic little story to illustrate a real-world example that succesfully masks what'd otherwise be a dry excercise in implementing simple maths.
As another commenter pointed out, I'm a little disappointed that Codewars is accepting the less accurate implementation w/ simple percentages instead of the proper exponential equation, but I assume that's at no fault of the author and a limitation of either the website or maybe Ruby itself.
This comment has been hidden.
The test cases are always precise because they provide an input and a specific solution that must be returned. It is not the fault of the test case itself but I'm guessing it could be a rounding issue embeded within the code. If both versions pass the tests then essentially they are both correct, even if one method is more precise than the other.
This comment has been hidden.
I've tried your code and it works for me. Seems like a temporary bug with codewars.
looks like u solved it
This comment has been hidden.
The building's strength is decreased using exponential decay, meaning you subract 1% of strength which gives you a new strength. Then you subtract 1% of that new strength, not the original 1000 each time. Therefore in theory the building's strength will never reach 0 as you are only subrtacting a percentage of the new value each time. Follow this link for more info on exponential decay: https://en.wikipedia.org/wiki/Exponential_decay
Read comments below if it is still unclear!
I've ported this kata to Haskell. Also * symbols in your arithmetic expression are parsed as italics markers, hence I escaped them with backticks.
'alr approved some time ago'
This comment has been hidden.
I've taken the Python version down because I have a very limited knowledge of the language.
I've tried to fixed (and re-published) it.
@jolaf: I used a variable named
exp
which collided with importedexp
function; Can you try it again, please ?Fine now, thanks!
Python translation kumited.
(Tests shuffled) more info on how to approve it ( or not )
I'll approve it now!
Fine. Ruby translation also kumited.
(Test shuffled) Same way to approve (or not)
"Exponential decay" is when a value decreases by a fixed percentage per time interval. I'd suggest using that phrase to explain how the strength of the building decreases, and include a link to https://en.wikipedia.org/wiki/Exponential_decay.
Thank you! I was struggling to put it into words.
Ok, I'll mark the suggestion resolved.
Hi, I'm not sure if test case no. 4 is correct:
{ 'earthquake': [ [ 5, 1, 7 ], [ 1, 1, 1 ], [ 4, 1, 2 ] ], 'age': 100 }
Expected: Safe!, instead got: Needs Reinforcement!
But if
then strength of that building should be 0.
Thanks,
suic
Hi,
The strength is reduced by 1% after each year, then that new decreased strength is decreased by 1%, not the original 10000. This means that in theory the building's strength will never reach zero as you are only taking off a percentage each time, not a set value. I'm going to change the wording of the description to make that clearer!
Thanks, Jack
Hi, thanks, now it's clear.