552
\$\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 requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

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

3850 Answers 3850

1
112 113
114
115 116
129
0
\$\begingroup\$

Iterative Quine

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Welcome to Code Golf and Coding Challenges, and thank you for using the sandbox! Could you give a rough example of what a submission might look like? \$\endgroup\$
    – user
    Oct 8, 2021 at 21:42
  • 1
    \$\begingroup\$ @user hi! sorry for taking so long, heres my rlly rough example, obvs i can write it better for the actual challenge but i just wanted to get the point across. lmk any feedback u have :) \$\endgroup\$ Oct 9, 2021 at 0:41
  • 1
    \$\begingroup\$ Thanks for the example (it's alright if it's rough, a lot of challenges do that). Unfortunately, as hyper-neutrino said in chat, this feels like two challenges in one: one about simply printing a string, and the other about making a quine, and we already have challenges to do that. Instead, could you spice up this challenge somehow? Maybe you could make people print programs that print larger programs that print even larger programs or something like that? \$\endgroup\$
    – user
    Oct 9, 2021 at 12:38
  • \$\begingroup\$ @user Oh that is a good point, hmm. Well ok, i have two ideas then: note to self: there is no newline on mobile, hitting return just posts... 1. Have the program in lang A print a larger program in lang B, which prints a larger program in lang A.. and then get scored in iterations and how short the original code is? or 2. Lang A prints a program in Lang B which prints a program in lang C which is a quine, and youre scored on iterations and total size of all of the code? those are my ideas, pls lmk any feedback :) i may check out the chat later as well but i want to stay here just for now \$\endgroup\$ Oct 9, 2021 at 15:54
  • \$\begingroup\$ i guess variation 1 could technically go on forever via simple tricks where each one extends the other by 1. id have to workshop that part hmm \$\endgroup\$ Oct 9, 2021 at 15:59
  • 1
    \$\begingroup\$ Well, to the chat I go. I do have a new, probably better idea for this that stays within the spirit \$\endgroup\$ Oct 11, 2021 at 18:30
0
\$\begingroup\$

Pattern in Prime

Given a positive integer less than 100 with no preceding zeros we have to find all 12 digit primes that contains the maximum number of time the given pattern.

Note: Pattern's occurance can overlap. For example 11 occur 6 times in 1111111

Example:

pattern = 1 , count = 13 the maximum occurance is in 111111110111, eleven, and those 12 digit primes are {101111111111,111011111111,111111011111,111111110111,111111111101,111111111511,111111111611,111111211111,111113111111,111211111111,111511111111,116111111111,311111111111}

pattern = 22 , count = 1 {522222222229}

pattern = 69, count = 162

pattern = 37, count = 151

Output format: first line should be count of such primes, and then print the primes in sorted order

If possible while answering please write a short explanation of what you did. This is , so the shortest answer in bytes per language wins.

\$\endgroup\$
0
\$\begingroup\$

Best Rotation

If we rotate a raster image by some angle that is not a multiple of \$90°\$, we will have to use some kind of interpolation. Depending on what kind of interpolation method we use, we get a better or a worse quality. This is especially apparent if we repeat the rotation multiple times. In the following image we se the original on the top left, and then the result of different interpolation methods when used to rotate the original \$360\$ times by \$1°\$.

salvator mundi \$\renewcommand\phi\varphi\$

Challenge

Given some angle \$\phi\$ Your task is to find a method to find a (deterministic) function \$f_\phi\$ that takes some image \$I\$ and rotates it by \$\phi\$.

Scoring (not solved yet)

META this is the issue. Ideally we'd like to have some objective criterion. But so far I have not managed to find one that cannot be gamed:

  1. If we just let the participants rotate an image by some angle \$\phi\$ how can we then compare it to the "exact" solution? Maybe their method is better than the best standard method, even if they have to apply it repeatedly. So it seems we can only truly check against a total rotation that is a multiple of \$90°\$.

  2. Let's say we say we use an angle of \$\phi = 2\pi/n\$ and let them apply their "rotation" \$n\$ times to measure e.g. the \$l^2\$-error \$E = \Vert I - f_\phi(\ldots f_\phi(I)\ldots)\Vert_2\$ . This means they could just use \$f_\phi = id\$.

  3. If we instead use a total rotation of e.g. \$\pi/2\$ (that is \$\phi = \frac{\pi}{2n}\$, with \$n\$ rotations). Then the participants could just use some permutation of pixels that just happens to rotate the image after \$n\$ rotations exactly (or maybe exactly except for some pixels).

So does anyone have another suggestion of how to objectively measure it without introducing any hand-wavey rules?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ My gut feeling is that if this problem were phrasable in an objective manner it would basically already be solved. \$\endgroup\$
    – Wheat Wizard Mod
    Oct 14, 2021 at 21:50
  • \$\begingroup\$ @WheatWitch Maybe it is solved but I don't think the objective "rules" matter - I'm just trying to make rules that don't have loopholes. For instance for the approach of measuring the error of repeted rotations totalling 90° I'd like that the intermediate images also look very much like the original. Any "sane" algo would obey that, but I just struggle to find a way to enforce this without any hand-waveyness. \$\endgroup\$
    – flawr
    Oct 15, 2021 at 11:48
  • \$\begingroup\$ As an alternative I'm considering actually dropping the idea of seeking "sane" algorithms and encouraging pathologic algorithms that manage to do great 90° rotations while having visually nonsense intermediate images. But I think that this is trivial, as I outlined in (3.). \$\endgroup\$
    – flawr
    Oct 15, 2021 at 11:50
  • \$\begingroup\$ A third idea would be some kind of king-of-the-hill where each submission will be paired with every other submission to rotate the image a total of 90° and then find some kind of average score. \$\endgroup\$
    – flawr
    Oct 15, 2021 at 11:51
0
\$\begingroup\$

Halve Code Regen

TODO: This is a horrible title.

Your challenge is to write a program, and when I half the program, the output must stay the same. Then, I will halve it and add the last two characters, and the output should be the same with the program's last two characters at the end.

Sometimes the code can't be halved evenly, and when that happens, I will do something similar to floor division:

blahy => bl
horse => ho
meddle => med (regular halving)
oof => o

Example for "the output should be the same with the program's last two characters at the end"

Let's say we have this code:

q|w_a2e(o+2ei2ere

and the output is

q|w_a2e(o+2ei2ere

when I change it to

q|w_a2e(o+2ei2erere

by adding the last two characters (re), the output should look like

q|w_a2e(o+2ei2erere

(Note the extra re at the)

Rules

  • No padding with comments
  • The program must have at least 2 characters.
  • Standard loopholes apply
  • The output cannot be empty.

Scoring

This is , so the answer with the least bytes wins.

How I came up with the random code in the example two sections ago

q means quine. | is a separator. w_a2e means when the last two characters are added to the end. (o+2e means add the last two characters to the end. i2ere means ignore a repeated 2e at the end.

Meta

  • Is this even possible?
  • If so, any other suggestions?
\$\endgroup\$
7
  • 1
    \$\begingroup\$ I think this would be more interesting if multiple halves of the program had to work. Otherwise it's just output something (or nothing since it doesn't look like you've ruled that out.) and then pad the program out with comments. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 27, 2021 at 13:30
  • \$\begingroup\$ @WheatWizard Fixed. Any idea for a better title? \$\endgroup\$
    – Bgil Midol
    Sep 27, 2021 at 13:34
  • 1
    \$\begingroup\$ That's not quite what I meant. I mean that splitting the same program in half multiple ways ought to preserve the output. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 27, 2021 at 13:39
  • \$\begingroup\$ Also you should definitely restrict the output further. At the very least it should have to be non-empty. You should also require the programs to be at least 1 or 2 bytes long. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 27, 2021 at 13:39
  • \$\begingroup\$ @WheatWizard Fixed. \$\endgroup\$
    – Bgil Midol
    Sep 27, 2021 at 13:43
  • \$\begingroup\$ I still can't decide on a better title, though. \$\endgroup\$
    – Bgil Midol
    Sep 27, 2021 at 14:17
  • \$\begingroup\$ I don't understand what the "the output should be the same with the program's last two characters at the end" part means. Can you show a full example of what you do to the program? \$\endgroup\$ Oct 16, 2021 at 19:05
0
\$\begingroup\$

Integer points on Hyperspheres

Given two non-negative integers \$r\$ and \$d\$, write a program that will output the number of integer points that lie on all hyperspheres of dimension \$d\$ or lower with radius \$r\$ or lower.

For example, given \$r = 5, d = 2\$, the program would do something like this:

The hypersphere of dimension 2 is a circle. The radius is 5. There are 12 integer points on this circle, as follows: $$(5,0),(4,3),(3,4),(0,5),(-3,4),(-4,3),(-5,0),(-4,-3),(-3,-4),(0,-5),(3,-4),(4,-3)$$

If the radius is 4, there are 4 integer points: $$(4,0),(0,4),(-4,0),(0,-4)$$

If the radius is 3, again it's 4 integer points. If the radius is 2, again 4. Radius 1 - again, 4. Radius 0 has only 1 integer point. If we add all these up it's 12 + 4 + 4 + 4 + 4 + 1 , or 29 points total for the 2 dimensional hyperspheres with radius \$<=5\$.

Now if we take the dimension 1 hypersphere, it is interpreted as 2 points in a one dimensional space, distance r from the origin. For example the 1 dimensional hypersphere with radius 5 has only two points, $$(5),(-5)$$ and their coordinates are only single dimensional. So, the dimension 1 hypersphere with radius 5 has two integer points. The dimension 1 hypersphere with radius 4 also has 2 integer points, and so on. The total integer points on all 1 dimensional hypspheres with radius 0 to 5 is 2 + 2 + 2 + 2 + 2 + 1, or 11.

The dimension 0 hypersphere is defined for this challenge to have 0 points.

So the final output of a program with input \$r = 5, d = 2\$ will be 29 + 11 + 0, or 40.

  • You may assume that r and d will be low enough so that the integer type of your language will be large enough so that it can represent the answer. In other words if your language has only 16 bit integers, then you can write a program that assumes r and d will be low enough so that the final answer is between 0 and 65535.

  • This is Code Golf, lowest # of bytes wins

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This is essentially Pythagorean triples but generalised to d-tuples, right? (and allowing 0) \$\endgroup\$
    – pxeger
    Oct 18, 2021 at 10:42
  • \$\begingroup\$ i think so, yes, that sounds correct... \$\endgroup\$
    – don bright
    Oct 19, 2021 at 2:11
0
\$\begingroup\$

Same String Regardless of Repetition

Challenge

Write a full program that prints a string that has a length of at least 1. When the source code is repeated any amount of times, that string should still be outputted. For example, if my source code is ABC and it prints Hello, World!, then ABCABC will still print Hello, World! and ABCABCABC will also print Hello, World! and etc.

Rules

  • It has to be a full program that takes no input (or have an unused input if this is impossible) and prints the string to STDOUT.
  • The program and the string have to be at least 1 byte long.
  • The strings that are outputted with each repetition have to be exactly the same. Trailing or leading spaces make the strings different.
  • There must be only one output.
  • There is no code between repetitions.
  • Comments in your code are not allowed.
  • This is code-golf, so programs are scored in bytes, with less bytes being better.
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I’m not too sure if “comments are not allowed” is an easy rule to enforce… everything else seems fine, +1 from me \$\endgroup\$
    – W D
    Oct 22, 2021 at 2:47
  • 1
    \$\begingroup\$ Maybe require the program to print a number alongside the Hello, World! to enforce that the code has to account for the repetitions? so ABC => 1. Hello, World!, ABCABC => 2. Hello, World! etc., and just make sure to specify that code can't read itself? This way, if you just comment out the rest of the code, it will fail. \$\endgroup\$ Oct 22, 2021 at 12:47
  • 1
    \$\begingroup\$ To avoid comment abuse and answers along the lines of print('Hello, World!');exit; you could require the program to be irreducible. However I suspect this challenge will still be really easy in most golfing languages. Here is an example (2 byte program repeated 3 times), and I don't even know Japt. \$\endgroup\$
    – Dingus
    Oct 24, 2021 at 3:26
0
\$\begingroup\$

Make an ASCII Quasi-Golden Rectangle

While this challenge does involve making a golden rectangle, we're going to do something a bit different.

Task

Given an input n, using three distinct, non-whitespace characters (+s, |s, and -s will be used in examples) as well as spaces and newlines, generate a grid of n squares that form a rectangle.

Rules

  • Each square of your rectangle must use one character for corners, one for vertical lines, and one for horizontal lines.
  • Within each square, there must be an x by x region of whitespace, where x follows this sequence (Fibonacci sequence, but with 1s added to account for the border).
  • Besides the first two 1 by 1 squares, no two squares may be the same size.
  • Your output must include exactly n squares (or n + 1 if you're 0-indexing, which is allowed).
  • Adjacent squares must share their borders.
  • Orientation does not matter, so reflections and rotations are OK.
  • Leading/trailing whitespace per line or at the end of the output is OK, so long as it doesn't disrupt the rectangle.

Correct Examples

Examples are 1-indexed, but bear in mind that you are allowed to 0-index. n = 1: (Note that this is the only valid output for n = 1, save for any trailing whitespace.)

+-+
| |
+-+

n = 2:

+-+-+
| | |
+-+-+

The other valid answer would be

+-+
| |
+-+
| |
+-+

n = 3: (Note the internal +, as it is still at a corner)

+---+
|   |
|   |
|   |
+-+-+
| | |
+-+-+

n = 4:

+-----+---+
|     |   |
|     |   |
|     |   |
|     +-+-+
|     | | |
+-----+-+-+

Incorrect examples

Extra borders

+---++-+
|   || |
|   |+-+
|   || |
+---++-+

Missing corner

+---+-+
|   | |
|   |-+
|   | |
+---+-+

Wrong size

+-----+--+
|     |  |
|     |  |
|     +--+
|     |  |
|     |  |
+-----+--+

Disruptive whitepsace

+-+

| |

+-+

Scoring

Code golf. Shortest wins.

Meta

Is the part with the OEIS link phrased ok? And the parts about indexing?

In general, is this clearly written?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ If you measure border to border, then your square sizes are 2, 2, 4, 6, 10... \$\endgroup\$
    – Neil
    Oct 22, 2021 at 9:16
  • \$\begingroup\$ @Neil oh, so it is Fibonacci-like. I can work with that, thank you. \$\endgroup\$ Oct 22, 2021 at 12:27
0
\$\begingroup\$

In 1960 Andrey Kolmogorov conjectured that any algorithm to multiply two integers would require \$\Omega(n^2)\$* steps.

Within a week of presenting this conjecture it was proven false by graduate student Anatoly Karatsuba. Karatsuba's algorithm is an algorithm to multiply two numbers which takes in the worst case \$O(n^{\log_2 3})\$ time.

Your task will be to implement this algorithm. You will receive as input two binary strings. These can be lists of ints, arrays of bools etc.

You should then output the binary representation of their product in the same format.

It's hard to say in precise terms what it means to implement a particular algorithm. So here we will require only that your algorithm have asymptotic time complexity of \$O(n^{\log_2 3})\$ and \$\Omega(n^{\log_2 3})\$ where \$n\$ is the total number of bits in the input. Which is to say that it is neither better nor worse than Karatsuba's algorithm up to a constant factor.

This is so answers will be scored in bytes with lower bytes being the goal.


* In this challenge we will use \$f\in \Omega(g)\$ to mean that \$\displaystyle\limsup_{x\to \infty}\dfrac{f(x)}{g(x)}\$ does not converge to \$0\$. Also stated as \$f \in \Omega(g) \iff \exists k.\forall x.\exists x'.f(x')\geq k\cdot g(x')\$. This is the Hardy-Littlewood definition.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Python is known to use the exact algorithm under the hood, and it may be true for some other langs as well. Is it OK to use such built-in? Also, is it OK to use even faster multiplication and just slow it down with dummy recursion? \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 5:24
  • \$\begingroup\$ As bubbler mentioned, I would suggest remove the lower bound from the question, as the answer may implement a better algorithm (I don't know if it exist or not) and then slow it down by appending some dummy operations. \$\endgroup\$
    – tsh
    Oct 26, 2021 at 6:28
  • \$\begingroup\$ Also, you should explain what does \$n\$ means in the formula (length of input). As it is not very clear to readers. \$\endgroup\$
    – tsh
    Oct 26, 2021 at 6:29
  • \$\begingroup\$ @tsh is "where n is the total number of bits in the input." unclear? I'm not sure how I can explain it more directly than that. \$\endgroup\$
    – Wheat Wizard Mod
    Oct 26, 2021 at 7:50
  • \$\begingroup\$ @Bubbler RE builtins: I don't ban builtins, I don't think it makes challenges better and only leads to confusion. It's up to the user whether they want to have fun. RE faster algos: The point of this challenge to implement this algorithm, not faster ones. The lower bound is there to encourage the algo. If you use a faster algorithm you are going to have to pay the cost to pad it out to the correct run time. \$\endgroup\$
    – Wheat Wizard Mod
    Oct 26, 2021 at 8:33
  • 2
    \$\begingroup\$ I guess it could be better to further specify "the total number of bits of the two input numbers". Also probably move it closer to the first use of n. \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 8:52
  • \$\begingroup\$ @Bubbler Technically the \$n\$ in the initial statement is a little more complex. It's just a explainer so I don't think it's worth getting into all the details when in basically works like the default meaning of \$n\$. \$\endgroup\$
    – Wheat Wizard Mod
    Oct 26, 2021 at 9:07
0
\$\begingroup\$

Solve linear equations over the integers

All variables in this question are integer valued.

Input

4 integers w, x, y, z. They can be positive or negative and will be less than 1048576 in absolute value.

Output

The general solution to the equation.

\$ aw+bx+cy+dz = 0 \$.

The variables \$a, b, c, d\$ must all be integer values.

Output format

Your output should consist of three tuples each with four parts, one for each of the values a, b, c, d. Let me explain by example:

Input: -118, 989, 918, -512

Answer: b = 2 n_0 
        c = 9 n_0 + 256 n_1 + 81 a
        d = 20 n_0 + 459 n_1 + 145 a

Explanation: n_0 and n_1 are integers that you can set to anything you like. The solution says: a can also be set to any integer value, b must be twice whatever you set n_0 to. This means that a can be set to any integer, c can now be calculated in terms of three variables we have already set and so can d.

The format of your output should be 3 tuples (#,#,#,#), (#,#,#,#), (#,#,#,#). We can assume three free integer variables n0, n1 and n2 and so (a,b,c,d) = (#,#,#,#)n0 + (#,#,#,#)n1 + (#,#,#,#)n2. In the example above the output would therefore be:

Output: (0, 2, 9, 20), (0, 0, 256, 459), (1, 0, 81, 145)

Examples

Example one:

 Input: -6, 3, 7, 8

 Answer:  c = 2a + 3b + 8n
          d = -a - 3b - 7n 
          n is any integer

Output: (1, 0, 2, -1), (0, 1, 3, -3), (0, 0, 8, -7)

Example two:

Input: -116, 60, 897, 578

Answer: c = 578 n + 158 a + 576 b
        d = -897 n - 245 a - 894 b 
        n is any integer

Output: (1, 0, 158, -245), (0, 1, 576, -894), (0, 0, 578, -897)

Example three:

Input: 159, -736, -845, -96

Output: (1, 0, 27, -236), (0, 1, 64, -571), (0, 0, 96, -845)

Discussion

To understand this challenge further it is worth looking at this possible general solution which does not work [(z, 0, 0, -w), (0, z, 0, -x), (0, 0, z, -y)]. The problem with this is that there are solutions to the problem instances above which are not the sum of any integer multiples of those tuples. For example: take input -6, 3, 7, 8 from Example 1. The proposed solution would give the tuples:

(8, 0, 0, 6), (0, 8, 0, -3), (0, 0, 8, -7)

Why doesn't this work?

There is a solution for this instance with a = 1, b = 1, c = 13, d = -11 because -6+3+7*13-11*8 = 0. However there are no integers n_0, n_1, n_2 to make n_0 * (8, 0, 0, 6) + n_1 * (0, 8, 0, -3) + n_2 * (0, 0, 8, -7) = (1, 1, 13, -11) .

\$\endgroup\$
17
  • \$\begingroup\$ I expect the most common form of outputs would be (a,b,c,d) = (#,#,#,#)x + (#,#,#,#)y + (#,#,#,#)z, where #s are some integer constants and x,y,z are free variables. In this case, may I simply output the three vectors of length 4? \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 2:35
  • \$\begingroup\$ @Bubbler. The inputs are labelled w,x,y,z. I assume your x,y,z are not those? \$\endgroup\$
    – user7467
    Oct 26, 2021 at 3:32
  • \$\begingroup\$ I mean, (a,b,c,d) = (#,#,#,#)n0 + (#,#,#,#)n1 + (#,#,#,#)n2 if it reads better. Or in four separate equations: a = #n0 + #n1 + #n2; b = #n0 + #n1 + #n2; .... \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 3:34
  • \$\begingroup\$ @Bubbler what worries me slightly about that formulation is that it might force the coefficients to be really large. You seem to get much smaller coefficients if you express the variables in terms of previous ones and some free variables. \$\endgroup\$
    – user7467
    Oct 26, 2021 at 3:37
  • \$\begingroup\$ No, the coefficient size is irrelevant. Your example output in my format is a = 0*n_0 + 0*n_1 + 1*n_2; b = 2*n_0 + 0*n_1 + 0*n_2; c = 9*n_0 + 256*n_1 + 81*n_2; d = 20*n_0 + 459*n_1 + 145*n_2, or (a,b,c,d) = (0,2,9,20)n_0 + (0,0,256,459)n_1 + (1,0,81,145)n_2 in short. I'm only asking about the output format here. Is outputting [[0,2,9,20], [0,0,256,459], [1,0,81,145]] OK? \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 3:39
  • \$\begingroup\$ Let me think if you would ever have to express d in terms of c which in turn is expressed in terms of b. \$\endgroup\$
    – user7467
    Oct 26, 2021 at 3:44
  • \$\begingroup\$ Such situation can always be simplified to my form using substitution followed by expansion. \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 3:47
  • \$\begingroup\$ Yes. That’s where my concern about coefficient size comes in I believe. \$\endgroup\$
    – user7467
    Oct 26, 2021 at 3:49
  • \$\begingroup\$ Why are you concerning about the coefficient size in the first place? Isn't it plain code golf and we're allowed to output any solution that solves the problem I assume? \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 3:52
  • \$\begingroup\$ Maybe I shouldn’t worry about it. You can solve the problem so that you get ugly answers with huge coefficients (which is what sympy does). I thought it would be good to avoid that. \$\endgroup\$
    – user7467
    Oct 26, 2021 at 4:11
  • \$\begingroup\$ Thanks for your understanding. But still you didn't answer my original question about the output format. \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 4:15
  • \$\begingroup\$ If you have to scale your byte count by a factor which is how much larger (in absolute value) your largest coefficient is than the examples is that then code-challenge? \$\endgroup\$
    – user7467
    Oct 26, 2021 at 4:16
  • \$\begingroup\$ I really like your output format. I am just trying to work if it causes problems which I want to avoid. An alternative is to have 3 coefficients for a, 4 for b, 5 for c and 6 for d. That would enable you to express each one in terms of both the free variables and the other variables. \$\endgroup\$
    – user7467
    Oct 26, 2021 at 4:17
  • \$\begingroup\$ No, mixing code length with some other metric doesn't work (believe me, I tried it once and failed). Just go pure code-challenge (must run in reasonable amount of time, smallest coefficient wins) or pure code-golf (no time limit, output anything valid). For the former, you also need to prepare a good amount of hidden test cases (test-battery), otherwise you can't avoid hardcoded solutions. \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 4:23
  • \$\begingroup\$ The point is that "fully general format" as in your examples is way too tedious to actually output in non-Mathematica languages, so I'm suggesting a structured output which tries to simplify that. And all possible outputs can be expressed in the format I'm suggesting. If you decided for code-golf, you should absolutely stop worrying about the coefficient size. Please. \$\endgroup\$
    – Bubbler
    Oct 26, 2021 at 4:41
0
\$\begingroup\$

Is someone eavesdropping? (WIP)

Alice and Bob, who are quantum physicists, are being watched by Eve, a quantum FBI agent. Eve has quantum tunneled underneath Bob's house and is tapping all his quantum channels. Luckily, Alice and Bob are using the BB84 protocol to exchange quantum keys to encode their quantum messages. Your job is to write a program/function to help Alice and Bob determine if Eve is evesdropping.

\$\endgroup\$
0
\$\begingroup\$

Posted here

\$\endgroup\$
0
\$\begingroup\$

posted here

\$\endgroup\$
2
  • \$\begingroup\$ Will input word contains duplicate characters? What is expected output for top, [to, two, too], equipment, [queue, queen, quine]? \$\endgroup\$
    – tsh
    Oct 26, 2021 at 6:24
  • \$\begingroup\$ Updated examples. \$\endgroup\$
    – Seggan
    Oct 26, 2021 at 15:01
0
\$\begingroup\$

Implement every dirname (1p)

Implement the dirname utility from scratch. It can be either a program or a fucntion. Assume input string satisfies these constraints:

The dirname utility, however, has two kinds of implementations. This is because some POSIX systems treat //foo/bar differently from /foo/bar. So in this challenge, you must output every possible outputs, in any order. They can be duplicated.

Here is the algorithm to implement the utility, provided string to be input:

  1. If string is //, skip steps 2 to 5.
  2. If string consists entirely of <slash> characters, string shall be set to a single <slash> character. In this case, skip steps 3 to 8.
  3. If there are any trailing <slash> characters in string, they shall be removed.
  4. If there are no <slash> characters remaining in string, string shall be set to a single <period> character. In this case, skip steps 5 to 8.
  5. If there are any trailing non- <slash> characters in string, they shall be removed.
  6. If the remaining string is //, it is implementation-defined whether steps 7 and 8 are skipped or processed.
  7. If there are any trailing <slash> characters in string, they shall be removed.
  8. If the remaining string is empty, string shall be set to a single <slash> character.

The final string is the output.

Standard I/O rules apply. Standard Loopholes apply. No builtins or libraries that does exactly same functionality. Shortest code wins.

Examples

Some examples are taken from POSIX explaination of basename().

* means an empty string. 1st column is input and 2nd and 3rd are possible outputs.

usr               .
usr/              .
*                 .
..                .
../               .
/                 /
//                /          //
///               /
/usr/             /
//usr/            /          //
///usr/           /
/usr/lib          /usr
//usr//lib//      //usr
/home//dwc//test  /home//dwc

Meta

  • ?
\$\endgroup\$
0
\$\begingroup\$

Write a Stack Exchange compliant brainfuck explainer

\$\endgroup\$
6
  • \$\begingroup\$ @Adám But i prefer using 4 spaces \$\endgroup\$
    – Fmbalbuena
    Nov 14, 2021 at 22:40
  • \$\begingroup\$ I'm not sure what you mean by stating your preferences. Either it is allowed, or not. \$\endgroup\$
    – Adám
    Nov 14, 2021 at 22:41
  • 1
    \$\begingroup\$ ~ is ascii 126 \$\endgroup\$
    – tsh
    Nov 15, 2021 at 5:10
  • \$\begingroup\$ I would suggest avoid characters [] in description so they are ensured to be comment. \$\endgroup\$
    – tsh
    Nov 15, 2021 at 5:12
  • \$\begingroup\$ @tsh Oh, that's interesting, then the code remains runnable, even when fully explained. \$\endgroup\$
    – Adám
    Nov 15, 2021 at 7:32
  • 2
    \$\begingroup\$ I still strongly recommend giving the explanation strings as an argument, or even giving both explanation strings and symbols as arguments; that'd make the solution into a general code explainer. \$\endgroup\$
    – Adám
    Nov 15, 2021 at 8:10
0
\$\begingroup\$

Escape the maze

Introduction

Here is a random maze:

#####
#M.#E
#.##.
#.##.
#....
#####

Here M is the starting point and E is the endpoint. # is a maze wall and . is a path.

Now we can get out of this maze by following the sequence sssdddwww. (s is dow, d is right, w is up, a is left.)

Your challenge

Given a maze, output the shortest possible route to the endpoint. (E) You may assume the maze is solvable.

Test cases

#####
#M.#E
#.##.
#.##.
#....
#####

outputs

#####
#..#E
#M##.
#.##.
#....
#####

#####
#..#E
#.##.
#M##.
#....
#####

#####
#..#E
#.##.
#.##.
#M...
#####

#####
#..#E
#.##.
#.##.
#.M..
#####

#####
#..#E
#.##.
#.##.
#..M.
#####

#####
#..#E
#.##.
#.##.
#...M
#####

#####
#..#E
#.##.
#.##M
#....
#####

#####
#..#E
#.##M
#.##.
#....
#####

#####
#..#M
#.##.
#.##.
#....
#####

(Notice the newlines between the steps.)

Scoring

This is , so shortest code wins.


Todo

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Meta code golf. add tag maze :p \$\endgroup\$
    – Fmbalbuena
    Nov 18, 2021 at 20:21
  • \$\begingroup\$ @Fmbalbuena Done. \$\endgroup\$
    – Bgil Midol
    Nov 18, 2021 at 20:22
  • \$\begingroup\$ Dupe of Find the shortest path from point A to point B. That challenge has itself been closed as a dupe of Textual maze solver, a decision I don't necessarily agree with, but better to reopen the existing challenge than create a new one. \$\endgroup\$
    – Dingus
    Nov 18, 2021 at 22:31
0
\$\begingroup\$

Solve the halting problem for Minyrinth

Introduction

Minyrinth is the stripped-down version of Labyrinth. It has the same routing semantics as Labyrinth but only four non-wall commands, and only one register (that can hold unbounded signed integers) instead of two stacks. The register is initialized to zero.

Commands

  • " is a no-op path.
  • @ halts the program.
  • ) increments the register.
  • ( decrements the register.

You may assume that the input only contains the four command characters plus spaces (non-path) and newlines (used for 2D layout).

Execution semantics

Copied directly from the README, with some parts edited for Minyrinth:

The source code consists of single-character instructions and is interpreted as a 2D grid. The instruction pointer starts at the first non-whitespace character in the file (in reading order) going right.

Labyrinth is interpreted in a simple loop. At each step, the command under the instruction pointer is executed, then the new movement direction is determined, and then the instruction pointer moves one cell in that direction. The edges of the grid are not connected.

The instruction pointer will generally follow "corridors" of instructions. Junctions can be used for non-trivial control flow. How the new movement direction is determined depends on the number of available steps (i.e. number of direct neighbours with known commands):

  • 4 neighbours: The top of the main stack is examined. If it's 0, keep moving straight ahead. If it's negative, turn left. If it's positive, turn right.

  • 3 neighbours: Do the same as for four neighbours, but if you hit the wall, reverse the direction. Hence, a T-junction hit from the side differentiates between 0 and non-zero. A T-junction hit from the bottom on the other hand sends negative/positive to the left/right whereas a 0 value reverses the direction.

  • 2 neighbours: The first rule here is, don't turn around. So if you came from one of the two directions, continue in the other direction. If this is not the case, but one of the two directions is straight ahead, follow that one (this can happen, for instance, at the start of the program in a corner).

  • 1 neighbour: Go towards the only available direction. Usually, this means you have hit a dead end and turn around on the spot (executing the command you turn around on only once).

  • 0 neighbours: Remain where you are without changing your direction. This can occur at the very start of the program.

Challenge

Solve the halting problem for Minyrinth. Unlike Labyrinth which is Turing-complete, Minyrinth simulates a specific case of a pushdown automaton whose halting problem is decidable.

For output, you can choose to

  • output truthy/falsy using your language's convention (swapping is allowed), or
  • use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.

Standard rules apply. The shortest code in bytes wins.

Some hints can be found in CS Stack Exchange: Decidability of halting problem for DPDAs with \$\epsilon\$-transitions?, Counter Machine (Halting Problem)

\$\endgroup\$
0
\$\begingroup\$

Plan my factory

"Factory games", such as Factorio, Mindustry, and Satisfactory are my favourite genre of video games, and the way I play them involve a lot of ratio calculations to make sure the factory is running as efficiently as possible.

Given a list of recipe specifications, and a desired production rate of an end product, output the necessary input rates of raw materials, where "raw material" is any ingredient that does not have a provided recipe.

For example:

Recipes:

[
    {
        name: "Iron Plate",
        time: 3.2,
        quantity: 1,
        input: [{
            name: "Iron Ore",
            quantity: 1
        }]
    },
    {
        name: "Copper Plate",
        time: 3.2,
        quantity: 1,
        input: [{
            name: "Copper Ore",
            quantity: 1
        }]
    },
    {
        name: "Iron Gear",
        time: 0.5,
        quantity: 1,
        input: [{
            name: "Iron Plate",
            quantity: 2
        }]
    },
    {
        name: "Automation Science Pack",
        time: 5,
        quantity: 1,
        input: [
            {
                name: "Iron Gear",
                quantity: 1
            },
            {
                name: "Copper Plate",
                quantity: 1
            }
        ]
    },
]

Desired production rate:

{
    name: "Automation Science Pack",
    rate: 60
}

Expected output:

[
    {
        name: "Iron Ore",
        rate: 120
    },
    {
        name: "Copper Ore",
        rate: 60
    }
]

Both input and output may be any standard IO format that represents item names as strings and quantities/rates as integers.

Testcases

TBA

Sandbox

Is this a chameleon challenge?

\$\endgroup\$
0
\$\begingroup\$

Golf a Friedman's tree sequence for 3 colors

Friedman proved that given a sequence of 3-labelled rooted trees with following conditions, TREE sequence, must be finite and defined maximum length of such sequence as TREE(3).

  • \$i\$th tree, \$T_i\$, should have no more than \$i\$ vertices. (index is 1-based)
  • No tree \$T_i\$ can be homeomorphically embeddable into any of the following tree \$T_j\$ if \$i < j\$.
    • A tree \$A\$ is said to be homeomorphically embeddable to tree \$B\$ if and only if there exists a function \$f\$ from vertices of \$A\$ to vertices of \$B\$ which satisfies following conditions:
      1. \$f\$ preserves label. That is, \$v\$ and \$f(v)\$ has same label.
      2. If \$u\$ is ancestor of \$v\$, then \$f(u)\$ is ancestor of \$f(v)\$.
      3. If \$u_1\$ and \$u_2\$ are children of \$v\$, then the path from \$f(u_1)\$ to \$f(u_2)\$ contains \$f(v)\$.
    • There is a guide with examples in this youtube video.

It is well known that TREE(3) is far larger than \$2^{64}\$.

Challenge

Find a TREE sequence with length of \$2^{64}\$ or longer. Your task is to implement a program or a function or a subroutine that takes one 64-bit integer \$i\$ and outputs a tree \$T_i\$ of your TREE sequence.

Rules

  • Standard loopholes apply.
  • Standard I/O rules apply.
  • Shortest code wins.
  • Output can be any format as long as it describes a 3-labelled tree.
  • Describe how your outputs form valid TREE sequence.

Example of valid sequence, length 16

1 - {}              # 1 vertex tree with label {}. Note that any tree after this cannot contain node with label {}.
2 - [[]]            # 2 vertex tree with label both []. Any tree after this cannot contain two ancestor-child node with both label [].
3 - [(())]
4 - ([][])          # Root with label (), 2 children with label [].
5 - ([]((())))
6 - ([](()))
7 - [()]
8 - []
9 - ((((((((()))))))))
10 - (((((((())))))))
11 - ((((((()))))))
12 - (((((())))))
13 - ((((()))))
14 - (((())))
15 - ((()))
16 - (())

Meta

This is my first challenge. Suggestions?

I'm sure that normal computers will have serious difficulty to execute code for this problem, but also I don't want answers to just brute force TREE sequence and print ith term. How can I balance the question?

\$\endgroup\$
1
  • \$\begingroup\$ You definitely need some examples of the rules. Also, "homeomorphically embeddable" is not a term the average codegolfer is familiar with. \$\endgroup\$
    – NieDzejkob
    Nov 16, 2021 at 22:21
0
\$\begingroup\$

OEIS A049190

your task is to print all numbers of this sequence.

is separated by newline, is separated by space or separated by comma.

the first few numbers are:

1, 3, 5, 59, 245, 2491, 235253, 127756731, 330567489269, 258479716298484155, 36823182192123209878050549, 25576412117054296344209353299113896379, 10994511204169842163496446583221775727830456269734123253

How to get numbers of this sequence:

this is look and say but in binary and convert to decimal

Meta

  • How to clarify this?
\$\endgroup\$
0
\$\begingroup\$

Convert codepoint to UTF-1

\$\endgroup\$
0
\$\begingroup\$

Infinite ordinals from a well-ordering

\$\endgroup\$
3
  • \$\begingroup\$ Are the score categories essentially arbitrary? If so, it's not clear to me whether this is a good idea: it seems like these constraints provide the only motivation for choosing a well-ordering different from the 'default' (1, 2, 3, ...). Poor constraint choices could derail the challenge (i.e. make it too trivial or too hard). On the subject of scoring, looking at the bytes category for example, do you mean that if the default ordering is chosen, the code must be exactly 1 byte? \$\endgroup\$
    – Dingus
    Nov 12, 2021 at 0:48
  • \$\begingroup\$ Also, there's a typo under the second example: 2 < 101 is true. \$\endgroup\$
    – Dingus
    Nov 12, 2021 at 0:48
  • \$\begingroup\$ @Dingus I tried to clarify the scoring part. So if you choose \$\omega\cdot 2\$ you just try to golf an implementation of it. In this case someone has (hypothetically) managed to do it in one byte. As for the difficulty of the ordinals, the first two are one-liners in most languages, \$\omega^\omega\$ can be implemented with a while loop and \$\epsilon_0\$ with a tree. The score categories are not totally arbitrary. \$epsilon_0\$ is an important ordinal, and the smaller ones follow a natural pattern. Another option is to have just one ordinal, making this a normal golf and not a challenge. \$\endgroup\$
    – AnttiP
    Nov 12, 2021 at 7:41
0
\$\begingroup\$

Baloney Sandwich KOTH

Tags: [king-of-the-hill], [python]

Introduction

In this King Of The Hill Challenge, your bots will be playing Baloney Sandwich.

How Baloney Sandwich is played

  1. First, the entire deck is dealt equally to all players (EVERY BOT PLAYS; if there is more than 26 bots, it will be 2 decks mixed together).
  2. Then, the player with the ace of spades goes first.
  3. They play all of their aces
    • However! They could opt to "cheat" and instead play cards that are not aces, or mix and match aces with other cards.
  4. Every other player has their call_bs (bs = Baloney Sandwich) method called after this play, in turn until a player returns True; if a player returns True then the cards played are "revealed".
    • Every player has their bs_call_outcome method to "reveal" the cards
    • If no player returns True but the player was lying, the pb method is called (pb = Peanut Butter)
  5. Play continues with twos, threes, etc.; after kings, start over at aces

Creating A Player

Your player should be in this format:

class ExamplePlayer(AbstractBSPlayer):
    def __init__(self, hand: list[int]):
        super().__init__(hand)
        # Any necessary initialization goes here

    def call_bs(self, player_name: str, card_rank: int, number_of_cards: int) -> bool:
        """
        player_name is the name of the bot who just played
        The number of cards they played is number_of_cards
        The claimed rank is card_rank (1 is Ace; 11-13 are face cards)
        """
        # Magic decision maker
        return False # never calls "Baloney Sandwich"
        # return True would always call "Baloney Sandwich"
    
    def bs_call_outcome(self, player_name: str, caller_name: str, card_rank: int, cards: list[int], cheated: bool):
        """
        player_name is the name of the bot who just played
        caller_name is the name of the bot who called "Baloney Sandwich"
        The claimed rank is card_rank
        The cards they played is cards
        cheated is True if the player cheated
        """
        pass  # Couldn't care less
    
    def pb(self, player_name: str, card_rank: int, number_of_cards: int):
        """
        player_name is the name of the bot who just played
        The number of cards they played is number_of_cards
        The claimed rank is card_rank (1 is Ace; 11-13 are face cards)
        """
        pass # Couldn't care less

    def play_cards(self, card_rank: int) -> list[int]:
        """
        The rank you will claim to play is card_rank
        """
        # Magic decision maker
        return self.hand[0] # Always plays the first thing in hand

A player has access to the following instance variables:

  • self.store: A dictionary that is empty by default. The only instance variable allowed to be written to.
  • self.hand: A list of ints, each representing a card (1 is Ace, 11-13 are face cards)

Testing Your Player

The controller can be found at https://github.com/sethpeace/bs-koth. I apologize in advance that it is janky beyond comprehension.

Rules

Runtime Disqualifications

  • You must play at least one card every turn
  • You can't play cards you dont have in your hand
  • You can't take longer than one second to return from a function

Pre-runtime Disqualifications

  • No reading or writing to controller, runtime, or other submissions (bots can't read them; you can if you feel like it)
  • Only write to self.store instance variable
    • Other variables inside function scope are of course OK
  • Don't design a bot to defend or support specific bots
  • Bots can't use the same strategy as another bot
  • Standard loopholes apply
\$\endgroup\$
4
  • \$\begingroup\$ This seems too similar to codegolf.stackexchange.com/questions/48473/thats-bs-card-game \$\endgroup\$ Nov 27, 2021 at 16:45
  • \$\begingroup\$ @RedwolfPrograms you are correct; thank you \$\endgroup\$
    – Seth
    Nov 27, 2021 at 16:46
  • \$\begingroup\$ It's cool to see some more KotHs being written though! If you have any ideas for ones that you're not sure are dupes, feel free to bring them up in chat to save the effort of having to write out a whole spec first. \$\endgroup\$ Nov 27, 2021 at 16:48
  • \$\begingroup\$ @RedwolfPrograms alright thanks again :) \$\endgroup\$
    – Seth
    Nov 27, 2021 at 16:49
0
\$\begingroup\$

Implement xorshift128+

I don't have time to finish writing this draft at the moment.

Might also consider something like xoroshiro if it's more interesting to implement, but since xorshift128+ is so common it seems like a clearer choice.

(Possible idea: Given initial seed, determine number of iterations it'll take to get a certain random number with xorshift128+. It's not a CSPRNG, so there might be something more interesting than brute force.)

\$\endgroup\$
0
\$\begingroup\$

Radiate a prime checker into a sum program

Write a program or function that takes a number n and returns/print truthy if it is prime, and falsy otherwise. Additionally, if you remove 1 character of the source code, the program must now take a list of one or more numbers and return/print the sum. This must work for at least one character, and your score is however many characters that this does /not/ work for. Lowest score wins.

meta:

let me know if i need to clarify anything etc also: would it make sense to allow the programs to be the other way around (i.e. a sum checker where removing 1 character makes it a prime checker instead)? Just in case it could lead to a more interesting golf

\$\endgroup\$
2
  • \$\begingroup\$ It says "remove or change 1 character". By change, do you mean simply changing an arbitrary character to another arbitrary character, e.g. abc -> axc? If so, a lot of golfing languages will likely be able to make a trivial 0-score program where they simply change a 1-byte prime checker to a 1-byte sum command. That might not be a bad thing, per se, but it's something to keep in mind. \$\endgroup\$ Dec 8, 2021 at 21:16
  • \$\begingroup\$ @AaroneousMiller True, ill stick to just "remove". Wasn't sure of potential ramifications, thanks \$\endgroup\$ Dec 8, 2021 at 21:18
0
\$\begingroup\$

Quickly pour liquid nitrogen

I have a container of liquid nitrogen, but nothing to measure it with. I do have some containers, whose volumes I know, and I know how much I start with. My goal is to fill any container with a given amount of liquid nitrogen, with the fewest possible pours.

Importantly, liquid nitrogen boils away as I pour it. Every time I pour liquid nitrogen into a container, a milliliter is lost.

Pouring mechanics:

If I have two containers, a and b, and I pour a into b:

  • If both are empty, nothing changes
  • If b's unused volume is greater than or equal to the volume of liquid nitrogen in a, a is emptied into b, and a milliliter boils away from b
  • Otherwise, as much as possible is poured from a into b, and an additional milliliter is taken from a (so b will still be full)

If I have three containers, x, y, and z, they all have volumes of 25, and they contain 25, 10, and 18 milliliters of liquid nitrogen respectively, here are some example pours (one after another, not indiviudual):

  1. x into y: y is filled, and x is left with 9 milliliters
  2. y into z: z is filled, and y is left with 1 milliliter
  3. z into x: x remains full, z is left with 24 milliliters
  4. y into z: z remains at 24 milliliters, y is emptied

(Note that in your input, not all containers will have the same volume)

Task:

Given a list of container sizes, where the first container is initiallyfull and the amount of liquid nitrogen you must measure out, return the minimum number of pours that would be needed to leave that much in any container.

You may assume volumes are non-negative integers, and the initial amount of liquid nitrogen will never be less than the amount you should end with. The actual sequence of pours you use doesn't matter, as long as you output the minimum possible count.

Test cases:

Containers          Target      Output

7, 4                3           5
12, 3, 3            4           2
100, 10, 8          84          6
8, 8                5           3
10, 0               8           2
100, 20, 20, 17     73          7

Other:

I don't think this is a good challenge after doing the test cases

\$\endgroup\$
2
0
\$\begingroup\$

Chunk Sort a Sequence

\$\endgroup\$
6
  • \$\begingroup\$ use fastest-code there are few questions with both tags. \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2021 at 16:28
  • \$\begingroup\$ time spent on what interpreter? can you say TIO? \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2021 at 16:30
  • \$\begingroup\$ @Fmbalbuena what if the interpreter is not on TIO? \$\endgroup\$
    – Bgil Midol
    Dec 4, 2021 at 16:31
  • 2
    \$\begingroup\$ You'd need many more test cases to get significant results with fastest-code. Also, using TIO for timing is a bad idea (I'm sure there's a post on meta about that, but I don't know exactly where). \$\endgroup\$
    – Arnauld
    Dec 4, 2021 at 16:33
  • 1
    \$\begingroup\$ @Arnauld here \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2021 at 16:35
  • \$\begingroup\$ @Arnauld added more test cases \$\endgroup\$
    – Bgil Midol
    Dec 4, 2021 at 16:37
0
\$\begingroup\$

Tinla Resqua (Latin Square of rotated words)!

Based on this (currently closed) question on Puzzling, your task is to take a single word generate a valid 'latin square', not by permuting the letters in a word, but by rotating the word.

E.g. if one row was CENTURY then ENTURYC is a valid row, but ENTCTURY is not.

Also unlike some Latin Squares, no diagonal may contain repeated letters either.

1 2 3 4 5 6 7
C E N T U R Y
R Y C E N T U
T U R Y C E N
E N T U R Y C
Y C E N T U R
U R Y C E N T
N T U R Y C E

Is a valid grid.

\$\endgroup\$
5
  • \$\begingroup\$ For even-length words, I think it is impossible to create such square by only rotating the word. At least it is surely true for length 2 and 4. \$\endgroup\$
    – Bubbler
    Dec 14, 2021 at 23:38
  • \$\begingroup\$ @bubbler then they could error or return null or similar? \$\endgroup\$ Dec 15, 2021 at 0:02
  • \$\begingroup\$ That could work. (I'd make it more lenient and say "output something that can be distinguished from a valid solution".) Determining absence of solution is actually harder than that, because it's also impossible for 3. It seems to depend on the existence of solution to "toroidal n-queens problem". \$\endgroup\$
    – Bubbler
    Dec 15, 2021 at 0:19
  • \$\begingroup\$ I found the solution here, which states that such a square is possible exactly when the smallest prime factor is 5, which is equivalent to n%6 being 1 or 5. \$\endgroup\$
    – Bubbler
    Dec 15, 2021 at 0:44
  • \$\begingroup\$ @bubbler very interesting \$\endgroup\$ Dec 15, 2021 at 2:16
0
\$\begingroup\$

This was heavily inspired by the donut.c program


Challenge:

You have to come up with a program that prints (in console) a shape that looks exactly like the shape of your code.

For example, if your code's shape looks like this:

    2343
3kf5
     3o*/f
   3%kt^7

then the output's shape should look like this:

    9I8b
&yt^
     )ph67
   {}fgh]

(the byte don't need to match, just the shape)

Rules

  • Empty programs/whitespace-only programs are not allowed.

  • Your program should have more than 2 lines/statements of code.

  • Each line should not be identical to every other line.

  • All whitespace characters (space, tab,...) don't have to be identical.

  • Whitespaces characters don't count towards the minimum bytes count.

  • Your program's source code and the output should not be identical. It should be at least has one different character.

  • The output should have at least two different bytes on one line.

  • You should not use comments.

Scoring criteria

  • Longest code (in bytes) wins!

  • If two same programs have the same byte count, the one with the most unique characters in the output wins!

  • If two same programs have the same unique characters, the one with the most different characters in output compared to source code wins!


Meta

  • Does this question have any duplicates?

  • My wording is bad, can you improve it?

  • Is this question interesting? Fit within the rules of the site?

\$\endgroup\$
9
  • \$\begingroup\$ How will you tie-break solutions that change all characters from source to output, while having no duplicated characters in the output? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:06
  • \$\begingroup\$ Are programs without any whitespace allowed? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:12
  • \$\begingroup\$ Please avoid requiring minimum scores. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:15
  • \$\begingroup\$ Please avoid cumbersome I/O formats like requiring printing in a console, which also makes assumptions about language features and arbitrarily overrides the defaults. Instead, refer to the default for code golf output methods. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:19
  • \$\begingroup\$ I suggest changing "input" to "source code". \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:23
  • \$\begingroup\$ Can you confirm that this is an optimal answer (minimum allowed byte count changing all its characters while having no duplicates in the output) and that if I post this answer, I win? Note also that the source has no duplicated characters either, so that it won't help to add a rule for tie-breaking on unique characters in the source. Furthermore, code and output have no characters in common at all, preventing that as a tie-break too. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:25
  • \$\begingroup\$ I think "longest code wins" is problematic. People can probably make it as long as they want. \$\endgroup\$ Dec 15, 2021 at 11:54
  • \$\begingroup\$ Oh, I completely missed the change to code-bowling. Have a look at the tag wiki for tips and warnings. Also, note that the maximum number of unique characters will be 1114112. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 11:59
  • \$\begingroup\$ Closely related, potentially a duplicate \$\endgroup\$ Dec 15, 2021 at 12:41
0
\$\begingroup\$

Get all binary between a binary number and its reverse

\$\endgroup\$
0
\$\begingroup\$

Challenge

You should write a program that has one in (your code in bytes) chance to output a 4 (could be a function that returns a 4). So if your code has 10 bytes, your code should have 1 in an 10 chance to print out a 4. Otherwise, output "finding my dice".

Rules

  • You can use whitespaces, comments or any unnecessary code to get to the number of bytes that you want.
  • You shouldn't use any loopholes.

Winning criteria

This is , so shortest code in bytes wín!

\$\endgroup\$
6
  • \$\begingroup\$ What should the solution do in the n−1 out of n cases? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 13:42
  • \$\begingroup\$ @Adám Do you mean when it doesn't print 4? Just trying to clarify. \$\endgroup\$
    – Ginger
    Dec 15, 2021 at 13:58
  • \$\begingroup\$ Say my code is 10 bytes long and I run it 50 times. On average, 5 of those runs should print a 4. What should the remaining 45 runs do? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 13:59
  • \$\begingroup\$ You phrasing sounds a lot like a program that prints is required. Please clarify if a function (e.g. taking a dummy argument) that returns 4 is allowed. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 14:00
  • \$\begingroup\$ Are we allowed to embed unnecessary strings to reach a desired byte count? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 14:01
  • \$\begingroup\$ @Adám Wouldn't that just make your score worse though? \$\endgroup\$ Dec 15, 2021 at 16:58
1
112 113
114
115 116
129

You must log in to answer this question.

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