560
\$\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

4327 Answers 4327

1
128 129
130
131 132
145
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\$ 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\$ 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\$ 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
    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
    Nov 19, 2022 at 8:24
  • \$\begingroup\$ @mousetail. I’m sorry, but what are smart quotes? \$\endgroup\$ 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
    Nov 19, 2022 at 19:17
  • \$\begingroup\$ @mousetail Oh, I see. My iPad just does that, will fix \$\endgroup\$ 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\$ Nov 27, 2022 at 1:49
  • 1
    \$\begingroup\$ @Unrelated String how it works now? \$\endgroup\$
    – AZTECCO
    Nov 27, 2022 at 11:18
  • \$\begingroup\$ Yep, that's perfect! \$\endgroup\$ 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
    Dec 1, 2022 at 13:45
  • \$\begingroup\$ @pajonk Good feedback, thanks. \$\endgroup\$
    – Jordan
    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
    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
    Dec 6, 2022 at 9:16
  • \$\begingroup\$ @pajonk That makes sense; I will change that. \$\endgroup\$
    – Yousername
    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\$ Dec 4, 2022 at 2:58
  • \$\begingroup\$ @RadvylfPrograms Correct. \$\endgroup\$
    – Fmbalbuena
    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
    Dec 15, 2022 at 7:14
  • \$\begingroup\$ Maybe you should define what irreducible is in your question. \$\endgroup\$
    – tsh
    Dec 15, 2022 at 7:18
  • \$\begingroup\$ @tsh The challenge is already uploaded. \$\endgroup\$
    – Fmbalbuena
    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\$ Oct 17, 2022 at 15:47
  • \$\begingroup\$ I didn't think about it. In which case this assumption can be useful? \$\endgroup\$
    – matteo_c
    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
    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\$ 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\$
0
\$\begingroup\$

A map maps keys(string) to values(string). Basic operations includes:

  • Set. Given a key and a value, store it.
  • Get. Given a key, get the last value stored into this key, or ""(empty string) if nothing ever stored into.

For some reason, sometimes keys looks same but need to refer to different object. Therefore, color is introduced. Provided keys is therefore splitted, and to get colored key, color each part of keys, and concat them.

For example, say a is colored red, then

  • a is \$\color{red}a\$
  • aa is \$aa\$
  • a a is \$\color{red}{aa}\$
  • ab is \$ab\$
  • a b is \$\color{red}{a}b\$

Therefore, another operation is

  • Color. Given a keypart, resign its color. Color is a non-negative integer and default to 0.

Shortest code in each languages wins.

Test cases

[[GET, "a"],         // ""
 [SET, "a", "1"],
 [GET, "a"],         // "1"
 [COL, "a", 1],
 [GET, "a"],         // ""
 [SET, "a bb", "2"],
 [GET, "a b b"],     // "2"
 [COL, "a", 0],
 [GET, "a"]]         // "1"
\$\endgroup\$
0
\$\begingroup\$

Solve the "/" puzzles from Taiji

Spoilers for the game Taiji, it's really good you should play it

Taiji puzzles consist of a rectangular grid, a solution consists of setting each square to either on or off:

####
#...
##..

However, not every solution is correct, a puzzle can contain any number of colored slashes, here represented by numbers:

....
1...
..1.
....

A shape is defined as a contiguous area that all has the same state. (either on or off). Areas with the same color slash must have the same shape, but it may be rotated (but not mirrored). For example, if you have this:

1..1.
.22.1
1..1.

A solution would be:

.#.#.
##..#
.#.#.

Note that all 1s are a single square while both 2s are a T shape, in this case in opposite colors.

Note that the number must be in the same place in every shape, so if you have this puzzle:

.....
1..1.
.....

This would Not be valid:

#..##
..##.
#..##

Because one 1 is in the tip and the other is in the tail.

If the numbers are different the shapes must be different. However, they count as different if the number is in a different part of the shape.

A shape can contain multiple numbers. If it contains the same number twice that means the shape must be irrationally symmetric.

Your challenge is: Given a number, output a possible solution. Note: There will always be at least 2 possible solutions, since the inverse of any valid solution is also valid.

Test Cases

Note many of these have many valid solutions.

1..1.            #..#.
.22.1        --> ....#
1..1.            #..#.

....              ##..
123.          --> #.##
....              #.##


...               #.#
111           --> #.#
...               #.#

1.22.1            ##..##
......            ######
2....2        --> .####.
2....2            .####.
......            ######
1.22..            ##..##

3....             #####
11211         --> ..#..
3....             #####

....              #.#.
111.          --> #.#.
....              #.#.

You may take input as a 2d list of numbers, and use any constant value to represent a cell that does not create a hint (eg. 0). For output you may also use any 2 constant values to represent on and off.

\$\endgroup\$
1
  • \$\begingroup\$ Is mirrored same? \$\endgroup\$
    – l4m2
    Jan 25 at 13:27
0
\$\begingroup\$

Best Iterated Prisoner's Dilemma

\$\endgroup\$
1
  • \$\begingroup\$ this is a great idea. an example would be nice :-) \$\endgroup\$ Oct 8, 2022 at 20:30
0
\$\begingroup\$

Optimize your score on a biased multiple choice test

In a multiple choice test, sometimes, by chance, multiple questions in a row will have the same answer. Some of my teachers dislike this, and will change questions to ensure there are never more than \$n\$ of the same answer in a row.

In this challenge, for each question in a test, you'll be given a set of four confidence values from 0 to 1, which sum to 1. These represent the odds of each choice being correct (for example, [0.1, 0.6, 0.2, 0.1] if you're 60% sure that B is correct, 20% sure C is correct, and 10% sure either of the others could be right). You'll also be given a positive integer n, the maximum number of same-answer questions in a row.

Given this information, you must output the set of answers that would give you the highest estimated score.

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

Pushing boxes away but

I'll accept first fastest algorithm and then this challenge turns into .

Sandbox Notes

  • Some options are listed in comment
\$\endgroup\$
4
  • \$\begingroup\$ Upvote this comment if this idea of question is good \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • \$\begingroup\$ Upvote this comment if this idea of question is bad \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • 1
    \$\begingroup\$ Upvote this comment if this way of handling fastest-algorithm is good \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • 1
    \$\begingroup\$ Upvote this comment if this way of handling fastest-algorithm is bad \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
0
\$\begingroup\$

A randomly colored walk

Given two inputs, a distance \$d\$ and a number \$n\$ output \$n\$ random colors which each have distance \$d\$ from the previous.

Background

A random walk is a path which is defined by choosing a random direction and (usually) fixed distance to go at each step. We will be taking a random walk through the RGB color space using Euclidean distance as our metric.

The challenge

For this challenge you will take two inputs, \$n\$ and \$d\$. Let \$n\$ be the number of colors to output, this will always be an integer \$1 \leq n\$, and \$d\$ be the distance between consecutive elements, which will always be \$0 \leq d \leq 128\$. You may additionally assume that \$d\$ is an integer.

For each consecutive pair of elements \$(r_1, g_1, b_1), (r_2, g_2, b_2)\$ of the \$n\$ element sequence output, it must be the case that all values are between 0 and 255 inclusive (or \$[0,256)\$ for floats), and the distance between elements must be within 1 of d, that is \$|\sqrt{(r_1-r_2)^2+(g_1-g_2)^2+(b_1-b_2)^2} - d| < 1\$. This should allow one to restrict their output to integers if they so choose. The walk need not be uniform, but it does need to be random. The starting point of the walk should be random as well.

Standard i/o rules apply, input and output can be in any reasonable format. Graphical output is allowed (and encouraged, though I doubt it will be golfy to do so) so long as the order of the sequence is clear.

This is , so the shortest answer in bytes wins.

Test cases

For these test cases input is in the order \$n,d\$ and output is \$(r, g, b)\$ as integers. These are some possible results.

5, 5 -> (81, 60, 243), (81, 57, 239), (76, 60, 240), (80, 62, 241), (84, 60, 243)
4, 10 -> (163, 89, 77), (162, 83, 85), (166, 75, 79), (166, 82, 87)
4, 50 -> (212, 36, 232), (247, 1, 239), (220, 44, 243), (217, 81, 209)
\$\endgroup\$
0
\$\begingroup\$

Related

Play chess. You can't see the current board, and can only memory two bytes.

Each turn, you're given your current state(initially 0) and opponent's move(a special value if first move in the game). You then output a list of [moves,state] pair, and the first valid one will get used. If no valid move, then you automatically resign.

Aim is obviously win as many games and lose as less as possible.

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

4D rotation matrix to quaternions

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

Ternary 2-input logic gate

Objective

Given an expression of a ternary 2-input logic gate, pretty-print its truth table.

Ternary logic and ternary operators

L, E, and G are the truth values of the ternary logic dealt here. They correspond to Haskell's LT, EQ, and GT.

The expression can have two free variables, hence "2-input".

There are four operators that the expression can have: min, max, compare, and mappend. (Again, from Haskell.) Their truth tables are:

min|L E G
---+-----
L  |L L L
E  |L E E
G  |L E G

max|L E G
---+-----
L  |L E G
E  |E E G
G  |G G G

compare|L E G
-------+-----
L      |E L L
E      |G E L
G      |G G E

mappend|L E G
-------+-----
L      |L L L
E      |L E G
G      |G G G

where the first column is for the first argument and the first row is for the second argument.

I/O format

The input format shall be a nonempty binary tree whose branches are the operator and whose leaves are the free variables and the truth values.

The output format shall be like this:

 |L E G
-+-----
L|? ? ?
E|? ? ?
G|? ? ?

where ? is filled with appropriate truth values represented by L, E, or G. Again, the first column is for the first argument and the first row is for the second argument.

Examples

Let the free variables be P and Q in sake of demonstration.

Given P compare (E compare Q), the truth table is:

 |L E G
-+-----
L|L L E
E|L E G
G|E G G

Given (P min Q) compare (E compare (P max Q)), the truth table is:

 |L E G
-+-----
L|L E E
E|E E E
G|E E G

Given ((E compare (P max Q)) compare (P min Q)) mappend (P compare (E compare Q)), the truth table is:

 |L E G
-+-----
L|G L E
E|L E G
G|E G L

Given Q mappend P, the truth table is:

 |L E G
-+-----
L|L L G
E|L E G
G|L G G
\$\endgroup\$
1
128 129
130
131 132
145

You must log in to answer this question.

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