6 kyu
Multiply list by integer (with restrictions)
437 of 845suic
Loading description...
Puzzles
Lists
Functional Programming
Restricted
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.
On further experimentation, there are definitely JS test cases which expect the output to be
-0
when both the multipland and multiplier are positive numbers.In one random test case, for example,
n
(the multiplicand) is291
and the first integer in the array (the multiplier) is0
. The test is failing because it says that the result of that first multiplication is expected to be-0
.If we could expect all such cases (where the multiplicand and multiplier are both positive) to result in a negative zero for some reason, then fine: we could work around it sensibly. But not all the test cases expect negative zero in this "positive times positive" scenario.
Right now, this kata as described seems unsolvable in JavaScript. Perhaps the description needs updated if there is some implicit requirement for returning negative zero in certain conventionally-unexpected cases. But more likely, there is a bug in the test solution.
Fixed.
Why are we still getting -0 in the "expected" results in this kata, particularly in JavaScript?
It's not even conventionally possible to check for -0 in JavaScript using operators, Math.sign(), or the rest of the Math library, as far as I can tell. You can't even use right-shift to find that.
(I can find two ways to do it, but they are both highly obscure and one of them appears to be undocumented. I will mention them in a comment below with a spoiler tag for those interested.)
This comment has been hidden.
Fixed
Honestly it feels like the point of this is to not use multiplication and iteration over what you are given, but that is just my interpritation. This is a great Kata if you work under that idea but it seems most others went about it as finding built ins or other functions to get around the restrictions rather than figruing out the math solution.
C++ Translation.
I feel like banning the star operator makes sense in the Python translation but not JS. In Python, you can still multiply in a functional way without using the asterisk. In JS, not so much; there is nothing functional about the approach you'd have to take there.
Expected: '[-0, -357, 714, -1071, 1428, 1785, -2142, -2499, -2856, 3213, -3570, -3927, 4284, 4641, 4998, -5355, 5712, 6069, 6426, -6783, 7140, 7497, 7854, 8211, -8568, -8925, 9282, -9639, -9996, -10353, 10710, 11067, 11424, 11781, -12138, 12495, -12852, -13209, 13566, 13923, 14280, -14637, 14994, -15351]', instead got: '[0, -357, 714, -1071, 1428, 1785, -2142, -2499, -2856, 3213, -3570, -3927, 4284, 4641, 4998, -5355, 5712, 6069, 6426, -6783, 7140, 7497, 7854, 8211, -8568, -8925, 9282, -9639, -9996, -10353, 10710, 11067, 11424, 11781, -12138, 12495, -12852, -13209, 13566, 13923, 14280, -14637, 14994, -15351]'
It seems there is still a problem with negative zero.
python new test framework is required. updated in this fork
approved
This comment has been hidden.
Expected: '[-0, -618, -1236, 1854, -2472, 3090, 3708, -4326, 4944, -5562, 6180, 6798, -7416, -8034, 8652, 9270, -9888, 10506, 11124, 11742, -12360, 12978, 13596]', instead got: '[0, -618, -1236, 1854, -2472, 3090, 3708, -4326, 4944, -5562, 6180, 6798, -7416, -8034, 8652, 9270, -9888, 10506, 11124, 11742, -12360, 12978, 13596]'
Realy '-0' for multiplication result is correct? What did I missed?
I have the same issue! :)
Hi, thanks for reporting. Try now. Regards, suic
I have the same problem
having the same issue on javascript
Had the same issue. Now I learned that something like a negative 0 exists
Had to solve it with a little workaround
Fixed
Hello! Can you answer me, how happened this? -938 * 0 === 0 And -874 * 0 === -1 What the difference?
Which language?
js
In JavaScript version,It seems that only positive integers are tested. How about negative integers? Some solutions might not be accepted. Like this: multiply(-1,[1,2,3]) Some solutions use "while",and might lead to "dead cycle".
Thanks, you are right. The description states "integer(s)" not "positive integers(s)". In fact the original Python version tests only positive numbers too. I've change both. Please check the JS version. Regards, suic
The l (list) array appears to be surrounded by quotation marks, is this the reason that when I try to convert it to a string I end up with blackslashes with my results?
Hi, sorry I don't understand your question. Can you paste here your code and mark it as a spoiler? Thanks, suic
javascript translation created.
Lovely kata, thank you, suic!
My first solved python-kata! :-)
WOW:-)... And just approved (average was 6kyu;-))
Good job! :)
WOW! suic is back!
Right, I'm back for a moment :) Things didn't change much during my break. I'll take another break as I have a pile of ("thick and heavy") books which I want/have to read :) Enjoy playing codewars :)
Regards,
suic
This comment has been hidden.
Hi, interesting approach but you mustn't modify the input list. I've added it to description.
Thanks,
suic