6 kyu
Simple Fun #110: Array Operations
145 of 373myjinxin2015
Loading description...
Puzzles
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.
Very nice kata, not that easy to figure out as it seems at first.
too many tests are ran, and it times out, and it fails me even though my function is working perfectly fine (python)
That's a problem with your code, not a kata issue. Read the posts below.
yeah. performance katas are just harder in python, because it's that slow.
i repicated my code in js 1 to 1, and it passed, so uh :D
Well, then it shouldn't work in javascript either, I think you have to figure out a way of not doing those k loops, or at least that's the author's idea.
Nope - see my JS solution. It's 1 to 1 what my python solution was (except my python used a while). Python is just bad at performance.
C# tests generate warnings -->
tests/Fixture.cs(102,15): warning CS0219: The variable 'passed' is assigned but its value is never used
fixed
More fixed or random test coverage should be added (to invalidate wrong solution of mine)
Python --> wrong sol
JS --> wrong sol
Ruby --> wrong sol
C# --> wrong sol
One of such case being
do you by any chance have thoughts on how to generate those tests, what the characteristics are? you might not, which would be fine, but, you were able to come up with a case and you're aware your code is wrong so maybe you do.
Typescript translation https://www.codewars.com/kumite/630887dc966bf50f7f4ac9de?sel=630887dc966bf50f7f4ac9de
Python, C#, Javascript: test cases are a mess full of unused stuff, needs serious cleaning.
done for python
fixed for other languages
The case
k = 0
is only being tested in the random tests, where it's very unlikely to occur. A lot of the top solutions won't work fork = 0
, so adding this case to fixed tests would break too many solutions. I suggest removing its possibility from the random tests, and changing the description to reflect this (i.e.,k > 0
instead ofk >= 0
).Please specify the language(s) when raising an issue. No matter if all current languages are affected, think new future translations could not have it.
The possibility of
k = 0
is implied in the instruction for all languages.I have only solved the problem in python and JavaScript, where I can verify that
k = 0
is only being tested (very rarely) in random tests, and top solutions won't work for it.Ok. Apparently Ruby is affected too and not C#, though I'm not sure (testcases are a mess).
Description formatting is broken.
Fixed in this fork + Enabled Ruby 3.0
I don't feel like this is worded very well.
Is this supposed to be a coding puzzle, or a let's-see-if-we-can-correctly-interperate-the-author's-meaning puzzle?
It mentions an array
a
, but then in the description of the two steps to be done each itteration ofk
, it mentionsA
. Am I to assume thata
andA
are the same thing? Maybe that's what people are assuming, but I don't like to assume. Programming requires an attention to detail that appears to be missing here, making me assume thata
andA
reference the same array. But assumptions about the initial array parameter, aside...Then the instructions state "find M - maxumum element of the array" does that mean that I subtract the value of the maximum element of the array from some unknown value
M
? Or thatM
is litterally the last element in the array? A minus sign is used twice in the instructions, but it's apparently (maybe? I'm still not really sure) to be a hyphen in the first case and an actual subtraction operator in the second.The phrase "maximum element" seems really misleading. Does that mean the element in the array with the biggest index, or the element in the array with the biggest value (regardless of its index)? Trying to follow the two given examples, doesn't help. The biggest element (value-wise) is 0... well, it doesn't matter how many itterations you make applying the second operation to the array,
0 - a[i]
doesn't alter the original array at all. If you interperate "maxiumum element" to mean the last element in the array (the biggest or "maximum" one), you get the same0 - a[i]
since element 3 in the first example is 0.I even tried assuming (hate doing that...) that "maximum element" was talking about the values in the elements and not the indicies. Further, I tried assuming (again, grr...) that the author was from some planet where
-4 > 0 == true
(it's not... that's false just to be perfectly clear), and on a first itteration through the array initial array I get [0, -4, 3, -4]. That's:but this is already flawed to me, because I had to assume that -4 was somehow the "maxumum element".
Maybe I'm just stupid, or maybe this is less of an algorithmic challenge and more of a let's-see-if-we-can-correctly-interperate-the-instructions.
I would prefer algorithmic challenges with precise and clearly stated goals. An algorithmic challenge should never start by giving you the algorithm (i.e. find the max value then perform this operation).
A bad news to me. I'm not good at the English grammar ;-) If I am allowed to use Chinese, I think I will write a rigorous and detailed description ;-) 69 guys passed the tests and submitted their solutions. It seems that my descrption is not SOOO bad, right? I made the following changes:
Hope this will be helpful ;-) Thank you for your feedback.
Some reply about one part of your comment:
maximum element
. Hmmmm... Generally speaking, that is the maximum value/number in the array. For [1,200,3], it should be 200. For [4,500,6], it should be 500.biggest index
? Usually we call it by thelast element
.0 - a[i] doesn't alter the original array? No,
0 - (-3) = 3, 0 - (+3) = -3
;-)You showed how to do it, why even bother about the description ? Description is fine.
description is clear enough :)
What is the purpose of 100 000 tests?
Here should be the point to find solution, right?
BTW, Kata is very good, but I can't understand limited time.
no 100000 tests. Do you mean
k <= 1000000
? I think you never need to write a code with 1000000 times loop statement ;-)Can you set a limit on the solve time when creating a kata?I manged to brute force it the stupid way with 2 loops.Or I got lucky in the random tests.
Thanks for this kata
Happy coding
^_^
Is this a puzzle or an efficiency test?
Honest question. I can write a more efficient solution, but I'm not interested in that. I do not see the puzzle, but maybe I'm missing something.
The puzzle point is the thinking of
k
. Whenk = 1000
, I think smart guys don't let the code loop 1000 times. Generally speaking, the puzzle tag will give me a good reason to face a user questioning my description. I would say: "Hey, man, this is a puzzle, if you don't understand my description, please think hard." :]I had a nagging feeling it was a puzzle. I just didn't see a solution ( and I still don't).
Guess I'll have to think harder .. or get smarter. (Just not feeling very smart the last couple of days though. :P )
This is a good kata, I had to try several approaches before I got it to complete within the allotted time. It exposes that I should pay more attention to efficiency than I normally do. Thanks!
Thanks ;-)