568
\$\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".

\$\endgroup\$
0

4551 Answers 4551

1
134 135
136
137 138
152
0
\$\begingroup\$

Best Iterated Prisoner's Dilemma

\$\endgroup\$
1
  • \$\begingroup\$ this is a great idea. an example would be nice :-) \$\endgroup\$ Oct 8, 2022 at 20:30
0
\$\begingroup\$

Optimize your score on a biased multiple choice test

In a multiple choice test, sometimes, by chance, multiple questions in a row will have the same answer. Some of my teachers dislike this, and will change questions to ensure there are never more than \$n\$ of the same answer in a row.

In this challenge, for each question in a test, you'll be given a set of four confidence values from 0 to 1, which sum to 1. These represent the odds of each choice being correct (for example, [0.1, 0.6, 0.2, 0.1] if you're 60% sure that B is correct, 20% sure C is correct, and 10% sure either of the others could be right). You'll also be given a positive integer n, the maximum number of same-answer questions in a row.

Given this information, you must output the set of answers that would give you the highest estimated score.

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

Pushing boxes away but

I'll accept first fastest algorithm and then this challenge turns into .

Sandbox Notes

  • Some options are listed in comment
\$\endgroup\$
4
  • \$\begingroup\$ Upvote this comment if this idea of question is good \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • \$\begingroup\$ Upvote this comment if this idea of question is bad \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • 1
    \$\begingroup\$ Upvote this comment if this way of handling fastest-algorithm is good \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • 1
    \$\begingroup\$ Upvote this comment if this way of handling fastest-algorithm is bad \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
0
\$\begingroup\$

A randomly colored walk

Given two inputs, a distance \$d\$ and a number \$n\$ output \$n\$ random colors which each have distance \$d\$ from the previous.

Background

A random walk is a path which is defined by choosing a random direction and (usually) fixed distance to go at each step. We will be taking a random walk through the RGB color space using Euclidean distance as our metric.

The challenge

For this challenge you will take two inputs, \$n\$ and \$d\$. Let \$n\$ be the number of colors to output, this will always be an integer \$1 \leq n\$, and \$d\$ be the distance between consecutive elements, which will always be \$0 \leq d \leq 128\$. You may additionally assume that \$d\$ is an integer.

For each consecutive pair of elements \$(r_1, g_1, b_1), (r_2, g_2, b_2)\$ of the \$n\$ element sequence output, it must be the case that all values are between 0 and 255 inclusive (or \$[0,256)\$ for floats), and the distance between elements must be within 1 of d, that is \$|\sqrt{(r_1-r_2)^2+(g_1-g_2)^2+(b_1-b_2)^2} - d| < 1\$. This should allow one to restrict their output to integers if they so choose. The walk need not be uniform, but it does need to be random. The starting point of the walk should be random as well.

Standard i/o rules apply, input and output can be in any reasonable format. Graphical output is allowed (and encouraged, though I doubt it will be golfy to do so) so long as the order of the sequence is clear.

This is , so the shortest answer in bytes wins.

Test cases

For these test cases input is in the order \$n,d\$ and output is \$(r, g, b)\$ as integers. These are some possible results.

5, 5 -> (81, 60, 243), (81, 57, 239), (76, 60, 240), (80, 62, 241), (84, 60, 243)
4, 10 -> (163, 89, 77), (162, 83, 85), (166, 75, 79), (166, 82, 87)
4, 50 -> (212, 36, 232), (247, 1, 239), (220, 44, 243), (217, 81, 209)
\$\endgroup\$
0
\$\begingroup\$

Related

Play chess. You can't see the current board, and can only memory two bytes.

Each turn, you're given your current state(initially 0) and opponent's move(a special value if first move in the game). You then output a list of [moves,state] pair, and the first valid one will get used. If no valid move, then you automatically resign.

Aim is obviously win as many games and lose as less as possible.

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

4D rotation matrix to quaternions

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

Ternary 2-input logic gate

Objective

Given an expression of a ternary 2-input logic gate, pretty-print its truth table.

Ternary logic and ternary operators

L, E, and G are the truth values of the ternary logic dealt here. They correspond to Haskell's LT, EQ, and GT.

The expression can have two free variables, hence "2-input".

There are four operators that the expression can have: min, max, compare, and mappend. (Again, from Haskell.) Their truth tables are:

min|L E G
---+-----
L  |L L L
E  |L E E
G  |L E G

max|L E G
---+-----
L  |L E G
E  |E E G
G  |G G G

compare|L E G
-------+-----
L      |E L L
E      |G E L
G      |G G E

mappend|L E G
-------+-----
L      |L L L
E      |L E G
G      |G G G

where the first column is for the first argument and the first row is for the second argument.

I/O format

The input format shall be a nonempty binary tree whose branches are the operator and whose leaves are the free variables and the truth values.

The output format shall be like this:

 |L E G
-+-----
L|? ? ?
E|? ? ?
G|? ? ?

where ? is filled with appropriate truth values represented by L, E, or G. Again, the first column is for the first argument and the first row is for the second argument.

Examples

Let the free variables be P and Q in sake of demonstration.

Given P compare (E compare Q), the truth table is:

 |L E G
-+-----
L|L L E
E|L E G
G|E G G

Given (P min Q) compare (E compare (P max Q)), the truth table is:

 |L E G
-+-----
L|L E E
E|E E E
G|E E G

Given ((E compare (P max Q)) compare (P min Q)) mappend (P compare (E compare Q)), the truth table is:

 |L E G
-+-----
L|G L E
E|L E G
G|E G L

Given Q mappend P, the truth table is:

 |L E G
-+-----
L|L L G
E|L E G
G|L G G
\$\endgroup\$
0
\$\begingroup\$

Floating-point numbers have errors in addition, oh my!

Given two IEEE double-precision floating-point numbers \$x\$ and \$y\$, output the most accurate IEEE double-precision floating-point approximation of the error that would be caused by performing the floating-point addition \$x + y\$.

As a reminder, an error is defined as the approximation subtracted by the exact value.

The inputs must deal with denormal numbers and the negative zero as well. However, infinities and NaNs fall into don't care situation.

If the output is zero, its sign doesn't matter.

\$\endgroup\$
2
  • \$\begingroup\$ "If either of the operands is an infinity or a NaN, the output shall be NaN" - what about languages that don't support infinity/NaN. \$\endgroup\$
    – The Thonnu
    Feb 22 at 16:53
  • \$\begingroup\$ I'm thinking their equivalent of 1/0... or maybe just the strings "NaN" and "Infinity" \$\endgroup\$ Feb 24 at 12:10
0
\$\begingroup\$

A Fine sequence with fine interpretations

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

Making one shape out of dissections of another

\$\endgroup\$
7
  • \$\begingroup\$ Can the pieces be rotated and/or flipped? \$\endgroup\$
    – Bubbler
    Feb 22 at 7:29
  • \$\begingroup\$ @Bubbler Yes, they can be moved, rotated, and flipped, but nothing else. I will clarify in the post. \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:30
  • \$\begingroup\$ Two falsy test cases are actually truthy: tio.run/##S07MK0ss/v8/… \$\endgroup\$
    – Bubbler
    Feb 22 at 7:31
  • \$\begingroup\$ @Bubbler Lol f*** i am bad at puzzles \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:32
  • \$\begingroup\$ How am i gonna make the falsey test cases if i can't even make these simple ones lol \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:33
  • 1
    \$\begingroup\$ Well, the correct answer here is to write a working code yourself and generate test cases based on it :) \$\endgroup\$
    – Bubbler
    Feb 22 at 7:38
  • 1
    \$\begingroup\$ @Bubbler You overestimate my coding capabilities :( \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:39
0
\$\begingroup\$

Find the sum of the sub-list with the largest sum

Challenge

Given a list that contains an integer, a sub-list is a contiguous non-empty sequence of elements within that list.

For example, the list \$[1, 3, -2, 5, -6]\$, has some sub-lists \$[1]\$, \$[3, -2]\$, \$[3, -2, 5, -6]\$, etc.

Your job today is to find the sum of the sub-list with the largest sum.

For example \$[1, 3, -2, 5, -6]\$, the sum of the sub-list with the largest sum is \$7\$, the sub-list with the largest sum is \$[1, 3, -2, 5]\$.

Specification

  • Input / Output can be taken in any reasonable format, taking a list of numbers and returning a number, which is the sum of the sub-list with the largest sum
  • The input array is guaranteed to have at least one element.

Testcases:

[1, 3, -2, 5, -6] -> 7
[-2, 1, -3, 4, -1, 2, 1, -5, 4] -> 6
[-3, -6, -8, -1] -> -1
[5, 4, -1, 7, 8] -> 23

This is , so shortest answer (in bytes) wins!

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

Canonical form of a cubic Bézier curve

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

Draw Parcly Taxel's cutie mark

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

Generating all possible equations with 10 characters

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Welcome to CGCC, and thanks for using the Sandbox! This looks like an interesting challenge. You'll need to specify a winning criterion; it looks like you're interested in fastest-code (code should run as fast as possible), but we normally don't combine that with restricted-time (code must take less than an hour to run). fastest-code without the 1-hour restriction is one option; code-golf + restricted-time is another. If you're not sure which to choose, I recommend code-golf, since it's easier to calculate the score for submissions. \$\endgroup\$
    – DLosc
    Mar 1 at 23:21
  • \$\begingroup\$ @DLosc I wanted this "1 hour" part to be just a kind of side note for people to know what to expect regarding the performance. I changed my question to make it seem less like a winning requirement \$\endgroup\$
    – ordptt
    Mar 1 at 23:32
  • \$\begingroup\$ You need to objectively specify what does "as fast as possible" mean. See codegolf.stackexchange.com/tags/fastest-code/info and refer to other fastest-code challenges for inspirations: codegolf.stackexchange.com/questions/tagged/… \$\endgroup\$
    – pajonk
    Mar 2 at 7:51
  • \$\begingroup\$ @pajonk is it better? I edited it \$\endgroup\$
    – ordptt
    Mar 2 at 14:31
  • \$\begingroup\$ @ordptt for me it would be enough. Also, do I understand "There are no operators in sequence" correctly that this applies only to successive operators like 1*-1, but -1+2=1 is ok? What about 1-2=-1 - is this valid? Or 1*(-1)? \$\endgroup\$
    – pajonk
    Mar 2 at 19:07
  • \$\begingroup\$ @pajonk it means that there cannot be any *,+,-,/ adjacent to each other, so I believe you got it right. So 1*-1 is not valid but -1+2=1, 1*(-1) are. 1-2=-1 is not valid because the RHS is negative. \$\endgroup\$
    – ordptt
    Mar 2 at 20:30
0
\$\begingroup\$

Generate number from given range

\$\endgroup\$
10
  • 1
    \$\begingroup\$ This downvote was too fast :) \$\endgroup\$
    – EzioMercer
    Mar 3 at 21:32
  • \$\begingroup\$ Is the output a floating point number? \$\endgroup\$
    – noodle man
    Mar 5 at 14:29
  • \$\begingroup\$ @Jacob It is doesn't matter. For example if your function for inputs 10.55, -1, 1 will output 0 it is fine but if the output will be 0.55 it is also fine. In general the output can not be only integers because at least for range [0, 1] you can output integers 0 and 1 only for two different speed of wind, another wind speed must give some number from range (0, 1) \$\endgroup\$
    – EzioMercer
    Mar 5 at 14:41
  • \$\begingroup\$ Could you clarify the sentence "and multiply this value to -1 pseudo randomly"? \$\endgroup\$ Mar 5 at 18:59
  • \$\begingroup\$ @CommandMaster It is just part of story :) He do it to get the negative numbers too, because of speed of wind can not be negative number \$\endgroup\$
    – EzioMercer
    Mar 5 at 19:11
  • \$\begingroup\$ What's the range of the speed of wind? Can it be any real number? \$\endgroup\$ Mar 5 at 19:12
  • 2
    \$\begingroup\$ "Your function must output different result each time for different wind speed" - I think it may be impossible for some inputs because of floating point inaccuracies (there is in practice only a finite amount of floating point numbers between two integers) - or are we to ignore floating point errors? \$\endgroup\$
    – pajonk
    Mar 5 at 19:33
  • \$\begingroup\$ @CommandMaster It can be any float or double (it is up to you) number which provide your chosen language \$\endgroup\$
    – EzioMercer
    Mar 5 at 21:03
  • \$\begingroup\$ @pajonk Good point. Yes, of course you can ignore floating point errors. I will add it to challenge \$\endgroup\$
    – EzioMercer
    Mar 5 at 21:05
  • 1
    \$\begingroup\$ This is a pretty easy challenge but still fairly interesting \$\endgroup\$
    – noodle man
    Mar 5 at 22:41
0
\$\begingroup\$

The topology of origami

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

Guessing on straws

Dedicated to Martin Gardner, taken from his book

Background

In the old days, the Slavs had such divination. One girl was clutching six straws in her fist, and her friend was pairing first the top and then the bottom ends. If all straws were ring-tagged, the girl would be married.

Goal of challenge

Having the number of straws and the binding schemes, determine whether the single hole cycle will result.

enter image description here

Input

  • Number of straws N, even integer >= 2
  • Two nested lists as top and bottom links, for instance [[1, 4], [2, 5], [6, 3]]

Schemes may be valid or invalid! On one hand, it is guaranteed that are used only positive integers not more N; no self-links ([1, 1]), no tautologies ([[1, 2], [2, 1], …]), no broken lists ([[1], [ ], …]) etc.

Please note, that pairs are unordered, so eg [[1, 4], [2, 5], [6, 3]] and [[4, 1], [2, 5], [3, 6]] both valid (and equivalent) schemes.

But due to the girl’s inattention, followed cases can take place:

  • Missing pair (one or more): [[1, 4], [6, 3]], [[1, 10], [4, 5], [3, 7]] etc.
  • More than two binding straws: [[1, 4], [1, 5], [2, 6]] (and as result, free straws)

All of these inputs are invalid, your program must detect them and stop with appropriate message (see below).

Output

Any three distinct symbols for "Invalid input", "No loop", "Has loop" cases. Suitable for golfing on your language:

  • -1 for invalid input, 0 for "No loop", 1 for "Loop"
  • None, False and True respectively
    etc.

Test cases

N: 2, TopLinks: [[1, 2]], BottomLinks: [[2, 1]]  → True

N: 4, TopLinks: [[1, 2], [3, 4]], BottomLinks: [[2, 1], [3, 4] ]  → False

N: 4, TopLinks: [[1, 2], [2, 4]], BottomLinks: [[2, 1], [3, 4], [3, 2] ]  → Invalid

N: 8, TopLinks: [[1, 2], [3, 4], [6, 5], [7, 8]], 
BottomLinks: [[8, 1], [3, 2], [4, 5], [7, 6] ]  → True
\$\endgroup\$
2
  • 2
    \$\begingroup\$ We usually try to avoid requiring input validation, and I feel like in this case it doesn't make the challenge any more interesting. Is there a particular reason you want it? Additionally, I'll suggest allowing other reasonable input formats, for example a list of values from 1 to n/2 where paired indices have the same value. \$\endgroup\$ Mar 8 at 11:12
  • \$\begingroup\$ @CommandMaster Well, I thought without validation this is a very simple challenge. But I will take into account your proposal, I will probably remove validation when publishing \$\endgroup\$
    – lesobrod
    Mar 8 at 11:17
0
\$\begingroup\$

Shortest Code to Implement a Simple Encryption Algorithm

Write a program or function that implements a simple encryption algorithm. The algorithm takes in a string of ASCII characters and a key, and outputs an encrypted string.

Encryption Algorithm

  1. Convert each character in the input string to its ASCII value
  2. XOR each ASCII value with the corresponding byte in the key (cycling through the key if necessary)
  3. Convert the resulting XOR values back to ASCII characters
  4. Concatenate the ASCII characters into a single string and output the result

Your program or function should take in two inputs:

A string of ASCII characters (up to 1024 characters in length) A key string (up to 1024 characters in length) Your program or function should output a single string representing the encrypted message.

Test Cases

Input:
message: "Hello World"
key: "secret"
Output:
"UW]cU\xf3M]Z]^Y"

Input:
message: "12345"
key: "password"
Output:
"^%-'$#"

Input:
message: "This is a test message"
key: "key"
Output:
"\x03\x1a\x1c\x17\x02\x0eP\bI\x11\x07\x14N\x1d\x10M\r\b\x1f"

This is a codegolf challenge, so the goal is to write the shortest possible implementation of the encryption algorithm. The winner will be determined based on the length of their code, with ties broken by earlier submission time.

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

Mapping Passing Through Point

\$\endgroup\$
7
  • \$\begingroup\$ Maybe I'm just missing something, but this function doesn't seem very well-specified. Since you don't have to handle f(x1) or f(x2), isn't f(x)=y0 allowed? \$\endgroup\$
    – Bbrk24
    Mar 9 at 17:44
  • \$\begingroup\$ @Bbrk24 The image of the function has to be over the whole range -- in other words, for every \$y \in (y_1, y_2)\$, there must be some \$x \in (x_1, x_2)\$, such that \$f(x) = y\$. \$\endgroup\$ Mar 9 at 17:55
  • \$\begingroup\$ Ah, that makes more sense. I'd be a bit more direct about it in the question, then. \$\endgroup\$
    – Bbrk24
    Mar 9 at 17:56
  • 1
    \$\begingroup\$ Is it guaranteed \$x_1 < x_0 < x_2\$? \$\endgroup\$ Mar 10 at 4:56
  • 2
    \$\begingroup\$ Do you have to return \$f\$? Can you take \$ x_0, x_1, x_2, y_0, y_1, y_2, x\$ and return \$ f(x) \$ (deterministically)? \$\endgroup\$ Mar 10 at 4:59
  • \$\begingroup\$ @CommandMaster I thought this is part of the open-ended-function tag, but yeah, you can do it that way. \$\endgroup\$ Mar 10 at 17:26
  • \$\begingroup\$ @CommandMaster Yes -- and \$y_1 < y_0 < y_2\$. \$\endgroup\$ Mar 10 at 17:26
0
\$\begingroup\$

Optimize Distance Travelled By Thrown Object (With Air Resistance)

Suppose you're on a flat surface, then throw an object with some velocity \$v_0\$ at an angle \$\theta\$ above the ground. Assuming the only forces on the object are (constant) gravity and air resistance, we can model the horizontal and vertical components of the acceleration (the instantaneous change in velocity in the x and y direction) as follows:

$$a_x = v_x^2 * \delta$$ $$a_y = v_y^2 * \delta + g$$

Where \$v_x\$ and \$v_y\$ are the horizontal and vertical components of velocity, \$g\$ is acceleration due to gravity, and \$\delta\$ is the coefficient of acceleration due to drag (which is a single number which depends on the drag coefficient, cross-sectional area, and the density of the fluid, and the mass).

The initial x and y components of velocity are $$v_x = v_0 \cos \theta, v_y = v_0 \sin \theta$$

The object stops moving when it hits the ground again (when its \$y\$ position becomes 0 again). We want to find the angle \$\theta\$ which maximizes the horizontal distance \$x\$ that the object travels.

Your challenge is, given the initial velocity \$v_0\$, acceleration due to gravity \$g\$, and coefficient of acceleration due to drag \$\delta\$, output the angle \$\theta\$ (in either degrees or radians) which maximizes the horizontal distance travelled, within one percent of the true maximum.

Standard loopholes are forbidden. Since this is , the shortest program wins.

TODO: Test cases

\$\endgroup\$
1
  • \$\begingroup\$ Can the person who down-voted explain why? \$\endgroup\$ Mar 28 at 2:09
0
\$\begingroup\$

Soundproof Cell

Here's a message from the organizers:

Hello! We hope this message finds you well.

Unfortunately, your performance in the past games has been sub par. Your team is unimaginative and lacks creativity. Instead of inventing novel techniques to win our games, you keep sticking to the techniques you know. This is not the spirit we would like to encourage in our games.

Tomorrow's game will be very different from what you're used to. To give you some time to prepare, we are telling you the rules in advance.

There are 1000000 balloons whose values you can download here. These balloons lie on a straight line. Your job is to pop these balloons in an order to get the most "brownie points".

A balloon may have zero, one or two adjacent balloons. For example, a balloon at the middle of the line has two adjacent balloons. A balloon at the beginning of the line has one adjacent balloon. And if you pop the second balloon, which is the balloon to the right of the first balloon, the balloon at the beginning of the line will have zero adjacent balloons.

When you pop a balloon, the "brownie points" you will get will be equal to the average value of all balloons adjacent to the balloon you pop. If the balloon you pop has no adjacent balloons, you get no points. Remember that when a balloon is popped, it is totally destroyed and you can't pop it again. And no worries, you don't have to pop all the balloons.

We have a pretty intelligent robot here. It is currently partying inside a soundproof cell. Tomorrow it will pop the balloons on your behalf.

The robot, albeit intelligent, has no knowledge of the values of the balloons. It has knowledge of all programming languages in existence. Before the robot pops the balloons, you have to give it some code that when executed, outputs a sequence of balloon indices. You are allowed to use either 0-based or 1-based indices. If after finishing the instructions the robot doesn't get the most "brownie points" possible on your behalf, you are disqualified. But if the robot successfully gets the most "brownie points", your score will be the length of the code you give the robot. The shorter, the better! This is !

Summary

  • The array of balloon values is fixed in advance.
  • You write a program that outputs the optimal sequence of balloons to pop.
  • Shortest code wins.

Tips

  • The array of values is randomly generated with a CSPRNG and there is no meaningful way to compress it. However, the sequence of balloons has several important patterns that you can exploit.
  • There are many optimal sequences, choose the sequence that is the easiest to compress.
  • Remember you don't have to pop all the balloons.
  • Your code may be too large to fit in an answer. You can host your code elsewhere, and your answer can contain an explanation of how you come up with the code.
\$\endgroup\$
3
  • \$\begingroup\$ I think the normal version, where given a list of balloons you output the best popping order, is a lot more interesting than the kologmonov-complexity verison \$\endgroup\$
    – mousetail
    Apr 12 at 8:27
  • \$\begingroup\$ Brute force would have a clear advantage over the O(n) solution though. I want to force solvers to come up with an O(n) solution first. The optimal order then has a very clear structure and can be further compressed. The alternative would be to set a fastest-code challenge, but such a challenge would be hard to objectively grade. \$\endgroup\$ Apr 12 at 9:29
  • \$\begingroup\$ You could make it restricted-complexity to prohibit brute force solutions \$\endgroup\$
    – mousetail
    Apr 12 at 9:30
0
\$\begingroup\$

Is it a plausible chess move

\$\endgroup\$
3
  • \$\begingroup\$ I would phrase this as "Can any piece move in this way", not "Under any arrangement of pieces ..." because there's never a reason to have more than one piece on the board. \$\endgroup\$
    – isaacg
    Apr 19 at 15:57
  • \$\begingroup\$ Also, this should say "You need to know how the queen and knight move" - the rook is subsumed by the queen, as you point out. Also, you should mention that castling is ignored. \$\endgroup\$
    – isaacg
    Apr 19 at 15:59
  • \$\begingroup\$ @isaacg clarified and simplified. I thought I had removed the rook move part from that sentence but I guess I hadn't :p \$\endgroup\$
    – lyxal
    Apr 20 at 7:54
0
\$\begingroup\$

I'm Lost!


Lost is a 2d esolang where the instruction pointer starts at a random location. In this challenge, we'll replicate that for every language.

Your task is to write a program, which can be shifted any number of characters (these will be moved from the start to the end), and will still work. The program should print the string Which way is , followed any consistent string of your choice which is at least four characters, and a question mark.

Example:

Say my program is:

import print

print("Which way is Boston?")

What actually gets run might be:

port print

print("Which way is Boston?")im

(assuming there's no trailing newline)

Or:


print("Which way is Boston?")import print

Or:

ay is Boston?")import print

print("Which w

All of these must print the same, correct string.

Sandbox: I'm considering making the challenge to print how many characters your program was shifted by, but I'm worried that'd be impossible

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Maybe you can add to the score the number of shifts that are impossible? That would allow languages to compete where this would otherwise be impossible \$\endgroup\$
    – mousetail
    Apr 25 at 14:12
  • \$\begingroup\$ @mousetail Yeah, true. Ooh, what if I went with the print-the-amount-shifted-by thing, and factored the number of shift positions where it doesn't work into the score? \$\endgroup\$ Apr 25 at 16:57
  • \$\begingroup\$ Your challenge may be inspired by Lost, but the shifting of the entire program in this challenge has nothing to do with the random starting position & direction of a Lost program.. The "In this challenge, we'll replicate that for every language." is basically false. Maybe change that sentence to something along the lines of "Making a Lost program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky. In this challenge, we'll do something similar by having the same output for each rotation of your program, written in any language." \$\endgroup\$ May 15 at 10:15
  • \$\begingroup\$ @KevinCruijssen Well I mean, since most programming languages go from beginning to end, shifting it randomly does kinda emulate the random starting position. I do see what you mean tho, and I'll change that if I come back to this challenge at some point. \$\endgroup\$ May 15 at 13:33
0
\$\begingroup\$

Compute Pi using pure arithmetic

This is a sequel to the challenge Primality testing formula.

Given a positive integer \$ n \$ as input, write a Python 3 function or program that outputs the first \$ n \$ digits of Pi as an \$ n \$-digit decimal integer using pure arithmetic. This means that your source code can only contain:

  • operators =, +, -, *, **, //, %, <<, >>, &, |, ^, ~, <, >, <=, >=, ==, !=
  • variables
  • integer constants
  • parentheses ()
  • semi-colons/newlines (to separate statements)

Unlike with the other challenge, you may use = if it helps speed up or simplify your code. However you may not use loops, built-ins, or anything else that's not stated above. Yes, it's possible.

Scoring

The winning criterion for this challenge is . You will be scored on the highest \$ n = 10^b \$ your code can compute in one minute. The time taken for that run will be used to break ties.

Hardcoding to prioritize certain test cases is not allowed, and the code must work in theory for all positive values of \$ n \$.

Test Cases

  n | output
----+--------
  1 | 3
 10 | 3141592653
100 | 3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
\$\endgroup\$
0
\$\begingroup\$

Let's start with a fairly innocuous definition of a polygon:

A polygon is a set of points \$P\$ in Euclidean space and set of edges each having two distinct endpoints in \$P\$, such that the edges form a single cycle.

We will define a regular polygon then as:

Take each edge of the polygon and divide it into two halves of equal length. The polygon is regular if for any pair of half edges, \$A\$ and \$B\$, there is an isometry of ambient space that maps every half edge to another and maps \$A\$ to \$B\$.

This can informally be phrased as "no two edges or faces are distinguishable by anything other than absolute position". You may also hear the common phrasing "all edges are the same length and all angles are equal".

Now the astute among you will be quick to point out that while this allows for what we normally consider polygons it also includes so called "star-polygons" such as the pentagram:

A pentagram!

These edges intersect each other, but we didn't forbid this. So by the definition this is a valid 5-sided polygon.

These sort of edge cases are sort of common knowledge. However the even more astute among you may have noticed a much stranger loophole. I said "Euclidean space", not "2-dimensional Euclidean space".

Skew polygons

So can we make new polygons in higher dimensional spaces? Yes, for example here's a regular 6-sided polygon in 3D space:

Skew hexagon Image curteousy of Polytope wiki user Sycamore916, CC-BY-SA-4.0

It turns out for example we can take any even sided polygon and raise half of its vertices up out of the plane to get a "skew" version of it that is 3D. And in 4D we can do even stranger things.

Challenge statement

The challenge is going to be to count these skew polygons. You are going to take an integer > 2 and output a list \$a\$ where \$a_d\$ represents the number of distinct regular polygons in \$d\$ dimensions.

This is so the goal is to minimize the size of your source code as measured in bytes.

Definitions

In order for this to work we must add 2 more definitions, the first is what makes two polygons distinct and the second is the dimension of a polygon.

A polygon in \$d\$ dimensions is a polygon such that the affine span of its vertices is a \$d\$-dimensional subspace.

For example the following vertices form a triangle:

$$ (1,0,0)\\ (0,1,0)\\ (0,0,1) $$

Each coordinate is given in 3D, however the polygon itself is 2D since all of its vertices lie on the same plane.

Two polygons \$A\$ and \$B\$ are the same if there is an invertible linear transform taking \$A\$ to \$B\$. Two polygons are distinct if they are not the same.

For example the skew hexagon discussed earlier can be stretched vertically by any positive factor. These do not count as distinct polygons since stretching is an invertible linear transform. However the skew hexagon is distinct from the normal planar hexagon since the stretch factor would be 0, and that linear transformation is not invertable (you cannot divide by 0).

Very nicely these two definitions coincide so that if two polygons have different dimensions they are automatically distinct, so there is no ambiguity as to how to count them.

Test cases

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

Spoilers

Here's the part where I would explain where the magic numbers come from.

\$\endgroup\$
1
  • \$\begingroup\$ Your 6-sided polygon looks like a Cyclohexane... \$\endgroup\$
    – tsh
    Jun 8 at 7:53
0
\$\begingroup\$

Monopoly, But its in Creative Mode (sort of)

Disjointed Monopoly (?)

Starting Grid: 8x8 grid:

+--+--+--+--+--+--+--+--+
|XX|  |  |  |  |  |  |XX|
+--+--+--+--+--+--+--+--+
|  |+1|  |  |  |  |+1|  |
+--+--+--+--+--+--+--+--+
|  |  |+2|+1|+1|+2|  |  |
+--+--+--+--+--+--+--+--+
|  |  |+1|x2|x2|+1|  |  |
+--+--+--+--+--+--+--+--+
|  |  |+1|x2|x2|+1|  |  |
+--+--+--+--+--+--+--+--+
|  |  |+2|+1|+1|+2|  |  |
+--+--+--+--+--+--+--+--+
|  |+1|  |  |  |  |+1|  |
+--+--+--+--+--+--+--+--+
|XX|  |  |  |  |  |  |XX|
+--+--+--+--+--+--+--+--+

For each group of four players (grouped randomly), we run the game above with the four players starting at the +1 squares near the corner with 20 dollars each.

To ensure that no player is left over, each entry will be run four times. It is possible that two or more will compete against each other, but the grouping is random. (The order is also random.)

Objective: Eliminate all other players.

All players that has to pay more money than they can are eliminated.

(For all random numbers / choices, assume equal probability.)

We choose a random position and a random number of steps 1 ~ 4, and the bot moves in that directions. The map wraps around. Then, if the bot steps on...

  • a Player: That player is eliminated instantly, and you do not execute the current square action.
  • someone else's Property: Pay that someone the ammount equal to 2^rank dollars. rank is the rank of the property.
  • your own Property: Choose whether to upgrade the property rank by 1 costing you 2*2^rank dollars. rank is the current rank of the property.
  • any Utility station: get 2*rank dollars, and the utility station automatically upgrades its rank by 1.
  • corner of Board (XX): Lose 20% of your money, rounded down.
  • otherwise: Do an Action.

When you step on an empty cell (a cell not qualifying any of the above), you can do an Action. You can either:

  • Build your own Property: Use 10 dollars to build a Property right here with a random integer rank between 1 and 4.
  • Build your own Utility: Use 2 dollars to build a Utility station right here with a random integer rank between 1 and 4.
  • Demolish a Square's structure. This will not demolish the bonus on the structure (for instance *2 and +1) and can apply to XX squares. This action has 25% probability of successing.

Demolish cost (paid even if failed):

  • Property: 2*rank dollars. (Even if it is yours.)
  • Utility: rank dollars.
  • Other (including XX): no cost.

Bonus

Squares marked with +1, +2, and *2 have added bonus. The operations are applied to the rank when a structure is built on the square the bonus occupies. For instance, if a ranked 3 Utility is built on a *2 square, it will start at rank 6 instead. Everything else proceeds normally.

Meta: Gimme a better name for the challenge

\$\endgroup\$
5
  • \$\begingroup\$ Better name: Disjointed Monopoly \$\endgroup\$ May 24 at 13:57
  • \$\begingroup\$ I think something's wrong with the title that says Objective \$\endgroup\$ May 24 at 15:14
  • 1
    \$\begingroup\$ What does "disjointed" have to do with this? \$\endgroup\$ May 24 at 15:22
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian fixed \$\endgroup\$ May 24 at 23:56
  • \$\begingroup\$ @RydwolfPrograms hence searching for better name \$\endgroup\$ May 24 at 23:56
0
\$\begingroup\$

Trippples

Introduction

Tripples (BGG) is a board game from the 1970s.

It is played on an 8x8 grid, and each tile on that grid (except the corner starting tiles, and four blank tiles) contain three arrows. The three arrows each point in one of eight directions (up, down, left, right; and diagonally between those). There are therefore 56 tiles, and 56 unique combinations of arrows - so each tile is unique when placed in the correct orientation.

Tiles are placed on the board, and depending on the variant of the rules being played this can either happen before the game starts (face up, either randomly or players take turns to draw and place tiles as they choose), before the game starts (face down, randomly), or over the course of the game as an alternative player action, instead of moving their playing piece.

Players start in adjacent corners and attempt to cross the board to the diagonally-opposite corner before their opponents can do so.

Players take turns, and may move their playing piece one square per turn. The interesting thing about this game is that the direction they can move is limited to the directions indicated by the arrows underneath their opponent's playing piece.

The rules are ambivalent regarding how the blank pieces are treated - either you can't go there at all, you get a second move if you can go there, or (house rule) your opponent can choose to move in any direction if you land there.

The challenge

(sandbox note: I discovered this game recently and thought it could be the basis for an interesting challenge - what the challenge is, though, I'm flexible on; so I'm happy to take suggestions. What is below is just one idea)

Competitors write bots to play against another bot, in a Trippples competition.

*(sandbox query: which variant of the game rules is most interesting?)

A server program will provide the board state, and the competitor bot's function should return its next move.

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

Longest Tiles Combo

The New York Times has a puzzle game called Tiles on their website. This game consists of a grid of tiles, each made of multiple visual elements which are shared between tiles. The player first selects two tiles which share any visual element, removing those tiles from play. If the player then selects a third tile which matches some visual element with the second, their combo increases; they can repeat this process multiple times to increase their combo.

For example, take the following row:

enter image description here

The player could begin by selecting the middle and left tiles, which share the black middle square; they then could select the right tile, because the left and right tile share a purple square and a light blue background.


In this challenge, the grid of tiles will be represented by a list of tuples, where each tuple contains the same number of symbols; each symbol represents a visual element on the tile. For example, the above could be encoded as

[("light blue BG", "purple square", "small black square"), 
 ("orange BG", "purple circle", "small black square"),
 ("light blue BG", "purple square", "small black diamond")]

Note that for all of the tuples, the elements will be described in the same order -- e.g. the background will always be the first item in the tuple.

You can decide the set of symbols which are used; in the examples below, I'll use integers instead of strings, e.g.

[(1, 2, 3), (4, 5, 3), (1, 2, 6)]

The input format is flexible; for example, since order doesn't matter, you could use a set instead of a list, and instead of tuples you could use lists, strings, or sets.

Given the input as above, your goal is to output an integer indicating the largest possible combo length possible. You can assume there will be at least one matching pair of tiles -- i.e. the max combo will be at least one.

Test cases

Input Output
[(0), (0)] 1
[(0), (0), (1)] 1
[(2, 4), (2, 3), (2, 5)] 2
[(1, 2, 3), (4, 5, 3), (1, 2, 6)] 2
[(9, 1, 14), (9, 17, 5), (3, 10, 14), (0, 13, 11), (16, 13, 6)] 2
[(4, 3, 1), (8, 0, 2), (7, 6, 2), (8, 6, 5), (4, 6, 2)] 4
[(16, 8), (12, 8), (15, 17), (18, 5), (12, 6), (0, 5)] 2
[(5, 1), (2, 9), (3, 15), (11, 0), (5, 9), (2, 14)] 3

Here's some very inefficient code to generate your own test cases.

Standard loopholes are forbidden. Since this is , the shortest program wins.

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

What is possible with all these blocks?

In this challenge, you will write code (in any way) that outputs the number of permutations of all sub-tuples of a tuple of length \$n\$ (also A000522(n) ). Here’s an example:

You have three blocks. You can start by counting how many arrangements of three blocks are possible (6). Then, work out how many ways there are to arrange two blocks (2) and multiply that by the number of unique pairs of blocks you can pick from the three blocks (3) to get the sub-answer (6). Then, work out how many ways you can arrange 1 object (1) and multiply that by the number of unique blocks you can pick from the three blocks (3) to get the sub-answer (3). Then, remember the number of empty combinations (1). Add those together to get the answer (16).

This is code golf, so shortest answer wins!

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

https://chat.stackexchange.com/transcript/message/63012181#63012181

Make a 0-byte metagolfscript solution that outputs its name.

Shortest name wins.

\$\endgroup\$
3
  • \$\begingroup\$ I feel like this will be closed as a duplicate of the output your program’s name challenge. \$\endgroup\$ Jul 14 at 7:35
  • \$\begingroup\$ @Iamkindofalanguagedev No. In that question metagolfscript is banned due to standard loophole. In this only metagolfscript allowed \$\endgroup\$
    – l4m2
    Jul 14 at 23:54
  • \$\begingroup\$ This still seems like an underspecified challenge for some reason... \$\endgroup\$ Jul 15 at 7:37
1
134 135
136
137 138
152

You must log in to answer this question.

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