Fill the Bucket
up vote
8
down vote
favorite
Your task is to fill the bucket with numbers upto a given input.
Rules
Numbers occupy the leftmost position then rightmost, then leftmost and so on.
After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.
The examples should make it clear what the expected output is (Some rules are mentioned in the examples).
For more then 10, use the rightmost digit
Examples:
The bucket:
| | or | |
| | | |
| | | |
| | | |
|------| |______|
input:1 (You can start from either 0 or 1)
output:
| | (There can be whitespace to the left even if there is no overflow
| | but the bucket must not be distorted.)
| |
|1 |
|------|
input:6
output:
| |
| |
| |
|135642|
|------|
input:8
output:
| |
| |
|7 8|
|135642|
|------|
input:23
output:
|913 20|
|357864|
|791208|
|135642|
|------|
input:27
output:
|913420|
|357864|
|791208|
|135642|
75|------|6
input:30
output:
|913420|
|357864|
|791208|
9|135642|0
75|------|68
input:40
output:
|913420|
|357864|
5|791208|6
939|135642|040
7175|------|6828
input:54 (Maximum input for start=1)
3|913420|4
13|357864|42
915|791208|620
7939|135642|0408
57175|------|68286
This is code-golf so shortest code wins.
code-golf ascii-art
add a comment |
up vote
8
down vote
favorite
Your task is to fill the bucket with numbers upto a given input.
Rules
Numbers occupy the leftmost position then rightmost, then leftmost and so on.
After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.
The examples should make it clear what the expected output is (Some rules are mentioned in the examples).
For more then 10, use the rightmost digit
Examples:
The bucket:
| | or | |
| | | |
| | | |
| | | |
|------| |______|
input:1 (You can start from either 0 or 1)
output:
| | (There can be whitespace to the left even if there is no overflow
| | but the bucket must not be distorted.)
| |
|1 |
|------|
input:6
output:
| |
| |
| |
|135642|
|------|
input:8
output:
| |
| |
|7 8|
|135642|
|------|
input:23
output:
|913 20|
|357864|
|791208|
|135642|
|------|
input:27
output:
|913420|
|357864|
|791208|
|135642|
75|------|6
input:30
output:
|913420|
|357864|
|791208|
9|135642|0
75|------|68
input:40
output:
|913420|
|357864|
5|791208|6
939|135642|040
7175|------|6828
input:54 (Maximum input for start=1)
3|913420|4
13|357864|42
915|791208|620
7939|135642|0408
57175|------|68286
This is code-golf so shortest code wins.
code-golf ascii-art
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Your task is to fill the bucket with numbers upto a given input.
Rules
Numbers occupy the leftmost position then rightmost, then leftmost and so on.
After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.
The examples should make it clear what the expected output is (Some rules are mentioned in the examples).
For more then 10, use the rightmost digit
Examples:
The bucket:
| | or | |
| | | |
| | | |
| | | |
|------| |______|
input:1 (You can start from either 0 or 1)
output:
| | (There can be whitespace to the left even if there is no overflow
| | but the bucket must not be distorted.)
| |
|1 |
|------|
input:6
output:
| |
| |
| |
|135642|
|------|
input:8
output:
| |
| |
|7 8|
|135642|
|------|
input:23
output:
|913 20|
|357864|
|791208|
|135642|
|------|
input:27
output:
|913420|
|357864|
|791208|
|135642|
75|------|6
input:30
output:
|913420|
|357864|
|791208|
9|135642|0
75|------|68
input:40
output:
|913420|
|357864|
5|791208|6
939|135642|040
7175|------|6828
input:54 (Maximum input for start=1)
3|913420|4
13|357864|42
915|791208|620
7939|135642|0408
57175|------|68286
This is code-golf so shortest code wins.
code-golf ascii-art
Your task is to fill the bucket with numbers upto a given input.
Rules
Numbers occupy the leftmost position then rightmost, then leftmost and so on.
After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.
The examples should make it clear what the expected output is (Some rules are mentioned in the examples).
For more then 10, use the rightmost digit
Examples:
The bucket:
| | or | |
| | | |
| | | |
| | | |
|------| |______|
input:1 (You can start from either 0 or 1)
output:
| | (There can be whitespace to the left even if there is no overflow
| | but the bucket must not be distorted.)
| |
|1 |
|------|
input:6
output:
| |
| |
| |
|135642|
|------|
input:8
output:
| |
| |
|7 8|
|135642|
|------|
input:23
output:
|913 20|
|357864|
|791208|
|135642|
|------|
input:27
output:
|913420|
|357864|
|791208|
|135642|
75|------|6
input:30
output:
|913420|
|357864|
|791208|
9|135642|0
75|------|68
input:40
output:
|913420|
|357864|
5|791208|6
939|135642|040
7175|------|6828
input:54 (Maximum input for start=1)
3|913420|4
13|357864|42
915|791208|620
7939|135642|0408
57175|------|68286
This is code-golf so shortest code wins.
code-golf ascii-art
code-golf ascii-art
edited 4 hours ago
Arnauld
71k688298
71k688298
asked 4 hours ago
Vedant Kandoi
953223
953223
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
4
down vote
JavaScript (Node.js), 145 bytes
1-indexed.
n=>` g|EGIJHF|h
e]|?ACDB@|^f
c[U|9;=><:|V\d
aYSO|357864|PTZb
_WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')
Try it online!
add a comment |
up vote
0
down vote
Python 2, 170 bytes
I=input()
s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
i=1
exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
print s
Try it online!
add a comment |
up vote
0
down vote
Java 10, 168 bytes
n->" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))
Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting -
as bottom). If you like this answer, make sure to upvote him as well!
Try it online.
Explanation:
n-> // Method with integer parameter and no return-type
" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
// String containing the bucket and magic string
.chars().forEach(c-> // Loop over the characters (as integers)
System.out.print( // Print:
c<46|c==124? // If the character is "n", " ", "-", or "|":
(char)c // Output the character as is
:c<n+51? // Else-if the character value is smaller than the input + 51:
c%10 // Output a digit: the character value modulo-9
: // Else:
" ")) // Output a space
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
JavaScript (Node.js), 145 bytes
1-indexed.
n=>` g|EGIJHF|h
e]|?ACDB@|^f
c[U|9;=><:|V\d
aYSO|357864|PTZb
_WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')
Try it online!
add a comment |
up vote
4
down vote
JavaScript (Node.js), 145 bytes
1-indexed.
n=>` g|EGIJHF|h
e]|?ACDB@|^f
c[U|9;=><:|V\d
aYSO|357864|PTZb
_WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')
Try it online!
add a comment |
up vote
4
down vote
up vote
4
down vote
JavaScript (Node.js), 145 bytes
1-indexed.
n=>` g|EGIJHF|h
e]|?ACDB@|^f
c[U|9;=><:|V\d
aYSO|357864|PTZb
_WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')
Try it online!
JavaScript (Node.js), 145 bytes
1-indexed.
n=>` g|EGIJHF|h
e]|?ACDB@|^f
c[U|9;=><:|V\d
aYSO|357864|PTZb
_WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')
Try it online!
answered 3 hours ago
Arnauld
71k688298
71k688298
add a comment |
add a comment |
up vote
0
down vote
Python 2, 170 bytes
I=input()
s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
i=1
exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
print s
Try it online!
add a comment |
up vote
0
down vote
Python 2, 170 bytes
I=input()
s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
i=1
exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
print s
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
Python 2, 170 bytes
I=input()
s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
i=1
exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
print s
Try it online!
Python 2, 170 bytes
I=input()
s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
i=1
exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
print s
Try it online!
answered 3 hours ago
TFeld
13.9k21240
13.9k21240
add a comment |
add a comment |
up vote
0
down vote
Java 10, 168 bytes
n->" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))
Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting -
as bottom). If you like this answer, make sure to upvote him as well!
Try it online.
Explanation:
n-> // Method with integer parameter and no return-type
" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
// String containing the bucket and magic string
.chars().forEach(c-> // Loop over the characters (as integers)
System.out.print( // Print:
c<46|c==124? // If the character is "n", " ", "-", or "|":
(char)c // Output the character as is
:c<n+51? // Else-if the character value is smaller than the input + 51:
c%10 // Output a digit: the character value modulo-9
: // Else:
" ")) // Output a space
add a comment |
up vote
0
down vote
Java 10, 168 bytes
n->" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))
Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting -
as bottom). If you like this answer, make sure to upvote him as well!
Try it online.
Explanation:
n-> // Method with integer parameter and no return-type
" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
// String containing the bucket and magic string
.chars().forEach(c-> // Loop over the characters (as integers)
System.out.print( // Print:
c<46|c==124? // If the character is "n", " ", "-", or "|":
(char)c // Output the character as is
:c<n+51? // Else-if the character value is smaller than the input + 51:
c%10 // Output a digit: the character value modulo-9
: // Else:
" ")) // Output a space
add a comment |
up vote
0
down vote
up vote
0
down vote
Java 10, 168 bytes
n->" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))
Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting -
as bottom). If you like this answer, make sure to upvote him as well!
Try it online.
Explanation:
n-> // Method with integer parameter and no return-type
" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
// String containing the bucket and magic string
.chars().forEach(c-> // Loop over the characters (as integers)
System.out.print( // Print:
c<46|c==124? // If the character is "n", " ", "-", or "|":
(char)c // Output the character as is
:c<n+51? // Else-if the character value is smaller than the input + 51:
c%10 // Output a digit: the character value modulo-9
: // Else:
" ")) // Output a space
Java 10, 168 bytes
n->" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))
Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting -
as bottom). If you like this answer, make sure to upvote him as well!
Try it online.
Explanation:
n-> // Method with integer parameter and no return-type
" g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
// String containing the bucket and magic string
.chars().forEach(c-> // Loop over the characters (as integers)
System.out.print( // Print:
c<46|c==124? // If the character is "n", " ", "-", or "|":
(char)c // Output the character as is
:c<n+51? // Else-if the character value is smaller than the input + 51:
c%10 // Output a digit: the character value modulo-9
: // Else:
" ")) // Output a space
answered 7 mins ago
Kevin Cruijssen
35.1k554185
35.1k554185
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177365%2ffill-the-bucket%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown