541
\$\begingroup\$

This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. This is useful because writing a clear and fully specified challenge on your first try can be difficult, and there is a much better chance of your challenge being well received if you post it in the sandbox first.

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3655 Answers 3655

1
62 63
64
65 66
122
1
\$\begingroup\$
\$\endgroup\$
1
\$\begingroup\$
\$\endgroup\$
3
  • \$\begingroup\$ No, the Jimmies are on the backs of more Jimmies, and it's Jimmies all the way dow. \$\endgroup\$
    – emanresu A
    Sep 10 '21 at 10:19
  • \$\begingroup\$ What's the center of mass of -- or ----, and does it suffice to have a Jimmy's arm on one side of the central two? \$\endgroup\$
    – emanresu A
    Sep 10 '21 at 21:15
  • \$\begingroup\$ @emanresuA In the first it is at 1 and in the second it's at 2. (relative to the start of the platform) In either case the arm cannot be a place a Jimmy is directly touching so it must be in between two. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 10 '21 at 21:37
1
\$\begingroup\$

This question has been posted on the main site

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You might want to link to the question from here next time, although it doesn't really matter much. \$\endgroup\$
    – user
    Sep 26 '21 at 19:08
1
\$\begingroup\$
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Why not allow giving the first n numbers in the sequence? \$\endgroup\$
    – Adám
    Sep 19 '21 at 13:29
  • \$\begingroup\$ @Adám I don't really see any reason why one would want to do that. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 19 '21 at 13:44
1
\$\begingroup\$

Pythagoras' Golfing Grid

\$\endgroup\$
1
  • \$\begingroup\$ Does it matter which solution is output? At the very least e and h can be any pair of factors for \$ f - T \$, and you could swap dg with jk, etc. You say "integer" but your example only uses positive integers. Do you mean positive integers? If you do, there might be some T which do not have a solution. \$\endgroup\$ Sep 17 '21 at 16:06
1
\$\begingroup\$

Let's go for a rollercodester ride

\$\endgroup\$
4
  • \$\begingroup\$ also considering using absolute change for scoring instead of curvature \$\endgroup\$
    – M Virts
    Sep 10 '21 at 20:53
  • \$\begingroup\$ Seems interesting, but I think a program that just switches between something like unary and denser languages like Jelly would be optimal and probably not too difficult. (Although it does seem like it could be a good challenge, making something like that is probably non trivial) \$\endgroup\$ Sep 10 '21 at 20:53
  • \$\begingroup\$ Would it be improved by only allowing each language once? I was also thinking a zip bomb type answer could dominate, but maybe that's not a bad thing. I could divide the score of each step by the sum of the code lengths that went into it, so it would be normalized and always less than 2 (theoretically 0,100,0 becomes +100,-100 becomes -200, from code lengths 0+100+0, leaving 200/100=2. That's the best I can think of). I like that because longer sequences would be the only way to reach higher score values. I guess the minimum sequence would need 3 languages to be scorable. \$\endgroup\$
    – M Virts
    Sep 11 '21 at 2:09
  • \$\begingroup\$ I'd assumed that each language was only allowed once anyway, so that's probably the best thing to do. A zip bomb type answer probably wouldn't win, because you need more than just a massive increase in size, you need to be able to control what the output is so you can make it do something useful. I think the number of languages should definitely be factored into the score though, since a single massive increase or decrease in size could be the easiest way to win at the moment. \$\endgroup\$ Sep 11 '21 at 15:23
1
\$\begingroup\$

Count occurences in Pascal's Triangle

\$\endgroup\$
3
  • \$\begingroup\$ The challenge itself looks good to post. That said, I don't think there are any interesting strategies beyond generating up to the nth row (starting from the zeroth), flattening and counting \$\endgroup\$ Sep 18 '21 at 3:03
  • \$\begingroup\$ Also, it appears this sequence isn't on OEIS, and that the closest sequence is A006987 \$\endgroup\$ Sep 18 '21 at 3:07
  • \$\begingroup\$ @cairdcoinheringaahing oeis.org/A003016 \$\endgroup\$
    – tsh
    Sep 18 '21 at 8:26
1
\$\begingroup\$

Minimizing flights of stairs climbed

\$\endgroup\$
2
  • \$\begingroup\$ I think the bonus is the most interesting part and should be the main challenge. For now it's just a simple formula. Also, why the room numbers, not just floor numbers (which are room//100)? \$\endgroup\$
    – pajonk
    Sep 23 '21 at 12:03
  • 1
    \$\begingroup\$ @pajonk I'll make the bonus be the main challenge then. They are room numbers to add a bit of extra challenge for converting into the floor number. \$\endgroup\$
    – Yousername
    Sep 23 '21 at 16:05
1
\$\begingroup\$

Multiplication for geometric algebra

\$\endgroup\$
3
  • 1
    \$\begingroup\$ If you're looking for feedback here in the sandbox, I think it would be nice to remove the challenge from main site for now. \$\endgroup\$
    – pajonk
    Sep 23 '21 at 11:56
  • \$\begingroup\$ very interesting challenge. \$\endgroup\$
    – don bright
    Sep 27 '21 at 2:15
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Sep 30 '21 at 1:02
1
\$\begingroup\$

Newton Polynomial

A newton polynomial is a interpolation polynomial where the coefficients are found using the Newton's divided differences method. The relevant Wiki is here.

Your task has two parts:

  1. Given a set of inputs and outputs to find and display the polynomial that describes the series. The input can be as two lists or a dictionary like structure. e.g. $$ [x_1:y_2,\;x_2:y_2,\;...\;, x_{n-1}:y_{n-1},\; x_n:y_n] $$
  2. Given any real number, return the interpolated value.

Examples

enter image description here

Presentation of the polynomial must be in a format that is recognisable.

As ever this is code golf: so shortest answer wins.

\$\endgroup\$
7
  • \$\begingroup\$ A summary of the method would be welcome (in addition to the Wikipedia link). From a super quick skim I think there might be errors in the final example output: shouldn't \$(n-1)(n-2)\$ be \$(n-1)(n-3)\$, and similarly \$(n-1)(n-2)(n-3)\$ be \$(n-1)(n-3)(n-7)\$? \$\endgroup\$
    – Dingus
    Oct 12 '21 at 4:49
  • \$\begingroup\$ computers don't use real numbers. but still an interesting challenge. do you care what format the output polynomial is in? \$\endgroup\$
    – don bright
    Oct 18 '21 at 3:14
  • \$\begingroup\$ @Dingus thanks, yes working on a summary of the method, wanting to keep it consice though. no every term is included so '(n-1)(n-2)(n-3) etc. \$\endgroup\$
    – george
    Oct 18 '21 at 20:44
  • \$\begingroup\$ @donbright true, but I haven't had time to look into using complex numbers. I'm currently not interested in using them for this. Id want the polynomial to be readable, what did you have in mind? \$\endgroup\$
    – george
    Oct 18 '21 at 20:47
  • \$\begingroup\$ no i mean, "given any real number" should be something like "given a 32 bit floating point number in your languages format". as far as the polynomial format i was wondering if you would accept it all expanded out to \$a_nx^n + a_{n-1}x^{n-1}...a_0\$ form, to the point where it can be represented as an array of numbers, the numbers in the array are coefficients and the position in the array is the exponent. thanks. \$\endgroup\$
    – don bright
    Oct 19 '21 at 2:09
  • \$\begingroup\$ @donbright ah I see what you're saying, yes I will amend that then. I'm not sure I quite understand how you want to layout it out. Maybe expecting a particular format is too hard and I should just ask for an array of coefficient, were you thinking of expanding (n-1)(n-2)(n-3)... for example? \$\endgroup\$
    – george
    Oct 19 '21 at 23:06
  • \$\begingroup\$ yes the final result should be a polynomial, would it be ok to return a string saying 23.4n^4 + 3920n^3 ... \$\endgroup\$
    – don bright
    Oct 20 '21 at 2:32
1
\$\begingroup\$

Wave square

Task

Given an integer \$n\$ with the constraints \$0 < n \leq 9\$, output the corresponding square, that for each row shifts the sequence from \$1\to n\$ by one, overflowing when needed.

I/O

Input is an integer \$n\$, \$ 0 < n \leq 9\$. Output can be as a returned String, matrix, array or to STDOUT. You can write a full program or a function.

Examples

5:

12345
23451
34512
45123
51234

2:

12
21

1:

1

9:

123456789
234567891
345678912
456789123
567891234
678912345
789123456
891234567
912345678

meta

Thoughts on extending the challenge to allow for inputs bigger than 9, which would then just be taken mod 10?

\$\endgroup\$
2
  • 3
    \$\begingroup\$ One idea - using letters for numbers greater than 9 (i.e a for 10, b for 11, etc.) would allow for inputs of up to 35 without disrupting the format. \$\endgroup\$
    – Dingus
    Oct 18 '21 at 2:33
  • \$\begingroup\$ Thanks! I don't know if that'd be enough to make it distinct from another challenge though (someone posted it was a dupe in the nineteenth byte) \$\endgroup\$
    – Jadefalke
    Oct 18 '21 at 8:22
1
\$\begingroup\$

Largest turing incomplete subset of ASCII

We have challenges about trying to find a short, turing complete number of characters in a language. In this challenge, you'll do the opposite, trying to find the largest subset of characters which is not turing complete.

Rules:

  • Like , competition is purely within a language, not between different ones
  • Languages with SBCSs or other custom code pages may use those instead of ASCII
    • SBCS submissions will not compete against ASCII submissions in the same language
  • In this challenge, "ASCII" is not short for "printable ASCII". All of 0x00 to 0x7f is allowed
    • So, the highest score possible would be 127 (for non-SBCS submissions), if there was a single character which is always needed for a TC program
  • The language you use must be turing complete (and must be TC with full ASCII or its SBCS, whichever you choose)

Possible rule:

You must be able to write a valid program using only (and all of) the chosen subset of ASCII/the SBCS. It doesn't need to do anything useful, it just can't error.

This prevents padding the subset with characters that would never be allowed in a valid program in your language, or not including just one critical character needed in every program. However, strings and comments could be a problem.

\$\endgroup\$
7
  • \$\begingroup\$ If a language is using SBCS, that would allow for a score higher than 94, wouldn't it? \$\endgroup\$ Oct 20 '21 at 15:03
  • \$\begingroup\$ @AaroneousMiller It would, yes (this is fine since it's a competition within the language) \$\endgroup\$ Oct 20 '21 at 15:10
  • \$\begingroup\$ An empty program is valid in some languages. \$\endgroup\$
    – xnor
    Oct 20 '21 at 18:09
  • \$\begingroup\$ @xnor Ah, I meant using all of the characters in the chosen subset. Will fix. \$\endgroup\$ Oct 20 '21 at 18:18
  • 2
    \$\begingroup\$ Maybe just allow all 256 bytes 0x00 to 0xff so it's a fair playing field? \$\endgroup\$
    – emanresu A
    Oct 20 '21 at 19:00
  • \$\begingroup\$ I don't think the "possible rule" is needed. The equivalent challenge is to find a small set of chars/bytes such that some of them are absolutely needed for the lang to be TC, and take the set complement. IMO the first part is totally fair across languages (assuming full byte range), and the second part only depends on how you define the full set. So for maximum fairness I'd suggest "every char/byte is on the table, even the ones that cannot appear in any valid program". \$\endgroup\$
    – Bubbler
    Oct 20 '21 at 23:30
  • 1
    \$\begingroup\$ @Bubbler To be fair, it's not meant to be fair to all languages. It'll be like code golf where scoring is per language. But I guess I agree the possible rule probably isn't needed. \$\endgroup\$ Oct 20 '21 at 23:45
1
\$\begingroup\$

Find all paths

\$\endgroup\$
6
  • \$\begingroup\$ More test cases would be needed. Is this oeis.org/A121788? \$\endgroup\$
    – Luis Mendo
    Jun 27 '21 at 15:24
  • \$\begingroup\$ I dont think this is that problem in the link \$\endgroup\$
    – PyGamer0
    Jun 27 '21 at 15:34
  • \$\begingroup\$ Anyway, please include more test cases \$\endgroup\$
    – Luis Mendo
    Jun 27 '21 at 16:24
  • \$\begingroup\$ Is this oeis.org/A001184? \$\endgroup\$
    – tsh
    Jun 28 '21 at 8:22
  • \$\begingroup\$ yes it is @tsh updated! \$\endgroup\$
    – PyGamer0
    Jun 28 '21 at 8:37
  • \$\begingroup\$ === Looks good! === \$\endgroup\$
    – emanresu A
    Jun 28 '21 at 8:43
1
\$\begingroup\$

What's the valency?

The challenge.

Given an element, for simplicity lets assume the element is entered as a string of the symbol of the element (any consistent casing of your choice) and the only elements are the first 20 elements of the periodic table.

You have to output the valency of the element. The valency of the element has to be with the sign and as per the below cases.

All cases

h  ->  1
he ->  0
li ->  1
be ->  2
b  ->  3
c  ->  4
n  -> -3
o  -> -2
f  -> -1
ne ->  0
na ->  1
mg ->  2
al ->  3
si ->  4
p  -> -3
s  -> -2
cl -> -1
ar ->  0
k  ->  1
ca ->  2

This is code-golf so the shortest answer in bytes wins.

\$\endgroup\$
8
  • 3
    \$\begingroup\$ Since we require that challenges be self contained, you would need to provide the valency for each of the elements that you want to include. \$\endgroup\$ Sep 20 '21 at 18:25
  • \$\begingroup\$ Adding to FryAmTheEggman's comment, several elements have more than one valency. For each element you need either to specify which valency/valencies to output or allow answers to choose. \$\endgroup\$
    – Dingus
    Oct 19 '21 at 4:49
  • \$\begingroup\$ @FryAmTheEggman edited the question. It now includes all 20 cases. \$\endgroup\$
    – PyGamer0
    Oct 19 '21 at 6:11
  • \$\begingroup\$ This looks much better! Now I would recommend allowing the inputs to be in whatever consistent casing (upper, lower, title) the answerer prefers. Otherwise, I think it is good to go. \$\endgroup\$ Oct 19 '21 at 14:08
  • \$\begingroup\$ @FryAmTheEggman edited. \$\endgroup\$
    – PyGamer0
    Oct 19 '21 at 15:18
  • \$\begingroup\$ @PyGamer0 The wording "(any case)" isn't clear enough – it could also mean that the program has to be able to handle any case. \$\endgroup\$
    – m90
    Oct 19 '21 at 15:21
  • 1
    \$\begingroup\$ Perhaps "any consistent casing of your choice"? \$\endgroup\$ Oct 19 '21 at 15:38
  • 6
    \$\begingroup\$ How many more "build an optimal lookup table" questions do we need? \$\endgroup\$
    – pxeger
    Oct 19 '21 at 16:18
1
\$\begingroup\$

Input two positive integers m, n; Output a grid looks like below:

┌──────────────┐
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
└──────────────┘

Here is an example for 5×4 grid.

Characters used in the grid is shown as this table:

Char Code Point
Space U+0020
U+2500
U+2502
U+250C
U+2510
U+2514
U+2518
U+251C
U+2524
U+252C
U+2534

You may alternative use a CJK space   (U+3000) instead of two ASCII spaces (U+0020 U+0020). If you chose this option, you should use a single horizontal grid line (U+2500) instead of two. You may verify this behavior in the code snippet at bottom.

You may output:

  • a single string
    • an array of characters, an array of integers (whose value is the code point of each character);
  • an array of strings, as the single string split by new lines;
    • or an array of array of characters, an array of array of integers;

Use ASCII Space:

<pre lang="en">┌──────────────┐
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
├──┬──┬──┬──┬──┤
│  │  │  │  │  │
├──┴──┴──┴──┴──┤
└──────────────┘</pre>

Use CJK Space:

<pre lang="zh">┌─────────┐
├─┬─┬─┬─┬─┤
│ │ │ │ │ │
├─┴─┴─┴─┴─┤
├─┬─┬─┬─┬─┤
│ │ │ │ │ │
├─┴─┴─┴─┴─┤
├─┬─┬─┬─┬─┤
│ │ │ │ │ │
├─┴─┴─┴─┴─┤
├─┬─┬─┬─┬─┤
│ │ │ │ │ │
├─┴─┴─┴─┴─┤
└─────────┘</pre>

\$\endgroup\$
1
1
\$\begingroup\$

Calculate Smith normal form of an integer matrix

Given an \$m \times n\$ matrix of integers A, there exist a \$m \times m\$ matrix P, an \$m \times n\$ matrix D, and an \$n \times n\$ matrix Q such that:

  • P and Q are unimodular matrices (i.e. matrices which are invertible and whose inverses are also integer matrices);
  • D is diagonal;
  • each diagonal entry \$d_{ii}\$ of D is nonnegative; and
  • \$d_{11} \mid d_{22} \mid \cdots \mid d_{nn} \$.

Furthermore, the matrix D is unique in this representation.

One common way to calculate D is via an algorithm that looks like a combination of the Euclidean algorithm for calculating gcd and Gaussian elimination -- applying elementary row and column operations until the matrix is in the desired format for D. Another way to calculate D is to use the fact that for each i, \$d_{11} d_{22} \cdots d_{ii}\$ is equal to the gcd of all determinants of \$i\times i\$ submatrices (including non-contiguous submatrices) of A.

The challenge

You are to write a function or program that calculates the Smith normal form of an input matrix. The output may either be in the form of the full matrix D, or in the form of a list of the diagonal entries of D. In an imperative programming language, it is also acceptable to write a function that takes a matrix by reference and mutates the matrix into its Smith normal form.

Rules

  • This is code-golf: shortest code wins.
  • Standard loophole prohibitions apply.
  • You do not need to worry about integer overflow, if that applies in your language.

Examples

1 2 3       1 0 0
4 5 6  ->   0 3 0
7 8 9       0 0 0

6  10       1 0
10 15  ->   0 10

6 0  0        1 0  0
0 10 0   ->   0 30 0
0 0  15       0 0  30

2 2       2 0
2 -2  ->  0 4

2 2  4 6       2 0 0 0
2 -2 0 -2  ->  0 4 0 0

Note: Mathematica already has a built-in to calculate Smith normal form. As such, you can use this to play around with test cases: Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Three new matrices are introduced at the top of the post and it isn't immediately obvious which one is the Smith normal form. Suggest stating that it's D after the first set of bullet points. \$\endgroup\$
    – Dingus
    Nov 9 '21 at 23:34
1
\$\begingroup\$

Climbing up slippery stairs

Challenge

You're standing in front of a stairway with \$n\$ stairs in total. (If you label each staircase \$1,\cdots,n\$, the starting point counts as the 0th staircase.) You can climb up \$1,2,\cdots,k\$ stairs at a time. But some stairs are slippery; if you step on it, it will cause you to slip backwards until you stand on a non-slippery one (or the starting point). In how many ways can you get to the \$n\$th staircase with exactly \$s\$ steps?

Task: Given the list of staircases of length \$n\$ marked with either "slippery" or "non-slippery" (you can choose any two consistent values) and the values of \$k\$ and \$s\$, answer the above question.

The \$n\$th staircase is guaranteed to be non-slippery, and you cannot move further than the \$n\$th. This implies that reaching the destination before you spend \$s\$ steps doesn't count.

For example, if the stairway is [non-slippery, slippery, non-slippery] and \$k=2\$, two possible first steps (climbing one or two stairs) will result in the same position (the first staircase), but count as two distinct possible moves. And if you try to climb one stair as the second step, you will end up not moving at all, but it still counts as a step.

You may assume \$1 \le k \le n\$ and \$s \ge 1\$. Some inputs may have no way to reach the destination at all; in that case, your code should output the value of zero for any value of \$s\$.

Example and test cases

N means non-slippery, and S means slippery. 1-1-3 notation means that you can reach the top in three steps, trying to advance 1, 1, and 3 stairs at once.

N = [N, S, N, N]
k = 3
s = 1: answer = 0 (no way to climb 4 stairs at once)
s = 2: answer = 3 (1-3, 2-3, 3-1)
s = 3: answer = 4 (1-1-3, 1-2-1, 2-1-3, 2-2-1)

N = [S, S, N, S, S, N]
k = 4
s = 1: answer = 0
s = 2: answer = 2 (3-3, 4-3)
s = 3: answer = 8 (1-3-3, 1-4-3, 2-3-3, 2-4-3, 3-1-3, 3-2-3, 4-1-3, 4-2-3)

More test cases coming soon.

\$\endgroup\$
1
\$\begingroup\$

⧵begin{alignat} ... ⧵end{alignat}

Note: The title intentionally uses &#10741; (reverse solidus operator) instead of plain backslash, because otherwise MathJax would happily translate the entire title to... uh... a MathJax error box.

Background

\begin{alignat}{n} ... \end{alignat} is a lesser known LaTeX/MathJax block that allows aligning multiple parts of multi-line equations.

\begin{alignat}{5}
A&=&B&\\
 & &B&=&C&\\
 & & & &C&=&D&\\
 & & & & & &D&=&E
\end{alignat}

\begin{alignat}{5} A&=&B\\ & &B&=&C&\\ & & & &C&=&D&\\ & & & & & &D&=&E \end{alignat}

\begin{alignat}{5}
x&=&-3&a&-&2&b\\
y&=& 2&a&+& &b
\end{alignat}

\begin{alignat}{5} x&=& 3&a&-&2&b\\ y&=&-2&a&+& &b \end{alignat}

Challenge

Implement "Poor Man's ASCII-Only Alignat", which tries to replicate the behavior of MathJax but in plain text. The spec of PMAOA is as follows:

  • Let's define a "word" to be each part of a line delimited by the & character. A word can be empty, and the parts before the first & and after the last & also count as words.
  • Given a multi-line string input, identify the 1st, 2nd, 3rd, ... word of each line.
  • Right-align the 1st words of all lines, right-align the 2nd words of all lines, ..., and concatenate the aligned blocks horizontally. Padding is done with minimal amount of space characters. Trailing whitespace at the end of each line is optional.

Standard rules apply. The shortest code in bytes wins.

Test cases

Coming soon.

\$\endgroup\$
2
  • \$\begingroup\$ By saying align, is extra spaces allowed? For example, `"a&b\ncd&e" -> "..a..b\n.cd..e" \$\endgroup\$
    – tsh
    Nov 9 '21 at 10:02
  • \$\begingroup\$ @tsh No, the padding should be minimal. \$\endgroup\$
    – Bubbler
    Nov 9 '21 at 10:14
1
\$\begingroup\$

What is the maximum value generated by interleaving?

INTERCAL has an interleave operator which does the following operation. Let left operand be asdf and right one qwer in binary, respectively. The operation produces a binary value aqswdefr.

INTERCAL internally treats data as unsigned integers, so the value of the eight-bit value represents 0 to 255 in decimal, inclusively.

If one operand has fewer bits than the other, the fewer one gets padded with zero before operation. So, asd interleaving with qwer is equal to 0asd interleaving with qwer, which is 0qawsedr: it represents 0 to 127 in decimal.

Also, INTERCAL has an extension that handles any bases. Let's assume if 3-base numbers are handled. If each operand has 1 and 3 digits respectively, the maximum value for each operand is represented as 2 and 222 in 3-base number, respectively. Interleaving them results in 020222, which is 188 in decimal.

Task

Given an input of three unsigned integers, output the largest possible value generated by interleaving. The three integers are: number of digits for left operand, number of digits for right operand, and in what base those operands are described with.

Restrictions

  • Base shall be 2 or greater.
  • Each operand has at least 1 digit.

Rules

  • In either function or a program.
  • Standard I/O rules apply, as long as every input and output value is represented as same base or same representation.
    • So varying output base is not allowed.
  • If input is represented as a list-like format, any orders of arguments or input values are fine.
  • No standard loopholes.
  • Shortest code wins

Test cases

TODO.

meta

  • Am I missing any appropriate tags yet?
\$\endgroup\$
1
  • 1
    \$\begingroup\$ The I/O rules seem fine. I'd suggest changing the title to something like 'What is the maximum value generated by interleaving?' Also, 'output what the possibly largest value interleaving generates' -> 'output the largest possible value generated by interleaving'. \$\endgroup\$
    – Dingus
    Nov 12 '21 at 4:14
1
\$\begingroup\$

Constructing Solar Panels from Squares part 2

Thanks to all your generous contributions of code, my horde of minions can now precisely calculate how to construct solar panels of any size, but there's a problem.

The logistics department used these results to calculate how many square panels they would need for every size up to 1,000,000, which is way too many panels. As it turns out, larger panels are more expensive than cheaper ones, so I've decided we need to try to use the largest square panels we can wherever possible.

To make matters worse, my team of scientists tell me that we should avoid using multiple panels of the same size in our configuration, except for our tiny 1x1 panels, to make sure the panels don't fall apart.

The Challenge

Given a positive integer n, output a list of square numbers that sums to n containing the largest squares possible such that no square number other than 1 appears multiple times.

A square number is any integer that is the result of multiplying an integer by itself. For example 16 is a square number because 4 x 4 = 16 This is A000290

For example: For n = 12, you could achieve the desired size with 4 panels of sizes [9, 1, 1, 1]. As 9 is the largest square possible in this configuration, this is the best answer. For n = 13, you can achieve the desired size with only 2 panels: [9, 4]

If n is a square number, the output should be [n].

Input

A positive integer n representing the total desired surface area of the solar panels. Note that 0 is not positive.

Output

A list of square numbers that sums to n containing the largest squares possible.

Testcases

1 -> [1]
2 -> [1,1]
3 -> [1,1,1]
4 -> [4]
7 -> [4,1,1,1]
8 -> [4,4]
9 -> [9]
12 -> [9,1,1,1]
13 -> [9,4]
18 -> [16,1,1]
30 -> [25,4,1]
50 -> [49,1]
60 -> [49,9,1,1]
70 -> [64,4,1,1]
95 -> [81,9,4,1]
300 -> [289,9,1,1]
1246 -> [1225,16,4,1]
12460 -> [12321,121,16,1,1]
172593 -> [172225,361,4,1,1,1]

Sandbox

I don't think this challenge is similar enough to part 1 to be considered a dupe, as while some answers from part 1 could be trivially modified to work for part 2, they would likely be out-golfed by better approaches.

That said I'm not sure how well-worded the output requirement is. a list of square numbers that sums to n containing the largest squares possible such that no square number other than 1 appears multiple times. feels poorly worded, but I'm not sure how I could word it better.

\$\endgroup\$
7
  • \$\begingroup\$ The challenge is unclear. I think you copied part 1 but forgot to edit testcase and example of challenge \$\endgroup\$
    – okie
    Nov 17 '21 at 1:04
  • 1
    \$\begingroup\$ such that no square number other than 1 appears multiple times - test cases don't agree. \$\endgroup\$
    – pajonk
    Nov 17 '21 at 5:24
  • \$\begingroup\$ I did generate new testcases when I wrote this, but I guess I messed up when putting them in. I'll re-run and update the testcases now \$\endgroup\$
    – Mayube
    Nov 17 '21 at 22:15
  • \$\begingroup\$ 8->4,4 having 2 4 \$\endgroup\$
    – okie
    Nov 18 '21 at 0:43
  • \$\begingroup\$ Am not sure if this question may be solved by modify the previous one trivially. But there would be many answer be very similar though. I'm not sure if it would be a duplicate to that one in such case. \$\endgroup\$
    – tsh
    Nov 18 '21 at 3:59
  • \$\begingroup\$ @okie yeah, the problem is with the wording of the challenge, not the testcases. Not sure how best to word it... \$\endgroup\$
    – Mayube
    Nov 18 '21 at 14:07
  • \$\begingroup\$ So only the largest and 1 can appear multiple time? \$\endgroup\$
    – okie
    Nov 18 '21 at 23:27
1
\$\begingroup\$

Implement Unix Timestamp to Daytime

Given an unsigned integer that represents a timestamp since 1970/01/01 00:00:00 (which is Unix epoch time), output one of these to represent the daytime in GMT timezone:

  • An array that stores year, month, date, hour, minute, second.
  • A string in format YYYYMMDDHHmmss.
  • Or whatever similar, as long as it complies with standard i/o rules.

Rules

  • Implement the function or the full program from vanilla.
    • So no built-ins nor libraries that has the fuctionality (see next section).
  • Implement leap year, too; but don't leap second (although leap second is not supported).
  • You just need to support up to 2038/01/19 (so input range shall be 0 to 2147483647 (inclusive)).
  • Standard loopholes apply.
  • Standard I/O rules apply.
  • Input and output format should be consistent and not ambiguous.
    • So, for example, if output is a string like 1970121000, it's unqualified, as it can be recognized as 1970/01/21 00:00:00, 1970/12/01 00:00:00, or 1970/01/02 10:00:00.
  • Shortest code wins.

Examples of bad answers

Test cases

0
-> 1970/01/01 00:00:00
999999999
-> 2001/09/09 01:46:39
1145141919
-> 2006/04/15 22:58:39
1330500000
-> 2012/02/29 07:20:00
1633773293
-> 2021/10/09 09:54:53
2147483647
-> 2038/01/19 03:14:07

Hint

Here are implementations:

Related problems

Meta

  • I once posted here but it's closed.
  • TODO. define what builtins are.
    • The most problem is that that KSH answer has a function that directly converts to the objective string; should I prohibit it?
  • Maybe I wanted to say no date objects allowed.
  • Is what is so-called date object ambiguos?
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Unix Timestamp does not support leap seconds. So there is nothing to do to require someone implement leap second support for an Unix Timestamp. \$\endgroup\$
    – tsh
    Oct 12 '21 at 6:28
  • 1
    \$\begingroup\$ Am I required to support year above 2038? As, you know, support only 1970~2038 would avoid some leap year issues for 2100 or 2200. \$\endgroup\$
    – tsh
    Oct 12 '21 at 6:31
  • \$\begingroup\$ @tsh 1. Thank you for pointing out leap seconds. 2. I clarified to support until 2038. \$\endgroup\$
    – user100411
    Oct 12 '21 at 12:27
1
\$\begingroup\$

Permutation of all the number which separated by ':' and ','

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf and thanks for using the Sandbox! This is a great challenge, but as it stands it's a little unclear from the instructions what's being asked. For example it's clear from the example that 1-2,11,44:110-113 means output every permutation of 1,2,11,44 on the left column and 110,111,112,113 on the right column, but that's not explained in the instructions. \$\endgroup\$
    – Mayube
    Nov 12 '21 at 20:52
  • \$\begingroup\$ @Mayube Thanks for your comment, I've updated the instructions. \$\endgroup\$
    – obnews
    Nov 12 '21 at 22:02
1
\$\begingroup\$

Print random characters indefinitely

Task


Continuously print a random character (a-z, A-Z, 0-9) not separated by a newline (\n).

Expected output


b7gFDRtgFc67h90h8H76f5dD55f7GJ6GRT86hG7TH6T7302f2f4 ...

Note: output should be randomised.

Requirements/Rules


  1. Output must be continuous (i.e. never ending),
  2. Output may not comprise of newlines,
  3. Output must be random,
  4. Output must be only composed of characters: a-z, A-Z, 0-9.
  5. No loopholes, regarding programming language version(s). Use only the tools available with that programming language, no third-party packages, modules, or other addons.

Points


  • Smallest file size (in bytes)

Notes

Concerns: None at the moment...

\$\endgroup\$
9
  • 1
    \$\begingroup\$ I think this would count as a duplicate of this. It's a language specific version, and indefinite, but making something loop forever isn't really the hard part of the challenge I think. \$\endgroup\$
    – Riker
    Nov 29 '21 at 0:51
  • \$\begingroup\$ @Rɪᴋᴇʀ no, not because different. \$\endgroup\$
    – Fmbalbuena
    Nov 29 '21 at 0:51
  • 1
    \$\begingroup\$ Is "creativity" part of the scoring? If so, there's no way to objectively determine how creative something is, so you can't use that as a scoring criterion. You should probably clarify Python 3.8 is the only allowed language, or just drop that entirely (which I'd strongly recommend). \$\endgroup\$ Nov 29 '21 at 0:52
  • 1
    \$\begingroup\$ @RedwolfPrograms and Riker thank you for the tips, i'll make the suggested edits to the criterias ASAP. \$\endgroup\$ Nov 29 '21 at 0:57
  • 1
    \$\begingroup\$ Not limited to python, this might be different enough. I consider something a duplicate if the more specific challenge doesn't really encourage any different approaches than whatever worked for the previous ones, but limiting to alphanumeric and forcing an infinite stream is probably good. You should probably check if there's any other ones tagged [random] that look too similar though. \$\endgroup\$
    – Riker
    Nov 29 '21 at 0:59
  • \$\begingroup\$ @Rɪᴋᴇʀ Understood. Thanks again! \$\endgroup\$ Nov 29 '21 at 1:01
  • 1
    \$\begingroup\$ No problem! It's an interesting challenge, and if it really hasn't been done before then I think it would be quite fun to do. \$\endgroup\$
    – Riker
    Nov 29 '21 at 1:13
  • \$\begingroup\$ Ok! Will post this in ~22 hours... \$\endgroup\$ Nov 29 '21 at 1:16
  • \$\begingroup\$ We've had similar versions of this challenge before, and they've all been closed as a dupe of this and/or this. Personally, I would hammer this closed as a dupe of those two, as I don't think this adds anything that they don't - it's just a trivial combination of the two \$\endgroup\$ Nov 29 '21 at 1:20
1
\$\begingroup\$

Largest SKI Reduction in under 100 characters

The challenge

Create a program in SKI Combinator Calculus in under 100 characters that produces the largest result after terminating.

Scoring

The score will be the number of characters in the final reduction. The highest is the winner.

\$\endgroup\$
1
\$\begingroup\$

Fully matched numbers

\$\endgroup\$
1
\$\begingroup\$

Convert superscript numbers to normal numbers

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Maybe specify exactly what characters will be included in the input? \$\endgroup\$
    – emanresu A
    Dec 11 '21 at 22:02
  • \$\begingroup\$ @emanresuA Done \$\endgroup\$ Dec 12 '21 at 0:05
1
\$\begingroup\$

Posted here

\$\endgroup\$
1
\$\begingroup\$

Rotate two differently cased subwords independently

You have one string made of two subwords in different cases, the upper case first, then the lowercase:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

And you must return each subword cycled by a given increment. (N.b. the letters aren't rotated through the alphabet, but each character is shifted in the word)

The subwords are not always the same length as each other, and are part of the same 'data' structure. If your language cannot store strings, you're permitted to store the 'string' in a single array, e.g. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

Here are the test cases:

Input Output
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyzabcdefghijklm", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyz'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 26 'ABCDEFGHIJKLMNOPQRSTUVWXYZopqrstuvwxyzn'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyz'
"ABCnopqrstuvwxyz", 2 'BCAyznopqrstuvwx'
"AAABBBcccddd", 2 "BBAAABddcccd"
"AAABBBcccddd", 6 "AAABBBcccddd"
"HELLOworld", 5 'LLOHErldwo'
"CODEgolf", 0 'CODEgolf'

Here is an ungolfed example program:

const subWordRotate = (original, rot) => [...original.split(/([A-Z]+)(?![A-Z][a-z]+)/)].map(list => [, ...list].reduce((memo, char, index, input) => {
  memo = memo.slice(0, input.length);
  memo.splice((index + rot) % (input.length), 1, char);
  return memo
}, Array(original.length).fill('')).join('')).join('')


const testCases = [
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 13],
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyzabcdefghijklm", 13],
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 26],
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 13],
  ["ABCnopqrstuvwxyz", 2],
  ["AAABBBcccddd", 2],
  ["AAABBBcccddd", 3],
  ["AAABBBcccddd", 4],
  ["AAABBBcccddd", 5],
  ["AAABBBcccddd", 6],
  ["AAABBBcccddd", 7],
  ["AAABBBcccddd", 8],
  ["AAABBBcccddd", 9],
  ["AAABBBcccddd", 10],
  ["HELLOworld", 69],
  ["CODEgolf", 0]
]
testCases.forEach(
    testCase => console.log(`original: ${testCase[0]}, rotated by ${testCase[1]}: ${subWordRotate(...testCase)}`)
  );


Sandbox note: I think there is a bug in my code, such that ["AAABBBcccddd", 6],["AAABBBcccddd", 7], return the same values. I think this is the same bug that is preventing me specifying how negative numbers work. Any help fixing the code would be much appreciated

\$\endgroup\$
1
\$\begingroup\$

The Most Wanted Prime Numbers

\$\endgroup\$
1
\$\begingroup\$

Can we patch the corona certificate validation code (part 1/3)?

The new chancellor of Germany, Mr. Olaf Scholz, is in deep trouble: the Covid app does not show the vaccination status correctly beginning with booster vaccinations. He was not involved in the development of the app, since that was under chancellor Angela Merkel. He is now hiring you, Secret Agent 0x007, in order to understand the problem and later apply a strategy to fix the problem.

In step 1, Mr. Scholz wants to understand how the app has worked correctly when booster vaccinations were not even thought of. Mr. Scholz is an important person, so he has no time to read lengthy source code. Your code has to be .

These are the rules of valid vaccinations:

  • There are 4 vaccination types in Germany: BioNTech (B), Moderna (M), Astra Zeneca (A) and Johnson&Johnson (J).
  • A person is considered vaccinated 14 days after the necessary amount of injections.
  • Biontech, Moderna and Astra Zeneca need 2 injections, Johnson needs 1 injection only.
  • If 2 injections are needed, the second injection may occur earliest 28 days after the first injection.
  • If 2 injections are needed, the second injection may only be with the same vaccination type.
  • You get an entry in your vaccination pass which has the date in the format YYMMDD. COVID-19 is all post 2000, so we never need a 4 digit year.
  • A full entry is in the form YYMMDD X followed by a newline, where X is the vaccination type.

How the application works:

You get the input in a reasonable form, e.g.

  • from stdin, separated by newlines of your platform
  • an array of strings (like argv)
  • a function with variable number of arguments (like ...)

The first line/entry is today's date, which you check the validity against. This comes from a time server, so it's always valid. Each following line/entry is for one injection. There may be many of them, mainly limited by your platform (254 is certainly enough, also for part 2 and 3).

The application gives the following output:

  • injected after a successful injection with the 14 days period not over
  • vaccinated 14 days after the necessary amount of injections
  • manipulated in case things do not match

manipulated takes precedence over vaccinated over injected. The output may contain arbitrary leading or trailing whitespace. A newline is not needed (it will be displayed in a mobile phone app textbox anyway).

The output can be

  • on stdout
  • the return value of the function

As there are quite some anti-vaxxers, the application checks for manipulations.

  • Totally invalid vaccination types (like Y)
  • Mix of vaccination types for the first and second injection
  • More injections than needed
  • Invalid date (like 200231 - there is no February 31st)
  • Date too early (earlier than 200101, the beginning of the pandemic)
  • Injection date later than today
  • Injections in wrong order (second date before first date)

You don't need to consider:

  • dates other than 6 digits
  • characters in the date other than 0-9
  • other character than space as the separator
  • more than 1 character as vaccination type

Test cases:

<any date>
200231 X
= manipulated (invalid vaccination type)

<any date>
210301 B
210329 A
= manipulated (different vaccination types)

<any date>
210301 B
210329 B
210426 B
= manipulated (too many injections)

210814
210301 J
210814 J
= manipulated (too many injections)

<any date>
200231 B 
= manipulated (invalid date February 31st)

<any date>
191231 B 
= manipulated (date earlier than the pandemic)

210301
210302 J
= manipulated (date of the injection is tomorrow)
 
210301
210301 J
= injected (14 days not over)

210315
210301 J
= vaccinated (14 days over, only 1 injection needed)

210315
210301 B
= injected (14 days over, but 2 injections needed)

<any date>
210301 B
210302 B
= manipulated (28 days between 2 injections required)

210331
210301 B
210329 B
= injected (28 days between 2 injections, but not 14 days after the last one)

210412
210301 B
210329 B
= vaccinated (28 days between 2 injections, 14 days after the last one)

210412
210329 B
210301 B
= manipulated (injections in wrong order)

About realism: while this challenge has a realistic background, not all vaccination of rules in Germany are considered. Do not claim that your program can calculate the validity of a COVID-19 vaccination certificate.

Coming up:

  • part 2, in which you need to consider booster vaccinations the wrong way
  • part 3, in which you check whether you can patch the wrong code of part 2 to make it work correctly

I would appreciate if you participate in all 3 parts.

\$\endgroup\$
5
  • \$\begingroup\$ Regarding the process: I will start writing part 2 when I have received feedback on part 1. I will start writing part 3 when I received feedback on part 2. I want to release part 1 not before all 3 parts were reviewed. Would that be fine? \$\endgroup\$ Dec 18 '21 at 21:06
  • \$\begingroup\$ Interesting question, and I like it. The only thing that really sticks out to me is the input format, you should probably clarify before anybody asks - can you take input as an array/list of strings, rather than a newline delimited string? i.e. ["a", "b"] instead of "a\nb". It really doesn't matter much which you pick but since newline delimited strings would take more bytes for most langs, it's probably going to get asked immediately. \$\endgroup\$
    – Riker
    Dec 18 '21 at 21:24
  • \$\begingroup\$ @Riker: thank you for the feedback. Yes, if that's a common thing to have for input, that's totally fine. Is there an example for a formulation considering all the common inputs? \$\endgroup\$ Dec 18 '21 at 21:26
  • 1
    \$\begingroup\$ I'm unsure if it counts as common, but yeah - it's just that indexing an array is probably shorter than calling .split("\n") for many languages, lol. Regarding posting 3 challenges, I think it's worthwhile to sandbox all 3 before posting any of course, but then posting maybe each one on sunday or something for 3 weeks would be fun. Somebody in chat compared it to a mini advent of code (golf) :) \$\endgroup\$
    – Riker
    Dec 18 '21 at 21:29
  • \$\begingroup\$ I implemented this challenge (non-golfed) and all test cases work. I'll start working on the next one now. \$\endgroup\$ Dec 27 '21 at 15:22
1
62 63
64
65 66
122

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .