# Sandbox for Proposed Challenges

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

Sandbox FAQ

## Posting

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

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

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

## Discussion

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

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

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

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

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

## Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

# Check if the string is reshaped.

• I don't understand this. Can you try to reword it? Dec 16, 2021 at 19:58
• @pxeger read examples carefully Dec 16, 2021 at 20:00
• @Fmbalbuena I did, but it's really not clear what you mean by "reshape" Dec 16, 2021 at 20:01
• @RedwolfPrograms ⍴ in APL. Dec 16, 2021 at 20:04
• @Fmbalbuena I don't know APL, and you can't expect people solving the challenge to either. You need to explain what you mean by "reshape", in a way that people will be able to understand without a background in any particular language. Dec 16, 2021 at 20:09
• @RedwolfPrograms ask to Adám. Dec 16, 2021 at 20:15

# Dumbo octopus flashing time code-challenge

Day 11 of this year's AoC was about a grid of bioluminescent dumbo octopi. I'll try to explain how this works, click on the link for a better explanation.

You have a 10x10 grid of octopi which slowly gain energy and flash when fully charged. Each octopus has an energy level from 0 to 9:

5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526


The flashes and energy amounts can be modelled with steps. At each step:

• All octopi have their energy level increase by 1
• Then, any octopus with an energy level greater than 9 flash. When an octopus flashes, it increments the energy levels of all octopi adjacent (orthogonally or diagonally) to it.
• The flashing repeats until no more octopi can flash. Then, all octopi that flashed during this step have their energy level reset to 0.

For example (stolen from AoC):


Before any steps:
11111
19991
19191
19991
11111

After step 1:
34543
40004
50005
40004
34543

After step 2:
45654
51115
61116
51115
45654


In step 1, the octopi with energy level 9 are all incremented to 10 and flash, all incrementing the octopus with energy level 1 (initially incremented to 2) in the center and causing it to flash as well.

The second part of the puzzle asks how long a configuration will take to have all octopi simultaneously flash in the same step. However, not all configurations will do this - some will fall into other cycles. Eventually, all of the configurations will repeat themselves, as there's only $$\10^{10 \cdot 10 } = 10^{100}\$$ possible configurations - still a huge amount, but finite.

Your challenge is to find a configuration that takes as many steps as possible to return to a configuration it's reached before, with more steps being better.

People on reddit have been investigating this, and the number to beat is 372886.

## Meta

Is the explanation good, and should I bother with it?

Better examples?

• Why is it not $10^{100}$ configurations? Also, it's not initially clear that an octopus increments for each adjacent flash.
– att
Dec 20, 2021 at 8:40
• @att Oops, made a mistake with #1 and I'll try clear up #2 Dec 20, 2021 at 8:42
• @att Better now? Dec 20, 2021 at 8:45
• Yeah, I think so
– att
Dec 20, 2021 at 8:51

# Kolmogorov-simple numbers

• Why not more flexible IO? Requiring a print seems pointless to me. Dec 15, 2021 at 8:50
• Seems like this would be better if the challenge was stated as "output the smallest number $l$ in $n$ bytes, such that $l < \log_{256}(n + 1)$". I agree with pxeger, it's a lot more simple to just use our standard I/O rules, and not worry about it Dec 15, 2021 at 12:58
• I've edited this down to a stub now that it's been posted to save space Dec 22, 2021 at 1:04

# Return all letter counts as an integer

• I've edited this down to a stub now that it's been posted to save space Dec 22, 2021 at 1:06

# Event scheduler

• Thanks for using the sandbox. The challenge type is called fastest-code here. It looks well-defined in general, but a few minor issues: 1) You don't really need restrictions in time complexity (the requirement 1) when submissions are competing for it. 2) Looks like the build instruction is linux only. If so, it should be clarified as such (along with dependencies like cmake). Dec 7, 2021 at 2:12
• FYI, language-specific challenges are discouraged here, and fastest-code without language restriction is usually done by measuring time on a single machine (often the challenge author's). (Not sure how to adapt this specific challenge to other languages, so I'd say it's fine in this case.) And unfortunately we're not like other competitive programming sites, and therefore have very few C++ users. Dec 7, 2021 at 2:15
• OK so would it be acceptable to submit a sample C++ code as guidance and open up to other languages?
– user108147
Dec 7, 2021 at 5:12
• @Bubbler Changed the terms of the challenge. Does it look better as it stands?
– user108147
Dec 7, 2021 at 5:28
• I mean, because of the nature of the task, it's near impossible to establish fair comparison across languages. Normally you'd feed input in a standardized format through STDIN and let the programs output through STDOUT, but 1e8 events would make I/O time way too significant. And not all languages have mt19937 implementation or seeding it like C++ does. So I was saying that limiting to C++ is fine here, though it won't get many answers on this site. Dec 7, 2021 at 5:36
• Hmm we could then open by classes like in boxing but per language here. Winner for C++, Java, Python, etc. And the IO is really not much - just generate a random sequence in memory and submit.
– user108147
Dec 7, 2021 at 5:38

### Identify basic building blocks for new natural and programming language

(Based on Invent new programming language and write Hello world in it, but re-phrased to gain more focus on answers).

There exists variety of different programming languages, also variety of natural languages.

If we could create new programming language, which in a turn would possess structure of natural language - what basic structures you would choose ?

one example of artificially constructed language is Toki Pona:

It can be used as natural language, but not as a programming language.

One example of programming language is for loop - for example in C#:

for(int i = 0; i < 10; i++) { ... }

If you want to express this kind of sentence in natural language - then you can use 'equals' for '=', 'less than' for '<' - but scope begins ('{') and scope ends ('}') is relatively long and difficult to express / pronounce.

What basic language structures you would propose for new language ?

# Find out what type of adjective it is

There are 3 types of adjectives: absolute, comparative, and superlative adjectives. Your program should print what type of adjective it is. The program is supposed to work on finite lost of words.

## Notes

• Input will be a string, (not always 1 word), it'll be an adjective (the number of words will be finite)
• Output must be anything that represents absolute, comparative and superlative.
• The 15 adjectives below should be used as test cases and your program should be at least 90% accurate.

This is , so the shortest code wins!

Test cases:

pushiest => superlative
homeliest => superlative
most miserly => superlative
outgoing => absolute
most feline => superlative
roasted => absolute
frightening => absolute
fairer => comparative
more uncomfortable => comparative
more classic => comparative
smarter => comparative
muffled => absolute
scratchier => comparative
meager => absolute
tartest => superlative

• So it only needs to correctly identify 14 of the below 15? Jun 30, 2021 at 14:00
• @rak1507 at least. I'll add more test cases if necessary Jun 30, 2021 at 14:02
• @rak1507 but checking everyone of these won't work, as it's code golf Jun 30, 2021 at 14:04
• It should be made very clear whether the program is supposed to work on a finite list of words (as currently suggested) or on any input in theory. The approaches are going to be very different. Jun 30, 2021 at 22:34
• "tartest" is a superlative. Jul 17, 2021 at 2:04
• @DjinTonic okay done Jul 25, 2021 at 7:58

# Is it a mathy-county-number

So I recently reinvented some boring type of number. Reinvented because I'm sure somebody else invented it before, but 'till figure out who invented it, let's call these numbers mathy-county-numbers.

## So what is a mathy-county-number?

A mathy-county-number number is a number whose count of each digit also appears in the number.
It's a number like 332222410.
The number 3 occurs 2 times, so there must be a 2. The number 2 occurs 4 times, so there must be a 4. 4 occurs once, and some other numbers occur 0 times.

The task is simple: Write a program to check if a number (received by the input) is a mathy-county-number.

## Rules

• Default loopholes apply
• Default I/O rules apply
• Output must be a truthy or falsy value
• No digit will appear more than 9 times

## Examples

332222410
> True

33222241
> False

1
> False

33222
> False

1122233334444455555566666667777777788888888890
> True

112223333444445555556666666777777778888888889
> True

122334444456789
> False

• "The number 3 occurs 2 times, so there must be a 2." Does this means "3312" is valid as there is a 2 (although not followed by 3).
– tsh
Jul 26, 2021 at 9:48
• Why "1" is falsy?
– tsh
Jul 26, 2021 at 9:49
• @tsh 1: no, because in 3312 there's no 0. but eg. 03312 would be valid Jul 26, 2021 at 10:44
• @tsh 2: 0 is not there, 9, 8, 7, ... occur 0 times Jul 26, 2021 at 10:54
• "If any digit occurs more than 9 times, count it as a 9." is needlessly complicated, I'd suggest just saying that no digit will appear more than 9 times. The output for the last 2 test cases in unclear - what is sdcvbhnjmk supposed to represent? Just use something like true/false. Additionally, why is 33222 true? By the same logic as the example, it contains "some other numbers zero times", so should include a 0 to be true, right? Aug 6, 2021 at 14:02
• @cairdcoinheringaahing thanks, don't know why I'm addressing the changes now Jan 7 at 13:06
• If 0 does not occur in a number, does that mean that some number appears 0 times? Jan 7 at 14:03
• 0 has to occur in a mathy-county-number if some number appears 0 times. Example 112 would be invalid because eg. 3 appears 0 times. 1120 would be valid though. Jan 7 at 14:20
• @thejonymyster ^ Jan 7 at 14:30
• in the number 123456789, 0 appears 0 times. However, there is no 0 in the number to account for the fact that there is 0 of that number. Should this output truthy or falsy? (Note: this is a paradox) Jan 7 at 14:33
• Also, you should clearly define what makes a number mathy-county, rather than having the user rely on an example. (Not that it isn't easy to figure out, but it's good practice and leads to no assumptions being made, especially ones you weren't prepared for) Jan 7 at 14:34
• @thejonymyster I'd say the number itself should be falsy because there is no 0. However even if you add a 0 it'll stay falsy. Jan 7 at 14:40
• Thanks, I'll add that in Jan 7 at 14:41
• @mathcat so any number without a 0 in it should return falsy. Also, numbers with leading 0s being counted differently is strange. How is 01 different from 1, numerically? Jan 7 at 15:09

# Wordle

The game Wordle is quickly becoming popular.

The way the game works is as follows:

1. Players are trying to guess a 5 letter word
2. Players have six attempts to guess the word
3. After each attempt, the player is told:
a. which letters are in the right place (index)
b. which letters are in the word, but in the wrong place
c. which letters are not in the word at all

The aim of this challenge is to create a Wordle application, as follows:

1. On startup, the application reads from a dictionary of 5-letter words and selects one at random
2. The application then prompts for user input
3. On input:
a. The application checks the input to ensure it is also a 5-letter word and in the dictionary. If it is not, the application returns any failure message and exits
b. If the input matches the chosen word, the application returns any success message and exits
c. Otherwise, the application checks the letters of the input against the letters of the word, and returns to the user an indicator for each letter of whether it is correct, misplaced, or incorrect. If a letter is repeated in the input, only the first occurrence is marked as correct/misplaced; the remaining occurrences are marked as incorrect [sandbox qn: what happens if the actual word has repeated letters?]
4. Steps 2 and 3 are repeated until the application aborts in step 3a or 3b; or the user has failed to guess the word a total of 6 times; at which point the application exits

## Sandbox

I am thinking of this as a code-golf challenge, but I wonder if there's another approach where people create the bot that's trying to solve the challenge, as well as the bot that's providing the challenge? Or something else? I'm not familiar with the other types of challenges to suggest something.

• The hints wordle gives back are a little more complicated when a letter appears multiple times in the guess. I still think there's a lot left to clear up here otherwise but that sort of edge case behavior is one thing that should be made clear.
– Wheat Wizard Mod
Jan 11 at 15:04
• @WheatWizard Thanks, yes, that's why I put it in the sandbox! Jan 11 at 15:04
• Somone has played around and found out the repeated letter rules over on Reddit. Jan 11 at 23:29
• IMHO in its current form it contains too many tasks in one challenge. Maybe limit the challenge just to step 3 or even just step 3c? Jan 12 at 11:10
• @JonathanAllan thanks, that's helpful. Jan 13 at 15:24
• @pajonk I agree it's probably too complicated as-is for a [code-golf] challenge. I don't want to reduce it to just a simple "which letters are in the correct place" challenge though - I feel that's not interesting enough. What about a different scoring system - perhaps a variant of [king-of-the-hill], where you're either trying to create a bot that can solve Wordle quickly; or a bot that picks words to avoid being solved easily - and they're pitted against each other. Would that be more interesting? Jan 13 at 15:27

# Universal Command Sequence

Posted

• Very related: Shortest universal maze exit string
– xnor
Jan 6 at 8:59
• I feel like answers to this will be very hard to test. Probably the golfiest way to do this, if it's valid, would be not to code anything with mazes, but just to produce some massive random-looking sequence of directions. If the length is a fast-enough growing function of n, with overwhelmingly high probability works on every maze for every n. Like, "output 3^3^3^n in base 4".
– xnor
Jan 6 at 9:06
• @xnor This question is actually from a Russian math olympics problem :D that problem is to prove the existence of the sequence. The proof states that the sequence can be generated by following a certain rule (a certain rule of concatenating sequences, to be exact). And I think I do have written a testing code for it; see section "Test Code" (sorry but English isn't my mother tongue, but now I know it is called a "validator", isn't it?) Jan 6 at 15:42
• Ah yes I rembered, it's 1998 All-Russian Math Olympiad, Grade level 9, Day 1, Problem 4. Original problem is 8x8 grid, but the proof can be generalized to nxn. Jan 6 at 16:02

# Generate Fmbalbuena Numbers

• so both the second step and last step need to be true? Jan 6 at 11:35
• @Razetime 2nd and last step need to be true. Jan 6 at 11:36
• combine step 1 and step 2 into "Check if the number of digits is a multiple of 3", and change "N/3 digits" to something like "Length / 3 digits" (to me "N/3" reads like the original number divided by 3). Jan 6 at 14:22
• "equals the last digits" → "equals the last digits modulus 10"
Jan 7 at 0:01
• You should state clearly that having a digit count that isn't divisible by 3 is enough to make a number not be a Fmbalbuena number.
Jan 7 at 0:02
• What is the goal of the challenge? decision-problem for a single given number (I recommend that) or generating the sequence up until a limit, or maybe the first n number, or "infinitely" spitting out more?
Jan 7 at 0:04

# Generate Matching Regexes

Write a program that takes two lists of strings and generates a javascript regex that fully matches all the strings in the first list and matches none of the strings in the second list.

To be specific when for all stings in the first list str.match(\[your-output]\) must produce a match for the full string and for all strings in the second list str.match(\[your-output]\) must produce no matches.

## Scoring

Your score is the average length of the regexes you produce not the length of your program. Your regexes should be tested against this file: https://pastebin.com/9iNZvGJC. Take the file in blocks of 20 lines and run your program with the first ten lines to match and the second ten to not match. Average the lengths of your program's output for all of the blocks in the file. This is your score.

## Rules

• Do not output the \ for the regex
• I'm guessing this is a Sandbox for this closed challenge, and that you're aiming to improve the existing one? I'd suggest clarifying the scoring system, I'm not fully sure how exactly it works? Jan 15 at 22:46
• Yes it is. Could you clarify what you find confusing about the scoring system? Jan 15 at 23:06
• "Take the file in blocks of 20 lines and run your program with the first ten lines to match and the second ten to not match." Seems like it would be simpler to just provide the lines to match and the lines to not match, rather than doing the line splitting bit Jan 15 at 23:10
• You would have to split it into blocks anyway so that doesn't really seem easier? Jan 15 at 23:17

# Help Bob split his apples

Bob has a lot of apples, and he wants to split his apples with his friends evenly. (Including Bob.) However, every $$\k\$$th friend already has a lot of apples and does not need apples. Bob, however, is kind so he gives each $$\k\$$th friend the number of apples the friend already gives floor divided by three.

Given the input format below, a number $$\k\$$, and a number $$\a\$$ for the number of apples, output the number of apples that each person receives.

# Test Cases

[0, 0, 80, 0, 0, 45, 0, 0, 12] 3 100 => [10, 9, 26, 9, 9, 15, 9, 9, 4]

• Could you try to clarify a bit more? Jan 19 at 13:46

# Move the next greater number, with fewest fails to take everything

Your task is to move the next greater number, with fewest fails to take everything

A fail counts if a step is the lower number (not counting equal)

The starting point is the top left corner

Example:

1234


Can do like this

>>>


Because moves to right, the next number is greater than previous

But

124
435


Is impossible so the fewest fails are:

>>v<<


1 > 2 > 4 > 5 < 3 > 4

So this has 1 fail

## Test cases:

The output is not exact, there are multiple possible solutions

Input:

123
245
175


Output:

>>vv<<^>


Input:

123456789


Output:

>>>>>>>>


Input:

987654321


Output:

>>>>>>>>


Input:

123
456
789


Output:

>>vv<<^>


Input:

123456789
987654321
123456789


Output:

>>>>>>>>v<<<<<<<<v>>>>>>>>


# Meta:

• Any feedback?
• I like the idea but I think the explanation could include the definition of a "fail". Jan 19 at 16:28
• @Wezl-yizl Added Jan 19 at 16:31

# Euler Irregular Primes

Your challenge is to find all Euler Irregular Primes (A prime p is Euler-irregular if it divides an Euler number E(2n) with 0<2n<p−1) under n.

## Scoring

Your goal is to use the least amount of bytes.

• welcome to this website ! challenges should be self contained, so while the link is good, you should Also include a definition of euler irregular primes Jan 20 at 1:49
• Could you provide some test cases and define "storage" clearly? Jan 21 at 10:45

# Approximate Euler's Number

Euler's number (e) is one of the most well-known mathematical constants, with a simple way to approximate it. All you have to do is repeatedly generate a random number between 0 and 1, and add it to an accumulator. Record how many times you have to do this for the accumulator to exceed 1. If you do this over and over again, the average of all the times it takes will approximate Euler's number.

Write a program that, given a number of iterations as input, approximates Euler's number using the above method and prints the result.

## Scoring

This is code-golf, so shortest answer wins. However, if the language you are using does not include a random number builtin, you may exclude from your byte count the code required to import it. For example, if you're writing a Python program to do this, you may assume the random module is already imported.

## Example implementation (ungolfed)

import random
acc = 0
res = []
for x in range(int(input())):
while acc < 1:
acc += random.random()
res.append(acc)
acc = 0
total = 0
for x in res:
total += x
print(total / len(res))

• This looks like it's probably unobservable. You also need to specify how "random" is defined: can programs use a biased RNG (which will inevitably produce an inaccurate approximation)? Jan 24 at 17:55
• @pxeger Good point. How should I go about fixing this? Jan 24 at 17:56
• IMO the interesting part of this is never going to be the random number generation, but the calculation based on them. You could just have challenges accept an input of a list of numbers, presuming them to be random, and give the approximation calculated if that list were the source of random numbers. So an input of [random.random() for _ in range(10000)] will produce about 2.72, but an input of [0] * 10000 will produce some completely wrong output Jan 24 at 18:00
• Also, your code is missing a parenthesis on line 4, and outputs $e / 2$, not $e$. Jan 24 at 18:00
• @pxeger I know the RNG is boring, whcih is why it's excluded from the byte count. Sorry about the bugs, I'm fixing them. Jan 24 at 18:02

# Count the ways to transform (3)

Your input is an infinite matrix (2d array) of nonneagtive integers where a finite area of the matrix contains nonzero integers. For example:

$$\begin{matrix} \ddots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \cdot^{\cdot^\cdot} \\ \cdots & 0 & 0 & 0 & 0 & 0 & 0 & \cdots \\ \cdots & 0 & 1 & 0 & 0 & 6 & 0 & \cdots \\ \cdots & 0 & 3 & 5 & 4 & 3 & 0 & \cdots \\ \cdots & 0 & 2 & 0 & 0 & 0 & 0 & \cdots \\ \cdots & 0 & 0 & 0 & 0 & 0 & 0 & \cdots \\ \cdot^{\cdot^\cdot} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots \end{matrix}$$

A semi-continuous transformation of this matrix is a rearranging of elements that preserves immediate neighbors. For example, we can swap the $$\2\$$ in the bottom left, and the $$\1\$$ in the top left corner.

$$\begin{matrix} \ddots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \cdot^{\cdot^\cdot} \\ \cdots & 0 & 0 & 0 & 0 & 0 & 0 & \cdots \\ \cdots & 0 & 2 & 0 & 0 & 6 & 0 & \cdots \\ \cdots & 0 & 3 & 5 & 4 & 3 & 0 & \cdots \\ \cdots & 0 & 1 & 0 & 0 & 0 & 0 & \cdots \\ \cdots & 0 & 0 & 0 & 0 & 0 & 0 & \cdots \\ \cdot^{\cdot^\cdot} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots \end{matrix}$$

This is fine, because every number has the same neighborhood counts. That is, we can make a sorted list of numbers and their neighbors, and verify the they are the same:

$$\begin{matrix} \text{Number} & \text{Neighbors} \\ 0 & 0,0,0,1 \\ 0 & 0,0,0,1 \\ 0 & 0,0,0,2 \\ 0 & 0,0,0,2 \\ 0 & 0,0,0,3 \\ 0 & 0,0,0,3 \\ 0 & 0,0,0,3 \\ 0 & 0,0,0,4 \\ 0 & 0,0,0,6 \\ 0 & 0,0,0,6 \\ 0 & 0,0,1,4 \\ 0 & 0,0,2,5 \\ 0 & 0,0,4,6 \\ 1 & 0,0,0,3 \\ 2 & 0,0,0,3 \\ 3 & 0,0,3,6 \\ 3 & 0,1,2,5 \\ 4 & 0,0,3,5 \\ 5 & 0,0,3,4 \\ 6 & 0,0,0,3 \\ \end{matrix}$$

(we ignore zeros that have 4 zeros next them, since there are always infinitely many)

# TODO: Add example where non-semi-continuous transformation changes the neighborhood counts.

To clarify, semi-continuity is a property of a transformation on some specific matrix.

Your code will take an infinite matrix as input and output the number of (unique) semi-continuous transformations. Two transformations are different if the output is different. So for example swapping two identical numbers is the same as the identity transform (doing nothing). Also, since it's an infinite grid, simply translating the pattern is the same as doing nothing. You can assume the output number will always be finite.

Or in other words: Your code will take an infinite matrix and return the number of matrices with those dimensions that have the same neighbor-list.

Input can be in any reasonable format. You can decide if your input has to have some amount zero-padding or if you always take a square matrix, etc.

# Meta

Is this more interesting than version 2?

• not sure what being infinite adds to the challenge since all that changes is that translations do nothing Jan 25 at 15:39
• If the non-zero portions form multiple disconnected segments with more than one $0$ separating them the result can be infinite. For example if the finite portion is entirely within $1,0,0,2$ then you can just move the two non-zero values as far apart as you wish.
– Wheat Wizard Mod
Jan 25 at 15:41
• @WheatWizard Yes, that's what I meant with "You can assume the output number will always be finite" Jan 25 at 16:22

(To do.)

# Test Cases

[[1, 2, 3], [4, 5, 6]] => [[1, 4], [[1, 2, 3], [4, 5, 6], [3, 2, 1], [6, 5, 4]]
[[1, 1, 1]] => [[1, 1, 1], [1, 1, 1]]
[[]] => [[]]


# Ragged Matrix

A ragged matrix, is a matrix that has a different number of elements in each row. Your challenge is to write a program in any favorable language to find the indices of all occurrences of target in the ragged matrix.

# Input:

A list of ragged lists (can be empty) of positive integers and a target range e.g. 56-26. The target range, given 2 positive integers. For languages that do not support this type of list, you can input it as a string representation

You may assume that a<=b

# Output:

If a number in the ragged list is within the range or equal to a or equal to b, output the index of the ragged list then the index of the number in that ragged list e.g. 0 4 - The 0 is the first ragged list in the input and the 4 is the index of the number in the first ragged list

# Test cases:

[[[1,3,2,32,19],[19,2,48,19],[],[9,35,4],[3,19]],19-53]
->
[[0,3],[0,4],[1,0],[1,2],[1,3],[3,1],[4,1]]

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


You can choose to follow the output format above or output it in the following as well:

[[[1,3,2,32,19],[19,2,48,19],[],[9,35,4],[3,19]],19-53]
->
0 3 0 4 1 0 1 2 1 3 3 1 4 1


0-based and 1-based indexing is allowed

You can output your answers in any way as long as it is distinguishable what the indexes of the number and matrix are

# Tags:

code-golf

matrix

ragged-list

• Please consider adding tags below the title (refer to the template). Please also consider loosening the input criteria (e.g. allowing also inputting a and b as integers with assumption that a<=b). You may also explicitly state that both 1- and 0- indexing is ok. Jan 26 at 8:24
• are my edits ok now pajonk? i have changed it accordingly Jan 26 at 10:44

# Truncatable Primes

A left-truncatable prime is a prime number and when the first digit is removed continuously, the result is always prime.

A right-truncatable prime is a prime number and when the last digit is removed continuously, the result is always prime.

If the integer is only a left-truncatable prime, return left

If the integer is only a right-truncatable prime, return right

Otherwise, return False

# Test cases

9137 -> left
9137, 137, 37 and 7 are all prime

5939 -> right
5939, 593, 59 and 5 are all prime

139 -> False
1 and 9 are non-prime, so 139 cannot be truncatable from either way

103 -> False
It contains a 0 digit, which is not prime(even though 103 and 3 are primes)


You may assume that the input will never be both left and right truncatable, so an integer such as 5 will not appear in the input (it is prime and single digit so it is counted as both)

You are allowed to print False as 0 and left as 2 and right as 1

OR

left as 1 and right as 2

Otherwise, you are allowed to use any 3 distinct 3 values/string representation of left, right and False

# Tags:

primes

classification

• Rather than those specific strings, I would recommend letting people choose their own four distinct values
– user
Jan 26 at 12:24
• Also, I think there’s a tag for classification challenges
– user
Jan 26 at 12:25
• I'd recommend allowing some inputs to be both left and right-truncatable because it makes the challenge more exciting, but that's all up to you. Jan 31 at 12:54

# D'Hondt method

the D'Hondt method is a method for allocating seats in parliaments.

Given the Amount of representatives the district you're calculating for is given, and the total amount of voters, and a map or dictionary of every party alongside all the votes they got, you will be asked to give the amount of representatives each party will get from that electoral district as a map or dictionary depending on your language, or as a list/array of whose first index will contain of the party name as a string or char[], then the second the number of representatives as a number (the type is all fine as long as it doesn't have any decimals and is not negative, and their string conversions are something like this: f123 -> "123")

like as output those are all fine:

return mapOf(
"Party A" to 4
"Party B" to 3
)


or

return arrayOf(
"Party A",  "1",
"Party B",  "2"
)


you can even give Array as an output as long as you clarify how to get proper values from it somewhere in the answer (in easy terms of course) like:

arrayOf(
"Party A" to 4
"Party B" to 8
)


and you can post a snippet like

for(value in output)
{
if(value::class == Int::class) println(value as Int)
if(value::class == String::class) println(value as String)
}


The Input will be similiar as such:

• mutableMap<String, Int>
• "Partyname": Amount of votes it got
• Amount of Voters in that district
• Amount of representatives to be assigned to the parliament from that district

The Output will be something like:

• mutableMap<String, Int>
• "Partyname": Amount of representatives it got or
• mutableList<String, String>
• "Partyname": amount of representatives it got in a comprehensible form
• Like: [PartyA, 5, PartyB, 10, PartyC, 15] or
• List<List<String, String>
• Like: [ [PartyA, 5], [PartyB, 10], [PartyC, 15] ]

Those are not strict rules and just a general remind that as long as the input/output is comprehensible it is fine

• Challenges must be self-contained so you should describe the method directly in the post instead of relying on links. I'd recommend deferring to our I/O defaults rather than spending so much text describing possible formats (you've said yourself that there are no strict rules). Lastly, avoid using language-specific terms/concepts like mutableMap<String, Int>. Jan 31 at 11:13
• Actually, looks like this challenge has already been done: It's election time! Hopefully the advice in my previous comment will be helpful for future posts. Jan 31 at 11:15
• will sure keep this in mind, also, thanks for showing me the actual post about this. Jan 31 at 12:26
• should I delete this Jan 31 at 12:26
• I think so, yes. Unfortunately it's a duplicate of the earlier challenge. Jan 31 at 22:08

# Tips for golfing in Seriously

I am looking for tips to code in this golfing language Seriously, and was wondering what some of the best/subtle ways for golfing this language is. Thx in advance!

• Not much of a corpus left to learn from by example... Jan 31 at 6:25

# Where is the line

Given a grid consisting of + and a constant $$\m\$$, change all the + to x, where the center of the + is above the graph $$\y=mx\$$.
Considering:

• The origin is the bottom-left corner of bottom-left +.
• One unit is the width=height of a plus
• The center of the bottom-left plus is located in $$\(0.5, 0.5)\$$

# Rules

• Input can be given as an iterable, string or a binary matrix.
• Instead of a grid, input can also be the $$\height\$$ and the $$\width\$$ of the matrix.
• Output must consist of + and x
• Standard Loopholes apply

# Example

[In]:
++
++
0

[Out]:
xx
xx

[In]:
++
++
1

[Out]:
xx
x+

[In]:
+++++
+++++
+++++
+++++
2

[Out]:
xx+++
xx+++
x++++
x++++
+++++


# Meta

Did I explain it good enough?

Posted here.

# The Futuristic Battle Royale

After a five-year hiatus, I am interested in extending The Futuristic Gun Duel to a battle royale format. If this is not a bad idea, I will propose some rules and then start coding using some JS framework that uses WebWorkers. The primary motivation is that this should significantly change the strategy.

# Iterate over pairs of nonnegative integers

Find and implement an iteration over the set of pairs of nonnegative integers ($$\\mathbb N_0^2\$$).

(0, 0) (0, 1) (0, 2) (0, 3) ...
(1, 0) (1, 1) (1, 2) (1, 3) ...
(2, 0) (2, 1) (2, 2) (2, 3) ...
(3, 0) (3, 1) (3, 2) (3, 3) ...
...


For example, diagonalization:

(0, 0), (0, 1), (1, 0), (0, 2), (1, 1), (2, 0), (0, 3), (1, 2), (2, 1), (3, 0), ...


You must specify which iteration your answer uses. You must specify if your answer is 0 or 1-indexed. Your code must be deterministic.

This is a challenge. You may...

• Take a positive integer $$\n\$$ and output the first $$\n\$$ values.
• Take a positive integer $$\n\$$ and output the value for $$\n\$$.
• Take no input and output values indefinitely.

This is a challenge, so the smallest code as measured in bytes wins. Standard loopholes apply.

# Loopless unending program

Your task is simple: Make a program in your language of choice that never exits. However, you are forbidden to use any looping constructs (for, while, etc). in your source. You may use any other instruction in your language to accomplish this goal.

This is , so shortest answer wins.

• Can you define what a "looping construct" is? Also, you might run into (this issue)[codegolf.meta.stackexchange.com/a/8067/107310] with langs that just don't loop the same way. Feb 8 at 17:34
• Related Feb 9 at 4:14
• I think "without looping" is not a well-defined requirement. You could instead require programs to block forever, which is observable at the OS level, although I think that then isn't very interesting challenge. Feb 9 at 7:21