# What is the Sandbox?

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

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

## Auto Tic Tac Toe

Okay, so after thinking about the comment I think I thought of a way to make it more interesting.

### Challenge

Given no input, write a program or function which outputs an entire game of Tic-Tac-Toe where X always wins, or the game ends in a tie.

### Requirements

• X goes first
• O must make moves at random
• X must make smart moves such that it always wins the game, or the game ends in a tie

### Example

Here's what I would expect a game to look like:

X--
---
---

XO-
---
---

XO-
-X-
---

XOO
-X-
---

XOO
-X-
--X


### Notes:

• X does not need to win in the fewest moves, it is enough to just make it always block O from winning
• You can output the game in whatever form you like, as long as it is easily conveys every turn of the game. For example you could output a string like above, or a list of lists of ints like below, where 0 is an empty space and 1, 2 are X, O respectively:
[
[1,0,0, 0,0,0, 0,0,0],
[1,2,0, 0,0,0, 0,0,0],
[1,2,0, 0,1,0, 0,0,0],
[1,2,2, 0,1,0, 0,0,0],
[1,2,2, 0,1,0, 0,0,1]
]


This is code golf, answer in the fewest bytes wins. Standard rules apply.

Is this a better challenge? I'd love to know what people think

Working example of ungolfed code: Try it online!

• I suspect this hasn't been asked because the huge majority of the work is spent on IO and not on an interesting problem. If you want to ask a tic-tac-toe challenge, you might be better served asking something like "can the next move win" which might still be a lot of parsing, but prevents excessive output at least. That said, you did do a good job of alleviating these problems in your notes, so you may be fine - most of what I've written here is my opinion, not precise advice. – FryAmTheEggman Jan 26 at 19:31
• @FryAmTheEggman Made a pretty big edit, do you think this would be less boring? – Quinn Feb 1 at 1:15
• I think the problem I have with this version is that it is probably more work to make a tic-tac-toe AI than it is to encode all the possible games and just pick one at random to output. It is possible that that isn't true, I haven't tried yet, but it still feels a bit tedious. But this might be the right direction - perhaps instead just ask for one random valid final tic-tac-toe board? Then it will likely be an encoding problem, but perhaps one with interesting strategies. Again, all opinion here, the challenge is written well, etc. – FryAmTheEggman Feb 1 at 5:13
• Do you mean "uniformly distributed" when you write "random"? – Jonathan Frech Feb 4 at 9:54
• Is the challenge in its current form not a kolmogorov-complexity challenge with choice? – Jonathan Frech Feb 25 at 1:25
• @FryAmTheEggman I don't think making the AI is actually that hard for tic-tac-toe, though if im underestimating it, i could make a change that X always go first, which I think would make the ai pretty trivial – Quinn Feb 25 at 14:14
• @JonathanFrech You tell me i have no clue, is that meaning the amount of code to output all possible tictactoe outcomes? – Quinn Feb 25 at 14:15
• I am just saying that if you take no input and require a (semi-)static output, a part of the challenge is to find out which tic-tac-toe game requires the least bytes to represent and the rest is a kolmogorov-complexity task, which in my opinion is s slightly over-used challenge format. – Jonathan Frech Feb 25 at 15:59
• kolmogorov-complexity challenges are code golf challenges with no input and a static output. – Jonathan Frech Feb 25 at 15:59
• @JonathanFrech Is that a bad thing then? Do you think this challenge wouldn't be fun? – Quinn Feb 25 at 20:18
• @FryAmTheEggman okay fixed my example, hopefully that illustrates how simple the ai could be – Quinn Feb 25 at 20:32
• I feel as though your example does more to demonstrate that nobody would approach this by writing an AI - they would just encode each possible game as Jonathan is suggesting. That doesn't mean it isn't a good challenge, the problem I am trying to get at is that the phrasing of the challenge implies that writing a "player" is required - which I think is a bad requirement. If the challenge was just "output a random, valid, tic-tac-toe board" you could still maybe get an AI solution, if it happened to be shorter, but wouldn't come with a lot of needless baggage. Sorry if this sounds a bit rambly. – FryAmTheEggman Feb 25 at 20:39
• @FryAmTheEggman well my example has tons of unnecessary baggage and is not doing anything in an efficient way in terms of golfing, i just wanted the general algorithm to be shown, id imagine it could easily be shortened to a couple hundred bytes in most languages. That said if they can find a way to output winning board states so long as they show each turn that was played than that would be valid, I don't intend to require anyone to write an AI, just achieve the desired output. Not sure how to rephrase the question to make sure its clear that that is a valid answer. – Quinn Feb 25 at 21:15
• @Quinn However, finding such a game would not be done in the submission but to be able to write the submission, leaving the actual challenge itself to be a bit of a boilerplate. – Jonathan Frech Feb 25 at 21:19
• I guess I've posted one, exactly same but ask for O's input – l4m2 May 14 at 7:30

### Determine the Kth character in the concatenated string

You are given a list that contains $$\N\$$ strings of lowercase English alphabets. Any number of contiguous strings can be found together to form a new string. The grouping function accepts two integers $$\X\$$ and $$\Y\$$ and concatenates all strings between indices $$\X\$$ and $$\Y\$$ (inclusive) and returns a modified string in which the alphabets of the concatenated string are sorted.

You are asked $$\Q\$$ questions each containing two integers $$\L\$$ and $$\R\$$. Determine the $$\K^{th}\$$ character in the concatenated string if we pass $$\L\$$ and $$\R\$$ to the grouping function.

### Input Format

• First Line: $$\N\$$(number of strings in the list)
• Next $$\N\$$ lines: String $$\S_i\$$
• Next line $$\Q\$$(number of questions)
• Next $$\Q\$$ lines : Three space-separated integers $$\L\$$, $$\R\$$ and $$\K\$$

### Output Format

• For each question, print the $$\K^{th}\$$ character of the concatenated string in a new line.

### Test Cases

Sample Input                 Sample Output

5                                 c
aaaaa                             d
bbbbb                             e
ccccc
ddddd
eeeee
3
3 3 3
1 5 16
3 5 15


### Explanation

• Q1 Grouped String - ccccc. 3rd character is c
• Q2 Grouped String - aaaaabbbbbcccccdddddeeeee. 16th character is d
• Q3 Grouped String - cccccdddddeeeee. 15th character is e

Note: It is always guaranteed that the $$\K^{th}\$$ position is valid

This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• The challenge sounds too much like a challenge on a competitive programming site. Input format is too rigid; we usually allow any convenient I/O format for submissions (and we also allow function submissions, if you didn't notice). Also, solving Q questions of the same kind isn't the interesting part of the problem. I suggest to simply say "your program should take a list of strings S and three integers L, R, K, and output the Kth character of the output of the grouping function". – Bubbler Mar 2 at 5:26
• One more thing: I'd like to see a test case that demonstrates the "grouping function" better, specifically on the strings of different lengths and mixed-up letters, e.g. ["abx", "cedy", "zzzbbb", "q"]. If I'm understanding it correctly, the grouping function given L=R=2 should give cdey and L=2, R=3 give bbbcdeyzzz, right? – Bubbler Mar 2 at 5:32

# Compute the Pareto frontier

Given a set of triplets, output its Pareto frontier.

## Definitions

A triplet is a list of 3 positive integers, for example [120, 15, 21] (order matters).

A triplet [A, B, C] is objectively worse than [a, b, c] when A >= a, B >= b, and C >= c (lower is better).

A triplet is on the Pareto frontier when it's not objectively worse than any other triplet in the input.

## I/O rules

Input and output are both a set of triplets. Each triplet must be represented as either a list of integers ([1, 2, 3]) or a /-delimited string ("1/2/3"). The format of the outer sets is flexible (built-in set type, list, or delimited string are all okay).

## Test cases

[[1, 1, 1], [2, 2, 2]] => [[1, 1, 1]]
[[3, 3, 1], [3, 1, 3], [1, 3, 3], [2, 2, 2]] => [[3, 3, 1], [3, 1, 3], [1, 3, 3], [2, 2, 2]]
... (more to come) ...

• I had sandboxed a similar challenge, but it didn't seem to be going anywhere and I wasn't going to post it. Maybe the discussion on it about filtering is somewhat relevant to this. – xnor Mar 8 at 18:42
• The IO rule for the triplets seems odd, why not any kind of ordered list? – FryAmTheEggman Mar 8 at 19:35

A similar challenge was posted here but that's outdated and I have a few twists.

## Challenge

Write a program, expression or subroutine which, given an arithmetical expression in infix notation, like 1 + 2, outputs the same expression in postfix notation except the numbers are now float representative in the string, i.e. 1.0 2.0 +.

The input can include parentheses (()), exponents (^), division (/) and multiplication (*), addition (+) and subtraction (-) (in that order of operation), such as

4 ^ (2 / 3) * 9 * 3 - - 4 * 6

output the same expression in prefix notation.

4.0 2.0 3.0 / ^ 9.0 * 3.0 * -4.0 6.0 * -

Spaces are optional in the input as well as the output.

## Twists

• Must support using floats too, instead of just integers. so 4 ^ (2.0/3.0) * 9.0 * 3.0 - - 4 *6 output's is the same as the ones above.
• Must return a string with all numbers as its float representative instead of as its original form, so 9 -> 9.0 and if it was 9.0 it stays 9.0.
• Must support negation (see example above "3.0 - - 4" ends up with "-4.0", negative sign stays in place).
• Cannot use exec() or eval() functions.

## Assumptions

• You can assume that there will not be any special numbers such as those in scientific notation or those with hanging zeroes, e.g. 000004 or 0005.000000.
• You should also not assume the commutative or associative properties. This means that, while the operators will move around, the numbers will always remain in the same order.
• You can always assume a valid infix input.

## Clarifications

• You should not evaluate any expression.
• The output should not contain any unneeded parentheses. ((2+1))-1 should reduce to 2+1-1.

## Game Winning Criteria

Fewest amount of characters wins. Bytes are not of a matter here.

• To reiterate my comment on the original question: 1. Using the word "twist" is not recommended. 2. Don't ban exec/eval just because you don't like it. The task isn't about evaluating the value, so it is unnecessary and pretty much arbitrary. 3. You say "prefix notation", but 4.0 2.0 3.0 / ^ 9.0 * 3.0 * -4.0 6.0 * - is in postfix, not prefix. You should fix either the description or the example result. – Bubbler Mar 12 at 1:27
• And you didn't explain why you want to handle unary negation in a different way (which is essentially changing the underlying expression, which seems against "You should not evaluate any expression"). By using a different symbol for unary minus (say ~), it is possible to translate the example to postfix as 4.0 2.0 3.0 / ^ 9.0 * 3.0 * 4.0 ~ 6.0 * -. – Bubbler Mar 12 at 1:34
• For code-golf scoring, scoring by bytes is preferred over characters. (I believe there must be a more persuasive argument somewhere...) – Bubbler Mar 12 at 1:47
• The second line in "clarifications" is unnecessary because "postfix notation" implies no parentheses. For the floating-point output, do you have a reason to demand adding .0 to integer values? A floating-point number 4 can be printed as 4, 4., or 4.0, and all of them represent the same value anyway. – Bubbler Mar 12 at 2:13
• The linked challenge explicitly assumes left-associativity for all operators ^ * / + - (that is, 1 - 2 + 3 = (1 - 2) + 3, 4 / 5 * 6 = (4 / 5) * 6, and 7 ^ 8 ^ 9 = (7 ^ 8) ^ 9), but ^ is mathematically right-associative (7 ^ 8 ^ 9 = 7 ^ (8 ^ 9) != (7 ^ 8) ^ 9). Which one should we use? – Bubbler Mar 12 at 2:17
• Can negation be stacked? i.e. is 1 - - - 1 a valid input? Doesn't negation in the output kinda negate (heh) the point of it being postfix, because it it prefix? – Jo King Mar 12 at 2:33

## Lucky Numbers in a Matrix

Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

### Test cases

Case 1:

Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output: [15]
Explanation: 15 is the only lucky number since it is the minimum in its row
and the maximum in its column


Case 2:

Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output: [12]
Explanation: 12 is the only lucky number since it is the minimum in its row
and the maximum in its column.

• What will be the smallest size of the matrix? Also, I suggest formatting the matrices 2-dimensionally in the test cases so that it is easier to see the corresponding output tio.run/##SyzI0U2pTMzJT/8PBI/… – user41805 Mar 15 at 8:11

## Balance a Binary Search Tree

Given a binary search tree, return a balanced binary search tree with the same node values.

A binary search tree is balanced if and only if the depth of the two subtrees of every node never differ by more than 1.

If there is more than one answer, return any of them.

Test Case:

Input: root = [1,null,2,null,3,null,4,null,null]
Output: [2,1,3,null,null,null,4]
Explanation: This is not the only correct answer, [3,1,4,null,2,null,null] is also correct.

• Perhaps, you can include an explanation of this input format in the challenge body. What counts as valid input formats for the binary tree? – user41805 Mar 15 at 8:18

# Bot Factory

Main Post

### Description

Start with an array initialized to zeros with indices starting at 1 and a series of operations to perform on segments of the list. Each operation will consist of a starting and ending index within the array, and a number to add to each element within that range.

Determine the maximum value in the final array.

For example, start with an array of 5 elements: list = [0, 0, 0, 0, 0]. The variables a and b represent the starting and ending indices, inclusive. Another variable, k, is the addend. The first element is at index 1.


a    b    k             list

[  0,  0,  0,  0,  0]

1    2   10    [ 10, 10,  0,  0,  0]

2    4    5    [ 10, 15,  5,  5,  0]

3    5   12    [ 10, 15, 17, 17, 12]


The maximum value in the resultant array is 17. That is the value to be determined.

Function description

The function must return a long integer that denotes the largest value in the array after all operations have been performed.

listMax has the following parameters:

n: an integer, the size of the initial array.
operations: a 2D integer array where each element contains an operation.


Test Cases

Sample Input

5

3

3

1 2 100

2 5 100

3 4 100


Sample Output

200

Return the maximum value in the final list, 200, as the answer.


Explanation

Perform the following sequence of o = 3 operations on list = [0, 0, 0, 0, 0]:

1. Add k = 100 to every element in the inclusive range [1, 2], resulting in list = [100, 100, 0, 0, 0].

2. Add k = 100 to every element in the inclusive range [2, 5], resulting in list = [100, 200, 100, 100, 100].

3. Add k = 100 to every element in the inclusive range [3, 4], resulting in list = [100, 200, 200, 200, 100].

This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

# Dilapidated art gallery problem

In a typical art gallery problem, the objective is to place as few guards as necessary inside an arbitrary polygon so that all of it is visible by some guard. This time, we'll make some changes to simplify the task:

• The gallery can only afford to pay one guard. No more. This means that it won't be possible to keep everything in sight, so the objective becomes to maximize the amount of art visible.
• Not even a dilapidated art gallery is barbaric enough to put art on the floor, and they don't have enough money to afford pedestals, so we only care about how much wall area is visible.
• Since the art gallery doesn't even have a roof, the whole floor is visible anyways. If you are wondering how the guard manages to hover high above the gallery - he doesn't. He has a telescopic camera tied to a weather balloon. There. Problem solved. Therefore, what counts for visibility isn't occlusion. The only thing that matters is that the walls are facing the right way.
• You can assume the floor plan is a (not necessarily connected) union of rectangles. I was thinking about including diagonal walls, but this version fits better with the theme. Any internal walls have a definite thickness. If they didn't, you could just ignore them, and that's no good.
• The guard doesn't have to be inside the gallery. They can sit outside, or even lean against the walls. You, however, cannot place the guard with infinite precision. If you try to align the guard with one of the walls, they will be displaced infinitesimally in one direction chosen with uniform probability. But yes, you can try.

The input will consists of the following characters:

• The space character represents 1m x 1m of empty space. It's up to you to decide if it's inside the gallery, or outside. You may assume that the input encodes a rectangular area that includes all of the gallery floor and that all of the walls are depicted.
• - and | represent 1m x 1m squares with walls (east-west and north-south respectively) passing through their centers. Each wall will be adjoined by either the same type of wall or a corner in its lengthwise direction, and empty space in its transverse direction.
• + Represents a corner. Each corner will be adjoined by an east-west wall either on its east side or on its west side, but not both, and by a north-south wall either on its north side or its south side, but not both, and by empty space on the remaining two sides, and in all four diagonally neighboring tiles.

Your objective is to determine and mark all guard locations - tile centers - that maximize the number of wall segments viewed from the correct side - empty space should be marked with . and wall tiles should be marked with #.
In the event that none of the optimal spots align with tile centers, do not mark any tile as optimal. It is the user's responsibility to provide a more detailed floor plan. You may optionally display an error message in that case. If you choose so, the error message must be: displayed in every situation in which no optimal tile would have been marked; same for every input that causes it to be shown; includes at one character not allowed in any valid output.

Example cases:

+----+    +----+
|    |    |....|
|    | => |....|
|    |    |....|
+----+    +----+


The guard can be anywhere inside the gallery, but they can't lean against the wall because they might suddenly find themself on the other side of that wall unexpectedly.

+---+        +---+
|   |        |   |  .
+---+ +-+    +---+ +-+
| | =>       | |
| |          | |
| |          | |
+-+          +-+


In this case, the gallery consists of two separate buildings, and the guard's best spot lies outside either of them.

+---+
|   |
|   +-+ => error
+-+   |
|   |
+---+


In this case, there is a 1m x 2m area in which the guard can see all of the walls, but there's no way to depict that in the output. You may pass the input unmodified, or you may output an error message.

+-----+    +-----+
|     |    |.   .|
| +-+ |    | +-+ |
| | | | => | | | |
| +-+ |    | +-+ |
|     |    |.   .|
+-----+    +-----+


This art gallery has a courtyard. Two inner walls must be left unprotected, but it doesn't matter which ones.

  +-+          +-+
| |         .#.#...
+-+ +-+     .###.##+
| |     .....#.|
+-+   +-+ => +##...##+
| |          |.#.....
+-+ +-+      +##.###.
| |       ...#.#.
+-+          +-+


For every wall but four, there is another wall such that exactly one of the two can be seen at any given time. As long as the other four walls are guarded, the number of walls guarded is maximized. This is also one of the rare cases where the guard can lean against a wall - if they fall through, they'll wind up guarding another wall instead.

+-------------+


This is not an art gallery. It's a fence with no inside or outside. Invalid input.

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


You might think this depicts two rooms with an internal wall, or three rooms with two internal walls - either way, internal walls are banned. Also, fences are banned. Invalid input.

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


This building has a clear interior and exterior, but the southern corridor is too narrow, the dent in the north-east corner is too jagged to leave enough room for art, and the nearby closet is too close to the main building. Each of these reasons suffices to make this an invalid input.

|---------+
| +-+     |
|    *a k |
| ei 32A  |
+-+++-+--++


There's a gap in the northwest corner, debris all over the floor, and the southern wall has exposed scaffolding. All wrong.

• I'm not sure if I'm misreading, but I feel as though there is a lot of excess information provided, while certain more basic concepts are left unexplained. For example, the rule about guard displacement being uniformly random and the size of the tiles being 1m2 seem unnecessary for computing the output, whereas the rule for what the guard sees was difficult for me to interpret. My understanding is that the guard sees infinitely far in every direction, but not through walls? – FryAmTheEggman Mar 20 at 16:00
• @FryAmTheEggman from the third point: "Therefore, what counts for visibility isn't occlusion. The only thing that matters is that the walls are facing the right way". Are you suggesting I should reformulate that? – John Dvorak Mar 20 at 16:09
• Yes, that part wasn't totally clear to me, and it feels like a very important detail that is somewhat buried amongst much less relevant information. – FryAmTheEggman Mar 20 at 16:24

# For How Long am I Alone? code-golf

You are a factory worker, whose shift is from time X to time Y. It's a very boring job, and you want to know if any other workers are working during your shift. Given a list of start and end times for the other workers and your own shift time, output the longest amount of time that you are the only one working in the factory.

# Input

List of start and end times. Any reasonable format is allowed, such as a list of tuples representing (startHour, startMinutes, endHour, endMinutes) or a list of date objects.

A pair of times, which represent your own start and end times. These may be received as a tuple/list or as separate arguments. Again, the times can be passed as a tuple, date objects, or two object array representing (hour, minutes), or you can pass the hours and minutes as separate arguments.

Each person starts working precisely at their start time and gets off work right when the end time starts. For example, if someone is working from 8:00 to 17:00, at 17:00 they are not considered to be at work anymore.

Each person does his shift 7 days a week.

If you choose to use date objects, the "Year" field of the date objects must always be the same across all inputs.

Note that the end time of your shift can look like it's earlier than your start time, e.g. 21:30 - 5:30. This means that your shift starts at 21:30 at the first day and ends at 5:30 on the next day.

# Output

The longest interval in minutes in which you are the only one working in the factory.

# Test Cases

In the form of [(hh:mm,hh:mm)...], hh:mm, hh:mm

[(3:30, 12:00), (13:00, 21:40)], (8:30), (16:30) -> 60
[(1:01, 1:03), (1:04, 1:06), (1:07, 1:10)], (1:00), (1:10) -> 1
[(21:00, 5:00), (22:30, 7:00)], (0:00), (4:00) -> 0


# Questions

Should I keep the part about the shift being able to stretch across midnight?

Is the input specification clear enough?

Any suggestions welcome.

• Say my shift is overnight and someone has a shift that isn't overnight. How do I know what day said shift belongs to? e.g. if I'm working from 21:30 to 5:30 and I get another input as 1:00 to 4:00 how do I know if I haven't even started? – RGS Mar 20 at 13:26
• @RGS Good question. Added a part about the shifts being 7 days a week, so there is no confusion. I feel like the part about having a overnight shift might make this challenge unnecessarily complicated; What do you think? – Embodiment of Ignorance Mar 20 at 18:13
• I am not a sandbox veteran, but from my POV this challenge will have us handling intervals and do arithmetics with the interval endpoints and that is probably the main core of the challenge. But adding the overnight shifts means we are trying to intersect segments of a circumference, instead of regular intervals, which is also interesting, I think! (do you understand what I mean with this?) So maybe either remove overnight shifts or rephrase the challenge as intersecting segments of a circumference? So that it becomes more clear that it isn't just an edge case, but the core challenge itself – RGS Mar 20 at 19:00
• As for the title, I would have "For how long am I alone" because "How long am I alone" looks like you are asking for your length when you are alone, instead of the amount of time during which you will be alone. – RGS Mar 20 at 19:01
• Instead of "must always be the same across all inputs", I suggest "will always be the same across all inputs". This makes it more clear that you don't have to deal with the year. – S.S. Anne Mar 20 at 23:56

# Decimal to String with Mandatory Length

## Introduction:

Inspired by this SO question, which asks for the most accurate precision of decimal values using either rounding or scientific notation as string, with at most 15 characters long. This would include the -, ., and E in the output-string.

## Challenge:

Inputs:

• A decimal value $$\s\$$
• An integer output-length $$\n\$$

Output:

• A string of the most accurate representation of the given decimal value, with a length exactly equal to the output-length $$\n\$$. NOTE: the linked SO question ask for at most 15 characters long, but this challenge asks for exactly $$\n\$$ characters long instead.

## Challenge rules:

• The output-length input is guaranteed to be $$\n\geq7\$$
• The decimal string input is guaranteed to be valid and non-empty
• You are allowed to take the input-decimal $$\s\$$ as string
• The input-decimal is guaranteed to only contain the characters 0123456789-., and will not start with an . (but 0. instead), nor start with unnecessary leading 0s like 001.23 instead of 1.23 (except for 0.).
• The output-string is guaranteed to only contain the characters 0123456789-.E (or e instead of E). The restrictions mentioned one bullet-point above doesn't apply here however!
• If the length of the integer part of a number (including - for negative values) is larger than the given output-length: use a scientific notation (with either e or E) and rounded precision. I.e. with inputs s = "-987654321987654321.987654321"; n = 15, the output is supposed to be one of these: ["-987654321.99E9", "-9876543219.9E8", "-98765432199.E7"]
• It is allowed to add leading 0s to get to length $$\n\$$ without changing its decimal (base-10) value. I.e. with inputs s = "-123.00"; n = 15, the output "-00000000000123" would be valid.
• It is allowed to add trailing 0s to the decimal parts to get to length $$\n\$$ without changing its decimal (base-10) value. I.e. with inputs s = "-1.23"; n = 15, the output "-1.230000000000" or "-1.2300000000E0" are both valid. With inputs s = "-0.123456789123456789"; n = 15, the only possible output is "-.1234567891235".
• Rounding can be one of: HALF_UP, HALF_DOWN, HALF_EVEN (please specify which one your answer is using). (My test cases where this applies use HALF_UP.)
• If multiple outputs are possible, just output one, multiple, or all of them.

## General rules:

• This is , so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
• Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
• Default Loopholes are forbidden.

## Test cases:

All these test cases will use the output-length as 15 (and rounding mode HALF_UP):

Input:                           Possible Outputs:
"987654321987654321.987654321"   "987654321.988E9","9876543219.88E8","98765432198.8E7","987654321988.E6"
"-987654321987654321.987654321"  "-987654321.99E9","-9876543219.9E8","-98765432199.E7"
"1234567891234567.123456789"     "1234567.89123E9","12345678.9123E8","123456789.123E7","1234567891.23E6","12345678912.3E5","123456789123.E4"
"-1234567891234567.123456789"    "-1234567.8912E9","-12345678.912E8","-123456789.12E7","-1234567891.2E6","-12345678912.E5"
"0.123456789123456789"           ".12345678912346"
"-0.123456789123456789"          "-.1234567891235"
"5.5555555555555555555555555"    "5.5555555555556"
"-5.5555555555555555555555555"   "-5.555555555556"
"123456789123456"                "123456789123456"
"-123456789123456"               "-123456.78912E9","-1234567.8912E8","-12345678.912E7","-123456789.12E6","-1234567891.2E5","-12345678912.E4"
"123.00"                         "123.00000000000","0123.0000000000","00123.000000000","000123.00000000","0000123.0000000","00000123.000000","000000123.00000","0000000123.0000","00000000123.000","000000000123.00","0000000000123.0","00000000000123.","000000000000123","123.000000000E0","0123.00000000E0","00123.0000000E0","000123.000000E0","0000123.00000E0","00000123.0000E0","000000123.000E0","0000000123.00E0","00000000123.0E0","000000000123.E0","12.3000000000E1","012.300000000E1","0012.30000000E1","00012.3000000E1","000012.300000E1","0000012.30000E1","00000012.3000E1","000000012.300E1","0000000012.30E1","00000000012.3E1","1.23000000000E2","01.2300000000E2","001.230000000E2","0001.23000000E2","00001.2300000E2","000001.230000E2","0000001.23000E2","00000001.2300E2","000000001.230E2","0000000001.23E2",".123000000000E3","0.12300000000E3","00.1230000000E3","000.123000000E3","0000.12300000E3","00000.1230000E3","000000.123000E3","0000000.12300E3","00000000.1230E3","000000000.123E3","1230.0000000E-1","01230.000000E-1","001230.00000E-1","0001230.0000E-1","00001230.000E-1","000001230.00E-1","0000001230.0E-1","00000001230.E-1","000000001230E-1","12300.000000E-2","012300.00000E-2","0012300.0000E-2","00012300.000E-2","000012300.00E-2","0000012300.0E-2","00000012300.E-2","000000012300E-2","123000.00000E-3","0123000.0000E-3","00123000.000E-3","000123000.00E-3","0000123000.0E-3","00000123000.E-3","000000123000E-3","1230000.0000E-4","01230000.000E-4","001230000.00E-4","0001230000.0E-4","00001230000.E-4","000001230000E-4","12300000.000E-5","123000000.00E-5","1230000000.0E-5","12300000000.E-5","123000000000E-5","123000000.00E-6","1230000000.0E-6","12300000000.E-6","123000000000E-6","1230000000.0E-7","12300000000.E-7","123000000000E-7","12300000000.E-8","123000000000E-8","123000000000E-9"
"-123.00"                        "-123.0000000000","-0123.000000000","-00123.00000000","-000123.0000000","-0000123.000000","-00000123.00000","-000000123.0000","-0000000123.000","-00000000123.00","-000000000123.0","-0000000000123.","-00000000000123","-123.00000000E0","-0123.0000000E0","-00123.000000E0","-000123.00000E0","-0000123.0000E0","-00000123.000E0","-000000123.00E0","-0000000123.0E0","-00000000123.E0","-000000000123E0","-12.300000000E1","-012.30000000E1","-0012.3000000E1","-00012.300000E1","-000012.30000E1","-0000012.3000E1","-00000012.300E1","-000000012.30E1","-0000000012.3E1","-1.2300000000E2","-01.230000000E2","-001.23000000E2","-0001.2300000E2","-00001.230000E2","-000001.23000E2","-0000001.2300E2","-00000001.230E2","-000000001.23E2","-.12300000000E3","-0.1230000000E3","-00.123000000E3","-000.12300000E3","-0000.1230000E3","-00000.123000E3","-000000.12300E3","-0000000.1230E3","-00000000.123E3","-1230.000000E-1","-01230.00000E-1","-001230.0000E-1","-0001230.000E-1","-00001230.00E-1","-000001230.0E-1","-0000001230.E-1","-00000001230E-1","-12300.00000E-2","-012300.0000E-2","-0012300.000E-2","-00012300.00E-2","-000012300.0E-2","-0000012300.E-2","-00000012300E-2","-123000.0000E-3","-0123000.000E-3","-00123000.00E-3","-000123000.0E-3","-0000123000.E-3","-00000123000E-3","-1230000.000E-4","-01230000.00E-4","-001230000.0E-4","-0001230000.E-4","-00001230000E-4","-12300000.00E-5","-123000000.0E-5","-1230000000.E-5","-12300000000E-5","-123000000.0E-6","-1230000000.E-6","-12300000000E-6","-1230000000.E-7","-12300000000E-7","-12300000000E-8"


TODO: Fix the possible outputs of the other test cases as well:

"0.123"                          ".12300000000000"
"-0.123"                         "-.1230000000000"
"1.23"                           "1.2300000000000"
"-1.23"                          "-1.230000000000"
"0.000000000000001"              "10000000000E-25" // Currently incorrect in my reference implementation
"0"                              "000000000000000"


All these test cases will use the output-length as 7 (and rounding mode HALF_UP):

Input:                           Output:
"987654321987654321.987654321"   "9.88E17"
"-987654321987654321.987654321"  "-9.9E17"
"1234567891234567.123456789"     "1.23E15"
"-1234567891234567.123456789"    "-1.2E15"
"0.123456789123456789"           ".123457"
"-0.123456789123456789"          "-.12346"
"5.5555555555555555555555555"    "5.55556"
"-5.5555555555555555555555555"   "-5.5556"
"123456789123456"                "1.23E14"
"-123456789123456"               "-1.2E14"
"123.00"                         "0000123" or "01.23E2" or "1.230E2"
"-123.00"                        "-000123" or "-12.3E1"
"0.123"                          ".123000"
"-0.123"                         "-.12300"
"1.23"                           "1.23000"
"-1.23"                          "-1.2300"
"0.000000000000001"              "100E-17" or "1.0E-15" // Currently incorrect in my reference implementation
"0"                              "0000000"

• Suggest testcase: "0.0000000001", 10 -> ".000000000", "0", 10, "0000000000" – tsh Jan 13 at 1:50
• @tsh Added (although I've used n=15 instead of 10 so I could add it to the other list instead of creating two separated test cases for the n=10. Principle remains the same for your test cases, so thanks for the suggestion! – Kevin Cruijssen Jan 13 at 7:44
• @tsh Your test case actually made me realize that s="0.0000000001", n=10 should be "100000E-15" instead for the most accurate result. Will have to do some fixes to my reference implementation. – Kevin Cruijssen Jan 13 at 7:54
• Why should it be 100E-17, not 1.0E-15? The rule makes me confusing. – tsh Jan 13 at 9:14
• @tsh 1.0E-15 would be allowed as well. I still have to change the rules after realizing that 0.00000 would be an incorrect result for s="0.0000000001", n=7, but both 100E-17 and 1.0E-15 are allowed, since they are of length 7 and retain the same exact value as 0.0000000001. I currently don't have the time to revise the rules, test cases, and reference implementation unfortunately (and if I delete the Sandbox post temporarily I can't search back for it). – Kevin Cruijssen Jan 13 at 9:17
• You say this challenge asks for exactly 15 characters long but you then have outputs of varying length. I assume you want the latter. I'm being pedantic, I know, but it's the only thing I can find to fix at the moment ;) – Lyxal Jan 13 at 9:28
• @Jono2906 I've changed the part at the output-section. I hope it's a bit clearer now? – Kevin Cruijssen Jan 13 at 9:33
• @KevinCruijssen it is clearer now. I mean, as I said, I was just being pedantic about things. – Lyxal Jan 13 at 9:34
• @Jono2906 Well, it was still a valid remark that I agree with, so thanks. :) – Kevin Cruijssen Jan 13 at 9:36
• Just another thing: Perhaps The decimal string input is guaranteed to be valid and non-empty should be The decimal string input is guaranteed to be a valid float and non-empty – Lyxal Jan 13 at 10:41
• @Jono2906 Textual there isn't a difference between decimal/double/float, though. I had the sentence in my head as "the decimal string input is guaranteed to be (a) valid (decimal) and non-empty". I could change it to that if it makes it clearer, but talking about decimal first and float after that is more confusing than clarifying imho. But if you indeed meant "the decimal string input is guaranteed to be a valid decimal and non-empty" I'll change it. – Kevin Cruijssen Jan 13 at 11:49
• @KevinCruijssen Yep, I indeed meant decimal. I've no clue why I said float. – Lyxal Jan 13 at 20:10

# Ordinal to Cardinal

Given a positive integer represented as the English spelling of an ordinal number, return the equivalent cardinal number.

## Rules

• Where an integer requires multiple words to spell, only the last word changes.

• The following integers are strongly irregular:

• "one" becomes "first"
• "two" becomes "second"
• "three" becomes "third"
• Other integers take a suffix of "th", however there are a few integers that are weakly irregular:

• "five" becomes "fif(th)"
• "eight" becomes "eigh(th)"
• "nine" becomes "nin(th)"
• "twelve" becomes "twelf(th)"
• "twenty" to "ninety" become "twentie(th)" to "ninetie(th)".
• The input can be assumed to be the English spelling of an ordinal number that follows the above rules to transform it into the equivalent cardinal number.

## Examples

• "one hundred and nineteen" becomes "one hundred and nineteenth"
• "one hundred and twenty" becomes "one hundred and twentieth"
• "one hundred and twenty one" becomes "one hundred and twenty first"

This is , so the shortest program or function that breaks no standard loopholes wins!

• There are a lot of loosely related challenges, with this one being the closest. I don't think this is a dupe at all, though, since the amount to change is much more significant. Is there an upper limit on the input? If not, you definitely need to specify how the larger numbers might appear i.e. do we need to handle "milliard" as well as "million"? – FryAmTheEggman Mar 26 at 15:47
• @FryAmTheEggman That and the other challenge takes the numbers as digits rather than words, which IMHO is a significant difference already. As for large numbers, you can assume for the purposes of the question that any number I forgot about takes a "th" suffix. – Neil Mar 26 at 22:30
• Which integers do we need to handle? I'd suggest limiting it to, say, numbers from 1 to 99. Or if you do want all positive integers, could you please clarify how these are written out? – xnor Mar 27 at 20:57
• @xnor a) this challenge is about words, not numbers b) the rules are there, I don't understand what you're missing – Neil Mar 27 at 21:51
• @Neil Like, is "one billion, two hundred and thirty four million, five hundred and sixty seven thousand, eight hundred and ninety" a possible input, for which the output would be "one billion, two hundred and thirty four million, five hundred and sixty seven thousand, eight hundred and ninetieth"? If so, what is the exact format for such numbers? I understand that really only the last word matters for the conversion in the challenge, but it might make a difference for, say, a regex that does a replacement that might falsely trigger on something like "Duotrigintillion". – xnor Mar 27 at 22:01
• @xnor Why would it falsely trigger on duotrigintillion? Is there no duotrigintillionth? – Neil Mar 27 at 22:39
• @Neil I mean if it's part of a longer number and the regex does a replacement that doesn't check for the end of the string, but simply replaces certain sequences of characters. Duotrigintillion is an arbitrary example; I don't expect it specifically to actually "collide" with anything useful. – xnor Mar 27 at 22:42
• @xnor Well, surely if it collides as the last word, then it will collide as an earlier word, which would be an error, according to the first rule? – Neil Mar 27 at 23:41
• @Neil Oh, you're right, that would catch it. Maybe a more useful example is "one hundred and one" wrongly being made into 'first hundred and first". In any case, I think it would be useful to either add large-valued test cases or put an upper bound. – xnor Mar 28 at 0:54
• @xnor I still don't see that it needs an upper bound. You can just assume that the rules I've given apply, even if they don't in real life for some reason. – Neil Mar 28 at 1:07

# Context

Growing up with my mother, whenever she looked at a clock to check the time, she would always say "shoot, it's already X!" and then I would look at the clock and realize she was just rounding the time in a really weird way.

Given a time with hours and minutes, round it like my mom would. Rounding always occurs upwards. Say it is currently H hours and M minutes.

• if M is 0, no rounding occurs; my mom isn't that crazy;
• if M is 9 or less, my mom rounds to H:15;
• if M is 19 or less, my mom rounds to H:30;
• if M is 34 or less, my mom rounds to H:45;
• for any other value of M, my mom rounds to H+1:00.

# Input

You will take a time that needs rounding, in any sensible format. ISO strings for date/time, two integers representing hours/numbers, a string with two integers and a separator; these are all fair game.

# Output

The string "shoot, it's already X" with X replaced with the mom rounding time.

# Scoring

This is so shortest answer wins. However, if your source code contains the substring shoot, it's already then you may subtract 19 from your score.

# Test cases

Here is the program I use to generate the test cases.

11:00 -> shoot, it's already 11:00!
3:08 -> shoot, it's already 03:15!
1:09 -> shoot, it's already 01:15!
13:13 -> shoot, it's already 13:30!
2:35 -> shoot, it's already 03:00!


• +1 because my mom's rounding is similarly weird too. One thing though: shoot, it's already has a ' which must be escaped in many languages, and the substring condition is unfairly penalizing langauges without string literal support. – Bubbler Apr 1 at 0:16
• I suggest removing the unnecessary fluff about adding text and only keep the conversion. Bonuses in code golf are bad in general. Here it seems you try to even the playing field by explicitly disadvantaging languages with string compression, but end up making the false assumption that the substring will occur if used literally, even though some languages will need to escape the quote. – Adám Apr 1 at 6:17
• Assuming hours wrap around in 24-hour time, some test cases showing this would be good. – xnor Apr 1 at 9:25
• Those bullet-points should either be else-ifs instead of ifs or you should just define ranges. Currently a minute of 3 would first be rounded to 15 for being <=9, then 15 is rounded again to 30 for being <=19, and then again to 45 for being <=34. So basically: 0 remains 0; <=34 becomes 45, and >34 becomes 0 with the hour increasing, and the other bullet-points could be ignored. I think something like M=0→H:00; M=[1,9]→H:15; M=[10,19]→H:30; M=[20,34]→H:45; M=[35,59]→H+1:00 (perhaps in text form) would be clearer imo. – Kevin Cruijssen Apr 1 at 10:10
• @petStorm thanks for your edit but I would prefer if you did not edit any reference programs into my sandboxed posts (you may comment with a TIO link) nor edited the challenge to cope with the feedback I get from commenters, nor to include a whole "test cases" section (but you can include it in your TIO link). In particular, usually when I don't include test cases right from the start is because I want to polish the spec a bit before trying to understand what test cases are really relevant and needed. – RGS Apr 1 at 11:50
• And this is especially true because you create a whole section and then write "Here is the program I used to generate the test cases" as if you were me, which is not ok. – RGS Apr 1 at 11:52

• I like this idea. Do we have a default for taking "infinite lists" as input? I'd mildly suggest limiting the numbers to positive integers on general principle. – xnor Apr 2 at 4:26
• How do you propose taking an infinite list as input? I think the natural approach would use as "input" a program (or function with no arguments) that runs forever; the list would consist of the numbers that it outputs when run. (This would be sort of like a plug-in that your answer could use.) The problem is that that might make the challenge trivial. But I'm not sure how else to take the input list. – Mitchell Spector Apr 2 at 6:14
• In some languages the input could be a stream or iterator – simonalexander2005 Apr 2 at 8:36
• I don't know what you want to allow, but some other possible implementations of infinite lists could be as a generator function that produces a new value on each call, or a black-box function taking a natural n and giving the n'th value. – xnor Apr 2 at 12:35
• @xnor I don't think I will limit it to positive integers because positive integers are not bounded below, meaning sequences could only increase. This pretty radically changes the content of the challenge. – Wheat Wizard Apr 2 at 13:14
• Let the first and second items of the list be x and y respectively. This checks whether input-x is divisible by y-x. (Doesn't work sometimes, I'll take a look.) – user92069 Apr 3 at 7:27

# How many Temtem can I breed?

Temtem is a monster-catching MMORPG. Within the game you have the ability to breed two Temtem to create an egg which then hatches into the baby of its mother. The ability to do this depends on several properties of the parent Temtem:

• A Temtem has a gender, which is either male or female. To breed, you need one Temtem of each gender.
• A Temtem has one or two types. A pair of Temtem can only breed if they have a type in common.
• A Temtem has a fertility which ranges from 0 to 8. Temtem with a fertitilty of 0 can no longer breed in captivity. The fertility of each parent decreases by 1 when they breed.

The resulting Temtem inherits some of its properties from its parents.

• The baby Temtem's gender is random. For the purposes of this question, this means that you can choose the gender, but you cannot change it later.
• The baby Temtem inherits its mother's type. (This is not strictly true but it is always possible to evolve the baby to give the mother's type if necessary.)
• The baby Temtem inherits the lesser of its parents' fertility.

Simple example:

• One female Temtem with fertility 3 and one male Temtem with fertility 2 of the same type.
• Breeding reduces their fertility to 2 and 1 and we choose the baby, which also has 1 fertility, to be male.
• The female can breed again with both males, at which point all the Temtem now have 0 fertility.
• This gives you a total of five Temtem.

You challenge is to write a program or function which accepts a list of Temtem and outputs the maximum number of Temtem it is possible to breed, assuming luck is on your side.

You can use any convenient input method for the Temtem, as long as it breaks no standard loopholes. For instance, you could use a string of three or four characters encoding the gender, fertility and type(s). (Your input method must be able to support 12 different types and 132 different pairs of types.)

You can output either the total number or the number of new Temtem, or you can also output the resulting list of Temtem in the order they were born.

This is , so the shortest program or function wins!

• Without the types this makes an interesting "limited Fibonacci-like" growth - I'd be curious to see if it had already been studied. I think adding in the types makes it more likely that brute forcing will be the best approach. I haven't done much work on this yet, so of course I could be wrong. Separately, this definitely needs a test case where inter-type breeding gives a larger result than handling each separately, though I'm pretty sure you knew that. – FryAmTheEggman Apr 6 at 16:47

# Word Grid Puzzle Iterator

I commonly see an advert for a word-based game, where, by removing a word from a grid of letters, the remaining letters "collapse", horizontally and vertically, leading to further words being findable.

The challenge is to take in a grid of characters and a word as an input, and output the collapsed grid after that word has been removed.

Words in the grid could be oriented in any direction.

This is code-golf, usual exclusions apply.

## Example

The following set of examples follow on from each other - so the output from the first example is the input to the second.

### AIR

In:

N   F   A   D   S   T
I   O   I   E   N   T
A   G   R   W   O   H
R   L   I   A   H   A
S   L   E   E   W   W


Out: If the word "AIR" is removed, none of the rows or columns are empty and so the rest of the grid remains as-is:

N   F       D   S   T
I   O       E   N   T
A   G       W   O   H
R   L   I   A   H   A
S   L   E   E   W   W


### HAIL

If the word "HAIL" is removed, the letters in the 2nd-5th columns drop down one, making the word "SNOW" accessible:

N                   T
I   F       D   S   T
A   O       E   N   H
R   G       W   O   A
S   L   E   E   W   W


### SNOW

If SNOW is removed, the columns collapse horizontally:

N               T
I   F       D   T
A   O       E   H
R   G       W   A
S   L   E   E   W


### THAW

If THAW is removed, the T drops down so that SLEET is now accessible:

N
I   F       D
A   O       E
R   G       W
S   L   E   E   T


### SLEET

Removing SLEET clears a row and a column, and so the grid collapses in both directions:


N
I   F   D
A   O   E
R   G   W


### RAIN, DEW, FOG

The remaining three vertical words (RAIN, DEW, FOG) can then be removed individually:



F   D
O   E
G   W



F
O
G





# Notes

In the above examples, I have not resized the arrays as the outside rows/columns are made empty; instead just leaving them blank (i.e. the final array is 6x5, as is the starting array). Your program may also do this, or it may resize the array to remove empty rows and columns if you prefer.

For example, assuming the input is a 1x5 array:

H A T C E removing HAT could become _ _ _ C E or CE, both are valid. (underscores represent spaces for formatting purposes)

# Inputs and Outputs:

Any reasonable format is acceptable - arrays, strings, etc. But:

• you cannot assume that the orientation of the word to remove is the same as that in the input. e.g you won't get the input "LIAH" because the word HAIL is written right-to-left on the grid.
• the output must be the same format as the input (i.e. the program must accept the output from the previous iteration as the grid input to the next)
• You can assume the word will be in the grid, horizontally or vertically (not diagonally)
• Words will never contain spaces, only the letters A-Z; and if the word is found but with a space in it, then that doesn't count as matching the word
• You can assume the case of the word will match the grid, in whatever case suits your language (UPPER, lower, camelCase, whatever)
• You can assume that the Input word will only appear once on the grid

# Sandbox Questions

• Does this feel too much like multiple challenges (find the word, collapse the array)?
• I think the idea stands on its own logically, though perhaps there is a dupe out there somewhere. Separately, I think you should explain the situation where a word appears more than once. Your resizing comment also seems a bit odd: I would expect that if instead of HAIL the input was AGWOH the word wouldn't be able to be removed. – FryAmTheEggman Apr 3 at 20:20
• Thanks for your comments as always. I have tried to clarify. I'm not sure what you mean about the resizing comment - only empty rows and columns can be removed; and words will always be A-Z (or whatever case you prefer) and must match exactly the input, in any orientation. – simonalexander2005 Apr 6 at 7:43
• I see, that is what I expected, but when I read the challenge I was unsure. I think your edit makes it much clearer. (What I was trying to get at was that I expected gaps in unempty rows/columns to be "unmatchable", which I think before was made somewhat ambiguous by the wording of the purely aesthetic output) – FryAmTheEggman Apr 6 at 16:30

# Chase the Easter Bunny around the garden, and grab as many eggs as you can.

In this instance, the garden is a 2-dimensional grid with 49 rows and 49 columns.

The Easter Bunny™️ is in the center of the garden, minding his own business, holding on to 100 Easter eggs. He'll hop away from where the most people are.

When the Easter Bunny™️ hops, we all know he'll leave behind an Easter egg.

Grab an Easter egg for 1 point. Grab the Easter Bunny for 10 points.

The game starts with 4 hunters, one in each corner of the garden.

The hunters can take 1 step each turn, in one of the 4 cardinal directions (North, South, East or West). When they've each taken a step (or decided not to), the bunny will take a move.

The bunny can hop to any position up to 4 spaces away in both the x and y axes. It will decide where it will hop to by the position of the hunters.

It will hop north if there are more hunters to the south than to the north (ignoring the same row). If there are 3 to the south, and 1 to the north, it will hop north by 2 spaces. This same dynamic will be used to decide where it will hop to on the X axis.

The game ends when:

• The Easter Bunny™️ leaves the garden.
• The Easter Bunny™️ drops his last egg.
• The hunters catch the bunny.

## How to hunt the bunny?

Your code will take the form of an array of 4 JS functions, which will each control a hunter starting in these positions (in this order):

• North West (0, 0)
• North East (0, 48)
• South East (48, 48)
• South West (48, 0)

The functions should each have this fingerprint:

function(api, my_storage, shared_storage) {
}

• api is your function's interface to the game (see below)
• my_storage is an object available to this function each time it's called.
• shared_storage is an object available to all hunters each time they're called.

### The API

The api object presents these four movement functions:

• api.north()
• api.east()
• api.south()
• api.west()

If any of these are called during your function, the hunter will take one step in that direction (or the last called of these four directions). If none of thess are called during your function, the hunter will stand still.

It also provides information about the state of the game with these methods:

• api.turn - Returns a number of turns taken in this game so far.
• api.bunny - Returns an object of bunny-related info

{ x: 25, y: 25, eggs_left: 100 }

• api.hunters - always 4 results

[ {x: 0, y: 0, me: true}. ... ]

• api.eggs

[ x: 25, y: 25 ]

### Template

Teams.concat(
[
function(api, my_storage, shared_storage) {
// NW hunter
},
function(api, my_storage, shared_storage) {
// NE hunter
},
function(api, my_storage, shared_storage) {
// SE hunter
},
function(api, my_storage, shared_storage) {
// SW hunter
}
]
)


### How to participate (speculative)

• git clone git@github.com:someone/bunny_hunt.git
• cd bunny_hunt
• cp template_entry.js entries/my_entry.js
• node one_match.js entries/my_entry.js to see the result
• node all_matches.js to see all results (if you import more entries)

This will run until the 19th of April, one week after Easter Sunday (in the traditions which celebrate Easter Sunday on the 12th of April this year).

# chaining couples with parity code-golfmathintegersarray

## Rules

Take the $$\n\$$ first integers (with 0 included or not) with $$\n\$$ an even number except 0.

The goal is to produce a (not so) random chain of couples with these numbers, for example with $$\n=6\$$ : (5, 4), (1, 6), (3, 2)

But you have to respect a bit of parity and randomness :

1. Each second number in a couple must have the same parity than the first number of the next couple. No rule for the first number of the first couple and the second number of the last couple. So the example above is not a correct answer.

(5, 4), (6, 1), (3, 2) is a correct answer for $$\n=6\$$.

So this is a sort of parity chain.

1. First number (of the first couple) has to be chosen randomly (uniform) in the $$\n\$$ first integers.

## Input

An even number $$\n\$$ greater or equal than 2.

## Valid output examples

• Input: $$\n=2\$$ Outputs (1, 2) and (2, 1) are valid. (0, 1) and (1,0) are also.

• Input: $$\n=4\$$ Output: (0, 1), (3, 2) (if start with 0) because 1 and 3 are odd

• Input: $$\n=4\$$ Output: (1, 4), (2, 3) (if start with 0)

• Input: $$\n=6\$$ Output: (0, 5), (1, 3), (4, 2)

• Input: $$\n=8\$$ Output: (6, 7), (1, 0), (2, 5), (3, 4)

## Invalid output examples

• Input: $$\n=4\$$ Output:(1, 2), (3, 4) because 2 is even and 3 is odd.

• Input: $$\n=6\$$ Output:(5, 4), (1, 6), (3, 2) because 4 is even and 1 is odd and also because 6 is even and 3 is odd.

## What if $$\n\$$ is odd?

No rule for $$\n\$$ if it's odd. All outputs accepted!

No special formatting is expected. You just have to separate the couples such that one can correctly see them.

Duplicate?

## Convert CSV to GeoJSON

Given an input in this CSV format:

Latitude,Longitude,Name,Value
-37,145,Melbourne,4500000
-34,150,Sydney,5000000


produce this output (GeoJSON):

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"Name": "Melbourne",
"Value: "4500000"
},
"geometry": {
"type": "Point",
"coordinates": [-37, 145]
}
}
],
...
}


You may assume that:

• The input will always be a well formed CSV file in this format. (No meta rows/front matter, no quoted strings, no spaces between fields, no problematic characters.)
• The input will contain one "Longitude" and one "Latitude" column, capitalised that way.
• The Latitude and Longitude columns may not be in that order, nor necessarily the first two columns.
• The number of other columns may be zero or many. They must all be converted.
• There will always be one header row. There may not be any data rows.

Notes regarding the output:

• must be valid GeoJSON (test with geojsonlint.com if you're not sure). Note: There must be a properties object, even if it is {}.
• is correct if it is semantically equivalent. (The order of keys does not matter).
• Whitespace does not matter.
• Treat all properties as strings.

Input and output in any of the standard ways for text input/output. Note the output must be text, not an object. (Ie, in JavaScript, use JSON.stringify())

• What's the scoring mechanism? Code Golf I assume? – math junkie Apr 24 at 18:34

# Finitly inverese in base N code-golfmath

Your task is when given a base N (you can assume it's $$\ \geq2 \$$) you need to output all natural numbers for which the decimal expansion of $$\ \frac{1}{x} \$$ in base N is finite.

## Input

You can take the base N in any reasonable format, and you also may take an additional number N, depending on what output format you chose.

## Output

You have 3 options for the output format:

• Take a number n and output the n-th number in the sequence
• Take a number n and output first n numbers in the sequence
• Take no additional input and output the list indefinitely

# Test Cases

10 -> [1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 128, 160, 200, 250, 256, 320, 400, 500, 512, 625, 640, 800, 1000, 1024, 1250, 1280, 1600, 2000, 2048, 2500, 2560, 3125, 3200, 4000, 4096, 5000, 5120, 6250, 6400, 8000, 8192, 10000, ...]
2 -> [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, ...]

• So basically numbers such that their set of prime factors is a subset of N's set of prime factors? (assuming no repetitions in sets) – the default. Apr 16 at 10:31
• I'm not sure, but from what I've seen it seems like it – Command Master Apr 16 at 12:33

## This Question Has _____ Views code-golfstack-exchange-api

posted

• I think currently the challenge will only be who can get the shortest domain that'll respond with the output. I think you should limit the challenge to only accessing the stack exchange api, and not any other website – Command Master Apr 16 at 7:59
• @CommandMaster But any other domain will be wrong as soon as the number of views goes up. The program should always print out the number of views this question has at the moment you actually run the program. – izlin Apr 16 at 8:48
• someone can register a domain which will retrive the live number – Command Master Apr 16 at 8:51
• @CommandMaster that is either the "Fetching the desired output from an external source" or the "Outsourcing the real answer" loophole. – the default. Apr 16 at 10:30

# Making a programable computing chip

Make a programable chip with 8000 commands ROM and 48 16-bit unsigned words RAM initalized with zero.

These commands should be supported:

a = b + c  # mod 65536
a = b - c
a = b * c
a = b / c  # undefined behavior if c==0
a = b % c
a = b > c  # return 0 or 1
a = b >= c
a = b == c
a = b != c
if a goto b
if !a goto b
call a, b  # store ip of next command to b and goto a, then can return
input a
output a
a = [b] # You can decide constant k and l, such that [kn+l] is rn.
[a] = b # Using undefined [n] is UB


where a, b, c can be r0-r47 or a constant of a 16-bit integer or the ip of a command. Writing to a constant is a nop, so input 42 discards an input. Mixing ip and integer, running out of commands are undefined behavior.

For example,

L1: input r1
r0 = r0 + r1
output r0
if !0 goto L1
r2 = r1 + L1


takes input, and output sum of all inputs modulo 65536. r2 = r1 + L1 is undefined behavior, but since it's never executed it's not a problem.

The circuit consists of controlled gates (x,y,c,t), meaning that wire x and wire y are connected if wire c was active(t=1) or inactive(t=0), and programable wire (x,y,0,0), meaning that wire x and wire y can be programmed to be connected.

At the beginning, none of the wires, except IO wires(discuss later), is active. In each step, any wire connected to wire 0, whether directly or indirectly, is active.

IO is used to connect multiple such component. It contains 18 wires, where 16 of them store an integer to be passed, and two A and B meaning if there's data on the wire. When sender send, sender negate A; when reciever recieve, B negated. Therefore, there's data on the wire iff A!=B.

We write A on input, B on input, A on output, and B on output of the chip, as 4, 8, 5, 9, respectively, and the 16-bit input on 16-31, output on 32-47. You can active wires where you are expected to read from, but your chip should handle with another such chip (so if you write to input, you should handle cases when output is inputted).

For example, {(0,5,4,1),(0,8,9,1)} output zero whenever recieving an input.

You should submit a circuit (a set of 4-elem tuples) and a compiler. Smallest circuit win.

Given a $$\ 20 \times 20 \$$ grid, start at any arbitrary point. Then starting from this point, draw a sequence of straight lines each attached to two points on the grid. In addition, the lines must be in strictly increasing length, and such that no two intersect or touch each other. Call the number of lines drawn $$\ n \$$. The diagram below shows an example of a smaller $$\ 5 \times 5 \$$ grid, where $$\ n = 5 \$$. However, the maximum length for a $$\ 5 \times 5 \$$ grid is actually $$\ n = 9 \$$ (Try to find it yourself!).
This is , meaning the answer with the largest $$\ n \$$ wins!