557
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3992 Answers 3992

1
117 118
119
120 121
134
0
\$\begingroup\$

Generate Fmbalbuena Numbers

\$\endgroup\$
6
  • 1
    \$\begingroup\$ so both the second step and last step need to be true? \$\endgroup\$
    – Razetime
    Jan 6 at 11:35
  • \$\begingroup\$ @Razetime 2nd and last step need to be true. \$\endgroup\$
    – Fmbalbuena
    Jan 6 at 11:36
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ Jan 6 at 14:22
  • \$\begingroup\$ "equals the last digits" → "equals the last digits modulus 10" \$\endgroup\$
    – Adám
    Jan 7 at 0:01
  • \$\begingroup\$ 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. \$\endgroup\$
    – Adám
    Jan 7 at 0:02
  • \$\begingroup\$ 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? \$\endgroup\$
    – Adám
    Jan 7 at 0:04
0
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ 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? \$\endgroup\$ Jan 15 at 22:46
  • \$\begingroup\$ Yes it is. Could you clarify what you find confusing about the scoring system? \$\endgroup\$
    – user197974
    Jan 15 at 23:06
  • \$\begingroup\$ "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 \$\endgroup\$ Jan 15 at 23:10
  • \$\begingroup\$ You would have to split it into blocks anyway so that doesn't really seem easier? \$\endgroup\$
    – user197974
    Jan 15 at 23:17
0
\$\begingroup\$

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]
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Could you try to clarify a bit more? \$\endgroup\$
    – ophact
    Jan 19 at 13:46
0
\$\begingroup\$

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?
\$\endgroup\$
2
  • \$\begingroup\$ I like the idea but I think the explanation could include the definition of a "fail". \$\endgroup\$
    – Wezl oOvOo
    Jan 19 at 16:28
  • \$\begingroup\$ @Wezl-yizl Added \$\endgroup\$
    – Fmbalbuena
    Jan 19 at 16:31
0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$ Jan 20 at 1:49
  • \$\begingroup\$ Could you provide some test cases and define "storage" clearly? \$\endgroup\$
    – ophact
    Jan 21 at 10:45
0
\$\begingroup\$

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.

Your task

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))
\$\endgroup\$
5
  • \$\begingroup\$ 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)? \$\endgroup\$
    – pxeger
    Jan 24 at 17:55
  • \$\begingroup\$ @pxeger Good point. How should I go about fixing this? \$\endgroup\$
    – Ginger
    Jan 24 at 17:56
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – pxeger
    Jan 24 at 18:00
  • \$\begingroup\$ Also, your code is missing a parenthesis on line 4, and outputs \$ e / 2 \$, not \$ e \$. \$\endgroup\$
    – pxeger
    Jan 24 at 18:00
  • \$\begingroup\$ @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. \$\endgroup\$
    – Ginger
    Jan 24 at 18:02
0
\$\begingroup\$

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?

\$\endgroup\$
3
  • \$\begingroup\$ not sure what being infinite adds to the challenge since all that changes is that translations do nothing \$\endgroup\$ Jan 25 at 15:39
  • \$\begingroup\$ 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. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 25 at 15:41
  • \$\begingroup\$ @WheatWizard Yes, that's what I meant with "You can assume the output number will always be finite" \$\endgroup\$
    – AnttiP
    Jan 25 at 16:22
0
\$\begingroup\$

Alternate indexing

Task

(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]]
[[]] => [[]]
\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – pajonk
    Jan 26 at 8:24
  • \$\begingroup\$ are my edits ok now pajonk? i have changed it accordingly \$\endgroup\$
    – DialFrost
    Jan 26 at 10:44
0
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Rather than those specific strings, I would recommend letting people choose their own four distinct values \$\endgroup\$
    – user
    Jan 26 at 12:24
  • \$\begingroup\$ Also, I think there’s a tag for classification challenges \$\endgroup\$
    – user
    Jan 26 at 12:25
  • \$\begingroup\$ 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. \$\endgroup\$
    – ophact
    Jan 31 at 12:54
0
\$\begingroup\$

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")

the algorithm: https://plus.maths.org/content/maths-minute-dhondt-method another link: https://en.wikipedia.org/wiki/D%27Hondt_method#Procedure

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

\$\endgroup\$
5
  • \$\begingroup\$ 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>. \$\endgroup\$
    – Dingus
    Jan 31 at 11:13
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Dingus
    Jan 31 at 11:15
  • \$\begingroup\$ will sure keep this in mind, also, thanks for showing me the actual post about this. \$\endgroup\$ Jan 31 at 12:26
  • \$\begingroup\$ should I delete this \$\endgroup\$ Jan 31 at 12:26
  • 1
    \$\begingroup\$ I think so, yes. Unfortunately it's a duplicate of the earlier challenge. \$\endgroup\$
    – Dingus
    Jan 31 at 22:08
0
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Not much of a corpus left to learn from by example... \$\endgroup\$ Jan 31 at 6:25
0
\$\begingroup\$

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?

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

Solve Rubik's Clock

Posted here.

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

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.

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

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.

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

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.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ Feb 8 at 17:34
  • \$\begingroup\$ Related \$\endgroup\$
    – Aiden Chow
    Feb 9 at 4:14
  • \$\begingroup\$ 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. \$\endgroup\$
    – pxeger
    Feb 9 at 7:21
0
\$\begingroup\$

Return shortest integer-is-one-of function

This is a challenge, where you'll ...

Given a number of integers as input, your task is to write a function in JS, which returns a function that checks if an inputted integer is any of those. For example, f([1, 2, 4]) would return a function which would return true if given 1, 2, or 4, and false for any other inputs.

Task:

Your function will take any nonzero number of integers. There will not be any duplicates. This should return either a function, or a string containing the function's code.

The returned function should take a single integer as input. If the input is one of the integers inputted into the original function, it should return a truthy value, and a falsy one otherwise. You may also choose to return any two consistent values, or a consistent value for one possiblity (such as 0 for truthy) and any other value for the other.

Scoring:

This is metagolf, meaning the average of the byte counts of the returned programs for a certain set of inputs will be your score. This set of inputs will consist of:

  • All combinations one to four integers from -10 to 10
  • A random group of 2000 inputs consisting of between five and ten integers between -100 and 100
  • A random group of 1000 inputs consisting of between two and six integers between -10000 and 10000

Optimizing your solution for these specific test cases is disallowed.

Meta

  • I will generate a random list of test cases that will be used for scoring when I post this
  • This is my first time writing a metagolf challenge. Any improvements y'all can think of?
  • I think the number of bytes should be limited in the submitted function (not the generated ones). Suggestions?
  • Too many test cases? Too few?
\$\endgroup\$
7
  • \$\begingroup\$ The option to return a function is only available in JS, I'm assuming? I think you should disallow it, because it's unclear how you measure the size of a function object. \$\endgroup\$ May 21, 2021 at 14:22
  • \$\begingroup\$ Maybe you should include test cases with more than six integers? If not, is it allowed for a solution to be optimized for small sizes? (given that it's a a minority in the input space) \$\endgroup\$ May 21, 2021 at 14:23
  • \$\begingroup\$ @CommandMaster Oh, I meant to restrict this to JS anyway, wasn't sure if I was going to do that or not. It should be possible in any language with first class functions, though. If I open it up to any language I'll allow returning a string with a program. I'll add some test cases with more items. \$\endgroup\$ May 21, 2021 at 14:56
  • \$\begingroup\$ If you return a function, how do you count the byte count of it? \$\endgroup\$ May 21, 2021 at 15:14
  • \$\begingroup\$ .toString() (plus it's pretty likely they'll return a string form of the function anyway) \$\endgroup\$ May 21, 2021 at 15:28
  • 2
    \$\begingroup\$ .toString() doesn't work for that, for example in function f(i) { var l = a=>a+i return x=>l(x) } f().toString() is just x=>l(x), while that's clearly not the length of the code you want to count (it's also unclear what code you do want to count in such a case) \$\endgroup\$ May 21, 2021 at 15:39
  • 1
    \$\begingroup\$ @CommandMaster The functions will need to be independent from the meta function. As in, no closures/accessing variables in the above scope. \$\endgroup\$ May 21, 2021 at 15:55
0
\$\begingroup\$

Will the dominoes topple?

Your input contains a list of positive integers representing the height of a row of dominoes. As many of us know, when you have a row of dominoes and push the first one, the rest will topple in a chain reaction. But if the next domino is too big, it will not fall. This depends on the shape of the domino, so in addition to the list, your program will also receive a positive rational number \$r\$, so that domino \$n\$ will topple domino \$n+1\$ iff \$h_n\cdot r>h_{n+1}\$, where \$h_n\$ is the height of a domino.

Your task is to decide if all the dominoes topple or if the chain reaction stops before the end.

Your input is a non-empty list of positive integers (the height of the dominoes) and the rational number \$r\$.

You must use exact (integer) math, fp math is not allowed (though languages like Javascript and C can assume that the integer types are bigints).

Use standard output rules. This is , so shortest code per language wins.

Examples

[1,2,3], 5/2 -> True
[1,2,3], 3/2 -> False
[23,11,5,1], 1/2 -> True
[1,3,9,29], 10/3 -> True
[5,10,9,11], 2/1 -> False
[1,1], 1/1 -> False
[1], 1/1 -> True
\$\endgroup\$
0
\$\begingroup\$

Output up to n sets of n characters randomly

Given a positive integer n>1, output a random number of n-character strings, ranging from 1 to n strings.

Rules

  • Each string must differ from eachother by at least 1 char
  • Each string must be n chars long
  • Other than that, output strings do not have to be consistent in any way
  • However, our strings must be clearly delimited
  • A "random number" of strings means that each time the program is run with input n, non-deterministically, either 0, 1, 2, 3... up to n strings will be output
  • For smaller inputs, each possible number of strings should be displayed within a reasonable number of trials (to avoid cheesy solutions where one number gets chosen with probability ~1)

Examples

These are examples of valid outputs:

input => output
2 => af 4b
2 => 12 22
2 => ba
3 => WTF TL; VMB
3 => 0l3
3 => 04t <V<
3 => bop bAm
3 => AAA,AAB,AAC
3 => 
000
001
002
4 =>
w la
    
a,v 
 i  
3 => [tip, wor, kf3]

These would be invalid:

input => output
explanation of invalidity

2 => Ca Sa Da
too many strings output for this input

2 => asd sd mo
too many chars in a string for this input

3 => a Bad
too few chars in a string for this input

4 => 1234567890123456
strings are not clearly delimited

3 => 1   2   3   
strings are not clearly delimited

3 => A,B,BCD
strings are not clearly delimited

3 => CO CO LA
two or more strings are identical

Scoring

This is , so shortest code in bytes wins.

Meta

Is this too trivial? Also, can anything be phrased clearer (including the title)?

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

Weekday celebration with Doomsday

With the help of the Doomsday rule you can always calculate the day of the week for any date given. It includes any digit year.

Your code should determine which day of the week will be on the Valentine's Day of the given year.

The input is an integer representing the year, and the output is a number representing the day (1 - monday, 2 - tuesday, etc).

Test cases

2001 -> 3
1916 -> 1
41373 -> 7
312631 -> 1
71254065 -> 6
512836172 -> 5
-2735263 -> 3

This is code-golf, so shortest code wins.

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

Challenge: Create a program that plays the game of the goose

In this golfing challenge, write a program that simulates the game of the goose. If you don't know how it works, here's a rough explanation of it:

The game takes place on a grid of 63 cells: grid

Each turn, the first player rolls two dice and will *advance (number rolled) cells. Then the second player will roll two dice and do the same as player 1.

If a player lands on a goose, he will move again by the same number of cells.

If a player lands on the bridge, he will move to cell 12.

If a player lands in the tavern, he will skip 2 turns.

If a player's first rolls are 6 & 3, he will go to cell 26.

If a player lands in the well or the prison, he will wait until the other player lands in the same cell. Then the player goes to the other player's former cell.

If a player lands in the maze, he will go to cell 30.

If a player's first rolls are 4 & 5, he will go to cell 53.

If a player lands on death, he will go to the start.

Implementing it

Randomness

The dice rolls represent random numbers; the programming language you use needs to have a way to output (Any output method) and a way to generate random numbers.

Output

The program should output each iteration of the game; Each turn, it should output the player's position. Like this:

Turn 1: 16, 4

The first and second numbers represent each player respectively. When a player wins or after a certain maximum number of turns, the program will stop.

General Rules

  1. The player must be able to win.
  2. Making up your programming language is allowed, provided you made an interpreter available to the public for your programming language.
  3. Don't exploit standard loopholes.
  4. Make sure your code runs in at most 10 seconds.

Recommendations

  1. You should include a link to a website (for example https://tio.run) so that your code can be easily run.
  2. If you're using a compiled language, say which compiler you're using.

It's code golf, so the shortest code wins!

\$\endgroup\$
3
  • \$\begingroup\$ I have no idea why the grid didn't work. I tried to fix it in this edit. \$\endgroup\$
    – kevidryon2
    Feb 11 at 19:27
  • 1
    \$\begingroup\$ I'm too lazy to recreate the grid so here is an image of the grid. \$\endgroup\$
    – kevidryon2
    Feb 11 at 19:43
  • 3
    \$\begingroup\$ You should specify what kind of input/output the answers should have. For example, should the programs output the positions of the players every round until one player wins? \$\endgroup\$
    – AnttiP
    Feb 12 at 18:11
0
\$\begingroup\$

Mountain mapper

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

Uncountably long chain of subsets

A chain of subsets (a chain from now on) is a sequence of sets, so that every set is a (strict) superset of every preceding set. For example, here is a chain of length 3:

\$\{1,2\}\subset\{1,2,4,5\}\subset\{1,2,3,4,5\}\$

Chains can also be infinitely long. Here is a countably infinite chain:

\$\{2\}\subset\{2,4\}\subset\{2,4,8\}\subset\{2,4,8,16\}\subset\ldots\subset\{2,4,8,16,32,...\}\$

Your task is to make an uncountably infinite chain, consisting of sets of positive numbers.

Your gut reaction might be that this is impossible. But it's not. For example, consider the real numbers. We can define them as Dedekind cuts (meaning every real number is defined as the set of rational numbers that are smaller than it). Next we can associate every rational number with a positive integer. Now, under the standard ordering of the real numbers, we have a chain of subsets of the positive integers that is uncountably long.

Now that you've picked your favorite uncountably long chain of subsets of the positive integers, it's time to make a program that encodes it.

Your program will recieve two natural numbers. Your program will simply tell whether the first natural number appears before or at the same time as the second one in the chain. Or in other words: for inputs \$a\$ and \$b\$ return true iff \$b\in S\Rightarrow a\in S\$ for all sets \$S\$ in the chain. Your chain must contain every positive integer (however, this doesn't mean that it must contain the set of positive integers).

Bonus points if you achieve a cardinality different from \$2^{\aleph_0}\$

Edit:

Probably not gonna post this challenge as is, because of a rather trivial solution (lexicographic ordering)

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

Grid Aligned (Quad?) Linked List

Fluff

I was recently thinking about 2-dimensional linked lists, and realized that they could potentially become unaligned to a grid, unlike a singly linked list. To combat that, I need a program that checks if a quad-list is grid aligned or not, and it needs to be done as short as possible.

Challenge

Given a quad linked-list, return true or false (or any other 2 consistent values) whether or not the 2d list is grid aligned.

Input

Since linked lists can be implemented a variety of different ways in different languages, I'll keep the input format fairly simple. An input consists of tuples (or 4-lists, you can decide) which contain indices that refer to the input. Each tuple contains the indices of the node above, below, left, and right in that order. For nodes where not all directions are connected, the value will be -1.

Note: "above", "below", "left", "right" should be connected in that direction, but may not necessarily do so.

Examples

[(-1, 1, -1, -1), (0, -1, -1, -1)] -> true

0
|
1

[(-1, 1, -1, 3), (0, -1, -1, 2), (-1, -1, -1, -1), (-1, 2, 0, -1)] -> true

0---3
|   v
1 > 2

[(-1, 1, -1, 2), (0, -1, -1, 2), (0, -1, 1, -1)] -> false

0
| \
1--2

[(-1, 1, -1, -1), (-1, 2, -1, -1), (-1, -1, -1, 3), (4, -1, -1, -1), (-1, -1, 0, -1)] -> false

0 < 4
v   ^
1   |
v   |
2 > 3

[(0, -1, -1, -1)] -> false

0
^
0

This is , so the shortest code wins, good luck.

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

Determine if a number is base n heavy

Given a positive integer \$n\$ and a base number \$b\$, determine if the number is heavy in that base. A number is heavy if when converted to base \$b\$, has at least \$ \lfloor \log_{10}(n) \rfloor \$ \$b-1\$s on one end. (The left or right.)

Examples

When we convert 100 to base 2 (binary), we get

1100100

\$\log_{10}(100) = 2\$, and there are at least 2 ones (the max number in the base) on one end (the left side).

Scoring

Shortest code in bytes wins!

Test cases

Coming soon.


Feedback?

\$\endgroup\$
2
  • \$\begingroup\$ What do you mean by \$\lfloor \log_{10}(n) \rfloor b - 1 \$? Is this base \$n\$ or base \$b\$? \$\endgroup\$
    – tsh
    Feb 18 at 2:18
  • 1
    \$\begingroup\$ The base 10 logarithm feels a bit arbitrary. This also means that there are no heavy numbers if \$b>9\$ \$\endgroup\$
    – AnttiP
    Feb 18 at 9:10
0
\$\begingroup\$

Posted here

\$\endgroup\$
4
  • \$\begingroup\$ Question: is Python a valid language for this challenge? \$\endgroup\$ Feb 15 at 11:52
  • \$\begingroup\$ At first I wasn't going to allow other languages, but I think I can whip up a command line interface ;) \$\endgroup\$
    – Seggan
    Feb 15 at 15:46
  • \$\begingroup\$ @StackMeterPlus added a protocol \$\endgroup\$
    – Seggan
    Feb 15 at 20:59
  • \$\begingroup\$ you can clear this post now, by adding the link of the question here and deleting everything else \$\endgroup\$
    – DialFrost
    Feb 20 at 1:32
0
\$\begingroup\$

Ragged index of

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

Draw a battery indicator

Posted here

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

Implement Scordle

Background

TODO: Explain what Wordle and Scordle are

Challenge

Your task is to implement a modified version of Scordle with lists of numbers.

The input contains the following:

  • The possible numbers 1 to n that can be contained in a guess (think of this like there are 26 letters that can be used in regular Wordle)
  • The number sequence that represents the correct answer (assume that the answer contains only numbers between 1 and n)
  • Optional: the length l (at least 1) of the correct answer
  • The list (length 1 to 6) of the guesses (unlike Wordle, the list doesn't have to end in the correct answer, even if the length of the list is less than 6). Assume all guesses are valid.

Output a list of numbers that represent the number of possible number sequences that conform to all the clues at and before that point.

Example

Let's say that the answer is [3,2,1] and the possible numbers are from 1 to n=3. Before any guesses, there are \$3^3=27\$ possible number sequences that can potentially be the answer:

[1, 1, 1]
[1, 1, 2]
[1, 1, 3]
[1, 2, 1]
[1, 2, 2]
[1, 2, 3]
[1, 3, 1]
[1, 3, 2]
[1, 3, 3]
[2, 1, 1]
[2, 1, 2]
[2, 1, 3]
[2, 2, 1]
[2, 2, 2]
[2, 2, 3]
[2, 3, 1]
[2, 3, 2]
[2, 3, 3]
[3, 1, 1]
[3, 1, 2]
[3, 1, 3]
[3, 2, 1]
[3, 2, 2]
[3, 2, 3]
[3, 3, 1]
[3, 3, 2]
[3, 3, 3]

Let's say that the list of guesses is:

[[2,1,3],[2,2,2],[3,3,3],[3,2,1]]

After the first guess [2,1,3], all of them are yellow. Based on these clues, the remaining possible sequences are listed below:

[1, 3, 2]
[3, 2, 1]

Because there are 2 possibilities remaining, the first element in the output list will be 2.

In the second guess [2,2,2], the middle 2 will be green while the other two 2's are black. This eliminates [1,3,2] and leaves the only possibility [3,2,1]. So the second element in the output list will be a 1.

Any subsequent guesses will not affect the number of possibilities, so for the rest of the guesses, put 1 in the output list.

Scoring

This is , so the shortest code in byte count wins!

Test Cases (TODO)

answer, n, list of guesses, l
--> list of possibilities
--------------------------------
[3,2,1], 3, [[1,2,3],[2,2,2],[3,3,3],[3,2,1]], 3
--> [2,1,1,1]

Meta

  • Suggestions for tags?
  • I haven't put in the Background yet, but for people who already know what Wordle and Scordle are, is the task clear?
  • Suggested test cases?
  • Should I make it so that the guesses always have to end in the correct answer?
\$\endgroup\$
4
  • \$\begingroup\$ I think your list of guesses needs [2,1,3] in the first place. \$\endgroup\$
    – pajonk
    Feb 25 at 19:37
  • \$\begingroup\$ @pajonk "(unlike Wordle, the list doesn't have to end in the correct answer, even if the length of the list is less than 6)". Should I make it so that it has to end in the correct answer? \$\endgroup\$
    – Aiden Chow
    Feb 26 at 5:07
  • \$\begingroup\$ After the fix the part "After the first guess [1,2,3], all of them are yellow" is not true (2 is green). Re: ending in correct answer - I don't have a strong opinion either way. \$\endgroup\$
    – pajonk
    Feb 26 at 6:35
  • \$\begingroup\$ @pajonk oops I meant to keep [2,1,3] as the first guess, not [1,2,3]. As for ending in the correct answer, I think I'll just keep it as is, because if it always end in the correct answer, the last element of the output list will always be 1, but if it doesn't always end in the correct answer, the last element is not always 1, which is more interesting (I think?) . \$\endgroup\$
    – Aiden Chow
    Feb 26 at 7:09
1
117 118
119
120 121
134

You must log in to answer this question.

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