6 kyu

Playing on a chessboard

153 of 4,501g964
Description
Loading description...
Puzzles
Fundamentals
  • Please sign in or sign up to leave a comment.
  • trashy_incel Avatar

    C fork

    • it is explained what kind of pointer to return
    • better assertion messages
    • making the reference solution static
    • initial code no longer crashes
  • phaul Avatar

    This has confusing instructions. I don't mind the chessboard story or what's there but what's missing. There should be some explanation that you expect the results in a rational representation. It shouldn't be a guesswork that the returned array represents a rational number. I did go, and []int is not a natural way to express rationals.

    ok admittedly I haven't read the instructions for other languages which have a hint. I rephrase the suggestion as mentioning this as a language independent requirement at the top.

  • emanresu2 Avatar

    this whole thng can be done with simple trial and error.

  • emanresu2 Avatar

    if it doesn't have 8 rows and 8 columns, it is not a chessboard

  • ilikechocolat Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    C#: method name should be PascalCase (Please refer to implementation of backward compatibility here )

  • elrouss Avatar

    As some have written here I think this is kata 8kyu, not 6kyu. To be honest I didn't understand the description at all, just looked at 4-5 tests and in 10 minutes found the regularity which helped me to write the formula (and it's just 1 line). There are much more difficult tasks than this one :)

  • FATrOckMAn47 Avatar

    my code passes all tests to attempt 9 then times out, im not using a complex solution but i am using numpy for its arrays could this be the reason?

  • vmbot Avatar

    LMAO that was a hillarious solution... if only i didn't suck at math, could've figured it out in a sec. But seriously, question needs to be worded better.

  • akar-0 Avatar
  • ionling Avatar

    This comment has been hidden.

  • ejini战神 Avatar
    • Node 12 should be enabled (Refer this and this for more info)

    • Python new test framework should be used (Refer this & this for more detail)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

    • Typescript 3.3 or above should be enabled, refer this for more info

  • Feldman87 Avatar

    Why, when n = 1, the answer is 1 / 2. We need the first row completely, not the first element?

  • Feldman87 Avatar

    Didn't understand the concept of a party and what is the essence of the task?

  • gyrocosec Avatar

    I get the first two test right cause thats ok

    but then for an 8 by 8 grid

    it returns this massive fraction that is basically 32 but not quite as a fraction

  • _SOliD_ Avatar

    If you struggle with making your algorithm fast enough like me to pass the attempt tests, but are able to pass the normal tests, try to loop through every possible input from 1-10 or more and analyze the outputs to find simularities on them. Than you will realize the way to optimize your algorithm.

  • _SOliD_ Avatar

    I was having a hard time with this Kata, almost wrote a fraction library to solve it, but couldnt do it. Than i looked at the solutions and was devastated on how simple and good they were, after that i could see it myself in the test cases... But i wonder if you could find it out without them, my mathematical knowledge is pretty basic to bad. Is there anyone who accelerate or is smart enough in this field to give me a math breakdown or direction to look at for this? eager to better my logical and mathematical understanding!

  • aliasfox Avatar

    Maybe I'm wrong or it's just beause I did it in Python, but this doesn't seem like a 6 kyu. Perhaps I noticed the pattern/math too quickly but it feels more like an 8 kyu (maybe 7). But refactoring it was run regardless.

  • Twilight_Sun Avatar

    There was a bug in random tests for TypeScript - all 50 tests was with the same number, so I've fixed that. Hope hothing went wrong.

  • Antiherot Avatar

    This comment has been hidden.

  • Victor_F_Lurx Avatar

    Bad questions. If you don't use math skills to compute everything on paper or tablet, your code will never run successfully within only TWELVE SECOND!!!!!

  • RealKenshiro Avatar

    Didn't know this mathematical identity, thanks!

  • sbkn Avatar

    To any struggling coders, there is a very simple pattern that can be observed from the test cases and used to solve the kata.

  • SentAnestaun Avatar

    Good kata. The description is really clear. Kata is simple if a little bit think

  • dogma-n Avatar

    cant believe it took me so long to see that pattern. sometimes it helps to move away from the screen. brilliant kata

  • AlisaIsStillGodly Avatar

    I just noticed a pattern, although I realize that it can be derived mathematically. I was lucky :)

  • The_Paradox Avatar

    I was stuck on this forever until i realised a very neat trick that made it work with ease. Excellent Kata, just like all the others

  • skman Avatar

    In case someone is struggling with this, note that this essentially tests you skills in mathematics, specifically summing the fractions. Coding part is elementary. Best to work out using a pen and paper testing out some small input values.

  • Rud1 Avatar

    Great kata

  • Unnamed Avatar

    Missing begin in the Pascal initial solution.

  • raveneer Avatar

    great kata. bad decsription.

  • BohdanKh Avatar

    ChessBoardCases testBasics Log Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 266240 bytes) in /home/codewarrior/run.php on line 13 I get this when test results were passed

  • Rahul240499 Avatar

    All these puzzle related coding questions are really great but I request the kata sensei to please elaborate the question and mention some examples for it as it's pretty hard for most of the guys to understand it.

  • dbchristopher Avatar

    Maybe the most confusingly written instructions I've ever come across. Eventually gave up because I couldn't make sense of what they were actually asking.

  • xxmecmxx Avatar

    The only reason I was able to solve this was because of the test cases. I have no idea what this is actually asking....

  • StalkOfLeaf Avatar

    I love this so much

  • drcz Avatar

    Hi, racket version is missing #lang racket header!

  • krishp Avatar

    Honestly, thank you for the test cases. If you didn't give any I would have died.

  • Tosunami Avatar

    This comment has been hidden.

  • cliffstamp Avatar

    It should note there are performance requirements, as large boards will be used.

  • GabrielSaul Avatar

    The most simple answer is usually so blindingly obvious, it becomes almost invisible. A great kata that tests your observational skills more than anything else.

  • user8531172 Avatar

    I think it might be a good idea to mention/point out in the description that there are better ways to solve this than brute force (no need to tell anyone what that/those is though), but otherwise I think this is a good kata. I had a feeling straight away when I saw the description that there had to be an easier/faster way than brute force for this, but I didn't know it immediately. As someone else pointed out below, it's best to start writing this out and examining what the result is. Or actually, in this case, since we're working with grids of numbers, firing up your favourite spreadsheet program might be a good idea.

  • bmalloy0 Avatar

    This comment has been hidden.

  • raulbc777 Avatar

    I saw it many times and didn't want to solve it. I wonder why... Merci beaucoup pour ce kata. :) Très interessant!

  • paulc Avatar

    This comment has been hidden.

  • ahmose231 Avatar

    I am trying to solve it in C. I pass the first 2 tests but that's all. I am simplifying the fraction using a list of primes. My primes list is an array of 5000 integers. Could it be that it is not long enough? If I increase the array to 10000 then I get the error: "12000 ms, stopped".

  • Vokda Avatar

    This comment has been hidden.

  • shingtaklam1324 Avatar

    This comment has been hidden.

  • HenrikW Avatar

    Hello!

    I seem to have an issue. When I try to submit my solution (C language), it passes the 9 tests but it says that the process was terminated because it took longer than 12000ms. However, I logged n in these 9 tests and tested them in "Run Sample Tests". These times are no way near 12000 ms, "Time" in the upper left corner says 8ms and the log says "Completed in 2.779694ms". Any suggestions?

  • AurevoirXavier Avatar

    Great kata! Some people say this is a pure math kata (because you have already know this). In my opinion, just use a pen write down some example, you will find it rhythmical. Just try it first. As a developer you should use your observation ability first, rather than relying on the formula.

  • vikash_124124 Avatar

    Getting a failed test: Test Failed actual not equal to c(0). 1/1 mismatches [1] NaN - 0 == NaN

    Gentlemen, any suggestions??

  • HugoHub Avatar

    This is not coding task but pure math. Smart though!

  • Shebnik Avatar

    I pass all final tests except n=120000 Then I am getting "Error. Expected [7200000000] but got [1174620937839339520, 107042550662101]"

    is 7200000000 really correct value?

    Update: it was my fault with overflow. COrrected by further simplifying computations.

    P.S. damn... even after simplification it was brute force :-)

  • datapygirl Avatar

    I have problem with this warning: Traceback: in in game File "/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py", line 192, in ones a = empty(shape, dtype, order) MemoryError

    Is anybody who can explain me why my code is braked on test 10?

  • pladdy Avatar

    I hacked my way to solving it and looked at some other AWESOME solutions (well done all). I don't get this though: For n = 3, when I add the fractions up by hand I get 4.5, not 9 (3 * 3). What am I missing?

  • adrianhorning08 Avatar

    You guys couldn't just stick to monopoly?

  • JToulouse Avatar

    This kata is more about math than about coding as the coding part is for beginners...

  • Decimater Avatar

    This comment has been hidden.

  • Dworin Avatar

    This comment has been hidden.

  • tommie@berry.org Avatar

    I got this to work nicely and I believe it is correct, I even pass the first 8 tests, but it times out on test 9. Can someone tell me the n value for Test09 ? Test08 looks pretty fast to me, 62us? Log n=5014 ✔ Test Passed Completed in 0.062342ms

  • unclesnottie Avatar

    Draw a picture and add stuff up by hand. It's much easier then.

  • jdobrowner Avatar

    This comment has been hidden.

  • mn113 Avatar

    One that's actually easier to solve with a pencil and paper, than having access to the power of a programming language. Proof that computers make us all dumber.

  • PiotrGrzybowski Avatar

    Great Kata! A Stunning example which showing that even a very fast computer is too slow to execute unefficient algorithm. It took me quite much time today, at the begining I was happy with my O(n) complexity but it still wasn't enough, I finally noticed something and solved that as author of Kata. Goodluck to everyone!

  • rveshovda Avatar

    Took me a while to figure out how NOT to do brute force

  • DonHaron Avatar

    This comment has been hidden.

  • Eihcir0 Avatar

    I did it the brute force way quickly and it didn't pass. I was up late and tired but I really wanted to solve it. I came up with something that worked after doodling on a napkin but I missed the super eloquent 1 line solution!

  • Wizmann Avatar

    I implemented an O(n) solution with Python, but I got TLE. I really don't know why my code runs so slow, and of course, I have no idea about the upper bound of the input n.

    I'm depressed, by this problem, and by Codewars. I don't have enough information for solving the problem. I don't think it's a good idea to hide (or just ignore) the essential information for problem solving.

    Codewars is not a coder friendly online judge system. Let aside the confusing output format. (gosh)

    I'm confounded.

    I quit.

  • voncay Avatar

    This comment has been hidden.

  • DrMueller Avatar

    Can't get this going in C#, always way to big numbers, I even implemented my own Fraction-Struct. Probably I didn't get the Calculation of the Chess-Field right: Is my assumption right, that if the Chess-Field had the value 40, the last would have the Values 40/80?

  • levannar Avatar

    Hello! I tried to submit my solution, but the tests don't run. It says,

    Compilation succeeded - 1 warning(s)

    {"stdout":"","stderr":"/tmp/csharp116421-21-1b4kzjp/fixture.cs(8,8): warning CS0414: The private field `Suite2Tests.randomGenerator' is assigned but its value is never used\n","wallTime":0} Unknown error

    Since it's "unknown", I can't possibly figure out what's wrong with my code.

  • le0 Avatar

    I have finished this Kata ( submited successfully) but still "Solutions have been withheld. Since you have not yet solved this kata we have hidden the solutions from you....." is here when I wanna check other's solution. Any idea why?

  • Kokolo Avatar

    This comment has been hidden.

  • LoveYinger Avatar

    [[9000006]000001, 2] It was one of the output, so what does it mean? Why are there [] inside of []? I am thinking it may be too big or what?

  • HugeEuge Avatar

    Very nice Kata!

  • niekvanderreest Avatar

    This comment has been hidden.

  • javafan Avatar

    wow

  • mohchari1 Avatar

    I always overcomplicate things.

  • medve Avatar

    I love this problem. Great lesson, nummeric solution is so easy and clear, when brute force just doesn't pass testes!

  • kolinlob Avatar

    This comment has been hidden.

  • jpot Avatar

    This comment has been hidden.

  • howaldmg Avatar

    I've started looking at this one, but I'm having trouble understanding what is being asked.

    I've setup a function that will calculate the sum of all of the denominators and all the numerators for an arbitrary n. When I expand to the n = 8 example, the test is not passing. I assume I'm just not understanding what we're supposed to calculate. When you say:

    "When all numbers are on the chessboard each in turn we toss a coin. The one who get "head" wins and the other gives him, in dollars, the sum of the numbers on the chessboard"

    which numbers do you want summed?

    Thanks for the help in advance.

  • AlexHandy1 Avatar

    This comment has been hidden.

  • bkaes Avatar
    • you don't need to use a name like solution140312 to hide your function, since Haskell exports only what's listed in the export list.
    • your testGame doesn't provide any valuable output beside "Expected: " and "actual" iff the test case failed. Consider using printf "should return the correct result for %d" n instead.
  • GiacomoSorbi Avatar

    This comment has been hidden.

  • cjuehring Avatar

    This comment has been hidden.

  • bkaes Avatar

    Why not simply Ratio Integer in Haskell? Why even the special case about a denominator with 1 in any language?

  • AStoe87 Avatar

    You must be a genius... it took me a whole day to find a fast way to get the result and still you offer easier solutions :-D I did the kata in "Java" and at the beginning I only read the general Instruction and the hint for "Java" and had no clue that you expect fractions (that information is listed as hint for other languages)... maybe you could change the description so that dummies like me manage to understand your description straight away ;-)

  • bse Avatar

    The complicated return type is just tedious and IMHO doesn't add anything to the puzzle. Why not just return a tuple (in Haskell)?

  • MMMAAANNN Avatar

    In Python tests, if you just replace print with Test.describe and Test.it, it will work the same but with nicer output.

  • MMMAAANNN Avatar

    You describe chessboard as 8 x 8, but it looks like it actually has 6 rows. If it had 8 rows, the last would be 1/9, 2/10, 3/11, 4/12, 5/13, 6/14, 7/15, 8/16, if I got the pattern right. Or am I missing something?

  • Abbe Avatar

    This comment has been hidden.