6 kyu
Playing on a chessboard
153 of 4,501g964
Loading description...
Puzzles
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.
C fork
static
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.
this whole thng can be done with simple trial and error.
if it doesn't have 8 rows and 8 columns, it is not a chessboard
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )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 :)
a lot of the people on this platform don't know the math, it is very hard for them
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?
you shouldn't need any loop, for this task.
You don't need looping, examine the pattern first.
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.
COBOL translation.
approvable
Approved.
This comment has been hidden.
Everything is "just a maths/strings/memory/recursion/algorithm problem" if you know what to do - but that's precisely the point: figuring out is the hard, and therefore interesting, part of any kata.
Therefore please don't spoil, and also this isn't a Suggestion (a comment that you think would improve the kata in some way).
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
done, except for ruby
done for Ruby too
Why, when n = 1, the answer is 1 / 2. We need the first row completely, not the first element?
For n = 1, the board is 1 x 1 (one row, one column). The only fraction on the board is 1/2.
Thanks! I was thinking all the time 8 x 8
Didn't understand the concept of a party and what is the essence of the task?
Is this comment on the right kata? I don't see anything about a party mentioned in the description.
English is not my native language, I'm sorry. Party = Game
The game is the act of putting all the fractions on the board. The task is to find the sum of the fractions on the board.
Agreed, question is very poorly worded. Thanks @user9396321 for the simpler explanation.
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
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.
Thats a really good advice, thank you! I was boldly trying my solution for PowerShell and always takes too long!
the whole thing can be doe using trial and error
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!
tbh, i just did it using trial and error, i dind't know the math either
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.
It's a very simple thing to program given you know the pattern. In fact, that's true for almost any codewars problem. If you know or understand the problem, it should be quite easy. This problem is just particularly easy because it's only one to two lines.
Why are programmers so like "Oh it was so easy, I did it in 10 minutes..."
I'm a 1Kyu, so not stupid but I've spent a couple of hours on this and can't solve it. It's obviously a math problem, not a coding one.
A formula or pattern or what have you can be elusive. I'd say it's harder then a 6kyu.
Hi5 Davo36!
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.
I suppose nothing will go wrong... OK thanks!
This comment has been hidden.
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!!!!!
That's exactly why you have to calculate the formula on paper beforehand.
Didn't know this mathematical identity, thanks!
To any struggling coders, there is a very simple pattern that can be observed from the test cases and used to solve the kata.
Good kata. The description is really clear. Kata is simple if a little bit think
cant believe it took me so long to see that pattern. sometimes it helps to move away from the screen. brilliant kata
I just noticed a pattern, although I realize that it can be derived mathematically. I was lucky :)
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
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.
Great kata
Thanks!
Missing
begin
in the Pascal initial solution.Fixed, thanks!
great kata. bad decsription.
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
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.
I want to agree with you, but if the description was any more clearer, the answer would become obvious (as this kata is rather easy once the pattern becomes clear).
Some opacity is necessary by design.
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.
The only reason I was able to solve this was because of the test cases. I have no idea what this is actually asking....
I love this so much
Hi, racket version is missing
#lang racket
header!Fixed, thanks!
Honestly, thank you for the test cases. If you didn't give any I would have died.
This comment has been hidden.
Thanks!
It should note there are performance requirements, as large boards will be used.
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.
Thanks for the hint.
You are the real MVP.
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.
This comment has been hidden.
I saw it many times and didn't want to solve it. I wonder why... Merci beaucoup pour ce kata. :) Très interessant!
Thanks!
This comment has been hidden.
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".
Why primes?
because it is about finding factors, right? I forgot :)
You don't need primes to find factors.
This comment has been hidden.
The tests are correct but you are not!-( You are the only cheater amongst the 191 guys who passed the C++ translation.
Obviously I'm not correct. I just stumbled upon this "solution". If the tests are correct then something else must be wrong, though not necessarily your code, could be the website. An exit(1) should not result in a successful test (unless that's the answer).
It's not a problem of the kata. Report it as a bug: https://www.codewars.com/topics/bug-reports.
This comment has been hidden.
Some languages are easier than others but the kyu, given by a moderator, is the same for all languages...
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?
When you ask for an answer, don't post an issue but a question. Maybe your code is not fast enough or today CW is too slow.
I felt like I should reply, so that I don't confuse anyone! I investigated further and found my mistake. I am sorry for posting an issue prematurely!
Thanks!
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.
Getting a failed test: Test Failed
actual
not equal to c(0). 1/1 mismatches [1] NaN - 0 == NaNGentlemen, any suggestions??
This is not coding task but pure math. Smart though!
That comment is almost a spoiler :P
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 :-)
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?
seems you're storing too much data: inputs can be very big, here, so if you store a list the size of your input... (for example)
This comment has been hidden.
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?
This comment has been hidden.
This comment has been hidden.
You guys couldn't just stick to monopoly?
This kata is more about math than about coding as the coding part is for beginners...
This comment has been hidden.
This comment has been hidden.
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
How do I get the test cases used in the attempt ?
This comment has been hidden.
Draw a picture and add stuff up by hand. It's much easier then.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
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.
Well said!
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!
Took me a while to figure out how NOT to do brute force
This comment has been hidden.
Please which language? A request timeout is not the fault of the kata (so it is not an issue) but a problem - as it is said - of server load at CW. Post a bug if you want: https://www.codewars.com/topics/bug-reports or be patient and try later:-)
Javascript. And sorry, I pasted the wrong error message. The correct one was this:
The server attempted to execute your code but there was an issue with the request. This should be a rare issue. Please try running your code again. If the issue persists, please contact us.
So not a timeout issue, but a issue with the request itself as it seems. I tried running the same code on the server multiple times now, every time the same message.
I just tried a few different solutions and all worked fine. Try again but before that verify your code (infinite loop or...).
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!
This comment has been hidden.
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.
perhaps you can paste your code here(Mark as having spoiler content) and ask someone to help you ;-)
and in fact, this kata did not need more calcute but need more thinking ;-)
My code can deal with game(500000) in 5s. It's not that slow for an O(n) implementation of Python.
I know may be there is a way (or many ways) to optimize. But it's not the problem.
I want know the RANGE OF DATA!
If n is 10 or less, an O(n^2) solution is fine. If n is about 10000, an O(n) solution is enough. If n is greater than 1e7, an O(1) solution is necessary.
I'm fully aware the rules of solving algorithm problems. I'm experienced.
But I hate to rewrite to code again and again, because the the f* website hides the range of data.
At the very beginning, I thought the largest n is 8!
I'm really really depressed by what the problem I'm suffering here.
maybe you need an O(1) solution, the point of this kata is not calculate, is find a simple way to get the result.
For example, you want to calculate the sum of 1 to 100, you should not write:
you only need write:
You need find out a formula ;-)
I love the programming 101. Thank you!
There is not any hint or clue indicates that the n will greater than 3e6. I have to use my imagination to find out what time(or space) complexity is really required for this problem.
If it can't be described as confusing, I think the only word can be used here is - ridiculous.
This comment has been hidden.
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?
This comment has been hidden.
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.
The new version of C# put by CW is tighter... I suppressed the `Suite2Tests.randomGenerator' so there are no more warnings about that. Nevertheless since the compilation succeeded (it was only a warning) I fear there is a problem in your code. Please keep me informed.
I have this error too, even though I haven't written a single line of code. I tested on C# 10 and 8.
I tried your "solution". All I get is:
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?
It's not an issue of the kata! Report at CW as a bug.
Sorry man, didnt know the rules. Great Kata btw.
Thanks!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
[[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?
Please which language, Java? What is your input, what is your output? The brackets inside brackets usually mean where you have it wrong. It is how Junit works, not very clear but it's not my responsibility:-)
I got it already, found the bug in my code. thanks for your comment, by the way!
Very nice Kata!
Thanks for the encouragement!
This comment has been hidden.
Thanks for the feedback!
wow
I always overcomplicate things.
I love this problem. Great lesson, nummeric solution is so easy and clear, when brute force just doesn't pass testes!
Thanks for your feedback!
Yes, great lesson!!
Thanks!
This comment has been hidden.
Thanks for the feedback!
This comment has been hidden.
This comment has been hidden.
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.
It's not an issue! Rather a question!-) The sum of the numbers on the chessboard is 1/2 + 1/3 + ..., not the sum of the numerators or of the denominators. Here a number is a rational. Do you understand? If not, ask again.
This makes it more clear! I think my confusion stemmed from the idea of monopoly currency being mentioned that isn't compatible with fractions.
For final clarity for anyone confused like me: Add all of the fractional values on an n by n sized board and print the answer as a simplified fraction.
This problem is suddenly more interesting to me now. Thank you for the clarification.
I added your text... for final clarity:-) Thanks for the feedback!
This comment has been hidden.
Which language?
Ruby
Biggest n is about 3*10^6.
solution140312
to hide your function, since Haskell exports only what's listed in the export list.testGame
doesn't provide any valuable output beside "Expected: " and "actual" iff the test case failed. Consider usingprintf "should return the correct result for %d" n
instead.Don't you remember? I had printf with input (and output as far I remember) but you told me it was useless because when the tests failed users could see expected and actual. In a few kata I put a comment before the printf... So what must I do?
I found
solution140312
rather funny. Some time ago I didn't use things like that but MANNN... (I believed) showed me tests with these hidden names and from time to time I use them. Certainly useless but harmless too.That was probably a misunderstanding. If you use
property
, QuickCheck will show you the randomly generated values that failed the test. However,shouldBe
andit
won't show you the input for the function. That's why I suggest you to add it to yourprintf
, that way a user will know on which argument he failed.Here's the rationale: (almost) all other languages have
console.log
or similar, so you can always check the function's input. However, regular Haskell function's don't allow side effects. One could importSystem.IO.Unsafe
to useunsafePerformIO (print args)
, but that's messy. And that's why I suggest you to print the used arguments if you useprintf
do begin with.Yeah, the scripting languages need obfuscated function names, unless you put your solution into a local scope, so I understand where that comes from. By the way, MMMAAANNN's name is super easy to remember: every letter is there exactly three times :D. Either way, it's all just a suggestion, not an issue.
I will remember that in fixed tests I have to
printf
inputs. It's easy for numbers or strings, for lists I have to useshow
I suppose.Yeah,
show
is more reliable and doesn't need an additional import:I saw my name here :)
I must say that the main reason for adding random numbers to variable/function names in my katas is not to hide something from anyone, but to avoid collision with a possible choice of variable name by codewarrior in his/her solution. I had a couple of bugs with variables named
i
in my test fixtures, that's how I came to this habit.Thanks for your post!
BtW does somebody know what are "Achievements" in "Honor Breakdown" on the "Profile" page?
This comment has been hidden.
This comment has been hidden.
Without brute force it's even shorter. Thanks for your approval!
With brute force is probably not doable in the allotted time :D
And of course I finished it with a one-liner after I got the logic of it.
Thanks to you for your work :)
As for strings, @bkaes is rather unfair. Does he know and do you know my statistics about kata with strings and kata without?
Not sure why bkaes is quoted there, but if I may throw my 0.02€, often taking input from string or putting it into them is a rather meaningless chore which adds nothing to the fun.
Often, mind you: in some kata it makes sense (particularly taking, if you have to parse some nasty input strings), but otherwise I see little use for them and possibly even a waste, as CW luckily allows us to output data in many more formats.
That said, hey, I know I am only a guest benefitting from the gift and your work, so take it only as a honest feed, not certainly something that comes with bitter feelings or ungratefulness :)
This comment has been hidden.
In fact the "game" is useless. You should have realized that it only serves to present numbers on a chessboard with a funny property when you want to calculate their sum. Hint:
When you have understood the problem for 8x8, add a row and a column, fill them with numbers following the same rules as for a 8x8 chessboard. Now you are ready for a nxn chessboard. There are no spaces, no token to move around, the result depends heavily on n. Have a good day.
PS: it's useless to say that a description makes no sense:-)
I still don't get it. Moving on
Why not simply
Ratio Integer
in Haskell? Why even the special case about a denominator with1
in any language?Why not
Either Integer (Integer, Integer)
? Is it bad practice? Maybe I wanted to stay close to the other languages that don't have fractions. Why a special case about a denominator with1
? Because I thought one doesn' write5/1
but5
.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 ;-)
Thanks for your feedback, the description says:
I thought it meant: "'game' returns a string that mimicks the array returned by the other languages". I'll change this part.
The complicated return type is just tedious and IMHO doesn't add anything to the puzzle. Why not just return a tuple (in Haskell)?
In Python tests, if you just replace
print
withTest.describe
andTest.it
, it will work the same but with nicer output.Done.
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?
You are right, I pasted a bad row, thanks! Corrected.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.