4 kyu

Smallest possible sum

259 of 8,092dkhaburdzania
Description
Loading description...
Algorithms
Mathematics
Arrays
  • Please sign in or sign up to leave a comment.
  • Uoao1808 Avatar

    This comment has been hidden.

  • MelancholyMelancholy Avatar

    Scala Sample Test / Type Mismatch Error

    If the numbers within the Seq() do not contain the L to state the numbers are long. Then the compiler will throw a Type Mismatch Error. Therefore you have to can bypass the sample tests by submitting. Or you can change sample test by adding the L

    Example: (Seq(9L), 9L), (Seq(6L, 9L, 21L), 9L), (Seq(1L, 21L, 55L), 3L)

  • Боивой Прохраммист Avatar

    I have the problem with basic tests. In results actual value is 4, but 4 is not in tests.

  • ahmet_popaj Avatar

    Brilliant coding challenge...

  • R4gon Avatar

    Hhahaha what the evil author, the description is completely misleading

  • KayleighWasTaken Avatar

    Python random test generation can crash due to overflow.

  • zerschmetterling Avatar

    This comment has been hidden.

  • picadud Avatar

    This comment has been hidden.

  • SAC.489 Avatar

    this kata is broken :) even i used numpy and wrote a function with 4 lines but it is actually not accepting my solution what the fuck guys

  • andreafel Avatar

    My python code is passing all tests, but times out in the performance section after about 190 tests. I have tried different approaches and on my laptop the code executes in less than 0.1 seconds for arrays as large as 50000 and numbers in the array as large as 1000000. I am struggling to find a more efficient solution. Any one can give me a pointer? Thanks.

  • wobler Avatar

    Most fun kata I've seen so far but the description really needs to be improved.

  • geoffp Avatar

    Someone should rewrite the description of this kata. I see many complaints below pointing out that the algorithm is incompletely specified.

    This is what the description should have said:

    Choose any two array elements X[i] and X[j] with X[i] > X[j]. Set X[i] = X[i] - X[j].

    Repeat until no more subtractions are possible (because all array elements are equal).

    It can be shown that whenever there is more than one possible choice of the pair i,j, it doesn't matter which pair you choose: the answer will be the same in the end.

  • KayleighWasTaken Avatar
  • whiskeyZZ Avatar

    This comment has been hidden.

  • bidouille Avatar

    Before to even be a programming challenge, this kata is a total riddle as for directives. Reading if X[i] > X[j] then X[i] = X[i] - X[j], one expects a left to right parsing, and only for immediate neighbour. But then one has to decrypt the example. Let's try with arrow in other direction:

    X = [6, 9, 21]
    X_1 = [6, 9, 12] # <- X_1[2] = X[2] - X[1] = 21 - 9
    X_2 = [6, 9, 6]  # <- X_2[2] = X_1[2] - X_1[0] = 12 - 6
    X_3 = [6, 3, 6]  # <- X_3[1] = X_2[1] - X_2[0] = 9 - 6
    X_4 = [6, 3, 3]  # <- X_4[2] = X_3[2] - X_3[1] = 6 - 3
    X_5 = [3, 3, 3]  # <- X_5[1] = X_4[0] - X_4[1] = 6 - 3
    

    It seems we first substract 2 from 3, then 1 from 3, then 1 from 2, then 2 from 3, but lastly we substract 2 from 1. Not left to right, not immediate neighbours, so what? Deep right to left parsing? Greater from next greater? Greater from lower? Strictly none of those. Let's assume it's a deep right to left as far as possible then ending as possible. But what if [21, 9, 6]? Plus three poor test cases, can't help a lot.

    I really like puzzles, and this one could be great as a puzzle if it was clearly stated. If it's not a puzzle, then some things should be clarified, as a lot of people already noticed in discussion. Personnaly, I feel that tagging it as puzzle and replacing misleading instructions with some more examples/tests, would been more interesting… Then one can try it only when in "puzzle solving" state of mind.

  • Dmytro-Tarasenko Avatar

    The most difficult parts of such katas is to determine what the blood it`s about. A did not get it (((

  • HartlIKS Avatar

    TypeScript translation based on existing JavaScript translation.

  • CM_auto Avatar

    This is one of those problems, where solving is possible only with one specific algorithm

  • n1ni Avatar

    I dont understand this question, where the numbers in the examples are coming from

  • DE0000 Avatar

    This comment has been hidden.

  • dArksaur0n Avatar

    This comment has been hidden.

  • CarsonGH Avatar

    I am coding in golang and I pass every test case other than the "Input Mutation Test". I don't understand what this test is looking for/doing? The instructions don't say anything about this test case? Here is what the console spits out: Input mutation test Solution changed input Expected <[]int | len:7, cap:7>: [1, 1, 1, 1, 1, 1, 1] to equal <[]int | len:7, cap:7>: [1, 1, 2, 2, 2, 1, 1]

  • yang19 Avatar

    The test case in golang is wired. looks like expect []int{1, 1, 1, 1, 2, 2, 2} = []int{1, 1, 2, 2, 2, 1, 1} not Solution([]int{1, 1, 1, 1, 2, 2, 2}) = Solution([]int{1, 1, 2, 2, 2, 1, 1})

  • AlekseevJ Avatar

    This comment has been hidden.

  • didfuf Avatar

    What wrong with codewars? I write py code all works correct code working 150.40 ms but codewars send info to me more 12000 ms. I am disappointed

  • JihemM Avatar

    Sorry but i don't understand why in the first transformation 9 is used and not 6 and in the second it's 6 ! why not 9 again??!

  • OwlHoot Avatar

    This comment has been hidden.

  • mja_smith Avatar

    The description is too vague to be useful and needs to be clarified.

  • Connor56 Avatar

    Great fun! Please improve the description though, it's not immediately clear what you want us to do.

  • Fvbvke Avatar

    broken ass shit on python it has limit of 109 tests passed timed out for no reason, I did fastest I can

  • ProfMonkey07 Avatar

    This comment has been hidden.

  • de_naissance Avatar

    Has anyone been able to solve this problem in Kotlin? Always getting "Execution Timed Out"

  • zeffgo Avatar

    This comment has been hidden.

  • blanktix Avatar

    This comment has been hidden.

  • kvesterr Avatar

    Lol, I just tried to divied by zero...

  • kvesterr Avatar

    Why is my code running good in visual studio and get all tests, but in codewars I have: UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: FPE on unknown address 0x000000425719 (pc 0x000000425719 bp 0x7ffc046ee768 sp 0x7ffc046ee290 T1) ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer!

    Is anybody know?

  • cobalt88 Avatar

    This one is really throwing me for a loop. Ive managed to write a solution that passes 108 of tests, and in the test example is actually more perfomant than the example only needing 3 steps instead of 5, but i still time out every time. Guess its back to the drawing board again.

    Not complaining by the way, I like a good puzzle, just stating this one is more challengin than usual for me.

  • 98b7b8602eea3b00 Avatar

    With go, 208 tests pass and 1 fails. The failure is: "Input mutation test":

    Solution changed input Expected <[]int | len:7, cap:7>: [1, 1, 1, 1, 1, 1, 1] to equal <[]int | len:7, cap:7>: [1, 1, 2, 2, 2, 1, 1]

    Unclear what this test is testing for.

  • Avanta Avatar

    This comment has been hidden.

  • JoSevlad Avatar

    This comment has been hidden.

  • OmarAzizi Avatar

    why it keeps timing out in C++? even though i didint use recursion and it runs fine when i run it in my terminal without with less than a second

  • akar-0 Avatar
  • codingPhobia Avatar

    Could someone give a more clear description of this kata please? I might just be dumb but the one the author gave is really confusing me and I'm having a hard time getting started on the kata.

  • sid114 Avatar
  • Amar-jay Avatar

    Tests not running in go. Though, with the same solution it worked in python.

  • akar-0 Avatar

    Rust translation (author is inactive).

  • akar-0 Avatar

    C++: tests can generate inputs for which result overflows unsigned long long.

  • SamHenkels Avatar

    Frustration. Every test passes in 1.5 seconds except for the last one. I hit max recursion error. No idea how everyone gets around this...

  • krylovdash Avatar

    Bump: in Python it takes around 6 seconds even if one just writes "return None" in the body of the function. From the comments below, it seems related to Python 3 and this kata.

  • yakovkeselman Avatar

    This comment has been hidden.

  • akar-0 Avatar

    COBOL translation (author inactive).

  • alexc19 Avatar

    This was a fun kata, thank you. I have to say however that I was almost turned away by the description, which in my view needs improving.

    Indexes i, j are used without being defined. Also the part where the transformation example is presented could be more clear. I suggest to add X_0 [6, 9, 21] at the top of the sequence roll out, otherwise people will continue to think 12 is a typo instead of the result of 21 - 9.

  • sid114 Avatar

    Biggest facepalm of my life when I figured out the easy solution lmao great kata!

  • Zordid Avatar

    Sorry, but this Kata is just weird. I do not understand the description. This is so unlogical and not correct. You can't just come with i and j without saying anthing about them... What is i? What is j?

  • guntbert Avatar

    Correction: upon further reading I see that there are no transposed digits but the whole text is somewhat misleading

    I'd expect to have the

    • input in the first line, followed by the appropriate calculations,
    • the first result in the second line
      and so on.

    Python: The description and example contain two pairs of transposed digits ( 21 <-> 12)

    • description: The text states "...of the elements of input X = [6, 9, 21] is detailed below:" but the code starts with X_1 = [6, 9, 12]
    • example (in essence the same): we call solution([6, 9, 21]) #-> 9 but the detailed steps start with [6, 9, 12]

    The code shown assumes the correct values

  • ritvij-saxena Avatar

    This comment has been hidden.

  • wowthecoder Avatar

    Nice kata! Just a small tip: compare the result array and the original array and try to find a pattern. Good luck to future challengers!

  • MuhammadAli18 Avatar

    Timed OutPassed: 106Failed: ?Exit Code: 1 Test Results: Fixed Tests Should pass example tests (9 of 9 Assertions) Random Tests 100 random tests (97 of 97 Assertions)

    what is the problem it passed all exames

  • Unnamed Avatar

    Incorrect test structure in Crystal: "Basic tests" are not in an it block.

  • Unnamed Avatar

    Not fixed. The random tests in Crystal sometimes crash with

    Arithmetic overflow /solution_spec.cr:20:16 in 'sol'

  • regolas Avatar

    same for me in Javascript i get a max buffer size reached. the algorithm works fine until it gets tot he huge arrays. I am not sure how the help system works here, i guess we're not allowed to leave our code for others to help...

  • RNOH Avatar

    Cannot pass the attempt, my python code works fine for the test at 520ms, even for the random but it gets timed out. i dont think its an issue of the efficiency, its something else.

  • Unnamed Avatar

    I've been trying to fix the Python version and found out that something is actually different from something else and is an order of magnitude faster. The difference is much bigger that between different ways of generating random input, so I'm wondering if the size of performance tests should be descreased to compensate for slow random input generation (I have a faster version, but it still is not too fast) or increased because solutions like this just use the slow thing when there's a faster alternative. At the same time, random test case generation seems to be taken from the original Ruby kata and I'm not entirely sure why it's done like that, it causes solutions like this to be the fastest, although they have a horrible worst case performance. So I'm trying to understand if it's OK to replace the test generation code entirely or the current random tests generate the worst case data for a certain type of solutions. So what solution are there that are faster then a naive implementation, but not good enough to be acepted? (Don't forget about the spoiler flag when necessary.)

  • chucky-1 Avatar

    I'm passing 98 random tests out of 100. My algorithm can't handle an array of 42,000 numbers. Trouble :(

  • eylonmazor7 Avatar

    It's impossible to meet deadlines, my solution is the most effective I know and still not enough for the deadlines (of course there are no errors, and all my test passed in less 2500 ms) language : C++

    Please help! :)

  • allesrelatief Avatar

    Can someone please explain why the first transformation in the example [6,9,21] is 21 - 9 and not 9 - 6? Are you supposed to always take the maximum?

  • iCarly Avatar

    Tried testing with only returning a number, resulted in 4000+ ms, add 2 more lines, resulted in 7000+ ms, is this normal?

  • Kmelow Avatar

    What is not clear in the explanation are the indices i and j. They refer to algarisms in the same number or indices in a vector? In the first example an array of [6, 9, 12] is given, then there is a 21 that appears.

  • juliabakeryuhui0916 Avatar

    This comment has been hidden.

  • juliabakeryuhui0916 Avatar

    This is my 3rd Kata 4 attempt. I have submitted 4 versions, including one by framing the data to n*2 shape, so far all tests passed but failing on execution timeout. I am guessing that I need to utilise python standard library or other ones to optimise further. Are importing standard and non standard libraries allowed in codewars? I haven't imported any but survived to kata 4 tasks so far. Alternatively can someone give me some guidance on whether this task can go through without any library import, but with cleverer algorithms.....If so I will try harder on algorithm design.

  • Valeriy-Totubalin Avatar

    for [4, 8, 8] expected 24 why not 12? kata with mistakes

  • mouwat Avatar

    This comment has been hidden.

  • akar-0 Avatar

    (Python)On this kata, for the first time I get an error message trying to use lru_cache decorator: File "main.py", line 7, in test.assert_equals(solution ([9]), 9) TypeError: unhashable type: 'list'. Does anyone know the cause?

  • fibonaccios Avatar

    Meh... I knew it there was something fishy here :) The description though is out of this world!

  • AlexP9 Avatar

    This comment has been hidden.

  • NewDeveloper Avatar

    This comment has been hidden.

  • BAD_BOT Avatar

    Time: 2058ms Passed: 116 Failed: 0 Exit Code: 137 Test Results: Fixed Tests Should pass example tests (9 of 9 Assertions) Random Tests 100 random tests (100 of 100 Assertions) Performance Tests 100 random, huge tests (7 of 7 Assertions) STDERR Max Buffer Size Reached (1.5 MiB)

    WTF? What to do about it? Python.

  • FArekkusu Avatar

    This comment has been hidden.

  • MobulaKuhlii Avatar

    Python, I've managed to get RuntimeWarning: overflow encountered in long scalars on the line with arr = in performance tests, where randint from numpy is used. I don't know if this can affect tests (mine passed), but this could be completely avoided by tweaking the numbers.

  • vasilev-gregory Avatar

    ok i dont get it, whats up with this test?

    Testing for: numbers = [12 12]

    Expected : 24 to equal : 12

    every other test is passed

    im on golang

  • gndumbri Avatar

    In the example, in the first step, the first transformation is derived by taking 21-9 and getting [6,9,12] from [6,9,21].

    Why isn't the second transformation derived by taking 12-9 to get [6,9,3] from [6,9,12]?

    If X[i] > X[j] is the condition, then why does the direction of the condition go from X[2] - X[1] (21-9) in the first transformation to X[2] - X[0] (12-6) in the second transformation when X[2] - X[1] (12-9) in the second transformation satisfies the condition and would mirror the first transformation?

  • amajlaton Avatar

    I finally wrote a solution for Python 3.6 that comes close enough to passing all of the random tests within the time limit, that I was able to succeed after attempting the same solution about a dozen times. Does this kata really need hundreds of random tests?

    Also the description is STILL wrong, the 12 in the example list should be 21. That made this kata really difficult to understand at first.

  • SinanX Avatar

    It should have been like this "X_5 = [3, 3, 3] # -> X_5[0] = X_4[0] - X_4[1] = 6 - 3" instead of this "X_5 = [3, 3, 3] # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3" in the example which is given in instructions. Second element of array is assigned according to the example: "X_5[1] = X_4[0] - X_4[1]". Then, if you look at the result, first element is the one which is assigned. "X_5 = [3, 3, 3]". Am I missing something?

  • madatx Avatar

    This comment has been hidden.

  • cuckookernel Avatar

    I think part of the problem with timeout is that the tester is printing out the whole array to the console when it says testing for... This slows down testing quite a bit when arrays are tens of thousands of elements long.

  • EmperorMigx Avatar

    I noticed most of the katas that I'm solving these few days have Time Out issues. Creating an excellent algorithm and minimal codes are extreme.

  • beniolenio Avatar

    This comment has been hidden.

  • s4pfyr Avatar

    I submitted a second solution, but instead of my solution, the provided template was accepted as a solution. All further submission yield the same result. https://www.codewars.com/kata/reviews/5bc56a4d7bf31df2f0000319/groups/5e7f5abbbe09b60001b2a92e

  • teoriachaosu Avatar

    That's a nice one! I don't see any issues here, my solution made it in less than 4000ms (Python version).

  • fregin Avatar

    Is it possible to do at Kotlin? Performance tests are real killers

  • CarloWood Avatar

    I am not happy. I spent a lot of time on writing a solution that is O(log(n)) because the description said it was necessary to write an efficient algorithm (and it should be); then I find out that everyone else wrote a simplistic O(n) "solution" and got away with it. :/ That is not right.

  • ctn Avatar

    Random test sometimes generate negative integer values, although description says there are only positive ints in the array.

  • lonkaan Avatar

    Oh boy, If only Euclid could live these days.

  • cloudbear Avatar

    This comment has been hidden.

  • ostolc Avatar

    While solving the Go version I calculate 10, it wants 3022.

    Testing for:
    numbers = [1369 1616 1 1 16 7 9 1 1 1]
    Test Failed
    Log
    
    Expected
        <int>: 3022
    to equal
        <int>: 10
    

    How on Earth is it supposed to be 3022? Aren't there any more transformations possible?

  • h5kosmos Avatar

    I have same problem, keep getting "STDERR: Execution Timed Out (12000 ms)" during the 100 random huge test. Passed all Assertation..

  • DeltaG Avatar

    Spent 15 minutes coding, and another 15 testing. Not sure if my solution in is correct and the tests are broken or if my solution is incorrect and the tests are broken. Either way it passed and failed randomly. I couldn't find any pattern, so I just gave up and submitted lol

  • SunMaster Avatar

    What is the size of the random testdata in the Python version ? I was curious about this when I was looking at performance in C (which seems to have sizes up to 1M).

  • SunMaster Avatar

    While solving the C-version I find rare 0 values in the array - maybe sometimes the last array-entry. I see also one other solution stating and handling this the same way I do.

  • user8436785 Avatar

    C# and Dart translations.

  • GertjanMonkeyProof Avatar

    This comment has been hidden.

  • Dk221 Avatar

    Python Version Times out all the time with random tests

  • Dk221 Avatar

    Works fine with another online compiler times out all the time here. Big issue with Python !

  • vedamire Avatar

    This comment has been hidden.

  • rowcased Avatar
  • fire74 Avatar

    This is wrong kata. My solution on Python3 passes 92-189 tests. Code: def solution (a): return 3 get "STDERR: Execution Timed Out (12000 ms)"

    My solution on Python 2 passes 209 tests and get "STDERR: Execution Timed Out (12000 ms)"

  • TheOriginalTripleD Avatar

    Could the Kata description at least be updated to show that, as of October 2019, no solution is possible with Python 3 so that others do not spend time on a Sisyphean task?

  • geosaral Avatar

    Something wrong with this kata. My solution passes 149 tests (100 of them "random, huge tests") and then stderr with timeout.

  • sokhenguchiha Avatar

    Max Buffer Size Reached (1.5 MiB) Everything is correct but this happend. Can anyone tell me why?

  • SamuelLevi Avatar

    In python, even with return 0, timeout is received :/

  • docgunthrop Avatar

    Go translation awaiting approval.

  • KamuiYato Avatar

    This comment has been hidden.

  • KamuiYato Avatar

    This comment has been hidden.

  • dolamroth Avatar

    This comment has been hidden.

  • Forkineye Avatar

    Using python, I keep getting "STDERR: Execution Timed Out (12000 ms)" during the 100 random huge tests, even with

    def solution(a): return 0

    which I'd assume should just tell me all the tests have failed.

  • karatedog Avatar

    It has a typo in the example: X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9 (12 should be 21) And 'i' and 'j' have no defined order (where do they start? Is 'j' always larger than 'i'? etc.), so I can chose any order I want. But if I can chose any, the first step in the iteration could be as well: X_1 = [6, 9, 21] # -> X_1[1] = X[1] - X[0] = 9 - 6, because all the written rules apply to it. I didn't check if the result would be the same, but this specification is ambigous.

  • Hippunky Avatar

    Well, I definitely made a meal of that one - having seen the solutions I need to kick myself in the ar*e big time!

  • midwayfair Avatar

    This comment has been hidden.

  • victorazzam Avatar

    This comment has been hidden.

  • ukirik Avatar

    There is something fishy with this exercise, or better put, with the test cases. I get it, the first couple of attempts may not be optimal but when I ran my solution on large arrays (in fact much larger than stated in the instructions e.g.:

    l = np.random.randint(np.iinfo(np.int64).max - (1<<62) , np.iinfo(np.int64).max, size=1000000)

    it still completes in about 5 sec rather than taking longer than 12000 milsec timeout claimed by the test platform.

  • cocoderrr Avatar

    That's crazy: when in Python I type a function that does nothing

    def solution(a):
        return None
    

    it times out!

    The test harness is so computationally expensive that it times out without the code even having the chance to execute.

  • misztijanos Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    This comment has been hidden.

  • Bustuk Avatar

    How many tests are there for Python? I've got: Test Results: Fixed Tests Should pass example tests (9 of 9 Assertions) Random Tests 100 random tests (100 of 100 Assertions) Performance Tests 100 random, huge tests (100 of 100 Assertions)

    and still error because of execution time

  • maxchiodo Avatar

    Poorely stated problem with typos in the example. Skip!

  • andrewkharook Avatar

    This comment has been hidden.

  • edper Avatar

    What does "When no more transformations are possible" meant? Is it when all numbers in the array are the same? Or is it when the difference to any pair of numbers is 0 or negative?

  • Cipiripi73 Avatar

    This comment has been hidden.

  • hobovsky Avatar

    It might be a language thing because I am not a native English speaker, but IMO description is horrible and for life of me I could not figure out what i and j are supposed to mean and how should they be picked.

  • zecatox Avatar

    I'm not sure I follow the example given, or how it fits the description. We're told to basically repeatedly compare each value to all of the others and take action depending on this comparison. But then then the example seems to be foccusing on comparing the largest value with the largest of all other values instead.

    For instance :
    X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9
    No care is given to x[1] being bigger than x[0]

    If I follow the "i,j" instruction, I would expect the process to look more like this :

    [6, 9, 21]

    (edit - note : I initialy misread the example so here I used 1 as first index instead of 0) First pass : x[1] < x[2] => . x[1] < x[3] => . x[2] > x[1] => x[2] = x[2]-x[1] = 9 - 6 = 3 x[2] < x[3] => . x[3] > x[1] => x[3] = x[3]-x[1] = 21 - 6 = 15 x[3] > x[2] => x[3] = x[3]-x[2] = 18 - 3 = 12 => [6,3,12]

    Second pass : x1 > x2 => x1 = x1-x2 = 6 - 3 = 3 x1 < x3 x2 == x1 x2 < x3 x3 > x1 => x3 = x3-x1 = 12-3 = 9 x3 > x2 => x3 = x3-x2 = 9-3 = 6 => [3,3,6]

    Third x1==x2 x1 < x3 x2==x1 x2 < x3 x3 > x1 => x3 = x3-x1 = 6-3 = 3 x3 == x2 => [3,3,3] => 9

    The result is the same, but the process isn't (probably longer) => and my problem here is I don't see how to demonstrate that the method used in the example will always give that same result.

  • MM95 Avatar

    I think something is wrong with Python tests. My solution times out and everytime on different step... One time it even passed... But i didn't publish it, and now i can't get it to pass again. I did the same kata in JavaScript and that was so much easier to pass with similar code. I even tried to take a solution from somebody in "Solutions" and run it and it didn't pass LOL Edit: It got 100/100 in performance test and still didn't pass, Codewars says timed out 12000 ms... I switched to Python 2 and it passed...

  • Malrble Avatar

    i have a problem with C++ 14: why the test case has the type of vector the error show like this: main.cpp:161:20: error: no matching function for call to 'solution' Assert::That(solution(arr), Equals(sol(arr))); ^~~~~~~~ main.cpp:54:15: note: candidate function not viable: no known conversion from 'vector' to 'const vector' for 1st argument unsigned long solution(const std::vector& arr) ^ main.cpp:171:20: error: no matching function for call to 'solution' Assert::That(solution(arr), Equals(sol(arr))); ^~~~~~~~ main.cpp:54:15: note: candidate function not viable: no known conversion from 'vector' to 'const vector' for 1st argument unsigned long solution(const std::vector& arr) ^ 2 errors generated.

  • ilar Avatar

    This comment has been hidden.

  • 7097511 Avatar

    I propose to add to the test a variant of the array that contains zeros ...

  • locorocorolling Avatar

    This comment has been hidden.

  • ilar Avatar

    If you update "Smallest possible sum" description

    from "if X[i] > X[j] then X[i] = X[i] - X[j]"

    to "if X[j] > X[i] then X[j] = X[j] - X[i]"

    then you can pass the first of BasicTests as follows:

    "Assert::That(solution({1,21,55}), Equals(3));"

    Please fix that bug.

  • stranger26 Avatar

    In the given example given in the instruction as shown below:

    X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9 X_2 = [6, 9, 6] # -> X_2[2] = X_1[2] - X_1[0] = 12 - 6 X_3 = [6, 3, 6] # -> X_3[1] = X_2[1] - X_2[0] = 9 - 6 X_4 = [6, 3, 3] # -> X_4[2] = X_3[2] - X_3[1] = 6 - 3 X_5 = [3, 3, 3] # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3 Shouldn't X_5 = [3, 3, 3] # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3's X_5[1] be X_5[0]?

  • Unnamed Avatar

    This comment has been hidden.

  • kdmatrosov Avatar

    Kotlin Translation

    Please review, and comment or approve.

  • monadius Avatar

    This comment has been hidden.

  • dke Avatar

    Not exactly 4 kyu or Maybe the idea struck my mind too quickly.

  • GiacomoSorbi Avatar

    Crystal and c++ translations kumited :)

  • henrywoody Avatar

    Adding a small line to define i and j in the description would help this kata be more quickly understandable. Just something like "X[i] = X[i] - X[j] for all i,j in range(len(X))" Maybe adapt to be less Pythonic and more general.

  • zarf Avatar

    The kata is interesting, but the description is very confusing!

    I'd replace with something like below:

    Basically you pick two non-equal numbers from the array, and replace the largest of them with their subtraction. You repeat this till all numbers in array are same.

    Method returns sum of all elements in the final array.

  • pra007 Avatar

    I don't uderstand the solution step.

    X_4 = [6, 3, 3] # -> X_4[2] = X_3[2] - X_3[1] = 6 - 3 X_5 = [3, 3, 3] # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3

    Here how x_4[0] is converting from 6 to 3. I don't see any x_#[0] = something operations.

  • dio5 Avatar

    Is i not coming before j?

  • kontic Avatar

    Who can not remember the basis of geometry must solve it with brute force (I was in last group :( ). I hope this is not spoiler. Tanks for great kata.

  • maltesh Avatar

    This comment has been hidden.

  • ggsdc Avatar

    Hello,

    I think some of the first 100 random tests in python are having some problems. I got this one for example:

    [9303875, 695795, 26566380, 23696555, 11215955, 32798000, 9456395, 28526355, 27082220, 2269355, 24552620, 2539520, 22499955, 12238955, 10478000, 30970395, 3772080, 2194955, 15477680, 17084720, 4322795, 33227195, 28926720, 4426955, 576755, 23939595, 15282380, 6705920, 4017755, 7777280, 26952795, 1227755, 4692780, 14418875, 3487500, 6966320, 10721195, 26438195, 28792955, 22264355, 19533875, 37519920, 23094380, 35119280, 6705920, 5954480, 403155, 1458395, 14230395, 25048620, 2700720, 3869420, 4426955, 15971355, 36010220, 17291180, 6138155, 5247680, 13580480, 35119280, 2307020]

    Where the proposed solution was 12, which it can not be, as the smallest solution for any test is the length, as that would be the resault in case all the numbers were reduced to 1. For this case then it would have to be 61.

    The solution I was getting is 9455, I now that is hard to check, because they are random test, but I have been having problems with some of them, when I copy them and try them in my python console I get the same result with different aproaches to solving the problem (older slower versions).

    Is there any way to check if the generation of the test is being done properly?

  • codeScholar Avatar

    "TypeError: Return value of solution() must be of the type integer, none returned".

    I checked and the type of the variable I was returning was "integer".

    I suspected the tests for php might be broken so I changed the last line of my function.

    The last line of my function now simply reads: "return 9".

    I'm still getting the exact same error.

    Am I correct in assuming the error is not all on me? I just started learning php last week and haven't been coding for too long so forgive me if I'm not seeing something obvious.

  • tandav Avatar

    Can anyone tell me the test inputs of the speed test.

  • donaldsebleung Avatar

    PHP Translation Kumited - please carefully review and approve :D

  • donaldsebleung Avatar

    Codewars Forums - Kata Best Practices - Have Full Code Coverage

    JavaScript and Python versions seem fine, but Ruby version is lacking in terms of code coverage (only < 10 fixed assertions in the entire test suite) which makes it prone to allowing logically flawed and/or hardcoded solutions to pass. Please either (1) increase the number of distinct, unique fixed assertions in Ruby to at least 20 and including edge cases, or (2) write 100+ random tests as per standard Codewars practice (and generally preferred over only 20+ fixed assertions)

  • donaldsebleung Avatar

    This comment has been hidden.

  • kingcobra Avatar

    This comment has been hidden.

  • xaylastavx Avatar

    I guess there is a typo in the description in the first test case, the last element in the initial array should be 21 and not 12 for it to work the way it's written.

  • juliano7s Avatar

    This comment has been hidden.

  • lechevalier Avatar

    Incomplete description: Explain that X[i] is the largest element of X and X[j] is the smallest one.

  • JohanWiltink Avatar

    Haskell translation kumited.

    Please review, and comment or approve.

  • mdw Avatar

    The instructions are way more complicated than the problem itself. In case it sheds some light to prospective trainees:

    Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required:
    
    if X[i] > X[j] then X[i] = X[i] - X[j]
    
    When no more transformations are possible, return its sum ("smallest possible sum").
    
    For instance, the successive transformation of the elements of input X = [6, 9, 21] is detailed below:
    
    X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9
    X_2 = [6, 9, 6]  # -> X_2[2] = X_1[2] - X_1[0] = 12 - 6
    X_3 = [6, 3, 6]  # -> X_3[1] = X_2[1] - X_2[0] = 9 - 6
    X_4 = [6, 3, 3]  # -> X_4[2] = X_3[2] - X_3[1] = 6 - 3
    X_5 = [3, 3, 3]  # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3
    
    The returning output is the sum of the final transformation (here 9).
    
  • rxe Avatar

    Hello - small typo on python sample tests :

    """ test.assert_equals(solution ([6, 9, 21]), 3) """ <- should be 9

    Cheers!

  • lolisa Avatar

    This is way too simple for 4k.

  • mtngrown Avatar

    This looks like fun, but I don't really understand the directions.

  • Cyhan Avatar

    Python translation added :)

  • raulbc777 Avatar

    Good kata. We should improve the instructions as it seems that the author isn't active at the moment.

  • user5036852 Avatar

    Nice kata. Thanks. But the description is really more difficult than the kata itself.

  • bellmyer Avatar

    Your example is a little unclear. In the first step [6,9,21] you subtract the second-largest number from the largest (21-9). In the next step, you subtract the smallest number from the largest (12-6 instead of 12-9). This made it difficult to understand what you wanted.

  • hh9 Avatar

    This is a good exercise, but I thought the instructions were difficult to understand and I think they need to be more explicit.