8 kyu
Count the number of cubes with paint on
4,403 of 12,177jackchambers
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.
I love this Kata. Although it is simple, it contains some math tricks.
I found the kata interesting, but I agree that the explanation could be clearer. I spent a lot of time trying to interpret the logic behind the examples and the relationship between cuts and red cubes. Perhaps including a more detailed visual representation or reviewing the description would be very helpful to avoid confusion, especially for those just starting out. However, I enjoyed the challenge of finding a solution! For those who are still stuck, my tip is: visualize the problem in 3D, this helped a lot in my case. 😊
if you wanna rid of novices, just tell us in description of this kata
I've been agonizing over composing a formula for a long time. I had to look at the solutions. The formula turned out to be quite simple :)
The description mentions 0 cuts. Many solutions will be invalid if 0 cuts were tested (python)
The real challenge here is to actually figure out wtf are you suppose to do..
The second cube in the picture isn't cut once, that's 3 cuts.. (2 as an X in the top and 1 through the middle) Furthermore it says 2 CUTS should provide 26 squares? And a cube has 6 sides: 4 on the side + top and bottom, if you cut an X into it like the second picture (which is neither 1 cut as per the description, neither 2 cuts as per the examples) that gives you 4x6 which is 24, not 26?
In the second image it is 1 cut by dimension, 1 in x axis, 1 in y axis and 1 in z axis. The last image with 2 cuts by dimension, you get 27 cubes, but you only have 26 with paint on them.
The color issue is really important! Then think about counting all the cubes! How to do it the easiest way. In the end, the solution will be in your pocket.
Scala translation
Approved
CoffeeScript translation
Approved
the picture was quite misleading , it would lead to count instead of visualizing what would have happen to cube after it gets slice
stupid explanation
The picture of the cube after 2 cuts indicates 27 squares not 26 so the information is misleading
Illogical because one of the cubes is at the dead center, surrounded by all the other cubes, therefore cannot have any paint on it.
I was tired so I didn't read the kata well I apologize for this
nah kata itself was worded wrongly
I have no idea.
As the picture shows, after each 'round' there are:
1, 8, 27...
squares. Which are the cubes of1,2,3...
(3**1=1, 3**2=8, 3**3==27
), so for the first time it's cutted 0 times, second time - 3 cuts, third time - 6 cuts.And, I have no idea from where it was taken 26 and 98 for sencond and fourth times, if each round consists of
+3
more cuts than in the previous round, so for the fourth round the result should be 81 not 98.Very good kata, but I think, it is more difficult than 8 kyu
ranks can't be changed
so much more, haha
nothing makes sense about this.img with 1 cut has 3.maybe it means 1 cut per axis or smthng. nevermind,im blind its there
Image of cube not loading even after multiple refreshes
It seems to work for some users, but not for others? It can be related to your ISP, can you check if the image appears when viewed over VPN, or from another network?
maybe it's a school network that thinks imgur is cool to block or maybe a country with a dysfunctional government (could arguably describe every government but some more so than others) this is the url: https://i.imgur.com/36x8Fkv.png
even ignoring site blocking, external sites isn't ideal, unless it's something super reliable like wikipedia
Badly explained. Worst kata i've ever done
was frustrating for me too, but I think it's a good Kata.
The explanation can be better and the images don't help so much, but the question is nice for practice. U need much more mathematics than algorithm
Unclear description. Cant even see the screenshot/image (broken link?)
why if 2 cuts it return 26(according screenshot)? it should return 25 because in my opinion we should count upper cube and center cube as not colored
Upper cube has paint in its upper face.
epta. we count only inside cubes
never seen such a badly explained kata before.
This comment has been hidden.
a good one
Rust translation
This comment has been hidden.
Approved!
Java translation
I can build websites, but I have dyscalculia and there's NO way I could even BEGIN to solve this kata, unfortunately. ):
awful kata, really. We are here for math or for coding? useless kata.
This comment has been hidden.
Description is not clear. &^%$^*!!
I had the same problem, but remember. Two cuts = side length is 3 small cubes.
The instructions says we should return the number of cubes with at least one red face... But, by the examples, I think it means to return the number of red faces.
No. See the last cube with 2 cuts per dimension, how many red faces do you see? There are 54. The example for 2 cuts is
countSquares(2) --> 26
That means the description is even worse than it initially appears. Nothing about this problem clearly states that we are counting how many red faces are generated per cut. See, I just did a better job right there... Even better would be to explain that by reiterating that the interior is blue.
That's not what I meant, I was talking about this part of his comment:
And I showed him it wasn't possible with the values in the examples.
The instructions state this:
And that's exactly what you should do.
I don't understand. According to the description of the kata, the test cases are wrong!
What is your question tho?
@hobovsky The description is very unclear. My question is, what does the description actually mean?
For example for
n = 3
, the is large cube is cut into 27 (= 3 * 3 * 3) smaller cubes. Of those, the one in the middle wasn't on the surface so doesn't have paint on it. The rest all have paint on it. So the answer is 26.Does this make this clearer?
I guess the natural question is, what would be the correct answer then and why?
Oh wait, I think I undestand now! Thank you very much!
This comment has been hidden.
TypeScript Translation
Approved.
This comment has been hidden.
There is no mistake, not all cubes have paint on them.
Yes of course! I said that my english is bad. "cut" and "paint"... If paint: it is looks like orange for example. (cuts+1) outter slice, (cuts-1) inner slice. Thank you!
JavaScript update
Approved.
I'm having trouble conceptually with the maths here, are there any good resources that can help me understand the inner square growth?
you are overengineering by calculating inner square. Try math induction, write down equations for 2, 3, 4 with X and look for pattern, then simplify equation
This comment has been hidden.
Python update (new testing framework)
Approved
I agree that this is not an 8 kyu. In terms of code - yes, but in terms of all the formula stuff and the way task is formulated - at least 7 kyu
I don't understand the descriptions well could anyone explain to me?
Just count the cutted cubes that dont have any red color. It means ignore smaller cubes inside cutted cube / edges.
Thets why math - is a queen of Science!
I was about to give up but somehow I solved it... good job
This comment has been hidden.
This comment has been hidden.
trueee lol xdd
Amazing!
Nice kata!
Python new test framework should be used
Done
Thanks!
JS Node 14 should be enabled
Description should be language-agnostic
It seems the description is now language-agnostic, so closing this issue now~
I've really liked that Kata. It wasn't simple, I needed some time even to draw these cubes and cuts, but only after that I've found the regularity of numbers which helped me to write a formula. Good luck!
SQL Translation
Approved!
Please add a fixed test for 0. Many solution wouldn't pass this.
done
Is it just me or others who are not able to see the image?
I can see it fine.
Он порезал куб, просто порезал куб. Не каждую грань а весь куб, как хлеб.
It could be intimidating for the first few minutes, but I promise you, solve it on your own and you will love it!
Please make a test for the case 0 cuts. Many accepted solutions do not account for that case and they output 2 insead of 1.
Already mentioned as an issue below.
Solved this without fully understanding the problem. Looked at the number of cuts and the resulting number of cubes and found a pattern that just happened to solve the kata. I'm not sure if this one is 8kyu worthy or not. In some ways it is because it's simple math operations. In other ways it's not because it's not to easy to determine what those math operations are.
at least 7kyu , not 8 ...it is hard for the 8kyu..
I really can not understand the problem, can someone explain it in basic English please
This comment has been hidden.
The case cuts=0 is not tested in Ruby and Python.
Also not tested in Coffeescript & Dart
This comment has been hidden.
NASM approved
Very nice kata! Thanks!
This comment has been hidden.
Why not 10 kyu then?
how the slices are cut... https://i.imgur.com/36x8Fkv.png :)
Description is not clever, Thanks for the pic, It helps me to understand the question, but anyway I solved this question by finding the pattern.
added to the description, thanks :)
Poor description IMO
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
done
This comment has been hidden.
This comment has been hidden.
I just translated this in Java if somone could approve it. Thanks
Rejected by someone
Just starting codewars, this has been the most challening to me, had to draw several cubes, cut them in the dimmensions and counting to establish a pattern, finally passed the tests
This comment has been hidden.
https://math.stackexchange.com/a/1874800 --> Gives you the math formula.
I don't get it. Could you guys please break this kata into pieces so that I can get it?
Haskell translation
Bump.
This comment has been hidden.
Thank you for this. I looked at the disourse section because I couldn't make sense of the task. I even tried to research the painted cube problem to no avail :D
C translation kumited
please scrutinize for approval
That was fun
Reason translation: https://www.codewars.com/kumite/5c83b8cf2313de3bf64a5287/edit Please approve it.
Can't. It's a kumite, not a translation.
I could paste wrong link: It should work: https://www.codewars.com/kumite/5c83b8cf2313de3bf64a5287?sel=5c83b8cf2313de3bf64a5287
Dude, you should leave a picture of how the Cube will be cut. Because for non native English speaker, your discription is so hard to understand !
I read it several times, and I still don't understand... Don't get the examples either... :D
Ok ! I got it ! For the future lost guys after me : You cut only once ! I thought it was 1 cut, then 1 cut, then 1 cut... In fact, you have the same big cube, and the cut results in many small cubes, in only one operation ; if cuts=1, then you cut in the middle of the cube, in three directions. If cuts=4, then it's like you cut it 12 times (4*3) at the same time. Good luck ! :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
For me this was way more harder than the 5 and 4 kyu katas... i'm really bad in math :,v
Are we here to learn programming or maths?
both i think xD
Wow! Definitely one of the hardest 8 kyu that I've done. Ditto that it should be a 7. The code is really basic but I had to draw a lot of thumbnails like others have said to figure out the math.
imho: this is 7 kyu. For me a 8 kyu has to be a problem that I can solve without thinking more than ~5 seconds after reading the question. For this problem I started drawing a thumbsketch before I got that first solution. Simplify to a good solution took even longer - is it just me, that does very little math in daily business? Don't even have matlab in current project :(
No, it's not just you who does very little math in daily life. I have an MSEE and there was a lot of math during those studies, but as a software tester and I use math almost never. This problem seems like it belongs on Project Euler.
That was fun. -And first time I made a thumbsketch for a 8 kyu kata.
Initially I misinterpreted the description and went in a totally wrong direction. A simple example picture of a sliced cube would have helped me alot!
This comment has been hidden.
This comment has been hidden.
C++-Translation kumited!
Please check it and approve. Thanks! ;)
Approved
Very nice kata. ;-) Thanks!
This comment has been hidden.
This comment has been hidden.
C# translation submited, please approve :)
I previously made this one on Python, but I was having problems with C#'s version :( I'm learning the language, I got errors like "error CS0266: Cannot implicitly convert type 'double' to 'int'" Any suggestion that anyone could give to help me out? Thanks in advance :)! Great kata btw!!!
When using babel fallowing error occurs : ReferenceError: i is not defined at Object.Test.it at Object.Test.describe
The description is a little vague, it should be "subdivide the cube into cubes by cutting through the cube n times in each of the 3 dimensions." But, this is not a coding problem, it's a simple algebra problem. I don't see a way to make it an interesting coding problem.
This comment has been hidden.
Hi Sabry,
Thanks for your comment. In particular, which part of the description do you feel is lacking in detail? Would be good to know where you think it could be improved :)
I have reworded it slightly now but your input could help further.
Hi Jack It is much clearer now. Would it be better to say " ..cut through the cube in all three dimensions a number of times.."?
Many thanks.
Sabry
Hi Jack It clearer now. Would it be better to word that part as such: "..cut through the cube in all three dimensions a number of times..."?
Many Thanks.
Sabry
Agreed, I have made that change also!
Hi Sabry,
It seems to be stuck waiting for the issue to be resolved. I see above that you have marked it as resolved but could you please check if it requires marking still :)
Ruby translation kumited. Random tests up to 1000 cuts.
Python translation kumited. Random Tests added up to 1000 cuts. Hope you like it. :)
Hi Raul, translation looks great! I just tried approving it, but I changed something very minor in the original description and I am now being told that this change must be merged before I can approve yours.
Ok. Let's see if I can do something to solve that
This comment has been hidden.
So I have managed to approve the ruby version, but it seems the python translation has dissappeared?
This comment has been hidden.
Great! Now done :)
Due to the sheer number of fixed tests (well done :D ) I won't be raising this as an issue but it would be great if you included some random tests as well as fixed ones :)
Hi,
Thanks for the suggestion :) I will definitely add this, just need to look into how this is implemented as this is my first kata.
Jack
Random tests now added!