Beta
Balanced centrifuge configurator
Loading description...
Algorithms
Puzzles
Mathematics
Combinatorics
Arrays
Performance
Algebra
Dynamic Programming
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.
This comment has been hidden.
This comment has been hidden.
Thanks for solving my hard beta kata's.
Quick question:
Is there a number on the max number of colors used? If yes, it might be worth to mention it in description.
Or is the kata accepting the following solutions for
n=6, k=6
?[1, 2, 3, 1, 2, 3]
[1, 2, 1, 2, 1, 2]
Also do you plan to port this kata in Python?
Both solutions are accepted. There is no limit. I could try to port it to Python, unless lachesism wants to have a go at it. Whoever makes the translation, the algorithms used by lachesism and gpittarelli should pass in less than 2 seconds consistently when translated to Python. Any solution using a backtracking algorithm on updating and resetting colours on an array should time out. Also, smart usage of libraries such as numpy, gmpy2 and scipy should not be rewarded.
Thanks, any news about a port in Python?
You should poke lachesism, not sure he's on Discord. For me it would be a hell getting performance constraints correct in Python.
Some thoughts to improve random tests:
Generate balanceable test cases proportionally to unbalanceable ones.
Generate balanceable test cases proportionally based on the properties of
n
andk
.For example, the number of distinct prime factors of
n
and whetherk
can be represented by two distinct prime factors ofn
.by represented by two distinct prime factors, do you mean
a * p1 + b * p2 = k
?Yep.
added biased and unbiased random tests
The regular polygon requirement seems more restrictive than the original conjecture.
I have the following examples of my brute-force program that can not find a configuration that satisfies the regular polygon requirement.
Could you verify them?
Yes, this kata adds an additional restriction. You will not be provided with such test cases that you pointed out above.
Now I'm curious how you did that. 🤔
This comment has been hidden.
This comment has been hidden.
I have more time at the end of the week. Feel free to suggest a fork, you will remain eligible for rank/honour because you solved the kata. EDIT: let's wait some more submissions, it seems to be already very hard to solve ...
My solution is correct. I have seen it pass 430 tests before timing out ( though it often does fewer ). I am not interested in rewriting it for performance.
This is not an issue, a suggestion, or a question. I just wanted to tell you.
This comment has been hidden.
I haven't solved, so I can't read spoilers ( as of now, nobody has, so nobody can ). :]
Oh yeah :) Does your solution create the resulting array just once, or are you updating elements and backtracking all the time?
It's updating and backtracking. I told you I'm not interested in performance. :P
I have now seen it pass
447
tests and still time out. ( I've never seen the5 000 - 10 000
category, if that exists, though. ) You may want to be more precise about your number of tests spec.I was hoping to time out such solutions as the intended solution creates the array just once, without ever having to backtrack on it. This is possible using some fields I added in the tags. I'm surprised your solution almost passes though. I might need to tighten the random tests, as the ref sol still has lots of time to spare. I will update the description with a better spec of number of random tests.
It's possible I would never ever pass the largest random tests, but I have no way of testing that ( beyond forfeiting ). But you have my solution, you can test with it yourself.
Fair game, for a kata targeted at 2kyu. :]
I will definately play with your solution while awaiting other solutions. If it's fast enough to solve the biggest cases after some refactoring, I might even decide to lower perf constraints. For the moment, I keep constraints as they are. We're still in an early stage where we could still end up anywhere from 3 to 1 kyu.
I might try memoising my solution. I'm not very interested in using number theory to structurally speed up my solution, but using memoisation to speed up the backtracking is straight up programming, I can do that.
ok have fun :)
it's not doing anything
I did get to test
455
just now, I think4
tests completed in5 000 - 10 000
?I did not have that much time left for the biggest tests, so one of these days I might get very lucky and pass all
460
tests. My solution is definitely somewhere in the right Big-O complexity, it's down to micro-optimisation. If someone can find the right memoisation, it would probably fly through the tests.Well, you are very close to passing, and I'm sure refactoring the functional style to imperative with basic loops will speed up your solution. The question remains whether this type of solution should pass. I specifically wanted solutions working on updating the array while backtracking to time out. For now, I won't change perf specs. I want to see more attempts and solutions, also from other users, to get an idea on the current difficulty level. I am aiming at purple afterall.
here's ref sol timings, no memoisation, not even prime factors:
I don't want to do it imperatively :P
Individual test runtimes vary wildly:
Another option is I make this kata even harder, and make a second version aimed at 4 kyu that allows much more variation in solutions.
At first sight, it seems like a prime candidate to have an algorithmic and a performance version, if the performance version depends on some number-theoretic bit-niggling I can't even imagine right now. ( Because currently, I can't imagine how the reference solution is getting those times, if memoisation isn't working for me. )
But looking at your times, I don't know how much higher the reference solution can go. Ideally, you'd need another couple of orders of magnitude, and you don't seem to have that. I don't know if the difference between our solutions is actually big enough in terms of Big-O.
You are right, my solution can't go much higher as the current limit. I've lowered the constraints slightly. Your solution should just about make it in time now. Its time complexity seems on par with ref sol.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This is not good datatype design. A centrifuge with empty holes is a valid solution when
k = 0
, and should not be a return value whenk /= 0
, because it breaks a possible invariant that the number of non-empty holes should always bek
.Consider asking for
null
( because JS does not really have anOption
type ) or for throwing anError
( maybe aRangeError
).consider it done