561
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4333 Answers 4333

1
42 43
44
45 46
145
2
\$\begingroup\$

Output a random value from the last 16 values outputted

Output the numbers 1-16 (or any other set of 16 distinct items). Then, repeatedly, output a random value chosen uniformly from the last 16 items outputted.

After the same item is printed 16 times in a row or more, halt.

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

Roll a painted cube

\$\endgroup\$
2
  • \$\begingroup\$ May we map the directions to values 1-4 (or 0-3)? May we map the colors to values 1-6 (or 0-5)? \$\endgroup\$
    – pajonk
    Dec 12, 2022 at 5:24
  • \$\begingroup\$ Yes, that would be fine also \$\endgroup\$
    – mousetail
    Dec 12, 2022 at 6:20
2
\$\begingroup\$

Avoid the hole

xkcd

Given a continuous black-box function as a input, output a different continuous, differentiable function that never enters the box \$ 1.5 \leq x \leq 2 \wedge 1 \leq y \leq 1.5 \$. Your output must exactly match the input function when \$ x \leq 0 \vee 3 \leq x \$.

The output must be continuous. You may assume the input function is continous, and defined over all \$ \mathbb{R} \$. The function you output must also be defined over all \$ \mathbb{R} \$. Both functions must also be differentiable, meaning their derivative is defined everywhere.

You may optionally take the derivative of the input function as a second input.

You may assume your languages float type has infinite precision and all operations on it are exact.

\$\endgroup\$
9
  • \$\begingroup\$ An issue you are going to run into is that it's basically impossible (mathematically impossible not just really hard) to anything non-trivial with arbitrary real numbers. For example it is very easily undecidable whether the input even passes through the box. This is because an arbitrary real number takes up an infinite amount of memory, so any program that deals with them has to be able to treat them like streams of digits. \$\endgroup\$
    – Wheat Wizard Mod
    Feb 8 at 20:47
  • \$\begingroup\$ Yes, so for the width of the box the output of the original function would need to be entirely ignored, as like you say you don't know about any weired outlier that could happen in that area. In the space around the edges of the box, where this doesn't really matter, you would need to create some kind of interpolation function. \$\endgroup\$
    – mousetail
    Feb 8 at 20:49
  • \$\begingroup\$ There is actually a really simple solution of just creating 2 cubic beziers around the edges of each box \$\endgroup\$
    – mousetail
    Feb 8 at 20:50
  • \$\begingroup\$ I'm not sure if that "simple" solution is actually possible, for two reasons 1) Doing even basic math with arbitrary reals tends to be undecidable (addition is undecidable for example) 2) determining the derivative of a black box function is like super impossible, even with some pretty hefty assumptions. \$\endgroup\$
    – Wheat Wizard Mod
    Feb 8 at 20:54
  • 1
    \$\begingroup\$ I agree. This might be do-able if you limit it from a black-box function to a Polynomial with known values instead, although that may make it trivial \$\endgroup\$
    – ATaco
    Feb 8 at 21:00
  • \$\begingroup\$ @WheatWizard that's why you can take the derivative as a second input \$\endgroup\$
    – mousetail
    Feb 9 at 5:16
  • \$\begingroup\$ Also your solution just needs to theoretically work, ignoring numerical limits like always \$\endgroup\$
    – mousetail
    Feb 9 at 5:20
  • 1
    \$\begingroup\$ Hole on your picture displaces with your word \$\endgroup\$
    – l4m2
    Feb 10 at 8:28
  • \$\begingroup\$ @l4m2 sorry what do you mean? \$\endgroup\$
    – mousetail
    Feb 10 at 8:29
2
\$\begingroup\$

Time to shortest transposition

\$\endgroup\$
7
  • \$\begingroup\$ Is the answer 13:14? \$\endgroup\$
    – Seggan
    Feb 9 at 16:18
  • 1
    \$\begingroup\$ Why 14:21 not 413? \$\endgroup\$
    – l4m2
    Feb 9 at 17:36
  • \$\begingroup\$ Once you fix that, suggested test case: 23:41 -> Nil \$\endgroup\$
    – The Thonnu
    Feb 9 at 18:51
  • 1
    \$\begingroup\$ 413 is not a valid 24-hour string. Note that when you shift around the numbers, you must pick the time string that comes after the input and is a valid 24-hour string \$\endgroup\$ Feb 10 at 2:31
  • \$\begingroup\$ In this case, the transpositions are 12:41, 11:24, 11:42, and 14:12. Since all of these come before 14:21 , they cannot be picked. \$\endgroup\$ Feb 10 at 2:32
  • \$\begingroup\$ So the time must be in the same day? \$\endgroup\$
    – mousetail
    Feb 10 at 8:21
  • \$\begingroup\$ Technically, yes. \$\endgroup\$ Feb 10 at 8:31
2
\$\begingroup\$

Generate an emoticon

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

Ptolemy's table of chords

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

Print all pandigital numbers

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

Split some points

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

Primes with Distinct Prime Digits

\$\endgroup\$
7
  • \$\begingroup\$ This challenge seems a bit boring, also please use the default sequence rules \$\endgroup\$
    – noodle man
    Feb 12 at 0:55
  • \$\begingroup\$ @Jacob I thought I did follow the default sequence rules. Also, could you clarify what exactly makes the challenge boring? \$\endgroup\$
    – Bob th
    Feb 13 at 2:34
  • \$\begingroup\$ The default sequence rules state that the submission may either output the nth term, the first n terms, or the entire sequence. I changed my mind about the challenge being boring, there are likely a few interesting ways to solve this \$\endgroup\$
    – noodle man
    Feb 13 at 2:46
  • 1
    \$\begingroup\$ @Jacob Oh, I see, I misread the sequence page; it says the answers may use "one of the following", not "any of the following", so I got confused. Thanks for pointing that out \$\endgroup\$
    – Bob th
    Feb 13 at 2:50
  • \$\begingroup\$ Is infinite loop allowed if choosing to output whole sequence, like other sequence? \$\endgroup\$
    – l4m2
    Feb 14 at 4:57
  • \$\begingroup\$ @l4m2 it's not an infinite sequence, though. Could you elaborate on what would be printed in an infinite loop? \$\endgroup\$
    – Bob th
    Feb 14 at 19:25
  • \$\begingroup\$ Print nothing lol \$\endgroup\$
    – l4m2
    Feb 15 at 0:25
2
\$\begingroup\$

Generate a permutation from the high-water marks

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

Convert imperative code to functional

The imperative language

We'll consider 2 very simple languages, first a imperative one. The imperative language is a list of statements. Statements can be one of these 4 expressions:

[literal] // a literal
[variable] // a variable
([expression] # [expression]) // Some arbitrary operator
([expression] $ [expression]) // Some different arbitrary operator

Or one of these 3 statements:

[variable] = [expression] // assignment
while [expression] { [statement]* } // looping
if [expression] { [statement] } // condition

The last line is guaranteed to be a expression and it's value is the output of the entire program.

Note: Syntax isn't important here. You can take input as any arbitrary tree like structure. There is also no fixed format for variables, you can use any arbitrary infinite series to represent variables, and the same for literals. As long as all 6 values are distinct, you are good to go.

For example, take this code:

a=(5 # 2)
a=(a $ 7)
8 # a

This program would output 8. You could represent this like this:

[
    {op:'=', left:0, right:{op:'#',left:5,right:2},
    {op:'=', left:0, right:{op:'$',left:{op:'var',var:0},right:7},
    {op:'#',left:8,right:{op:'var',var:0}}
]

Or even more concisely [[4,0,[2,[0,5],[0,2]]],[4,0,[3,[1,0],[0,7]]],[2,[0,8],[1,0]]]. Where the first number represents the index of the expression type and the rest the arguments.

The operators are guarenteed to be saf

The functional language

The functional language has the following builtins:

[literal]         // a literal
[variable]        // a variable
(# [expr] [expr]) // one arbitrary operation, you don't need to worry about what it does
($ [expr] [expr]) // another arbitrary operation
(? [expr] [expr] [expr]) // if expression is truthy, return the first expression, otherwise the second
(lambda [variable]* [expr]) // define a function
([expr] [expr]*) // call a function with the given arguments

Again, you can use any built in tree-like structure to represent this, and use any data type with a potentially infinite number of items to represent variables and literals.

Your task

Your task is to convert some code in the imperative language to the functional equivalent. For example:

a=12
b=15
if b # a {
   b = b $ 12
}
c=(a # 12) $ (a # 18)
while a $ (a # b) {
    a = a # (c $ b)
}
a

Could be converted to:

(
   (lambda a:
       (lambda b:
           (lambda b:
                (lambda c:
                    (lambda y:
                        (
                            y,
                            lambda q: (
                                  lambda a: (
                                       lambda a: a,
                                       (? ($ a ($ a b)) (q (# a ($ c b)))) a)
                                  )
                            ), a)
                        )
                    ),
                    lambda a: (a a)
                ),
                ($ (# a 12) (# b 18))
           ),
           ((? (# b a) ($ b 12) b)
       ),
       15
   )),
   12
)

This is code golf, shortest code wins. Size of the output is irrelevant, specifically you can just repeat the y combinator every loop.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Could you explain in the challenge how to convert imperative to functional? In addition, a worked out simple example would be helpful. \$\endgroup\$
    – pajonk
    Mar 10 at 7:43
2
\$\begingroup\$

All languages have their strengths, right? (Cops' thread)

This is the cops' thread of a challenge. The robbers' thread can be found [here] (sandbox note: will add the link when posting)

The main idea of this challenge is whether there are languages which are always better than some other ones for .

As a cop, you will choose two languages, and claim that one of them (let's call it A) will always be better for code golf than the other (let's call it B). You post starts as uncracked.

Robbers have two avenues to crack your post:

  • If they think your claim is wrong, they can crack it by giving a code golf task and a solution to it in B.
  • If they think your claim is right, they can crack it by proving it.

If your post was cracked by a counterexample, you can counter the crack by giving a solution in A which is shorter than the given solution in B. This invalidates their crack, and makes your post uncracked once again. Robbers can now attempt to crack it again.

If your post was cracked by a proof you can't counter it (assuming the proof is correct).

Scoring

Each cop gains 1 point for every uncracked post, and loses 1 point for every cracked post. The goal is to get as many points as possible.

Rules

  • Both languages must be freely available.
  • Your claim must not be implied by transitivity from existing uncracked posts.
  • The robbers' tasks must disallow all standard loopholes, and allow all standard I/O methods.
  • The robbers' tasks must only have textual I/O.

All languages have their strengths, right? (Robbers' thread)

This is the robbers' thread of a challenge. The cops' thread can be found [here] (sandbox note: will add the link when posting)

The main idea of this challenge is whether there are languages which are always better than some other ones for .

As a robber, you have two ways to crack a claim:

  • If you think the claim is wrong, you can crack it by giving a code golf task and a solution to it in the language the claim states is worse.
    • This crack can be countered by the cop finding a shorter solution in the language they claim is better.
  • If you think the claim is right, you can crack it by proving it.
    • This crack can't be countered as long as the proof is correct.

Scoring

Each robber gains 1 point for every uncountered robbers post, and loses 1 point for every countered robbers post. The goal is to get as many points as possible.

Rules

Sandbox Questions

Does this format, where a cop claims something, a robber tries to refute/prove it, and the cop tries to defend it, seem interesting? Is it on-topic? What tags are appropriate? I haven't seen it before.

How should I disallow some types of builtins? I want to avoid the challenge turning to "find a builtin the other language doesn't have". In particular, if eval is allowed then the challenge of "Evaluate this language" will almost always be a universal robbers solution. However, I'm not sure how those builtins can be classified.

How should I prevent "output this specific error string" as a universal robbers solution?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I feel this might be too easy when considering languages that are very verbose but also have a very limited set of builtin like shakesphere. I'd suggest cops would need to have a challenge in mind that would crack it, to ensure it's actually possible, then reveal it after some time \$\endgroup\$
    – mousetail
    Mar 6 at 11:44
  • 1
    \$\begingroup\$ @mousetail I thought about that, but for a hard challenge the solution for the problem in the two languages will be close in length, so it's quite possible the cop will miss some optimization which turns their proposed counterexample false. Additionally, this changes the challenge from finding pairs of languages with one strictly better to finding pairs of languages with very similar code-golf performances, which while an interesting challenge isn't what I want. I'd prefer to prevent trivial submissions in some other way, for example by allowing a proof of the cop's claim as a crack. \$\endgroup\$ Mar 6 at 11:59
2
\$\begingroup\$

Generate a Random Integer

Your task is to create a program or function that outputs an integer from \$-\infty\$ to \$+\infty\$ non-deterministically (the output will not always be the same result). Each integer should have a nonzero chance of being outputted.

Rules

  • Please explain what your code does to confirm that it can produce any integer.
  • For the purpose of this challenge, you may ignore your language's number limits for storing an arbitrarily large/small number.
  • Output should be in decimal form.
  • This is , so the shortest answer in bytes wins.
\$\endgroup\$
3
  • \$\begingroup\$ How does "you may ignore number limits" interact with a builtin to produce a random value in the range [INT_MIN, INT_MAX]? \$\endgroup\$
    – Bbrk24
    Mar 10 at 23:32
  • \$\begingroup\$ @Bbrk24 What I mean is that you would be able to store an arbitrarily large number into a variable or other data structure. \$\endgroup\$
    – Yousername
    Mar 10 at 23:43
  • 2
    \$\begingroup\$ related, but with stricter probability requirements \$\endgroup\$
    – lyxal
    Mar 10 at 23:50
2
\$\begingroup\$

Idea:

Given a polyomino shape figure out the minimum number of cuts required to fill it with a herring-bone pattern of 2×1 tiles.

Gylda is a contractor who installs decks. She receives the deck plan from an architect who always chooses it to be shaped as a polyomino, that is a single connected piece cut from a square grid. The deck surface is manufactured in 2×1 rectangular tiles. Gylda installs the tiles in a herringbone pattern because it looks nice, and is stable. However not all shapes can be made perfectly with a herringbone pattern, sometimes Gylda is forced to cut a tile in half. Sometimes Gylda is forced to cut a lot of tiles in half. However how many cuts are needed, depends on exactly where the pattern is placed relative to the boundaries of the deck.

Now Gylda wants to minimize the number of cuts she has to make so she wants a computer program which will take a deck shape and will tell her the minimum number of cuts required. This is the number of cuts, not the number of half pieces used in the final construction. Each cut produces two 1×1 pieces which can both be used.

There is one catch. If a herringbone pattern would produce a layout where two half pieces are adjacent by an edge, Gylda will instead place a single 2×1 tile, even though it breaks the herringbone pattern. For example in the following layout:

 ====||
 ||====
 ||||==

There are two half pieces in the bottom right so instead we would lay out a single whole piece:

====||
||====
||====

This means the 3×3 square polyomino only requires 1 cut, not 2.

Gylda wants the program to take this special rule into account.

Task

Take a polyomino as input in any reasonable format. Output the minimum number of cuts Gylda needs to install that deck.

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

\$\endgroup\$
2
  • \$\begingroup\$ It would be helpful if you could define a herringbone pattern, and highlight the tiles in the example. \$\endgroup\$ Mar 18 at 7:53
  • \$\begingroup\$ @CommandMaster Yeah, this challenge is unfinished right now, so it's missing a deal of the specification. \$\endgroup\$
    – Wheat Wizard Mod
    Mar 18 at 15:42
2
\$\begingroup\$

Implement the <=> three-way comparison operator on numbers

Tags:

\$\endgroup\$
4
  • \$\begingroup\$ How do the bonuses stack? Is the final score (100-n)% of the program length, or 0.99^n? \$\endgroup\$
    – Bbrk24
    Mar 17 at 15:13
  • 1
    \$\begingroup\$ @Bbrk24 just edited the bonuses bit; if your solution is n bytes, and your solution supports k numeric types, your score is (100-(k-1)%) * n. \$\endgroup\$
    – bigyihsuan
    Mar 17 at 15:26
  • \$\begingroup\$ The bonus disadvantages languages with less number types, and seems non-observable. Additionally, in many languages you would have a solution which works for any comparable type, which can be user-defined. How would you define number types in that case? Regardless, bonuses are usually recommended against. \$\endgroup\$ Mar 18 at 8:06
  • 4
    \$\begingroup\$ Axed the bonuses. \$\endgroup\$
    – bigyihsuan
    Mar 18 at 15:05
2
\$\begingroup\$

Isolate the binary signals

There are n binary signals, with intervals of 1 through n. For example, for n=3 the lists could be [1], [0, 1], [1, 0, 1]. Each list represents a repeating pattern. So [0,1] is really [0, 1, 0, 1, 0, 1, ...]

The signals all start at the same time, but they are sent over the same channel. So you only know the sum of all the signals at a given time.

Given a list of length at least LCM(1..n) representing the sum of the values at each item of each signal.

If there are multiple possible options, you may output any of them.

Test Cases

List n Expected Result
[1, 3, 1, 2, 2, 2] 3 [1], [0,1], [1,0,1]
[2, 3, 3, 3, 1, 4, 3, 2, 2, 4, 2, 3] 4 [[1], [0, 1], [1, 0, 1], [0, 1, 1, 0]]
\$\endgroup\$
1
  • \$\begingroup\$ Is n part of the input? Or can you output any valid n as long as LCM(1..n) isn't greater than the input length? \$\endgroup\$ Mar 23 at 8:32
2
\$\begingroup\$

Draw the GKMS aperiodic tile

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

Play Rock Paper Scissors 25

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

Make a Custom Bayer Matrix

\$\endgroup\$
6
  • \$\begingroup\$ I think this part "successive numbers are as distant from each other as possible" needs more precise definition, as it's the main part of the challenge, as I get it. Also, as the input will be only 2,4,8 or 16, there is possibility that some approaches will just hardcode the outputs (no judgment, maybe it's intended). \$\endgroup\$
    – pajonk
    Feb 8 at 17:16
  • \$\begingroup\$ @pajonk I will try to make that part more clear. Yes, there is the option of hardcoding the output, but I would expect that in most programming languages that would not be the shortest possible answer. \$\endgroup\$
    – Yousername
    Feb 8 at 22:45
  • \$\begingroup\$ Is [0 3;2 1] valid? \$\endgroup\$
    – l4m2
    Feb 10 at 9:14
  • \$\begingroup\$ @l4m2 As long as your output format stays consitent with orher inputs, yes. \$\endgroup\$
    – Yousername
    Feb 10 at 14:07
  • \$\begingroup\$ It's not format, it's order when tie distance \$\endgroup\$
    – l4m2
    Feb 10 at 20:48
  • \$\begingroup\$ @l4m2 Yes, that is allowed (the third rule). \$\endgroup\$
    – Yousername
    Feb 10 at 21:10
2
\$\begingroup\$

Selection and Prediction

Your challenge: to select the strings A and B and predict others' selections in an -style .

All entries should be Python 3.10ish META: version? also possibly JS if I have time ._..

Part 1: Selection

You are tasked with selecting the strings A and B as randomly as possible. You are given the previous selections you have made and the guesses your 'opponent' has made. Each input is a string of A and B. For example, 'ABBAB' and 'ABABA' may be arguments passed to your program.

Your program should output either of A or B deterministically, meaning the same input should result in the same output. This means no calling random.choice() or similar, or using the date and time as seeds for a random number generator. META: maybe I should choose the first letter for them, since this constraint results in them always starting with the same letter You may also output a tuple (letter_str, state) and the state will be passed in as a keyword argument next round.

An example entry (this will compete):

Selector: AAAAAA, 3 bytes

Not much to say. This program loves the letter A

def aaaaaa(selections, guesses):
    return "A"

Part 2: Prediction

Your task is to predict the most likely move that your opponent will make. Same input, output and constraints as above.

Another example entry: (this will compete too)

Predictor: Anti-repeater, 3 bytes

Assumes you tend to repeat your previous selection.

def anti_repeater(selections, guesses):
    # It's fine to modify the lists
    return selections.pop()

Part 3: Scoring

Each Selector submission will go against each Predictor submission for a total of 110 rounds. They will select and predict for the first round, then select and predict again, and again, until all rounds have finished.

For each round correctly predicted (excluding the first 10 rounds, since they may be hard to predict) the Predictor submission wins 1 point. For each round incorrectly predicted (also excluding the first 10 rounds) the Selector submission wins 1 point.

The winners are the submissions with the most total points from all Selector and Predictor submissions. Since there are two winners no answer will be accepted.

If you type hint you get 0 extra points. my respect!

(Part 4: meta)

EDIT: added scoring

What do you call a where every cop goes against every robber and vice versa?

EDIT: Change 'key' to 'string' and fix up typo

EDIT: Some other stuff added

\$\endgroup\$
7
  • \$\begingroup\$ How will submissions be scored? \$\endgroup\$
    – mousetail
    Dec 18, 2022 at 12:06
  • \$\begingroup\$ It's a KOTH - they go against each other \$\endgroup\$
    – W D
    Dec 18, 2022 at 19:56
  • \$\begingroup\$ Who wins the KOTH though? \$\endgroup\$
    – mousetail
    Dec 18, 2022 at 20:26
  • \$\begingroup\$ forgot that >_< Added now \$\endgroup\$
    – W D
    Dec 19, 2022 at 20:33
  • \$\begingroup\$ Isn't it supposed to be random.choice()? \$\endgroup\$ Dec 20, 2022 at 12:57
  • \$\begingroup\$ Thanks @UndoneStudios don't know how I missed that \$\endgroup\$
    – W D
    Dec 20, 2022 at 23:00
  • \$\begingroup\$ Maybe you can allow seeded random.choice() as it still deterministic . \$\endgroup\$
    – tsh
    Jan 4 at 3:30
2
\$\begingroup\$

Posted

\$\endgroup\$
2
  • \$\begingroup\$ It's not exactly clear to me which doors are opened by which guards. I see the example of "i, 2, i..." but that doesn't form a clear pattern to me and I'm not sure why i is listed twice. \$\endgroup\$
    – Bbrk24
    Apr 1 at 15:16
  • \$\begingroup\$ @Bbrk24 Yes, make it more clear! \$\endgroup\$
    – lesobrod
    Apr 1 at 16:53
2
\$\begingroup\$

Enumeration of free polyominoes

Posted here

\$\endgroup\$
4
  • 2
    \$\begingroup\$ What makes a polyomino "free"? \$\endgroup\$
    – Bbrk24
    Mar 17 at 18:47
  • 3
    \$\begingroup\$ What is a "rigid transformation"? Is it an isometry, an orientation preserving isometry, a translation, something else ...? \$\endgroup\$
    – Wheat Wizard Mod
    Mar 17 at 23:16
  • 1
    \$\begingroup\$ @Wheat Wizard hope it's more clear now \$\endgroup\$
    – math scat
    Mar 18 at 7:55
  • \$\begingroup\$ I suggest listing drawings/ascii art of the polyominoes for the first few n. \$\endgroup\$
    – pajonk
    Mar 19 at 9:23
2
\$\begingroup\$

Shortest Path Around Obstacle

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

The number of solutions to Hertzsprung's Problem

Tags:

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

Find the Geometric Mean of a set of Numbers

Introduction

There isn't a geometric mean challenge here yet so I decided to post one.

Challenge

Calculate the geometric mean of a set of numbers without using a built in function for it because that's boring.

  • See here for input and output methods.
  • Input should be some sort of set of numbers (either as a list/array passed to a function or a list/array built by the program from user inputs).
  • You do not need to cope with negative numbers.

The winner will be determined by the shortest (functional) code length in bytes, in the case of 2 answers having the same number of bytes then the winner will be determined by score.

Example Input and Output

Input Output
[2,2,2] 2.00 or 2
[1,2,3] 1.82
[0,5,4,7] 0.00 or 0
[8,5,4,7] 0.79
[1.7,2,0.3] 1.00 or 1
[3,8] 4.9 or 4.90
[12,21] 15.87
[0.5] 0.5, or 0.50
[3,9,2,5,7] 4.52

Ungolfed Desmos example program:

f\left(l\right)=\sqrt[\operatorname{length}\left(l\right)]{\prod_{i=1}^{\operatorname{length}\left(l\right)}l\left[i\right]}
\$\endgroup\$
5
  • 2
    \$\begingroup\$ Consider defining what the geometric mean is for anyone unfamiliar \$\endgroup\$
    – emirps
    May 2 at 20:12
  • 5
    \$\begingroup\$ Banning Builtins is hard to enforce, I'd recommend allowing them, but encouraging non-builtin solutions to be included aswell. \$\endgroup\$
    – ATaco
    May 3 at 1:25
  • \$\begingroup\$ I mean like, you'ren't allowed to just go def f(x): return geomean(x) \$\endgroup\$ May 3 at 13:38
  • \$\begingroup\$ @emirps I'm not the OP but: To take the geometric mean of \$n\$ numbers, you multiply them all together, then raise this to the \$\frac1n\$th power, or take the \$n\$th root. \$\endgroup\$ May 4 at 16:40
  • 3
    \$\begingroup\$ Related, related. In addition to saying again that banning something as vague as a "built in function" is a bad idea, breaking ties by (vote?) score doesn't sound like it is a great idea. Ties are usually broken by earlier posting, but honestly determining the "winner" is not too important - the rules about scoring exist to be able to say if a score is better than another. Adding this score rule will add a weird ambiguity to what makes a submission good. \$\endgroup\$ May 5 at 16:03
2
\$\begingroup\$

Sort int64 with float64 values

Your challenge is to create the following total ordering of int64 and float64 values:

  • Apart from -0.0 which sorts before 0.0, two values of the same type sort according to which one is less than the other.
  • Where two values of different types are exactly equal, the float64 sorts before the int64 if negative or after if positive. Note that -0.0 counts as a negative float64 and 0.0 counts as a positive float64, and the int64 0 compares between the two.
  • int64 values that fall between the representations of two float64 values must sort between those two values. Similarly, float64 values that have fractional parts must sort between the nearest two integer values, although the previous rule allows you to simply truncate the float64 value towards zero to compare it to an int64 value.

Here are some int64 and float64 values in the correct order:

-9223372036854775808.0
-9223372036854775808
-9223372036854775807
-9223372036854774786
-9223372036854774785
-9223372036854774784.0
-9223372036854774784
-9223372036854774783
-9007199254740994.0
-9007199254740994
-9007199254740993
-9007199254740992.0
-9007199254740992
-4503599627370496.0
-4503599627370496
-4503599627370495.5
-4503599627370495.0
-4503599627370495
-4503599627370494.5
-1.5
-1.0
-1
-0.5
-0.0
0
0.0
0.5
1
1.0
1.5
4503599627370494.5
4503599627370495
4503599627370495.0
4503599627370495.5
4503599627370496
4503599627370496.0
9007199254740992
9007199254740992.0
9007199254740993
9007199254740994
9007199254740994.0
9223372036854774783
9223372036854774784
9223372036854774784.0
9223372036854774785
9223372036854774786
9223372036854775807
9223372036854775808.0

Your code can either implement a sort function for a list of elements or it can be a comparator for use with your language's built-in sort function or some other suitable way of indicating the sort ordering.

You can earn brownie points for supporting nonfinite float64 values and arbitrary precision integers.

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

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

Spell date in Japanese

Objective

Given a date, spell it out in Romanized Japanese.

I/O Format

The input format is MM/DD. The output format is <month spelling> <day spelling>; note the space. Otherwise flexible. You can freely mix cases in output.

Mapping

Months

Month Spelling
January Ichigatsu
February Nigatsu
March Sangatsu
April Shigatsu or Yongatsu
May Gogatsu
June Rokugatsu
July Shichigatsu or Nanagatsu
August Hachigatsu
September Kugatsu or Kyuugatsu
October Juugatsu
November Juuichigatsu
December Juunigatsu

Days

Irregular ones are marked *.

Day Spelling
1st Tsuitachi*
2nd Futsuka*
3rd Mikka*
4th Yokka*
5th Itsuka*
6th Muika*
7th Nanoka*
8th Youka*
9th Kokonoka*
10th Tooka*
11th Juuichinichi
12th Juuninichi
13th Juusannichi
14th Juuyokka*
15th Juugonichi
16th Juurokunichi
17th Juunananichi
18th Juuhachinichi
19th Juukyuunichi
20th Hatsuka*
21st Nijuuichinichi
22nd Nijuuninichi
23rd Nijuusannichi
24th Nijuuyokka*
25th Nijuugonichi
26th Nijuurokunichi
27th Nijuunananichi
28th Nijuuhachinichi
29th Nijuukyuunichi
30th Sanjuunichi
31st Sanjuuichinichi

Examples

  • 05/05Gogatsu Itsuka
  • 09/29Kugatsu Nijuukyuunichi or Kyuugatsu Nijuukyuunichi
  • 10/09Juugatsu Kokonoka
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Might want to double-check the ordinals, I see “31th” \$\endgroup\$
    – Bbrk24
    May 7 at 5:20
2
\$\begingroup\$

Complex remainder

Complex remainder can be defined in a similar way to real remainder as \$ y - x \lfloor \frac y x \rfloor \$. However this depends on a suitable complex floor function. There are a number of ways of defining a complex floor function (for at least one of which there has been a previous challenge), but for this challenge I will relax the requirements to the following:

  • Every complex number has exactly one floor which is a Gaussian integer.
  • \$ \lfloor z \rfloor = \lfloor \Re ( z ) \rfloor \$ if \$ \Im (z) = 0 \$.
  • \$ \lfloor z + n \rfloor = \lfloor z \rfloor + n \$ where \$ n \$ is a Gaussian integer.

Note that this implies that \$ \lfloor n \rfloor = n \$ for every Gaussian integer \$ n \$.

Please write a program or function that will perform complex remainder using a compatible definition.

Even if your language supports complex numbers you can choose to input them as separate real and imaginary parts. You can also choose to support only Gaussian integers as inputs and outputs.

If your language has suitable builtins for remainder or floor then you can earn extra brownie points by providing an additional solution that doesn't use them.

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

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Maybe some test cases? \$\endgroup\$
    – Adám
    May 8 at 13:27
  • \$\begingroup\$ How about negative numbers? There are, rather famously, multiple ways to give a sign to a remainder involving negative numbers. \$\endgroup\$
    – Adám
    May 8 at 13:28
  • \$\begingroup\$ @Adám I didn't want to provide test cases as they would assume a certain complex floor function. Also, the use of floor makes the result consistent for negative numbers (i.e. it's like Pascal's mod rather than rem). \$\endgroup\$
    – Neil
    May 8 at 14:06
  • \$\begingroup\$ How do we demonstrate correctness of a submission? \$\endgroup\$
    – Adám
    May 9 at 6:36
  • \$\begingroup\$ @Adám Probably showing that (y-y%x)/x is a Gaussian integer and (y+x)%x and (y+ix)%x both equal y%x for multple random test cases would be enough. \$\endgroup\$
    – Neil
    May 9 at 7:44
  • 1
    \$\begingroup\$ You should probably explicitly say a Gaussian integer is a complex number whose real and imaginary parts are integers to avoid an inevitable comment about it. Similarly, adding your response to Adám's question will probably save you some time. \$\endgroup\$ May 9 at 21:34
  • \$\begingroup\$ Will there ever be some different floor functions \$f_1\$ and \$f_2\$ both satisfy the requirement but have at least one \$x\in\mathbb{C}\$ that \$f_1(x)\ne f_2(x)\$? What if we change the second requirement into simply \$\lfloor 0\rfloor = 0\$? \$\endgroup\$
    – tsh
    May 11 at 5:49
  • \$\begingroup\$ @tsh Yes it's quite easy to have different satisfactory floor functions. I do want real modulus to continue to work as expected though. \$\endgroup\$
    – Neil
    May 11 at 7:00
2
\$\begingroup\$

Create an equation for a convex polygon

It turns out that it's possible to create an equation for any convex polygon. Here is a simple example:

$$ \sqrt { 1 - x } \sqrt { 1 - y } \sqrt { x + y } = 0 $$

I don't know how to create a link to a graph, but I was able to use the graphing calculator at https://www.mathway.com/Graph to draw this equation by pasting the text \sqrt { 1 - x } \sqrt { 1 - y } \sqrt { x + y } = 0 into its equation box. As you can see the result is a simple triangle, but it's possible to extend this idea to any convex polygon.

Please write a program or function that will take a list of points representing the vertices of a convex polygon and output an equation for that polygon in an acceptable format, typically TeX, but other formats would be acceptable if you can find a resource that will draw the polygon.

You can make reasonable assumptions regarding the input e.g. you can require the first point to be the one with the highest y-coordinate and the remaining points to follow the polygon in a clockwise direction.

Examples:

(-1, 1), (1, 1), (1, -1) => \sqrt { 1 - x } \sqrt { 1 - y } \sqrt { x + y } = 0
(0,1),(1,0),(0,-1),(-1,0) => \sqrt{1+x+y}\sqrt{1+x-y}\sqrt{1-x-y}\sqrt{1-x+y}=0

(I tried to write some more complex examples but even Mathway's calculator gave up at that point.)

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

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

Complexity of a binary matrix

This is a \$4\times 4\$ binary matrix:

$$ \begin{matrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 0 & 1 \\ 0 & 0 & 0 & 1 \\ \end{matrix} $$

A row-add operation takes one row and adds it to another one where addition is done mod 2. For example adding the second row to the third would give the following matrix:

$$ \begin{matrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{matrix} $$

It's possible to add a row to itself. This is the same as zeroing that row.

Task

Given a \$n\times n\$ binary matrix your task is to figure out how many row-addition steps it would take to get to that matrix starting from the identity matrix. I call this the "complexity" of the matrix.

For example if we were given the following matrix as input

$$ \begin{matrix} 0 & 1 & 1 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix} $$

Then your program would output \$5\$ since there's no shorter sequence than the following:

$$ \begin{matrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{matrix} $$ $$ 1\leftarrow 2 $$ $$ \begin{matrix} 1 & 1 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{matrix} $$ $$ 2\leftarrow 1 $$ $$ \begin{matrix} 1 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{matrix} $$ $$ 1\leftarrow 2 $$ $$ \begin{matrix} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{matrix} $$ $$ 1\leftarrow 3 $$ $$ \begin{matrix} 0 & 1 & 1 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{matrix} $$ $$ 3\leftarrow 3 $$ $$ \begin{matrix} 0 & 1 & 1 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \\ \end{matrix} $$

It's is always possible to get to any matrix from the identity matrix (proof left as an exercise to the reader)

Scoring

This is . I'll be running submissions on a Ryzen 1800X limited to 16GB of RAM (using ulimit).

Your code will take as input an infinite stream of matrices over stdin. A matrix is encoded as its size followed by the rows of the matrix. The input starts with 10 matrices of size 3 followed by 10 of size 4 and so on.

You must output (in order) to stdin the complexities of the matrices.

See this code for an example input. I'll use this code to generate the input (but using a secret seed).

I will run each submission for 5 minutes. The submission that manages to process the most matrices will win. Ties will be resolved by the time it took to output the last matrix.

TODO: add test inputs.

Bonus points

In case two submissions are tied to the nanosecond I might use these as a tiebreaker :D

Find a block diagonal matrix whose complexity is less than the sum of the complexities of the blocks on the diagonal.

Is there a block matrix whose complexity is less than one of the blocks on the diagonal?

\$\endgroup\$
2
  • \$\begingroup\$ So row addition is just XOR? \$\endgroup\$
    – mousetail
    2 days ago
  • \$\begingroup\$ @mousetail yep! \$\endgroup\$
    – AnttiP
    2 days ago
1
42 43
44
45 46
145

You must log in to answer this question.

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