18
3
Introduction:
I think everyone knows what a Lava Lamp is, but in case they do not:
They're basically glass tubes that contain wax in a translucent liquid. The bottom part is heated when the lamp is turned on, causing a change in density and thus the wax floats to the top. When it cools down, it falls down again, causing the effect we see above.
It usually takes about 45-60 minutes for the base of the lamp to rise in temperature high enough to change the solid wax to liquid wax (if the lamp is located in an area at room temperature).
More information on Wikipedia, which is also used as source for some of the text above.
Challenge:
Given a positive integer n
indicating the amount of minutes that have passed since we've turned the Lava Lamp on, output a random state of the Lava Lamp based on integers on five levels.
For this challenge we'll say the Lava Lamp contains 1000 units of wax in total, and we have five levels where the wax can be at.
1) If n
is below 45, the Lava Lamp is still heating up, so the output will be four empty lines with 1000
at the bottom:
1000
2) If n
is in the range [45, 60)
the Lava Lamp has increased in temperature enough for wax to move around, but no very high yet. The wax can reach up to and including the third level.
3) If n
is 60
or higher, the wax can be at any of the five levels.
So given the positive integer n
as input, we'll output a random state with the three rules above in mind.
Here are some example outputs:
Possible outputs for any n
that is >= 45
:
523
106
371
913
87
Possible outputs for any n
that is >= 60
:
73
113
312
5
497
284
55
637
24
Constant output for n
that is <= 44
(and possible output for any n
):
1000
Challenge rules:
- There can be empty lines, even though the level above it is not empty.
- Just
0
isn't allowed on any line. Should be empty instead. - Output is somewhat flexible. You are allowed to output a list/array of strings/objects instead of a new-line delimited result as above. The reason I say strings/objects is due to the rule above. An empty line should be
""
,null
,[]
, etc., but cannot be0
or a negative integer (nor can it befalse
) (I.e.["", "", 913, "", 87]
forn >= 45
). You are also allowed to reverse the output (I.e.1000\n\n\n\n
instead of\n\n\n\n1000
or[87, null, 913, null, null]
instead of[null, null, 913, null, 87]
). - The numbers should all be integers. The can be decimals with
0
as decimal value, but none of the numbers should have any decimal digits, and the integers should always sum to exactly1000
. - All possible random outputs based on
n
should have a non-zero chance of occurring. - A trailing new-line (so there are six lines of output) is allowed.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, adding an explanation for your answer is highly recommended.
Semi-related: "Random numbers with fixed sum" and Related stackoverflow answer for "Random numbers that add to 100" – Kevin Cruijssen – 2018-09-11T07:46:39.207
May an empty level be represented with a single space? – Arnauld – 2018-09-11T08:20:56.877
@Arnauld Sure. Can be anything except for
0
, a negative number, orfalse
. – Kevin Cruijssen – 2018-09-11T08:48:55.673Is the output always 5 levels, even when
n < 60
? – Emigna – 2018-09-11T09:18:24.160@Emigna Yes, the output is always 5 levels. For
n < 45
only 1 level is filled however (top or bottom depending on the order you output it in), which is1000
. With45 <= n < 60
three of the five, and withn >= 60
all five. But the output will always contain five 'lines'. – Kevin Cruijssen – 2018-09-11T10:04:43.887I assume it's not allowed, but it would be funny to bypass the
0
is an empty string by outputting in unary. – Jo King – 2018-09-12T02:06:20.330