572
\$\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

4674 Answers 4674

1
84 85
86
87 88
156
1
\$\begingroup\$

Is it a hyperjump?

Easy-mode of this challenge

A hyperjump is a sequence of numbers 0-9 (exclusive), where:

  • The first two digits can be any two
  • Each number after is the result of a simple math operation (*, /, +, -) on the previous two.
    • E.g. [3, 2] → 3+2=5, 3-2=1, 3*2=6, 3/2=not an integer
    • If the result is multiple digits, take the last one. E.g. [7, 5] → 7+5=1 2, 7*5=3 5
    • The third- and second-most-recent digits may combine to one number and be used. E.g. [4, 1, 3] → 41-3=3 8, …
  • The sequence should end with 9. There is no 9 in the list, but it should be able to be there by the rules outlined above.

For example, the sequence 7, 4, 3, 1, 2 is a hyperjump because 7-4=3, 4-3=1, 3-1=2, 31-2=9.

Your task is: Given a sequence of digits 1 through 8 inclusive, determine whether it is a valid hyperjump. You may output a truthy/falsy value, or choose two distinct values. This is , so the shortest submission in bytes per language wins.


Meta: I don’t have time to add test cases right now, I want to make sure this isn’t too similar to the other challenge before working on it more.

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

Determine NBA conference seedings

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

Draw a Regular Reuleaux Polygon

Related

A Reuleaux polygon is a curve of constant width made up of circular arcs of constant radius. The most well-known Reuleaux polygon is the Reuleaux triangle, which has three sides. In this challenge, you will be tasked to draw a regular Reuleaux polygon of a given number of sides.

A Reuleaux polygon is constructed by taking a polygon and replacing each of its sides with an arc centered at the opposite vertex.

This sort of shape can only be constructed from a polygon with an odd number of sides, so your input will be an odd number greater than or equal to three.

Reuleaux pentagon (5 sides) Reuleaux heptagon (7 sides)
constructed pentagon constructed heptagon
pentagon heptagon

The circles in the first row are shown to demonstrate the construction; Your program's output should be closer to that of the second row (though the border and center mark are optional.)

Given a odd number ≥ 3, draw a regular Reuleaux polygon with that many sides.

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

Single Transferable Vote (Ranked Choice Vote)

Single transferable vote is a algorithm for selecting the best N candidates from a set of ranked choice votes. It works like this:

  • Every voter must rank every candidate, first to last
  • Let the voting threshold be the number of voters divided by the number of available positions
  • While less than N candidates have been elected:
    • If the candidate with the most #1 votes has more votes than the threshold, elect them. Then remove that candidate from every voters ballot.
    • If no candidate has enough votes to be elected, eliminate the candidate with the lowest number of votes choosing them as #1. Remove this candidate from every ballot. In case of a tie tiebreaker is how often they are ranked #2, then #3 etc.

Given a list of votes, the number of open positions, and optionally a list of candidates, output which candidates get elected. Order doesn't matter.

You do not need to implement the algorithm above exactly as long as the result is the same.

Test Cases

Positions: 2
Votes: [1,2,3]
       [2,3,1]
       [3,2,1]
Outcome: 2, 1

More test cases TBD

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

Countdown solver

Input

An array of up to 6 integers, value 1..100, and a target integer 1..999

Output

A series of mathematical operations (in any sensible format), using each of the integers in the input array 0..1 times, and the mathematical operators +-*/ any number of times, to reach the target integer.

Intermediate operations may result in floats (e.g. (3/2) * 4 = 6), and there is no guarantee that the target is reachable at all (in which case the output is undefined). The input integers may not be concatenated (e.g. 1, 2 can't be used as 12)

Win criteria

Code golf, usual exclusions apply.

\$\endgroup\$
3
  • \$\begingroup\$ Is this a dupe of this challenge? \$\endgroup\$
    – Arnauld
    Apr 25, 2023 at 23:57
  • \$\begingroup\$ @Arnauld yes, looks like it might be. Oh well. Unless anyone thinks it's suitably different with a variable length input? \$\endgroup\$ Apr 27, 2023 at 14:41
  • \$\begingroup\$ It would be great if you can somehow make this one different enough, as the other challenge is quite old and didn't receive much attention. \$\endgroup\$
    – Arnauld
    Apr 27, 2023 at 16:48
1
\$\begingroup\$

Find Index of Rational Number in Calkin-Wilf Sequence

\$\endgroup\$
1
  • \$\begingroup\$ I think this is definitely different enough from the Stern-Brocot Tree \$\endgroup\$ Jan 24, 2023 at 21:21
1
\$\begingroup\$

Get all URLs on an HTML webpage

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

Langton's Ant

Langton's ant is a simple two-dimensional universal Turing machine. From Wikipedia:

Squares on a plane are colored variously either black or white. We arbitrarily identify one square as the "ant". The ant can travel in any of the four cardinal directions at each step it takes. The "ant" moves according to the rules below:

At a white square, turn 90° clockwise, flip the color of the square, move forward one unit

At a black square, turn 90° counter-clockwise, flip the color of the square, move forward one unit

In this challenge, you will be given three inputs:

  • A 2D square grid \$G\$ of two distinct symbols, where one represents a black cell and the other represents a white cell
  • A coordinate \$(x,y)\$ representing the location on the grid where the ant starts
  • A number of steps \$n\$

Your code should then return the grid after the ant starting at \$(x,y)\$ and facing upwards, completes \$n\$ steps.

You can use any reasonable form of indexing to describe the intial location of the ant on the grid (e.g. 0-based or 1-based).

You can assume that the ant will not attempt to go off the side of the grid at any point during the given steps.

Test cases

For these tests, I will assume that \$(0,0)\$ is the top-left corner of the board. I will also use 0 to represent a white cell and 1 to represent a black cell.

\$G\$ \$x\$ \$y\$ \$n\$ Result
[[0]] 0 0 0 [[0]]
[[1]] 0 0 0 [[1]]
[[0,0],[0,0]] 0 1 1 [[0,0],[1,0]]
[[0,0],[0,0]] 0 1 2 [[1,0],[1,0]]
[[0,0],[0,0]] 0 1 3 [[1,1],[1,0]]
[[0,0,0],[0,0,0],[0,0,0]] 1 1 7 [[0,1,1],[0,0,1],[1,1,0]]

Standard loopholes are forbidden. Since this is , shortest code wins.

\$\endgroup\$
3
  • \$\begingroup\$ Related \$\endgroup\$
    – mousetail
    Apr 24, 2023 at 15:48
  • \$\begingroup\$ Title appears to be a typo, should be Langton's ant, rather than Langston's ant? \$\endgroup\$
    – ATaco
    May 1, 2023 at 5:30
  • \$\begingroup\$ @ATaco Fixed it. \$\endgroup\$ May 1, 2023 at 14:11
1
\$\begingroup\$

Sanitize the Spaces

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

A Graphical Degree Sequence?

Write the shortest program to determine if a degree sequence is graphical.

Given a sequence of numbers S, output a Boolean value representing whether or not a graph with S as its degree sequence exists.

The degree sequence of a graph is a sequence representing the degrees of each of its vertices. The degree of a vertex is the number of edges connected to it. Generally the degree sequence is given in non-increasing order, but for this challenge, it may be specified in any order. This means that graphs may have multiple degree sequences.

Example

The following graph has a degree sequence of [4, 3, 2, 1, 1, 1] or any of its reorderings.

A Graph

Some degree sequences like [3, 3, 3, 2] are impossible. If you try to draw such a graph, it becomes clear why.

Test cases

[4, 3, 2, 1, 1, 1] -> True
[3, 3, 3, 2] -> False
[] -> True
[5, 5, 5, 5, 5, 5] -> True
[4, 4, 2, 4] -> False
[1, 2, 3, 2, 1, 4, 2] -> False
[3, 4, 4, 3, 3, 3, 4] -> True
[3, 0, 2, 1, 4, 2] -> True
[0, 0, 0] -> True
[2, 1, 2, 2, 2, 0, 2, 6] -> False
[2, 4, 2, 2, 2] -> True
[4, 4, 3, 2, 4] -> False
\$\endgroup\$
1
  • \$\begingroup\$ Related, but not quite the same. \$\endgroup\$
    – Bbrk24
    May 7, 2023 at 21:46
1
\$\begingroup\$

Evaluate Minkowski's question mark function at rational numbers

\$\endgroup\$
2
  • \$\begingroup\$ Could you please add some worked-out examples? \$\endgroup\$
    – pajonk
    May 9, 2023 at 8:21
  • 1
    \$\begingroup\$ @pajonk One example is there now. \$\endgroup\$ May 9, 2023 at 9:56
1
\$\begingroup\$

Draw any infinite fractal

Write a function that, given as input 2 positive integers for X and Y, outputs one of two distinct values, representing white and black. Your function should have the following properties:

  • No horizontal or vertical ray should infinitely repeat itself. A ray is a straight line that starts at one point then continues upto infinity. Mathematically \$ \not \exists x, y, \delta : \forall e \geq y+\delta: f(x,e)=f(x,e-\delta)\$ and the same with \$x\$ and \$y\$ reversed.
  • Large scale structure: For every positive integer Z there exists a ZxZ square that is entirely white and also a ZxZ square that is entirely black. This rule ensures no matter how much you zoom out you should still be able to see some shapes and not just grey.

For the purpose of this challenge you may ignore the numerical limits of your language. When proving that your function meets the requirements, assume they don't exist.

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

Cube calendar numbers

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

Output subsequent powers of two

Output endless powers of 2

\$\endgroup\$
12
  • \$\begingroup\$ You should clarify if the program must circumvent floating-point data type limitations. Those limitations prevent large powers of 2 to be output accurately. That is, must the program handle arbitrarily large powers exactly? From our default rules (see here and here) it could be interpreted that that's not necesssary. In any case, for this challenge I think it's better to be explicit about that \$\endgroup\$
    – Luis Mendo
    May 25, 2023 at 23:25
  • \$\begingroup\$ Perhaps another goal would be better, EG. A decision problem per this discussion. \$\endgroup\$
    – ATaco
    May 25, 2023 at 23:28
  • \$\begingroup\$ @ATaco It isn't a decision problem, as it is asking for subsequent powers of two, rather than testing if it is a power of two. (If I'm understanding your question correctly) \$\endgroup\$
    – Dadsdy
    May 26, 2023 at 0:32
  • \$\begingroup\$ I was suggesting this should be a decision problem challenge instead of an infinite sequence, as it better handles what I perceive to be the bulk of the challenge. \$\endgroup\$
    – ATaco
    May 26, 2023 at 0:47
  • \$\begingroup\$ @ATaco It intentionally is open either to doing it by incrementing numbers and outputting if it's a power of two (your way, it seems), or doubling (as in my example). Doubling wouldn't work if it were a decision problem. \$\endgroup\$
    – Dadsdy
    May 26, 2023 at 1:01
  • \$\begingroup\$ I could just start at 0, which is 2 to the minus infinity, and always print 0. \$\endgroup\$ May 26, 2023 at 9:23
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian 0 doesn't count as a power of 2. \$\endgroup\$
    – Dadsdy
    May 26, 2023 at 17:25
  • \$\begingroup\$ @Dadsdy enter print(2**float('-inf')) into Python IDLE \$\endgroup\$ May 26, 2023 at 17:29
  • \$\begingroup\$ infinity is also a power of 2. It is 2 to the power of infinity. \$\endgroup\$ May 26, 2023 at 17:32
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian Fair points. Now zero and infinity as starting points are no longer valid. Also removed ability to multiply by 4 each time. \$\endgroup\$
    – Dadsdy
    May 26, 2023 at 17:36
  • \$\begingroup\$ zero is finite. i would change the wording to "any finite non-zero power of 2". \$\endgroup\$ May 26, 2023 at 17:38
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian It couldn't be zero, as it has to output subsequent powers of two, (which would be always 0), and it has to output each sufficently large power of two after finite time. \$\endgroup\$
    – Dadsdy
    May 26, 2023 at 17:44
1
\$\begingroup\$

Split a string on unnested commas

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

Print every finite string

In this challenge, you're given the task to create a full program that generates and prints strings indefinitely. The strings must be printed on separate lines, and every finite string must (theoretically) be printed in finite time.

Rules

  • Your submission must be a full program, not a function.
  • You must output the strings to STDOUT.
  • There should be a single line feed between each string.
  • A string is a sequence of printable ASCII characters (0x20-0x7e, inclusive). You may also include any number of null-terminators (0x0), EOFs (0xff) or other zero-space characters.
  • The algorithm used must theoretically print any finite string in finite time. In practice, however, your program may fail after having printed at least 65535 strings.
  • No string can be printed twice. Zero-space characters don't count as part of the string, so the program cannot output both Hello and Hello(EOF).
  • The empty string may or may not be generated.

Valid strings:

Hello
AAAA
(space)
Hello(EOF)
Hello, World!
"#(){ :|~A

Invalid strings:

(tab)
(newline)
ë
ñ
ø
π

This is a , so the shortest answer in each language wins!

\$\endgroup\$
4
  • \$\begingroup\$ I've posted a similar challenge Output all strings though it takes the character set as an input \$\endgroup\$
    – xnor
    Jun 8, 2023 at 19:51
  • \$\begingroup\$ Does the program have to be deterministic? Or, Is it valid that for any string my program will output it with a probability of 1? The second one is simply repeat forever { s=generate random string; if (s not yet printed) { print(s) } }. \$\endgroup\$
    – tsh
    Jun 9, 2023 at 6:36
  • \$\begingroup\$ @xnor I didn't know of that challenge, thanks for notifying me :) I don't think I'll post this one, considering how similar it is to yours. \$\endgroup\$
    – Peter
    Jun 9, 2023 at 7:55
  • \$\begingroup\$ @tsh If all submissions had to be deterministic, they could just set the seed for functions generating random things, so I don't think I'll impose such restriction. \$\endgroup\$
    – Peter
    Jun 9, 2023 at 7:57
1
\$\begingroup\$

Output every second

\$\endgroup\$
2
  • \$\begingroup\$ time is a synonym for date, so maybe not what you want here. I'd also be unsurprised if this is a duplicate, though I'm not certain off the top of my head. \$\endgroup\$
    – Bbrk24
    Jun 21, 2023 at 20:04
  • \$\begingroup\$ @Bbrk24 The tag says "This challenge is intended to be solved using [...] clock times", so it should still be fine (maybe). If there are any other tags you think belong on this len be know. I searched, and didn't find any others that are the same. \$\endgroup\$
    – Dadsdy
    Jun 21, 2023 at 20:54
1
\$\begingroup\$

Counting black and white piano keys

Given a major or minor triad (3 note chord) name, return the amount of black and white piano keys needed to play it. (I will add more explanation later)


Little bit of music theory

A piano contains 88 keys: 52 whites and 36 blacks. The keys are divided into octaves which have 7 white keys and 5 black. The notes represented by the white keys go from A to G (although the starting note in an octave is C; notes from left to right are as following: C, D, E, F, G, A, B). The notes represented by the black keys are accidentals of the white keys. An accidental is either a sharp note (#) or a flat note (b). (There is an exception since there is only 5 black keys and 7 white keys, Should I expand on this?) . A sharp note is one semitone higher than the same note (C# is one semitone higher than C). A flat note is one semitone lower (Db is one semitone lower than D). There is one full tone in between notes except for E-F and B-C where there is a semitone instead and one semitone between keys.

I'll keep adding more details if needed

Note: For this challenge, we don't care which octave the triad is played on since it will be the same answer for any octave.

Example

Cmaj  = 3 white, 0 black 
Fmin  = 2 white, 1 black
G#maj = 1 white, 2 black
Gbmaj = 0 white, 3 black

Input can be the chord name or can be divided into 2 variables: Root (C, F, G#, Gb) and quality (maj, min). I will extend on music theory if this is accepted as a good challenge

Output must be an array of 2 position where the first one is the number of white keys and the second one the number of black keys


Has this been asked before?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Looks like a nice challenge idea. But, as you say in your post, this definitely needs more music theory to explain what the major/minor triad names really mean. PS: Welcome back! \$\endgroup\$
    – Arnauld
    Jun 29, 2023 at 13:21
  • \$\begingroup\$ @Arnauld An usual explaination is just [0,3,7] and [0,4,7], which is enough here \$\endgroup\$
    – l4m2
    Jul 3, 2023 at 11:46
  • \$\begingroup\$ @Arnauld thanks mate! Good to be back. I have to research more into this challenge (I know music theory but I dont know how to explain it very well) therefore I'll leave here until my inspiration comes back. I have another idea tho I'll be posting soon! \$\endgroup\$ Jul 12, 2023 at 19:15
1
\$\begingroup\$

Draw the initial positions of Mölkky pins in ASCII Art

\$\endgroup\$
5
  • 1
    \$\begingroup\$ I'm afraid this won't lead to many creative answers. Even with a short clever formula generating the pin numbers in the correct order, the cost of applying the correct formatting is very likely to give something longer than just hardcoding the output (for standard languages) or using a built-in string compression (for esolangs). \$\endgroup\$
    – Arnauld
    Jun 29, 2023 at 14:08
  • \$\begingroup\$ @Arnauld Sadly i found the same conclusion while trying to code it. For standard languages, would it be more interesting if i discouraged hardcoding by discouraging using too many digits, for example with a scoring system? (for esolangs, i think it's part of the game that anything goes and i shouldn't try to oppose it) \$\endgroup\$
    – Fhuvi
    Jun 29, 2023 at 15:00
  • 1
    \$\begingroup\$ This is usually a bad idea. Maybe it would be better to turn this into a slightly more complex ASCII art, giving more compression opportunities. Here is a quick attempt. \$\endgroup\$
    – Arnauld
    Jun 29, 2023 at 15:25
  • 1
    \$\begingroup\$ Alternate version \$\endgroup\$
    – Arnauld
    Jun 29, 2023 at 15:28
  • 1
    \$\begingroup\$ @Arnauld Thank you for your input. I've changed the challenge with your alternate version. I still hope that this would allow some clever and competitive formulas for the pins numbers! \$\endgroup\$
    – Fhuvi
    Jun 29, 2023 at 16:01
1
\$\begingroup\$

Critical Calculations

\$\endgroup\$
2
  • \$\begingroup\$ Computing the damage per ring instead of just the total damage seems like an unnecessary transformation, perhaps allow both? \$\endgroup\$ Jul 7, 2023 at 6:24
  • \$\begingroup\$ @CommandMaster Fair point, I think I will allow both \$\endgroup\$ Jul 7, 2023 at 14:23
1
\$\begingroup\$

Landmine Number IV

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

Tic-Tac-Toe: Maintain the Draw!

Tic-Tac-Toe is a game for two players who take turns marking the spaces in a 3x3 grid with an X or an O. If a player succeeds in placing three of their marks in a horizontal, vertical or diagonal line they are the winner; otherwise, the game is considered drawn.

Challenge

You have been chosen to represent the human race in a game of Tic-Tac-Toe against the AIs. Dauntingly, your opponent is a programme which always finds the optimal move in a given position. Worse still, you will be playing second. The only consolation is that you are required to survive for one move only: that is, you must make a single move in reply to the computer's opening gambit which leads to a position which is not theoretically lost. If you find such a move, humanity lives to fight another day; if not, ...

Assuming a Tic-Tac-Toe board with the following notation

1 2 3
4 5 6
7 8 9

given the AI's opening move output all possible replies which do not lead to a theoretically lost position.

Input

An integer \$n\$ (where \$1<=n<=9\$) which represents the machine's opening move as per the given board notation.

Output

A sorted list, array, etc. of integers which represents all possible solutions.

Explained Cases

Input => Output

1 => [5]
The only reply to a corner-square opening move which does not lead to a theoretical loss
is that which occupies the central square.

2 => [1, 3, 5, 8]

The only replies to an edge-square opening move which do not lead to a theoretical loss
are those which occupy the same row or column as that of your opponent's move.

5 => [1, 3, 7, 9]

The only replies to a central-square opening move which do not lead to a theoretical
loss are those which occupy one of the four corner squares.

Test Cases

Input => Output

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

This is , so shortest answer in bytes wins!

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

Tableing in 3 operations

There was a puzzle requiring to convert EBCDIC into ASCII in 4 operations. Actually, if big integers are allowed, 3 mathematical operations(so no bit shift, integer division, etc.) is enough, even for more complex mapping.

Given an array \$\left[x_1,x_2,x_3,...,x_n\right]\$, generate arguments \$a,b,c\$, such that \$ \forall 0 < k \le n, a \mod \left(bk+c\right) = x_k\$.

Fastest algorithm wins. Here word RAM model is used: bitwidth is by default \$\text O \left (\log \max\left\{ x_k, n\right\} \right)\$. You can cost \$2^t\$ time to extend the bitwidth to \$\text O\left(t\right)\$ without extra code. BigInts are treated as multiple ints, and take longer time to process larger values.

Sandbox Notes:

\$\endgroup\$
1
  • \$\begingroup\$ 1. Sandbo xNotes should be Sandbox Notes. 2. Your challenge needs a title 3. This might be confusing to people without a mathematical background, so you should probably explain it in plain English. \$\endgroup\$ Jul 16, 2023 at 11:18
1
\$\begingroup\$

Print all polynomials

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

WumpusWars King of the Hill

This is probably going to stay in the sandbox for a few weeks, until I get the time to write the actual scoring code up... Yep, I'm both lazy and busy :P I'm not very good at coding challenges but I'm good at thinking up creative ideas, so this time my idea is to try reviving the genre of KotH, as the last one on this site (Crazyhouse Chess) has been very unsuccessful (0 submissions for pretty obvious reasons) and the others are all many months old...

Inspired by Hunt the Wumpus, an early command line game. It is somewhat popular among esolang communities as a programming challenge, especially for languages like Befunge. However, the original, singleplayer version is boring, so I wanna upgrade it. Hence I created WumpusWars, a better version of it!

Story: You are a brave hunter in a dark cave, trying to kill the Wumpus, a mysterious monster. You start with 5 arrows that can kill the Wumpus if you shoot the arrow into the same room as the Wumpus. The cave consists of large rooms and small passageways in between. It can be represented, hence, with a graph, so that the rooms are nodes/vertices and the passageways are edges. There are a total of 50 vertices in the graph, each of them having a degree of at least 3, and the graph is guaranteed to be connected. Rooms are numbered from 0 to 49. You are spawned in a random room.

The place is so dark that you cannot see anything, but you can feel, smell, and hear. Hence you have access to the functions listed in the source code below. Lemme explain what the functions are associated with in more detail:

  1. Bats: There are 5 rooms in total that contain bats. Entering one of them will cause you to be carried away to a random empty room ("empty room" defined as a room without bats, pits, players, or the wumpus, but there can be corpses in the room).
  2. Pits: There are 5 rooms in total that contain a pit. Entering one of them will cause you to BOOM! CLASH! CRACK!
  3. Wumpus: It remains in its own room unless either an arrow is shot by anyone anywhere, or the game is in deathmatch mode (see gamemode list for explanation). If it enters your room then... You know what. When an arrow is shot or in deathmatch mode it moves randomly to adjacent rooms. Bats and pits do not affect it.
  4. Players: Other players. Note that you cannot shoot a player in the same room as you because the arrow is magically explosive and shooting in the same room as your own will cause you to BOOM! CLASH! CRACK!
  5. Corpse: When a player is killed by anything except a pit they become a corpse, and corpses don't move (obviously). You can collect arrows from the corpses, and if the corpse has already been arrow-collected there will be 0 arrows on it.

Also, every 10 rounds an arrow will spawn in an empty room. Entering that room will cause your number of arrows to be incremented by 1. Multiple arrows can spawn in the same room which gives you several at once, but that's pretty rare.

You need to write a player program in Python and submit it as an answer to the post. Use the "PlayerName" class template. You will have to define with the participate function which gamemodes are you participating in (the input to the function will be one of the abbreviation strings):

  1. Singleplayer (abbrev: "SP"). Precisely what the name says. Your score is the percentage of games in which you win (by shooting the Wumpus with an arrow). You lose if you die. After 100 rounds the game enters deathmatch mode, where the Wumpus keeps moving randomly every round regardless of whether an arrow is shot.
  2. Player vs Environment (abbrev: "PVE"). Same as singleplayer except that there are multiple players. The winner is the one who kills the Wumpus (if multiple players shoot it in the same round they split the point equally). If everyone dies then no one wins. Arrows have no effect on players. Deathmatch starts after 20*n rounds, where n is the number of players.
  3. Player vs Player (abbrev: "PVP"). Kinda PVE inverted. The Wumpus is now immortal –– but the players are not! If you get shot by other players or get eaten by the Wumpus you die and lose. The last one standing is the winner. If multiple people die last in the same round they split the point equally. It's deathmatch from start to finish.
  4. Among Us (abbrev: "IP" for Imposter and "CM" for Crewmate). The Wumpus is immortal. Some players become impostors. Others are crewmates. Impostors get 3 arrows at the beginning (number might change according to # of players). Crewmates start with no arrows (but can still pick randomly spawned arrows up). Crewmates are immune from arrows fired by other crewmates. If all impostors die then all crewmates (dead or alive) win a point. If all crewmates die then all impostors (dead or alive) win a point. No deathmatch.

If you have any ideas please lemme know!

Source code:

class Environment:
    def __init__():
        # Hidden
    def legal_moves(player) -> list:
        # Returns an ordered list of adjacent rooms
        # Example: [5, 8, 10]
    def bats(player) -> bool:
        # True if bats are in adjacent rooms, false otherwise
    def pits(player) -> bool:
        # True if pits are in adjacent rooms, false otherwise
    def wumpus(player) -> bool:
        # True if wumpus is in adjacent rooms, false otherwise
    def others(player) -> bool:
        # True if the shortest path from you to the nearest player passes at most 2 edges.
    def arrows(player) -> int:
        # Returns the number of arrows player has
    def corpse(player) -> list:
        # Returns a list of integers
        # The length of the list is the number of corpses in the player's room
        # Elements in the list are the number of arrows on each corpse
    # Other functions hidden

Template:

class PlayerName: # Change the name!
    def __init__(mode:str, room:int, env):
        # Gamemode. Such as 'SP'.
        self.mode = mode
        # Current room number.
        self.room = room
        # Environment
        self.env = env
    def participate() -> bool:
        # Add code here...
        
        # Return True if self.mode is a supported gamemode
        # False if not
    def action() -> tuple:
        legal_moves = self.env.legal_moves(self)
        bats = self.env.bats(self)
        pits = self.env.pits(self)
        wumpus = self.env.wumpus(self)
        others = self.env.others(self)
        arrows = self.env.arrows(self)
        corpse = self.env.corpse(self)

        # No methods or variables from Environment class allowed below here!
        # Suggested to first check which gamemode and use strats accordingly.

        # Add code here...

        # Return a tuple of type (bool, int)
        # The bool is True for shooting, False for moving
        # The int is the cave number to shoot or move to
        # An illegal move signifies doing nothing
```
\$\endgroup\$
1
\$\begingroup\$

Write a Turing machine that draws this fractal

This challenge is inspired by and similar to my other challange about a fractal matrix, but uses a slightly different matrix (for n up to 3 the matrices are nearly the same, but for n >= 4 they start to differ more significantly)


A 2D-Turing machine is like a regular Turing Machine but the memory tape is 2 dimensional, meaning that after each step you can in addition to moving left or right also move up or down.

[...]

Your task is to create a 2 dimensional Turing machine that prints the infinite fractal matrix generated by the following procedure:

  • Start with a single cell, set it to 1
  • repeat n times:
  1. add a copy of the previous matrix to the left of the previous matrix
  2. add a copy of the previous matrix below the previous matrix
  3. add a copy of the previous matrix with 1 and 0 swapped, diagonally to the bottom right of the previous matrix.

First few steps:

n=0:

1

n=1:

1 1
1 0

n=2:

1 1 1 1
1 0 1 0
1 1 0 0
1 0 0 1

n=3:

1 1 1 1 1 1 1 1
1 0 1 0 1 0 1 0
1 1 0 0 1 1 0 0
1 0 0 1 1 0 0 1
1 1 1 1 0 0 0 0
1 0 1 0 0 1 0 1
1 1 0 0 0 0 1 1
1 0 0 1 0 1 1 0

n=4:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0
1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1
1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1
1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1
1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0
1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0
1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1

Rules:

  • It is allowed to output/display any two (distinguishable) distinct cells values for the two different values in the matrix

  • Cells inside the matrix have to have the correct value more that 50% of the time (\$\lim_{steps \to \infty} \frac{correct}{steps} >0.5\$)

  • Cells outside the matrix should be empty more that 50% of the time.

  • The score of an answer is the number of distinct cell values used times the number of states of the Turing machine

  • This is the solution with the lowest score wins

related: generate the matrix


Meta:

  • Is this a duplicate?

  • Is my explanation clear?

  • Should I link to an example implementation of a 2D Turing machine?

\$\endgroup\$
2
  • \$\begingroup\$ I feel like saying "it differs for n>=4" suggests you might want an example for n = 4 at least :) \$\endgroup\$
    – RubenVerg
    Jul 22, 2023 at 18:06
  • \$\begingroup\$ Duplicate? \$\endgroup\$
    – alephalpha
    Jul 28, 2023 at 7:43
1
\$\begingroup\$

Pack the sequence!

You have a list of sequences of numbers (1 byte max, unsigned) as an input, e.g.:

4 6 4 9 3 15 150
3 2 1
9 6 4 1
…

Your task is to pack as many of them as possible into the square composed from the numbers from this list - the size of square is also an input.

The square of size 4 may look like:

10 13 56 30
98 11 10  4
15 36 77 86
 1  1 45 11

The numbers may repeat as many times as you want.

The sequence is considered "packed" if you can draw the line from the first number inside square to the next adjacent number in sequence and so on. Each number may be used only once for a single sequence.

For example, the sequence 36 11 77 11 is packed into the square above - the number may have up to 8 adjacent numbers: top, left, right, bottom and diagonals. While the sequence 11 36 10 11 is not - since the same number 11 can't be used twice.

Scoring

For the packed sequence of size S you get 2^S scores. Each sequence counts only once - even if you can pack it multiple times in the same square.

Victory Condition

The algorithm wins if it outputs the square of expected size with the maximum scoring for some hidden test lists. The algorithm is expected to be general enough to work with any random list.

Output

Program should output square as a sequence of numbers on a single line. For example: 1 2 3 4 5 6 7 8 9 is the square of size 3:

1 2 3
4 5 6
7 8 9

Limitations

  • Any list contains [1, 1000000] sequences.
  • Any sequence contains [N, 20] numbers, where N is size of square.
  • The size of square N is [2, 10].
  • Program should use no more than 1Gb of user-space memory.
  • Program should work no more than 60 seconds and use a single thread.
  • Program may output more than one square - one per line. The last full square after 60 seconds is considered the answer.
\$\endgroup\$
2
  • \$\begingroup\$ It's too likely that no two number is same, and best solution is trivial \$\endgroup\$
    – l4m2
    Aug 1, 2023 at 6:07
  • \$\begingroup\$ How is it likely? Numbers are limited in [0, 255]. Max possible 1000000*20 = 2'000'000 numbers in the list - they are definitely likely to be the same. Also in some test scenarios specifically numbers can be tuned to be in much smaller interval like [0, 9] only. \$\endgroup\$
    – abyss.7
    Aug 1, 2023 at 7:46
1
\$\begingroup\$

The New York Times have a new game -

Letter Boxed

(try it at https://www.nytimes.com/puzzles/letter-boxed, the rules below match it).

The game consists of a square, with three Letters on each side. The aim of the game is to join the letters to make words. Each word must start with the last letter of the previous word; and each letter must not share a side of the square with the previous letter. The aim is to solve (use all of the letters at least once) in as few words as possible.

For example:

  H  E  M

O         U

S         R

W         N

  A  I  G

You could use all of the letters in one go to form the word Housewarming, but Swim would be forbidden because the S and the W are consecutive and share a side on the square.

Additionally, HOUSE followed by ERGO would be allowed, but HOUSE followed by WARM would not because they don't share a last/first letter (E->W).

Letters can be repeated (e.g. WEARER), but not sequentially (so SEEN is forbidden), because they share a side.

The challenge

, usual rules.

The aim is to write a program that takes in the set of letters in any reasonably form (a string, or an array of arrays, for example); along with a word list (or you can read the word list in your code for free).

The output should be a word of sequential list of words that solve the puzzle by using all of the letters at least once.

The puzzle will always be solvable for the letters and word list given, but not always in one word.

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

Challenge

Create a program that, when entered two numbers A as a numerator and B as a denominator, generates a list of equivalent fractions based off the fraction A/B.

Definition

Equivalent fractions are any set of fractions that equal the same when converted to a decimal number. Example: 3/6 (three sixths), 2/4 (two fourths) and 1/2 (one half) are equivalent fractions, since each fraction equals 0.5 when converted to a decimal number.

Rules

  • Generate only the equivalent fractions with denominators smaller than B. Do not generate equivalent fractions with decimal points or negative numbers.
  • Your output must look like this: (This example is for entering 10 as A and 20 as B)
1/2 2/4 3/6 4/8 5/10 6/12 7/14 8/16 9/18 10/20
  • If you cannot generate equivalent fractions with denominators smaller than B, output A/B itself: (This example is for entering 1 as A and 2 as B)
1/2
  • The answer with the lowest amount of bytes wins.
  • You may use any programming language of your choice.
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Ideally, you should provide all the information needed to participate in the challenge, rather than linking to an external resource (though you may provide links for supplemental materials or further reading). Also, what do you mean by "only the ones smaller than A/B", if they definitionally have the same value? \$\endgroup\$
    – Bbrk24
    Aug 3, 2023 at 18:05
  • \$\begingroup\$ By smaller than "A/B" I meant having lower denominators. Sorry for the mixup \$\endgroup\$
    – boopsie84
    Aug 4, 2023 at 12:23
  • \$\begingroup\$ About the output formatting, I also recommend reading through our I/O defaults. The first couple pages of answers (if you sort by highest score) are pretty much accepted; once you get to the third page it's more controversial, and I think you can safely ignore the answers with score 6 or lower. \$\endgroup\$
    – Bbrk24
    Aug 4, 2023 at 12:49
  • 1
    \$\begingroup\$ You should add examples for the expected output given different inputs. For example: What should the program output for when the Input is 1 2? Can A or B become negative, if yes what happens in that case? \$\endgroup\$
    – bsoelch
    Aug 4, 2023 at 15:04
1
\$\begingroup\$

Comment Out the Comment

I'm back! Lately I've been working on something, but finally I've finished it and can return to CGCC! I'll be continuing the Fast & Golfiest Series soon, and also try to start working on (given I have the time and energy) WumpusWars. For now, a new question as a gift for everyone!

In LaTeX if you type %a, the a would be commented out. But if you type \%a, the a would still be there because the backwards slash converted the meaning of %. And if you type \\%a, the a would be commented out because the first backwards slash converted the meaning of the second one. So do you know what happens to the a if you type \\\\\\\\\\\%\\\%a? (Answer: The a is not commented out).

This is a code golf challenge so shortest code wins: the input is a string which consists exclusively of \ and %, except that at the end there is always %a. Output 1 or True if the a is commented out, and 0 or False otherwise.

\$\endgroup\$
2
  • \$\begingroup\$ Is \a valid?. \$\endgroup\$
    – l4m2
    Aug 12, 2023 at 3:02
  • \$\begingroup\$ @l4m2 Thanks for pointing that out! No. I'll add that a is always preceded by %. \$\endgroup\$ Aug 12, 2023 at 3:03
1
84 85
86
87 88
156

You must log in to answer this question.

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