571
\$\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\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$
    – mousetail
    Commented May 29 at 13:27

4706 Answers 4706

1
136 137
138
139 140
157
0
\$\begingroup\$

An Optimally Suboptimal Solution

You have grown disillusioned by finding optimal policies for heavy-tailed distributions and their "skew you" attitudes. You decide that for this challenge you are putting your foot down and refusing to optimize your policy further if it means having unbalanced errors. In fact, you're so focused on balance that you will only consider median errors - it's the principle of the thing.

The Challenge

Generate a policy that searches for hidden points on a line segment, \$L\$, where \$L\$ is the interval \$[0, 1]\$. The number of hidden points on \$L\$ is randomly chosen from the set \$\{0, 10\}\$. The position of each point, \$p\$, (if there are any) is drawn randomly from the uniform distribution on \$\{0, 1\}\$. The points are indistinguishable.

The problem is episodic. In each episode you search the line according to your policy. At each step in the episode you may continue to search the line, or you may reset.

To search the line

  1. Choose \$x \in[0, 0.9]\$
  2. Accrue a cost of \$2^x\$
  3. Discover all points where \$0 \leq p \leq x\$

To reset

  1. Generate a new line segment
  2. Draw a new number of hidden points to place on the line segment
  3. If there are any hidden points, place them on the line segment

An episode ends when your policy has discovered 10 hidden points on the interval \$[0, 0.9]\$.

Note: Your policy may not use information about the number of hidden points, nor their locations. When resetting, you do not keep any points you have previously found, but you do keep all costs accrued.

This setup is adapted from @graffe's Cunning Cousin Witch problem.

Scoring

Define a false negative to be when a policy chooses to reset a line segment and there were 10 hidden points on the interval \$[0, 0.9]\$, i.e. it was possible to complete the episode but the policy resets instead.

Define a false positive to be when a policy searches the entire interval \$[0, 0.9]\$, and there were fewer than 10 hidden points on the interval \$[0, 0.9]\$, i.e. it was not possible to complete the episode but the policy searches the entire available line segment.

Your policy's score is the median absolute difference between the number of false negatives and false positives your policy incurs over one million episodes. The score should be minimized.

$$\text{Score} = median(\lvert FN - FP \rvert)$$

Where \$FN\$ and \$FP\$ are vectors of length one million, and the nth element of each vector is the number of false negatives / positives the policy made in episode n.

If two policies have the same score, the one with the lower median cost from searching lines will rank higher.


Meta

I'm hoping to encourage some custom optimization methods with this one by asking for solutions that are not optimal with respect to the cost function, and by making the objective multi-criteria (because the tie-breaking cost of searching is a function of FN and FP). I think that the way points are discovered prevents optimizing with the cost = x from being equivalent to solving this one, but I haven't exhaustively tested it.

I'd especially appreciate feedback on whether this is an interesting / productive variation on the original version, and whether or not the optimization task is equivalent to a trivial formulation.

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

Implement the Hamming algorithm

Hamming error correction is a form of linear error-correction code which can detect and repair small errors in its input. Your job is to implement a program that, given an input of a sequence of bytes, encodes them using Hamming error correction and outputs the results.

The algorithm

Taken from Wikipedia, with some slight modifications

  1. Number all of the bits, starting from 1
  2. Write these numbers in binary
  3. Every bit position that is a power of 2 (has only one 1 bit in its binary position) is a parity bit, with the remaining bits being data bits.
  4. Set every parity bit with the values of every data bit where the bitwise AND of the parity bit's position and the data bit's position is nonzero

You may choose any parity (even or odd) but must state it in your answer.

Examples

These will use hexadecimal to represent the data.

0x1234 -> 0x2a3a1
0x4321 -> 0x8b28e
0xbadf00d -> 0x2f5be8064
\$\endgroup\$
1
0
\$\begingroup\$

Cut along the lines

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

Which weekday was it?

\$\endgroup\$
5
  • \$\begingroup\$ what span of years do we have to account for \$\endgroup\$ Commented Oct 3, 2022 at 13:40
  • \$\begingroup\$ only between 2000 to 2022. if you want it widened, i can do so \$\endgroup\$ Commented Oct 3, 2022 at 13:40
  • \$\begingroup\$ I think I'll leave out the suggested algorithm as people will use their own ideas for sure. However, I'll add a sentence discouraging built-ins - sth like "if you're using a built-in, consider adding a non-buit-in approach as well". Regarding the year span, i think a narrow one is a good idea, as we avoid problems with changing calendars etc. \$\endgroup\$
    – pajonk
    Commented Oct 5, 2022 at 6:45
  • \$\begingroup\$ Since you posted the question, the convention is to remove the content here and replace it with a link to the code golf post. \$\endgroup\$ Commented Oct 5, 2022 at 14:30
  • \$\begingroup\$ Oh right, forgot that \$\endgroup\$ Commented Oct 5, 2022 at 14:42
0
\$\begingroup\$

Minimum rotation to get the maximum value

\$\endgroup\$
2
  • \$\begingroup\$ Can you take the input as a list a b d c (or a c d b)? \$\endgroup\$ Commented Oct 20, 2022 at 16:53
  • \$\begingroup\$ @CommandMaster Yes. \$\endgroup\$
    – oeuf
    Commented Oct 21, 2022 at 1:07
0
\$\begingroup\$

Show a balanced binary tree

\$\endgroup\$
3
  • \$\begingroup\$ this is ascii-art tag. also, can we output via graphical-output instead? \$\endgroup\$
    – naffetS
    Commented Oct 3, 2022 at 19:07
  • 1
    \$\begingroup\$ @Steffan I think that would be a meaningfully different challenge, so no. \$\endgroup\$ Commented Oct 3, 2022 at 19:08
  • \$\begingroup\$ Suggested tag: open-ended-function \$\endgroup\$
    – DLosc
    Commented Oct 10, 2022 at 21:11
0
\$\begingroup\$

Speed Checkers KOTH


For this King of the Hill challenge, your bot will play checkers against an opponent. However, you should be careful when making complex calculations, because both sides have a limited amount of time to play! Each side will start with 1,000,000 cycles [or 1 second, depending on what I use for the API] to spend during their turn, and if this runs out they will lose the game.



This is my attempt at making a KOTH challenge where your runtime matters.

Before I do the rest of the write-up, is the concept good? Is the amount of time given right? Should I use a simpler game? Should the API be in an assembly language, or in a Java runner?

\$\endgroup\$
2
  • \$\begingroup\$ I'm not certain but I thought checkers (draughts) was solved. It might not fit well in an answer, but once could just hardcode every possibility and play perfectly instantly. I think you need to pick a slightly more complicated game to make this work. \$\endgroup\$ Commented Oct 27, 2022 at 17:57
  • \$\begingroup\$ Yes, it's solved, but you're not going to fit the entire move table in an SE answer. Solving it took I think years of calculation, so that's also off the table. \$\endgroup\$
    – RamenChef
    Commented Oct 27, 2022 at 19:03
0
\$\begingroup\$

Subleq image decoder

^^ edited 2022.11.03.

\$\endgroup\$
6
  • 4
    \$\begingroup\$ Welcome to Codegolf, and thanks for using the Sandbox! As it is, this isn't a great way to present your challenge. There is no way for the reader to know what they should be optimising for without downloading your archive and reading through the source code. There are a few other points of confusion: does the submission have to work for any image or just the reference, what incentive is there to compress the image if the score is code-golf, and are we supposed to submit a compression and a decompression program? \$\endgroup\$ Commented Oct 31, 2022 at 19:42
  • \$\begingroup\$ @FryAmTheEggman thank you for your feedback. 1. Task is exactly as I presented it: make smallest image.slif file, which is approved by test program. Nothing more. 2. I know that style of my challenge is unusual, it is made intentionally: it is part of the task to understand how to make such file. Test program is only 104 lines, I think it will be easy to undertand what it is doing. Even if reader do not know C#. 3. As I said, reference.bin should not be changed, original image is part of test program in other words. \$\endgroup\$
    – Vort
    Commented Oct 31, 2022 at 19:54
  • \$\begingroup\$ @FryAmTheEggman I modified text to make it more clear what is needed to be done. \$\endgroup\$
    – Vort
    Commented Nov 1, 2022 at 5:38
  • \$\begingroup\$ @FryAmTheEggman regarding tags: should I change code-golf to code-challenge? I still think that my challenge is more related to code-golf category, but at the same time I do not want to upset people who like competition between languages (which my challenge do not allows). \$\endgroup\$
    – Vort
    Commented Nov 1, 2022 at 10:58
  • 3
    \$\begingroup\$ Based on what you've said, you should make this code-challenge and highlight the scoring more explicitly. I still think this would be much better received if you explained what constituted a successful compression. Just because you've done it intentionally doesn't mean it improves the challenge. \$\endgroup\$ Commented Nov 1, 2022 at 13:16
  • \$\begingroup\$ @sʨɠɠan, @ fryamtheeggman, @ lyxal, @ mousetail, @ xnor, @ kevin-cruijssen, @ arnauld, I removed part of the challenge because of your requirements. Are "details or clarity" problems resolved now? \$\endgroup\$
    – Vort
    Commented Nov 3, 2022 at 6:46
0
\$\begingroup\$

A Number Sequence with Everything

Work in Progress

Watch Numberphile's video featuring Neil Sloane to learn more.

...

This is sequence A342585 in the OEIS.

If you like the oddly self-referential nature of this sequence, check out Van Eck's/Look and Say sequence (insert CGCC and Numberphile links here.)

This is one of those unconventional self-referential sequences. If you're intrigued, check out Van Eck's/Look and Say sequence (insert CGCC and Numberphile links here.)

$$ \begin{align} & 0_0\\ & 1_0 \quad 1_1 \quad 0_2\\ & 2_0 \quad 1_1 \quad 2_2 \quad 0_3 \\ & 3_0 \quad 2_1 \quad 4_2 \quad 1_3 \quad 1_4 \quad 0_5 \\ \end{align} $$


$$ 0_0 \;\cdot \;1_0 \quad 1_1 \quad 0_2 \;\cdot\; 2_0 \quad 1_1 \quad 2_2 \quad 0_3 \;\cdot\;3_0 \quad 2_1 \quad 4_2 \quad 1_3 \quad 1_4 \quad 0_5 $$


$$ 0^0 \;\cdot \;0^1 \quad 1^1 \quad 2^0 \;\cdot\; 0^2 \quad 1^1 \quad 2^2 \quad 3^0 \;\cdot\;0^3 \quad 1^2 \quad 2^4 \quad 3^1 \quad 4^1 \quad 5^0 $$

Rules

\$\endgroup\$
2
  • \$\begingroup\$ In the OEIS community, the name "inventory sequence" has been introduced for this sequence. This should also be stated in the description. The A-number of the sequence should be given as a link. The name is inappropriate in my opinion. "with everything" is more appropriate for a pizza order, and in the now more than 350,000 OEIS sequences there are many more candidates that could be considered for such an attribute depending on the viewer's taste. \$\endgroup\$ Commented Nov 13, 2022 at 9:31
  • \$\begingroup\$ You're absolutely right. It is called the inventory sequence, and not only within OEIS. That was the other name I was considering for the question. The "with everything" name comes verbatim from the Numberphile video. I agree that it's dramatic and clickbaity, and I'm open to changing it. I think this name is appropriate too, though, since it's meant to attract the people who watch that Numberphile video and come looking for the sequence. I think there's a sizable overlap as whenever there's a new sequence video on Numberphile, we have a corresponding CGCC challenge posted within 24 hours. \$\endgroup\$
    – AviFS
    Commented Nov 16, 2022 at 8:43
0
\$\begingroup\$

Lengthy numbers type C : remove one occurrece at time

A non negative integer number is a lengthy number type C if it can be erased by repeatedly removing only one occurrence of the length of the number from it.

  • Erasing means cancel all the digits.

For simplicity and allowing different approaches we restrict the input to a number up to 11 digits length or in other words in the range [0..98765432111]

  • Numbers less than 13 digits are guaranteed to have only one possible outcome while from 13 digits they require branches during the process because there can be overlaps.
    For example a 13 digits number 1139138765421 require to test both 13's in it because removing one instead of the other will give different results.

  • Numbers less than 12 digits are permutations of all the lengths in each step ( if they are lengthy C ) while from 12 digits there can be embedded lengths, for example 112087654321 has 12 inside 10.

Examples

123  -> remove 3
12   -> remove 2
1    -> remove 1 -> erased

133  -> remove 3
13   -> no 2 -> not a lengthy C

302  -> remove 3
02   -> remove 2
0    -> not a lengthy C

Test cases

Truthy

1, 12, 21, 123, 132, 213, 231, 312, 321, 1234, 4321, 42513, 635241, 3476251, 743986215, 3657211084, 11123456789, 11987654321

Falsy

0, 2, 3, 10, 11, 13, 20, 103, 133, 300, 301, 302, 303, 310, 322, 399, 1233, 1240, 3419, 4000, 632644, 1111111, 80000001, 1010101010, 10987654321, 1008765432, 11108765432, 11098765432, 11111111111

This is , standard rules apply.

  • Input can be given by any convenient method.

  • Output any two different values telling if the number is a lengthy number type C or not.

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

LS, Part 1: Ana Gram

Warning: Wouldn't you rather answer a challenge about ponies?1


If you have read The Hostile Hospital, you would know that the Baudelaire orphans, from one of the scraps of paper recovered from the Quagmire's notebooks, they discover a name, "Ana Gram". Later on, they realize that means the word "anagram", not a name. And that information helps them in finding out who Count Olaf disguised Violet Baudelaire as (Laura V. Bleediotie). They have to search through the entire hospital list, but trace the correct person down. However, what if they lived in a time where YOU helped them? Not personally, but with a program?

So your task today is simple. Given a string a and an array, return a smaller array that contains all the possible anagrams of a.

Rules:

  • This is , so shortest answer wins
  • Make sure to lowercase everything in the array and the string
  • Two strings that are the same are not anagrams
  • Make sure to watch out for initials! You should also remove them
  • There may be multiple possible anagrams. Output them all

Test cases:

String, Array 
-> Array

"Violet", ["Veilo","Efh", "Telvio","veliot"]
-> ["Telvio","veliot"]

"Krotasmon", ["Krota","Monsakrot", "Trokasmont","KROTASMON"]
-> ["Monsakrot"]

"Laura V. Bleediotie", ["Violet Baudelaire", "Violet. Baudelaire", "VIOLeT BAUDELAIRE", "BUADELIAR VIOLETM", "Laura V. Bleediotie"]
-> ["Violet Baudelaire", "Violet. Baudelaire", "VIOLeT BAUDELAIRE"]

META:

Does the array part still qualify this as a dupe?

1: Inspired by the "all rights reserved" page of LS: The Unauthorized Autobiography

\$\endgroup\$
1
  • \$\begingroup\$ There are a few other anagram challenges, but most of them seem to be just comparing two strings: 1, 2. Your rule about two strings being the same not being an anagram is pretty surprising. You should probably have a test case that includes that behaviour, or remove the rule. \$\endgroup\$ Commented Nov 17, 2022 at 17:16
0
\$\begingroup\$

Implement Casio's M

Posted

\$\endgroup\$
3
  • \$\begingroup\$ You should probably have a test case where double-digit (or more) numbers are used and require proper parsing. For your case, only reading the 0 in each number will still give the correct answer. \$\endgroup\$ Commented Nov 17, 2022 at 15:42
  • \$\begingroup\$ Additionally, I realised you don't have a case using M- properly, or an output that is negative. Also, what happens if the input is something like 9M+9MM+? Or 9M+MMM+? \$\endgroup\$ Commented Nov 17, 2022 at 15:50
  • 1
    \$\begingroup\$ @FryAmTheEggman Thanks! I have updated the test cases and the specifications. As for those two test cases, I have tested them on my dinosaur Casio machine and while 9M+9MM+ is valid, but 9M+MMM+ is not because of MM, so I have changed specs to let both of them be valid. \$\endgroup\$
    – oeuf
    Commented Nov 18, 2022 at 0:44
0
\$\begingroup\$

Intermediate Boolean Algebra Calculator

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

Minimum Overlapping Points in Continuous Line Drawing

A contour drawing is a type of drawing that is made of only one continuous line, meaning that the drawing utensil cannot leave the paper until the drawing is done. For the purposes of this challenge, we will only be using horizontal and vertical lines for the drawing utensil's movement from start to finish.

Your task is, given an 8x8 image representing a continuous line drawing, output the minimum number of overlapping points needed to draw the image continuously.

For example, for this image:

The minimum number of overlapping points needed is 2 because it can be drawn like this, with the red points marking overlapping points:

There is no way to draw it without overlapping points twice or more.

Rules

  • You can take the input in any convenient format, including as a matrix, list, image file, or ASCII art. You will need to specify what this expected input format is in your answer.
  • Output can be in any convenient format.
  • For every "step" of the drawing, the drawing utensil can only go left, right, up, or down for the purposes of this challenge.
  • Points that are overlapped on more than once are counted as extra overlapped points. (Thus the first test case outputs 3, not 2 for overlapping on the center twice)
  • You may assume that the input is valid and can be drawn with a continuous line.
  • Standard loopholes are forbidden.
  • This is , so the shortest code in bytes wins.

Test Cases

Input Output

........
..@.....
..@.....
..@.....
@@@@@@@.
..@.....
........
........
3

........
...@....
...@....
..@@@@@@
...@....
...@....
...@....
........
3

@@@@@@@@
@......@
@......@
@......@
@......@
@......@
@......@
@@@@@@@@
0

@@@@@@@@
@......@
@......@
@......@
@@@@@@@@
@......@
@......@
@@@@@@@@
0

@@@@....
@..@....
@..@....
@@@@@@@@
...@...@
...@...@
...@...@
...@@@@@
0

..@@@@@@
..@....@
@@@@@@.@
@.@..@.@
@.@@@@@@
@....@..
@....@..
@@@@@@..
1

........
.@@@@@..
.@.@.@..
.@@@@@..
.@.@.@..
.@@@@@..
........
........
4

@@@@@@@@
@.@@@@.@
@.@@@@.@
@@@@@@@@
@@.@@.@@
@@....@@
@@@@@@@@
@@@@@@@@
0

........
..@.@...
.@@@@@..
..@.@...
.@@@@@..
..@.@...
........
........
7

Meta

  • Are there any similar questions to this?
  • What would be some good tags to add?
  • Should I make the task to only find whether the input is possible without any overlapping?
  • Should there be an animation as explanation for the minimum overlapping points for each test case?
\$\endgroup\$
0
\$\begingroup\$

Getting over it with the space Cabbage, Wolf, Goat

Posted!

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Why are you using smart quotes instead of normal ones? That will make the examples very hard to copy paste \$\endgroup\$
    – mousetail
    Commented Nov 19, 2022 at 8:24
  • \$\begingroup\$ @mousetail. I’m sorry, but what are smart quotes? \$\endgroup\$ Commented Nov 19, 2022 at 19:16
  • 2
    \$\begingroup\$ The fancy quotes instead of the normal straight ones. You can see the left and right ones are different. Most programing languages have difficulty parsing text that contains special quotes. \$\endgroup\$
    – mousetail
    Commented Nov 19, 2022 at 19:17
  • \$\begingroup\$ @mousetail Oh, I see. My iPad just does that, will fix \$\endgroup\$ Commented Nov 19, 2022 at 23:39
0
\$\begingroup\$

1 to N column and row sums

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

Lengthy numbers type B : remove some occurrences of length

Given a non negative integer number tell if it can be erased by repeatedly removing some non overlapping occurrences of the length of that number from it.

  • Like lengthy numbers type A erasing means remove all digits.
    For example the number 4440 is not lengthy B because after removing three 4's you obtain 0 which cannot be erased.
    Neither the numbers 50022 and 50044 are lengthy B because you first remove 5 obtaining 0022 and 0044, which cannot be erased because of leading 0's.

Example with selection of some matches

151151599995515 has 15 digits and 4 15's in it  
xx115xx99995515 if you remove 1st and 3rd 15's  
11599995515 : remove 11  
599995515 : remove 9's
55515 : remove 5's
1 and finally remove 1

You can choose to remove almost all combinations of 2 15's but if you remove the 2nd and 3rd 15's you get stuck.
151151599995515
15199995515 -> 11 is no more available!

If you remove a number of 15's different than 2 you get stuck too.

Example with overlapping

44441111111 -> falsy because you can remove only 3 11's and not all 1's like you could if removing overlapping matches were allowed.

44411111111 -> falsy because if you remove all 11's you get 444.
If instead you remove 3 11's you get 44411 which is falsy too.

Test cases

Truthy

1, 12, 21, 22, 123, 321, 322, 331, 333, 4441, 4444, 12345, 987654321, 3610106226, 1010101010, 11111111111, 11131111311, 151151599995515, 10812816208148888188, 82428208832101683082414123828341883888, 1515515551555515555515555551555555155555155551555155151, 999199999915999991599999999915999915999999919399999999991915999999999999999999999915999999929999999, 10121111011011011011011011011011011012110110110121101110110121111011123101101101101121011011110110111, 15101251011012229752519101110101010101010111111101101101101101111011011011011110111101101101101101915, 2020220202202022020220202232020220202202022020223220232020222220220222202202202202202202202202202202202220223202202202202202202202202222022022022022022022222202202202202202222022022022022022023876543213

Falsy

0, 2, 9, 10, 11, 23, 100, 233, 444, 1224, 4440, 50022, 50044, 1101010101, 4444111110, 44441111111, 44411111111, 121666626162, 181811818128181818, 127271272722672224724122727122712242722472727272722472727272247272127272, 3919555395539111955255533922519455392511539551925395511,   
 1001023010023100160010010010010061110250100123001001001230061001010100102370100610016001001001110230, 1241242212412241241241241241241241241241241241141624124114241241241242612412412416241222412411424221241244124142412412144124, 108484298442981044294284942984429844294291042942942942849429429484284948429484842942942984104842984429429844298448429429429429429429429428494294294842942942948429428484942942942942984429429844284948429428494842849484284942942942942942984484294294284942942942942942942942942942910429429484294294

This is , standard rules apply.

  • Input can be given in any convenient method.

  • Output any two different values telling if the number is lengthy B or not.

\$\endgroup\$
3
  • \$\begingroup\$ Not a comment on the challenge itself, but could you use a full-size header (the same formatting as you have for the test cases header) for the challenge title moving forward? It makes Sandbox easier to browse and doesn't give the OSP bot trouble with automatic parsing. \$\endgroup\$ Commented Nov 27, 2022 at 1:49
  • 1
    \$\begingroup\$ @Unrelated String how it works now? \$\endgroup\$
    – AZTECCO
    Commented Nov 27, 2022 at 11:18
  • \$\begingroup\$ Yep, that's perfect! \$\endgroup\$ Commented Nov 27, 2022 at 21:35
0
\$\begingroup\$

Cistertian Numerals

Cistercian numerals are a method of representing any integer from 1 to 9,999 in a single "glyph".

Input

Any Integer, 1..9999

Output

An image or binary array (any standard accepted format) of the glyph representing the Input, in the form shown on the Wiki article - e.g. image

Examples

If using an array, it seems to me that all combinations should fit into a 6hx5w grid - e.g:

9999:

xxxxx
x x x
xxxxx
xxxxx
x x x
xxxxx

5555:

xxxxx
 xxx
  x
  x
 xxx
xxxxx

7643:

  x
 xxx
x x x
  x
x x x
xxx x
\$\endgroup\$
2
0
\$\begingroup\$

Four Candles

There is a tradition in Germany to have an Adventskranz in the run up to Christmas. This is basically four candles. One is lit each Sunday during advent (including the ones from the last Sundays) up until Christmas. This gave me an idea for an ASCII art challenge (we haven't had many of those recently).

The challenge: Reproduce the burning of the candles exactly as shown below.

  ||     ||     ||     ||   
 ____   ____   ____   ____
|    | |    | |    | |    |
|    | |    | |    | |    |
|    | |    | |    | |    |
|____| |___ | |____| |____|

         ||     ||     ||   
  ()    ____   ____   ____
 ____  |    | |    | |    |
|    | |    | |    | |    |
|    | |    | |    | |    |
|____| |___ | |____| |____|

                ||     ||   
         ()    ____   ____
  ()    ____  |    | |    |
 ____  |    | |    | |    |
|    | |    | |    | |    |
|____| |___ | |____| |____|

                       ||   
                ()    ____
         ()    ____  |    |
  ()    ____  |    | |    |
 ____  |    | |    | |    |
|____| |___ | |____| |____|

                       ()
                ()    ____
         ()    ____  |    |
  ()    ____  |    | |    |
______ |___ | |____| |____|

The rules: Very simple really...no input required, any amout of trailing newlines or spaces alowed as long as the output looks exactly as above. Please feel free to show each stage as a different frame and clear the screen between each but this is not a requirement. Simply printing (or retuning from a function) what is shown above is fine. Oh and also, this is ASCII art...printing or returning a list of lines is not good enough.

This is code golf. The shortest answer in any language will earn respect and I'm sure some upvotes. There will be no accepted answer so feel free to join in. The more languages the better no matter how long the answer is, as long as it is a best effort to make it as short as possible (golfed).

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

Make the cheapest cut

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I suggest allowing also outputting all cuts if there are ties, not just any; or guaranteeing unique solution (this is my personal preference, but I understand other views on that matter). Re 2.: Yes, some test-cases would be nice. \$\endgroup\$
    – pajonk
    Commented Dec 1, 2022 at 13:45
  • \$\begingroup\$ @pajonk Good feedback, thanks. \$\endgroup\$
    – Jordan
    Commented Dec 1, 2022 at 15:31
0
\$\begingroup\$

Find the box by its corners

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

Denoise a image

There are various de-noising algorithms available. This question focuses on a specific one that preserves sharp edges but is also very simple to implement.

Take 2 parameters, r and k, and a grayscale image.

For every pixel, draw a r by r square around it and select all pixels inside.

 r=1   r=3     r=5
              #####
       ###    #####
  p    #p#    ##p##
       ###    #####
              #####

Find the k pixels in this area that are closest to the source pixel in terms of absolute color difference.

Replace each pixel with the median of the k closest pixels in it's area. Include the pixel itself in it's area. If there are less than k closest pixels take all of them. This can happen for pixels near the edge.

Note: If r==0 or k==1 this will return the image unchanged

r is always odd.

Test Cases

In    K    R    Out
-------------------
000             000
010   1    1    010
000             000
-------------------
000             000
010    3    3   000
000             000
-------------------
000             000
010    3    3   010
100             100
-------------------
000             000    000
010    5    3   010 OR 010 since the median is tied
101             000    101
-------------------
12345           
23451
34512  5    5
45123
51234
-------------------

IO

Take input as either a image file or as a 2 dimensional array of integers between 0 and 255. Output in the same format.

\$\endgroup\$
1
  • \$\begingroup\$ The input requirements are not clear to me - what do you mean by a "greyscale image"? An image file? A matrix of floats from [0-1]? An integer matrix (as suggested by test-cases)? \$\endgroup\$
    – pajonk
    Commented Dec 5, 2022 at 12:50
0
\$\begingroup\$

Is It a Flat 3D Quadrilateral?

Your task is to write a program or function that, given a collection of four 3D points with Cartesian coordinates, outputs whether the shape formed by connecting those points is a flat 3D quadrilateral (i.e. all the points are coplanar).

Rules

  • The input will always have 4 points.
  • Each shape will be formed by connecting the points with lines in the order they were given and then back to the first point. You may assume that no two of these lines will intersect each other and that no three consecutive points will be collinear.
  • For each point \$(x, y, z)\$, \$x\$, \$y\$, and \$z\$ will all be integers within the range \$[0,8]\$.
  • You may choose any two distinct values to represent a truthy and falsy output, as long as it is consistent. Input can be in any convenient format.
  • This is , so the shortest code in bytes wins.

Test Cases

Input Output
(0, 0, 0) (0, 1, 0) (1, 2, 0) (1, 0, 0) true
(0, 0, 0) (0, 1, 0) (0, 0, 1) (1, 0, 0) false
(0, 0, 0) (1, 0, 0) (1, 1, 1) (0, 1, 1) true
(0, 1, 2) (3, 4, 6) (7, 8, 5) (4, 3, 2) false
(1, 1, 1) (2, 2, 2) (1, 3, 2) (2, 4, 5) false
(0, 4, 8) (4, 8, 4) (8, 4, 0) (4, 0, 4) true

Meta

  • Any additional test case suggestions?
\$\endgroup\$
2
  • \$\begingroup\$ I suggest that the input has exactly 4 points. The main approach will be anyway to check if the fourth point is coplanar with other 3, and then the fifth and so on, so maybe stick to the first task not to lose the main focus of the challenge? \$\endgroup\$
    – pajonk
    Commented Dec 6, 2022 at 9:16
  • \$\begingroup\$ @pajonk That makes sense; I will change that. \$\endgroup\$
    – Yousername
    Commented Dec 6, 2022 at 14:31
0
\$\begingroup\$

Find the representative submatrix

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

Rolling a 1x1x2 block

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

Write a program that prints a program that's almost quine.

\$\endgroup\$
5
  • \$\begingroup\$ So basically, we write a program, which given n, prints a program which prints its own first n characters, which are also the first n characters of all other programs that can be outputted? And the program has to be irreducible? \$\endgroup\$ Commented Dec 4, 2022 at 2:58
  • \$\begingroup\$ @RadvylfPrograms Correct. \$\endgroup\$
    – Fmbalbuena
    Commented Dec 4, 2022 at 15:58
  • \$\begingroup\$ What should the program do if input number is greater than its length? For example, my program has only 10 bytes, and i got an input 100. \$\endgroup\$
    – tsh
    Commented Dec 15, 2022 at 7:14
  • \$\begingroup\$ Maybe you should define what irreducible is in your question. \$\endgroup\$
    – tsh
    Commented Dec 15, 2022 at 7:18
  • \$\begingroup\$ @tsh The challenge is already uploaded. \$\endgroup\$
    – Fmbalbuena
    Commented Dec 15, 2022 at 15:29
0
\$\begingroup\$

Balanced Candy Distribution

There are 4 piles with 12 pieces of candy each, for a total of 48 pieces, and there are 12 kids to split that candy with, each kid will receive exactly 1 piece of candy from each pile, each piece of candy has a unique number on it, from 0 to 47, the candies with numbers 0 through 11 are on one pile, candies number 12 through 23 are on another, candies 24 through 35 are on a pile, and the last pile is candies 36 to 47. Candy #0 tastes amazing, and candy #47 tastes not so great, so to make it fair, each kid’s 4 candies should add up to the same number (which should be 94), there is an issue though, there are an unknown number of different flavors of candy, completely independent of their tastiness, and it would be unfair if Timmy was to, by bad luck, have all his 4 pieces of candy end up being cinnamon flavored, so, we introduce the idea of “Unfairness points”. For each kid, if we match each of their four candy pieces to their other three candies, for each pairing if both candies are the same flavor, we add one unfairness point, to illustrate this, let’s imagine a smaller example, with only four kids and 16 candies, if Timmy got 4 cinnamon candies, Laura got 1 cinnamon candy, 1 vanilla candy, and 2 chocolate candy, Johnny got 2 vanilla candies and 2 caramel candies, and Sam got 3 cinnamon candy and 1 strawberry candy, this arrangement would receive 12 unfairness points: 6 from Timmy, 1 from Laura, 2 from Johnny, and 3 from Sam.

Your code must output the arrangement that satisfies the two restrictions set forth in the beginning (each kid receives a single candy from each pile, and that for each kid all of their four candies add up to 94) that has the fewest unfairness points, if there is more than one arrangement that is tied for least number of unfairness points, you must output the list of all of those arrangements given a list of all the candies. This input could be formatted in any way that is convenient, but preferably something resembling a list of strings, where the index is the number of the candy and the string is the flavor, for example, in python, a valid input format would be

[“Chocolate”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Chocolate”,“Vanilla”,“Caramel”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Apple”,“Caramel”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Sour”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Sour”,“Pear”,“Pear”,“Caramel”,“Vanilla”,“Vanilla”,“Vanilla”,“Apple”,“Sour”,“Chocolate”,“Chocolate”,“Avocado”,“Apple”,“Sour”,“Pear”,“Pear”,“Chocolate”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Vanilla”,“Caramel”]

Or it could also be already separated into the piles

[[“Chocolate”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Chocolate”,“Vanilla”,“Caramel”,“Chocolate”,“Vanilla”,“Chocolate”],[“Apple”,“Ap...

Or it could include the number itself, if you wanted

[[0,“Chocolate”],[1,“Chocolate”],[2,“Chocolate”],[3,“Vanilla”],[4,“Chocolate”],[5,“Apple”],[6,“Chocola...

The output can be given in any way that makes it easy to interpret what the numbers of the candies each kid should get, for example, in python, an output like

[[0,19,30,45],[9,14,28,43],[5...

Is totally fine, and anything that is easy or understandable like that is fine.

This is code-golf and so lowest bytes wins


Sandbox questions:

  • English is my second language, is this written clearly enough?
  • Would it be better if it was generalized? As in "There are N piles with C pieces of candy each, for a total of N*C pieces, and there are C kids to split that candy with, each kid will receive exactly 1 piece of candy from each pile..."
  • Any other thoughts?
\$\endgroup\$
0
\$\begingroup\$

Wordle games without repeating letters

Given a word list, find all sets of five words of five letters each, such that the words of each set have 25 distinct letters in total.

This challenge was inspired by this video by Matt Parker.

Example

TODO

Rules

  • Standard I/O rules apply.
  • Words contain only lowercase (or alternatively, uppercase) alphabetic characters.
  • You can assume there are no empty words (i.e. words of length zero).
  • The input can contain words that cannot belong to any set that satisfies the property, such as words with less then five letters, words with more than five letters, and words with repeated letters.
### Scoring

This challenge wants to be an experimental mix of and .

If your solution has:

  • a time complexity of \$\Omega(f(n))\$ (see Big Omega notation) where \$f: \mathbb N \to \mathbb N\$ is a function of the form $$f(n) = (\log_2 \log_2 n)^{k_{-2}} \cdot (\log_2 n)^{k_{-1}} \cdot n^{k_0} \cdot 2^{k_1} \cdot 2^{(2^{k_2})} \cdot \ldots $$ where \$n\$ the the total number of the letters of the words in the input;
  • a length of \$x\$ bytes (or whatever unit of measurement is commonly used in the language of your choice);

then the score is \$f(x + 4)\$. Lowest score wins!

Notes
  • obviously, infinitely many terms \$k_i\$ can be \$0\$;
  • terms with three or more \$\log\$ (e.g. \$\log_2 \log_2 \log_2 n\$) cannot be used in function \$f\$ because they could be used to arbitrarily lower the score, unless we introduce further complex scoring rules (and most probably they won't be used as a real lower bound).
Scoring example

If your solution has a length of \$37\$ bytes, and it has a time complexity of \$\Omega(n^5)\$, then it has a score of \$(37+4)^5\$.

Edit: scoring rules postponed for a future challenge

\$\endgroup\$
4
  • \$\begingroup\$ can we assume that there will be at least one solution in the input? \$\endgroup\$ Commented Oct 17, 2022 at 15:47
  • \$\begingroup\$ I didn't think about it. In which case this assumption can be useful? \$\endgroup\$
    – matteo_c
    Commented Oct 17, 2022 at 22:01
  • 2
    \$\begingroup\$ I think that since the number of distinct five-letter words is constant, any algorithm taking a subset of them would be constant time. So, once you filter out words that not five letters long and de-duplicate, the complexity of the rest of the algorithm doesn't matter. Having the length "5" instead be a parameter could address this. \$\endgroup\$
    – xnor
    Commented Oct 18, 2022 at 2:22
  • 1
    \$\begingroup\$ assuming at least one solution avoids the "no solutions" edge case, which (depending on algorithm) may require extra code to handle logic that the bulk of the code doesn't handle. Example: if i have a loop which doesn't stop until i've seen some N>0 eligible words, it would run into an infinite loop in the "no solutions" scenario. Considering you have to output all solutions, however, I can see how it might not make a huuge difference. It's up to you tbh :-) \$\endgroup\$ Commented Oct 18, 2022 at 13:15
0
\$\begingroup\$

Tell 32-bit from 64-bit with most disallowed bytes

Decide an integer N. Take an array of length N, and output a x86 opcode, which when running, reach different position after leaving the opcode you provided.

  • No bytes given in input is allowed in your output.
  • You'll be in Ring 3, so some x86 features can't be used.
  • You can destroy all available registers, including XMM, x87, etc.
  • You can assume 4096 bytes of available stack under stack pointer.
  • It's not necessary a jmp. Other ways to reach different position are fine.
  • The destination should be in 256 bytes before your code or in 256 bytes after your code. jmp .+0xEBEBEBEB is not allowed unless your output is at least ~336859924 bytes.
  • Each destination should have at least 2 bytes of space to fit a jmp short instruction.

Here is a possible program with N=0:

([])=>[0x66, 0x40, 0x3D]

Assuming this program is loaded into 0, then in 32-bit mode, it goes to 7; in 64-bit mode, it goes to 5, both of which have enough space.

This is an example with N=1:

([x])=>x==0x66||x==0x41||x==0x3D?[0x24,0x00,0x40,0x74,0x74]:[0x66,0x41,0x3D]

Largest N wins.

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

Title Case (WIP)

Input a string with letters and spaces, input a set of mirror words. Output a string which is title case of the input string that follow the following rules:

  1. Cases is unchanged for any words already contains uppercase letters;
  2. Cases is unchanged for any words in the set mirror words AND is not the first word;
  3. For all other words, the first letter is changed into uppercase

The set mirror words is an input to your program / function. Here are mirror words used in testcases:

["a", "an", "and", "as", "as", "at", "but", "by", "for", "if", "in", "nor", "of", "off", "on", "or", "per", "so", "the", "to", "up", "via", "yet"]

Testcases

Input -> Output
the sun and the moon -> The Sun and the Moon
jQuery tutorial using jQuery plugins -> jQuery Tutorial Using jQuery Plugins
\$\endgroup\$
1
136 137
138
139 140
157

You must log in to answer this question.

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