541
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3616 Answers 3616

1
62 63
64
65 66
121
1
\$\begingroup\$

Constructing Solar Panels from Squares part 2

Thanks to all your generous contributions of code, my horde of minions can now precisely calculate how to construct solar panels of any size, but there's a problem.

The logistics department used these results to calculate how many square panels they would need for every size up to 1,000,000, which is way too many panels. As it turns out, larger panels are more expensive than cheaper ones, so I've decided we need to try to use the largest square panels we can wherever possible.

To make matters worse, my team of scientists tell me that we should avoid using multiple panels of the same size in our configuration, except for our tiny 1x1 panels, to make sure the panels don't fall apart.

The Challenge

Given a positive integer n, output a list of square numbers that sums to n containing the largest squares possible such that no square number other than 1 appears multiple times.

A square number is any integer that is the result of multiplying an integer by itself. For example 16 is a square number because 4 x 4 = 16 This is A000290

For example: For n = 12, you could achieve the desired size with 4 panels of sizes [9, 1, 1, 1]. As 9 is the largest square possible in this configuration, this is the best answer. For n = 13, you can achieve the desired size with only 2 panels: [9, 4]

If n is a square number, the output should be [n].

Input

A positive integer n representing the total desired surface area of the solar panels. Note that 0 is not positive.

Output

A list of square numbers that sums to n containing the largest squares possible.

Testcases

1 -> [1]
2 -> [1,1]
3 -> [1,1,1]
4 -> [4]
7 -> [4,1,1,1]
8 -> [4,4]
9 -> [9]
12 -> [9,1,1,1]
13 -> [9,4]
18 -> [16,1,1]
30 -> [25,4,1]
50 -> [49,1]
60 -> [49,9,1,1]
70 -> [64,4,1,1]
95 -> [81,9,4,1]
300 -> [289,9,1,1]
1246 -> [1225,16,4,1]
12460 -> [12321,121,16,1,1]
172593 -> [172225,361,4,1,1,1]

Sandbox

I don't think this challenge is similar enough to part 1 to be considered a dupe, as while some answers from part 1 could be trivially modified to work for part 2, they would likely be out-golfed by better approaches.

That said I'm not sure how well-worded the output requirement is. a list of square numbers that sums to n containing the largest squares possible such that no square number other than 1 appears multiple times. feels poorly worded, but I'm not sure how I could word it better.

\$\endgroup\$
7
  • \$\begingroup\$ The challenge is unclear. I think you copied part 1 but forgot to edit testcase and example of challenge \$\endgroup\$
    – okie
    Nov 17 '21 at 1:04
  • 1
    \$\begingroup\$ such that no square number other than 1 appears multiple times - test cases don't agree. \$\endgroup\$
    – pajonk
    Nov 17 '21 at 5:24
  • \$\begingroup\$ I did generate new testcases when I wrote this, but I guess I messed up when putting them in. I'll re-run and update the testcases now \$\endgroup\$
    – Mayube
    Nov 17 '21 at 22:15
  • \$\begingroup\$ 8->4,4 having 2 4 \$\endgroup\$
    – okie
    Nov 18 '21 at 0:43
  • \$\begingroup\$ Am not sure if this question may be solved by modify the previous one trivially. But there would be many answer be very similar though. I'm not sure if it would be a duplicate to that one in such case. \$\endgroup\$
    – tsh
    Nov 18 '21 at 3:59
  • \$\begingroup\$ @okie yeah, the problem is with the wording of the challenge, not the testcases. Not sure how best to word it... \$\endgroup\$
    – Mayube
    Nov 18 '21 at 14:07
  • \$\begingroup\$ So only the largest and 1 can appear multiple time? \$\endgroup\$
    – okie
    Nov 18 '21 at 23:27
1
\$\begingroup\$

Implement Unix Timestamp to Daytime

Given an unsigned integer that represents a timestamp since 1970/01/01 00:00:00 (which is Unix epoch time), output one of these to represent the daytime in GMT timezone:

  • An array that stores year, month, date, hour, minute, second.
  • A string in format YYYYMMDDHHmmss.
  • Or whatever similar, as long as it complies with standard i/o rules.

Rules

  • Implement the function or the full program from vanilla.
    • So no built-ins nor libraries that has the fuctionality (see next section).
  • Implement leap year, too; but don't leap second (although leap second is not supported).
  • You just need to support up to 2038/01/19 (so input range shall be 0 to 2147483647 (inclusive)).
  • Standard loopholes apply.
  • Standard I/O rules apply.
  • Input and output format should be consistent and not ambiguous.
    • So, for example, if output is a string like 1970121000, it's unqualified, as it can be recognized as 1970/01/21 00:00:00, 1970/12/01 00:00:00, or 1970/01/02 10:00:00.
  • Shortest code wins.

Examples of bad answers

Test cases

0
-> 1970/01/01 00:00:00
999999999
-> 2001/09/09 01:46:39
1145141919
-> 2006/04/15 22:58:39
1330500000
-> 2012/02/29 07:20:00
1633773293
-> 2021/10/09 09:54:53
2147483647
-> 2038/01/19 03:14:07

Hint

Here are implementations:

Related problems

Meta

  • I once posted here but it's closed.
  • TODO. define what builtins are.
    • The most problem is that that KSH answer has a function that directly converts to the objective string; should I prohibit it?
  • Maybe I wanted to say no date objects allowed.
  • Is what is so-called date object ambiguos?
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Unix Timestamp does not support leap seconds. So there is nothing to do to require someone implement leap second support for an Unix Timestamp. \$\endgroup\$
    – tsh
    Oct 12 '21 at 6:28
  • 1
    \$\begingroup\$ Am I required to support year above 2038? As, you know, support only 1970~2038 would avoid some leap year issues for 2100 or 2200. \$\endgroup\$
    – tsh
    Oct 12 '21 at 6:31
  • \$\begingroup\$ @tsh 1. Thank you for pointing out leap seconds. 2. I clarified to support until 2038. \$\endgroup\$
    – user100411
    Oct 12 '21 at 12:27
1
\$\begingroup\$

Permutation of all the number which separated by ':' and ','

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf and thanks for using the Sandbox! This is a great challenge, but as it stands it's a little unclear from the instructions what's being asked. For example it's clear from the example that 1-2,11,44:110-113 means output every permutation of 1,2,11,44 on the left column and 110,111,112,113 on the right column, but that's not explained in the instructions. \$\endgroup\$
    – Mayube
    Nov 12 '21 at 20:52
  • \$\begingroup\$ @Mayube Thanks for your comment, I've updated the instructions. \$\endgroup\$
    – obnews
    Nov 12 '21 at 22:02
1
\$\begingroup\$

Print random characters indefinitely

Task


Continuously print a random character (a-z, A-Z, 0-9) not separated by a newline (\n).

Expected output


b7gFDRtgFc67h90h8H76f5dD55f7GJ6GRT86hG7TH6T7302f2f4 ...

Note: output should be randomised.

Requirements/Rules


  1. Output must be continuous (i.e. never ending),
  2. Output may not comprise of newlines,
  3. Output must be random,
  4. Output must be only composed of characters: a-z, A-Z, 0-9.
  5. No loopholes, regarding programming language version(s). Use only the tools available with that programming language, no third-party packages, modules, or other addons.

Points


  • Smallest file size (in bytes)

Notes

Concerns: None at the moment...

\$\endgroup\$
9
  • 1
    \$\begingroup\$ I think this would count as a duplicate of this. It's a language specific version, and indefinite, but making something loop forever isn't really the hard part of the challenge I think. \$\endgroup\$
    – Riker
    Nov 29 '21 at 0:51
  • \$\begingroup\$ @Rɪᴋᴇʀ no, not because different. \$\endgroup\$
    – Fmbalbuena
    Nov 29 '21 at 0:51
  • 1
    \$\begingroup\$ Is "creativity" part of the scoring? If so, there's no way to objectively determine how creative something is, so you can't use that as a scoring criterion. You should probably clarify Python 3.8 is the only allowed language, or just drop that entirely (which I'd strongly recommend). \$\endgroup\$ Nov 29 '21 at 0:52
  • 1
    \$\begingroup\$ @RedwolfPrograms and Riker thank you for the tips, i'll make the suggested edits to the criterias ASAP. \$\endgroup\$ Nov 29 '21 at 0:57
  • 1
    \$\begingroup\$ Not limited to python, this might be different enough. I consider something a duplicate if the more specific challenge doesn't really encourage any different approaches than whatever worked for the previous ones, but limiting to alphanumeric and forcing an infinite stream is probably good. You should probably check if there's any other ones tagged [random] that look too similar though. \$\endgroup\$
    – Riker
    Nov 29 '21 at 0:59
  • \$\begingroup\$ @Rɪᴋᴇʀ Understood. Thanks again! \$\endgroup\$ Nov 29 '21 at 1:01
  • 1
    \$\begingroup\$ No problem! It's an interesting challenge, and if it really hasn't been done before then I think it would be quite fun to do. \$\endgroup\$
    – Riker
    Nov 29 '21 at 1:13
  • \$\begingroup\$ Ok! Will post this in ~22 hours... \$\endgroup\$ Nov 29 '21 at 1:16
  • \$\begingroup\$ We've had similar versions of this challenge before, and they've all been closed as a dupe of this and/or this. Personally, I would hammer this closed as a dupe of those two, as I don't think this adds anything that they don't - it's just a trivial combination of the two \$\endgroup\$ Nov 29 '21 at 1:20
1
\$\begingroup\$

Largest SKI Reduction in under 100 characters

The challenge

Create a program in SKI Combinator Calculus in under 100 characters that produces the largest result after terminating.

Scoring

The score will be the number of characters in the final reduction. The highest is the winner.

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

Fully matched numbers

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

Convert superscript numbers to normal numbers

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Maybe specify exactly what characters will be included in the input? \$\endgroup\$
    – emanresu A
    Dec 11 '21 at 22:02
  • \$\begingroup\$ @emanresuA Done \$\endgroup\$ Dec 12 '21 at 0:05
1
\$\begingroup\$

Posted here

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

Rotate two differently cased subwords independently

You have one string made of two subwords in different cases, the upper case first, then the lowercase:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

And you must return each subword cycled by a given increment. (N.b. the letters aren't rotated through the alphabet, but each character is shifted in the word)

The subwords are not always the same length as each other, and are part of the same 'data' structure. If your language cannot store strings, you're permitted to store the 'string' in a single array, e.g. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

Here are the test cases:

Input Output
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyzabcdefghijklm", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyz'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 26 'ABCDEFGHIJKLMNOPQRSTUVWXYZopqrstuvwxyzn'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyz'
"ABCnopqrstuvwxyz", 2 'BCAyznopqrstuvwx'
"AAABBBcccddd", 2 "BBAAABddcccd"
"AAABBBcccddd", 6 "AAABBBcccddd"
"HELLOworld", 5 'LLOHErldwo'
"CODEgolf", 0 'CODEgolf'

Here is an ungolfed example program:

const subWordRotate = (original, rot) => [...original.split(/([A-Z]+)(?![A-Z][a-z]+)/)].map(list => [, ...list].reduce((memo, char, index, input) => {
  memo = memo.slice(0, input.length);
  memo.splice((index + rot) % (input.length), 1, char);
  return memo
}, Array(original.length).fill('')).join('')).join('')


const testCases = [
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 13],
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyzabcdefghijklm", 13],
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 26],
  ["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 13],
  ["ABCnopqrstuvwxyz", 2],
  ["AAABBBcccddd", 2],
  ["AAABBBcccddd", 3],
  ["AAABBBcccddd", 4],
  ["AAABBBcccddd", 5],
  ["AAABBBcccddd", 6],
  ["AAABBBcccddd", 7],
  ["AAABBBcccddd", 8],
  ["AAABBBcccddd", 9],
  ["AAABBBcccddd", 10],
  ["HELLOworld", 69],
  ["CODEgolf", 0]
]
testCases.forEach(
    testCase => console.log(`original: ${testCase[0]}, rotated by ${testCase[1]}: ${subWordRotate(...testCase)}`)
  );


Sandbox note: I think there is a bug in my code, such that ["AAABBBcccddd", 6],["AAABBBcccddd", 7], return the same values. I think this is the same bug that is preventing me specifying how negative numbers work. Any help fixing the code would be much appreciated

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

The Most Wanted Prime Numbers

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

Can we patch the corona certificate validation code (part 1/3)?

The new chancellor of Germany, Mr. Olaf Scholz, is in deep trouble: the Covid app does not show the vaccination status correctly beginning with booster vaccinations. He was not involved in the development of the app, since that was under chancellor Angela Merkel. He is now hiring you, Secret Agent 0x007, in order to understand the problem and later apply a strategy to fix the problem.

In step 1, Mr. Scholz wants to understand how the app has worked correctly when booster vaccinations were not even thought of. Mr. Scholz is an important person, so he has no time to read lengthy source code. Your code has to be .

These are the rules of valid vaccinations:

  • There are 4 vaccination types in Germany: BioNTech (B), Moderna (M), Astra Zeneca (A) and Johnson&Johnson (J).
  • A person is considered vaccinated 14 days after the necessary amount of injections.
  • Biontech, Moderna and Astra Zeneca need 2 injections, Johnson needs 1 injection only.
  • If 2 injections are needed, the second injection may occur earliest 28 days after the first injection.
  • If 2 injections are needed, the second injection may only be with the same vaccination type.
  • You get an entry in your vaccination pass which has the date in the format YYMMDD. COVID-19 is all post 2000, so we never need a 4 digit year.
  • A full entry is in the form YYMMDD X followed by a newline, where X is the vaccination type.

How the application works:

You get the input in a reasonable form, e.g.

  • from stdin, separated by newlines of your platform
  • an array of strings (like argv)
  • a function with variable number of arguments (like ...)

The first line/entry is today's date, which you check the validity against. This comes from a time server, so it's always valid. Each following line/entry is for one injection. There may be many of them, mainly limited by your platform (254 is certainly enough, also for part 2 and 3).

The application gives the following output:

  • injected after a successful injection with the 14 days period not over
  • vaccinated 14 days after the necessary amount of injections
  • manipulated in case things do not match

manipulated takes precedence over vaccinated over injected. The output may contain arbitrary leading or trailing whitespace. A newline is not needed (it will be displayed in a mobile phone app textbox anyway).

The output can be

  • on stdout
  • the return value of the function

As there are quite some anti-vaxxers, the application checks for manipulations.

  • Totally invalid vaccination types (like Y)
  • Mix of vaccination types for the first and second injection
  • More injections than needed
  • Invalid date (like 200231 - there is no February 31st)
  • Date too early (earlier than 200101, the beginning of the pandemic)
  • Injection date later than today
  • Injections in wrong order (second date before first date)

You don't need to consider:

  • dates other than 6 digits
  • characters in the date other than 0-9
  • other character than space as the separator
  • more than 1 character as vaccination type

Test cases:

<any date>
200231 X
= manipulated (invalid vaccination type)

<any date>
210301 B
210329 A
= manipulated (different vaccination types)

<any date>
210301 B
210329 B
210426 B
= manipulated (too many injections)

210814
210301 J
210814 J
= manipulated (too many injections)

<any date>
200231 B 
= manipulated (invalid date February 31st)

<any date>
191231 B 
= manipulated (date earlier than the pandemic)

210301
210302 J
= manipulated (date of the injection is tomorrow)
 
210301
210301 J
= injected (14 days not over)

210315
210301 J
= vaccinated (14 days over, only 1 injection needed)

210315
210301 B
= injected (14 days over, but 2 injections needed)

<any date>
210301 B
210302 B
= manipulated (28 days between 2 injections required)

210331
210301 B
210329 B
= injected (28 days between 2 injections, but not 14 days after the last one)

210412
210301 B
210329 B
= vaccinated (28 days between 2 injections, 14 days after the last one)

210412
210329 B
210301 B
= manipulated (injections in wrong order)

About realism: while this challenge has a realistic background, not all vaccination of rules in Germany are considered. Do not claim that your program can calculate the validity of a COVID-19 vaccination certificate.

Coming up:

  • part 2, in which you need to consider booster vaccinations the wrong way
  • part 3, in which you check whether you can patch the wrong code of part 2 to make it work correctly

I would appreciate if you participate in all 3 parts.

\$\endgroup\$
5
  • \$\begingroup\$ Regarding the process: I will start writing part 2 when I have received feedback on part 1. I will start writing part 3 when I received feedback on part 2. I want to release part 1 not before all 3 parts were reviewed. Would that be fine? \$\endgroup\$ Dec 18 '21 at 21:06
  • \$\begingroup\$ Interesting question, and I like it. The only thing that really sticks out to me is the input format, you should probably clarify before anybody asks - can you take input as an array/list of strings, rather than a newline delimited string? i.e. ["a", "b"] instead of "a\nb". It really doesn't matter much which you pick but since newline delimited strings would take more bytes for most langs, it's probably going to get asked immediately. \$\endgroup\$
    – Riker
    Dec 18 '21 at 21:24
  • \$\begingroup\$ @Riker: thank you for the feedback. Yes, if that's a common thing to have for input, that's totally fine. Is there an example for a formulation considering all the common inputs? \$\endgroup\$ Dec 18 '21 at 21:26
  • 1
    \$\begingroup\$ I'm unsure if it counts as common, but yeah - it's just that indexing an array is probably shorter than calling .split("\n") for many languages, lol. Regarding posting 3 challenges, I think it's worthwhile to sandbox all 3 before posting any of course, but then posting maybe each one on sunday or something for 3 weeks would be fun. Somebody in chat compared it to a mini advent of code (golf) :) \$\endgroup\$
    – Riker
    Dec 18 '21 at 21:29
  • \$\begingroup\$ I implemented this challenge (non-golfed) and all test cases work. I'll start working on the next one now. \$\endgroup\$ Dec 27 '21 at 15:22
1
\$\begingroup\$

Fuzzy friends

Introduction

Congratulations! You've been selected to do research a a newly discovered animal called a fuzzy, a docile, simple creature that strongly resembles a cotton ball. Fuzzies love to be near other fuzzies, but not all fuzzies want to be near each other.

There are 6 types of fuzzies, 1a, 1b, 2a, 2b, 3a, and 3b. Each obeys different rules.

  • Type 1a fuzzies want to be near any type b fuzzy. (vice versa for 1b)

  • Type 3a fuzzies want to be near any type a fuzzy. (vice versa for 3b)

  • Finally, type 2 fuzzies want to be near any fuzzy type, a or b.

  • Perfect pairings are matches in which both fuzzies want to be near each other (ex. 1a and 1b)

  • Semiperfect pairings are matches in which only one fuzzy wants to be near the other (ex 3a and 1b)

  • Imperfect pairings are matches in which neither fuzzy wants to be with the other (ex. 3a and 3b)

Your Challenge

Given a list of fuzzies:

  1. Output the total number of perfect pairings. If there are any left:
  2. Output the number of semiperfect pairings. If there are any left:
  3. Output how many leftover bachelors there are.

Output and input format don't matter as long as you state them both.

Test cases

1a, 1b:
1a and 1b are a perfect match
> 1 perfect, 0 semiperfect, 0 bachelors
1a, 2b, 2a, 3b:
1a and 2b are a perfect match
2a and 3b are a semiperfect match
> 1 perfect, 1 semiperfect, 0 bachelors
1a, 1b, 2a, 3a, 3b, 3b:
1a and 1b are a perfect match
2a and 3a are a perfect match
3b and 3b are an imperfect match
> 2 perfect, 0 semiperfect, 1 bachelor
1b, 2a, 3a
1b and 2a are a perfect match
3a is left over
(note: could also be:
2a and 3a are a perfect match
1b is left over
for the same result)
> 1 perfect, 0 semiperfect, 1 bachelor

Scoring

This is , so shortest in bytes wins.

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

Make a negative afterimage

We've all seen the strange, inverted-color images of the American Flag or similar that look correct after you stare at them for a minute and look at a white object. These are called negative afterimages.

Your Challenge

Given an image as input, your program should return that same image, recolored to create a negative afterimage. To do this, simply invert each color in the image. Your program may take either raw image data or a path to an image file as input, and either create a new image file or display the inverted image as output.

Scoring

This is code-golf, so shortest answer wins.

\$\endgroup\$
2
  • \$\begingroup\$ What does inverted-color mean? For example, if input color is pink, should I output darkred, darkgreen or lightgreen? \$\endgroup\$
    – tsh
    Dec 23 '21 at 8:23
  • \$\begingroup\$ How many colors should I support at least. Is a program only support black-white image acceptable? Or what about 16 color image? \$\endgroup\$
    – tsh
    Dec 23 '21 at 8:24
1
\$\begingroup\$

Loading Circle Animation

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I think it would be simpler if a program was just required to output eight frames, then stop. The infinite looping is unnecessary. (I think it's fine how it is) \$\endgroup\$ Oct 28 '21 at 1:45
  • \$\begingroup\$ For example, someone submit a progrom like this: while True: print(".#\n#\n#..#\n.##);clearScreen();print(.##\n#\n#\n.##);clearScreen()... The program try to print a frame, and then clear the screen immediately. It in theory output each frame one by one. But user would be hard to distinguish each frames. Also, if you try to take a screenshot, most time you will got an empty screen (suppose clearScreen would be much slower than print). Is this still a valid answer? \$\endgroup\$
    – tsh
    Nov 4 '21 at 8:03
  • \$\begingroup\$ @tsh Yes, as long as the user can tell what the animation is. \$\endgroup\$
    – Yousername
    Nov 12 '21 at 22:59
1
\$\begingroup\$

Shuffle a subsequence

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

Recursive Pi


Given an integer \$n\$ with \$0 \leq n \leq 9\$, return all the digit \$d's\$ as the program goes through this process:

  • Find the digit \$d\$ in the decimals of \$\pi\$ with the index \$n\$, \$0\$-indexed
  • Run the same process with \$n\$ being the digit \$d\$

After at least \$10\$ steps, the program will always get stuck in a loop. That is when the program should terminate and output all the \$d's\$ / stop outputting \$d's\$.

All Cases

$$ 0 \to [1, 4, 9, 5, 2] \\ 1 \to [4, 9, 5, 2, 1] \\ 2 \to [1, 4, 9, 5, 2] \\ 3 \to [5, 2, 1, 4, 9] \\ 4 \to [9, 5, 2, 1, 4] \\ 5 \to [2, 1, 4, 9, 5] \\ 6 \to [6, 6] \\ 7 \to [5, 2, 1, 4, 9, 5] \\ 8 \to [3, 5, 2, 1, 4, 9] \\ 9 \to [5, 2, 1, 4, 9] \\ $$

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

Is this word in standard order?

Let \$ A \$ represent the alphabet, such that \$ A_1 = \$ a and \$ A_{26} = \$ z.

Let's define that a word \$ W = w_1 w_2 ... w_n \$ (where \$ w_c \in A\$) is in standard order if and only if:

  • \$ w_1 = A_1 \$, and
  • for \$ 2 \le i \le n \$, if \$ w_i = A_x \$ then \$ w_j = A_{x-1} \$ for some \$ j < i \$.

In other words, the word must start with a and each other letter can only appear in a word if the preceding letter in the alphabet has already appeared.

For example, ac is not in standard order, because there is no b before the c.

The following relationships exist between the property of standard order and some others:

Task

Given a string of letters, determine if it is in standard order according to the Latin alphabet.

Test cases

Truthy:

a
aaa
abab
abacabadabacaba
abcdefghijklmnopqrstuvwxyz

Falsey:

b
ac
bac
abbdc
bcdefghijklmnopqrstuvwxyza
abracadabra

Rules

  • You should represent true and false outputs using any two distinct values of your choice
  • You may assume the input is non-empty and only contains lowercase ASCII letters
  • You may use any standard I/O method
  • Standard loopholes are forbidden
  • This is , so the shortest code in bytes wins

Meta

  • "standard order" doesn't seem to be a well-used term in the literature. I can find it only in a tightly-knit web of sources all referencing each other
  • Is this a duplicate? Because of the lack of nomenclature, my searches were ineffectual
  • Is this clear enough?
\$\endgroup\$
3
  • \$\begingroup\$ IMO this would be better as an array challenge with arrays of [1,2,3] etc. \$\endgroup\$
    – emanresu A
    Dec 31 '21 at 22:07
  • \$\begingroup\$ @emanresuA I considered that, but I thought using letters might create some interesting solutions using regular expressions and what-not. Do you think I should allow working over any set (e.g. the natural numbers), not just the alphabet? Or would that be too complex? \$\endgroup\$
    – pxeger
    Dec 31 '21 at 22:14
  • \$\begingroup\$ And "some \$x\$"? \$\endgroup\$ Jan 10 at 12:35
1
\$\begingroup\$

Pluralize a Noun List

Currently Closed

\$\endgroup\$
7
  • \$\begingroup\$ Can you change dropbox to github? \$\endgroup\$
    – Fmbalbuena
    Jan 3 at 3:17
  • \$\begingroup\$ I can see if I can do that. Got some other big changes this thing probably needs though. \$\endgroup\$
    – Romanp
    Jan 4 at 4:02
  • \$\begingroup\$ most users use Github \$\endgroup\$
    – Fmbalbuena
    Jan 4 at 4:03
  • \$\begingroup\$ Got it. I realized that my lists of words were not particularly accurate, so as soon as I get better ones, I will switch to Github. \$\endgroup\$
    – Romanp
    Jan 5 at 12:58
  • \$\begingroup\$ The link example fakehtpps://python.org can be [link](fakehtpps://python.org) \$\endgroup\$
    – Fmbalbuena
    Jan 5 at 15:03
  • \$\begingroup\$ test-battery would be a good tag for this, I think \$\endgroup\$
    – user
    Jan 12 at 1:45
  • \$\begingroup\$ Now that this is posted, could you edit it down to a stub and delete it? \$\endgroup\$ Jan 12 at 3:05
1
\$\begingroup\$

Minimal Randomness

In this challenge, you take input and shuffle the letters in a random, non-deterministic way which minimizes the probability that the output is different from the input.

Rules

  1. Your program must take input and use only substitution and transposition to randomly modify the input.

  2. There must be a slight, non-zero probability that the output differs from the input.

  3. Your program is graded based on the probability of its output differing from the input, with a lower probability being better.

  4. If two programs are tied in score, the tie is settled by the code size, with a shorter code being better.

  5. Your program must be non-deterministic.

Meta

I'll post this to main soon unless there are any issues with it.

\$\endgroup\$
2
  • \$\begingroup\$ don't post it to main right away, wait for feedback and upvotes \$\endgroup\$ Jan 13 at 22:59
  • 1
    \$\begingroup\$ yeah. That's what I meant, sorry if it sounded like "if nobody looks at this, it must be amazing!" \$\endgroup\$
    – Binary198
    Jan 14 at 15:52
1
\$\begingroup\$

Short programs for fixed outputs

Inspired by Lynn's Jelly puzzles. Check them out if you're interested in practicing your Jelly skills

Cops

The cops should choose three things:

  • A freely available programming language,
  • a byte count \$B\$, and
  • a number of programs to write, \$n\$ (minimum 5)

They should then write \$n\$ programs, each of which:

  • is exactly \$B\$ bytes long, and

  • outputs a fixed, non-empty, non-whitespace output. That is, the output should contain at least one non-whitespace character. "Fixed" can mean that either:

    • it outputs the same thing no matter what input is provided, or
    • that it always outputs the same thing and takes no input.

    You may choose which of these meanings to take, but it must be the same for all \$n\$ programs. Please mention which of these options your programs use.

The cops should then reveal the following bits of information:

  • The programming language used,
  • the byte count \$B\$,
  • any command line flags used for specific outputs,
  • the \$n\$ outputs for each of the \$n\$ programs. If the outputs use any non-printable ASCII characters, please include a hexdump of the output.

The Robbers will be attempting to find \$B\$ byte long programs that output the same outputs, so you should keep your programs secret.

For example, if you choose to write 7 programs in Python, each of them 10 bytes, that output

4, True, 2 3 , 1, 72, ! and [0]

then you may have these 7 programs (one per line).

Robbers will crack one of your \$n\$ outputs if they can find any \$B\$ byte program in your language that has the same output. Note that the program does not have to be the same as the cop's program.

Any outputs that go a week without being cracked can be marked safe, and the programs for each output should be revealed. Until the program is revealed for a specific output, it can still be cracked.

You may post multiple answers, but each answer should be independent from all others. Your score is equal to the total number of safe outputs across all your answers. The user with the highest score wins.

Robbers

You should find a Cops answer with at least one uncracked, unsafe output, and attempt to crack any of the outputs. That is, find a program that is exactly \$B\$ bytes long that outputs the same fixed output. Note that your program does not have to be the same as the Cop's original answer, just that the output has to be equal.

If you crack an answer, please do the following:

  • Leave a comment on the Cop's answer, linking to either your answer or a TIO (or similar) link demonstrating the crack
  • If this is your first crack, post an answer to the Robbers thread with your crack, linking to the relevant Cop answer
  • For further cracks, edit them in to your existing answer, linking to the relevant Cop answer

A Robber's score is equal to the total number of cracks they make. The Robber with the highest score wins.


Meta

\$\endgroup\$
1
  • \$\begingroup\$ Other than the original inspiration, is there any reason to have multiple tasks in one cop submission? Since they're not related to each other and each one can be cracked individually, it seems like they should each be separate answers. \$\endgroup\$
    – DLosc
    Jan 15 at 0:46
1
\$\begingroup\$

BCD to binary, with bitwise


In this challenge, you'll convert an 8-digit BCD (Binary Coded Decimal) number to a 32 bit (unsigned) integer in the fewest instructions possible, with only bitwise instructions available.

Task:

You'll be given a single positive integer as input, from 00000000 to 999999999. It will be represented using BCD, as a 4-byte unsigned integer, with each nibble being a decimal digit from 0000 (0) to 1010 (10). More significant nibbles will correspond to more significant digits of the decimal number.

Your output should be that same number, as an ordinary 32-bit integer.

Instructions:

This is atomic code golf, so you can only use the following instructions, the number of which is used for scoring:

and [r], [r|I]      Bitwise AND
or  [r], [r|I]      Bitwise OR
xor [r], [r|I]      Bitwise XOR

not [r]             Bitwise NOT

shr [r], [r|I]      Shift right (zero fill)
shl [r], [r|I]      Shift left

mov [r], [r|I]      Copy

All instructions will write their output to the first register listed, and for the second argument [r|I] indicates either a register or an immediate (any 32-bit constant) can be provided.

You have four registers to work with, all of which hold a single 4 byte unsigned integer: ra, rb, rc, and rd. Any instruction using only registers costs 1 byte, and any with an immediate cost a total of 4 (this isn't technically possible, since the immediates are 4 bytes on their own, but I don't want to make them too costly).

Input will be provided in ra, and the contents of ra when your program is finished will be used as output. All other registers will be initialized to 0.

Other:

I don't actually know if this is an interesting challenge, or if more registers will be needed, or if there's already a well known solution. I'd try it myself but it's kinda late here so I'm too tired to, and if I don't post this now I'll forget about it lol

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

Climb a ragged list


Your task is to represent a ragged list as ASCII art that looks like a mountain.
You are given a list of lists, either having other lists inside them or being empty.

Here is somewhat a description:

Looping through every list:
    If entering a list, print (current_depth - max_depth - 1) newlines with a "/"
    If exiting a list, print (current_depth - max_depth - 1) newlines with a "\"

The printing in the description is from left to right, top to bottom.
So [[[[]], [[]]]] would output (max depth = 3):

  /\  /\
 /  \/  \
/        \

Rules

Test Cases:

In: [] # empty list
Out: 

In: [[]]
Out:
/\

In: [[], [[]], [[[]]]]
Out:
        /\  
   /\  /  \
/\/  \/    \

In: [[[[]], []]]
Out:
  /\    
 /  \/\
/      \

In: [[], [[]], [[], []], [[[]], []]]
Out:
              /\    
   /\  /\/\  /  \/\
/\/  \/    \/      \

In: [[[[], []], [[]]], [[[]], [[], [[], [], []]]], [[[], [], []]]]
Out:
                     /\/\/\
  /\/\  /\    /\  /\/      \    /\/\/\
 /    \/  \  /  \/          \  /      \
/          \/                \/        \

Good Luck!

Example Python script with a different approach

\$\endgroup\$
1
  • \$\begingroup\$ Seems like a dupe of this treating the array as a string... \$\endgroup\$
    – emanresu A
    22 hours ago
1
\$\begingroup\$

Mat printing

A manufacturing company wants to print a design on mats of varying dimensions, and they hired you to program a robot to make these mats. The design consists of alternating rings of any 2 symbols on a mat. Below are some sample looks:

Column 9 by Row 7

Symbol 1: @

Symbol 2: -

Input: 9 7 @ -

@@@@@@@@@
@-------@
@-@@@@@-@
@-@---@-@
@-@@@@@-@
@-------@
@@@@@@@@@

Column 13 by Row 5

Symbol 1: @

Symbol 2: -

Input: 12 5 @ -

@@@@@@@@@@@@@
@-----------@
@-@@@@@@@@@-@
@-----------@
@@@@@@@@@@@@@

Column 3 by Row 5

Symbol 1: $

Symbol 2: +

Input: 3 5 $ +

$$$
$+$
$+$
$+$
$$$

Column 1 by Row 1

Symbol 1: #

Symbol 2: )

#

Write a program that takes in the length, breadth, symbol 1 and symbol 2 and prints out the mat design on the screen.

*The row and column number is always odd

Shortest code wins!

Tags:

\$\endgroup\$
5
  • \$\begingroup\$ er wats default I/O @adam \$\endgroup\$
    – DialFrost
    12 hours ago
  • \$\begingroup\$ im sorry i dont understand @adam could u explain the defualt IO (i alr read the link doesnt rly help) or edit my post thx \$\endgroup\$
    – DialFrost
    12 hours ago
  • \$\begingroup\$ like this? i changed it \$\endgroup\$
    – DialFrost
    12 hours ago
  • \$\begingroup\$ Yeah, this looks great. Maybe put in the tags you plan on using. \$\endgroup\$
    – Adám
    12 hours ago
  • \$\begingroup\$ @adam pls edit the tags if its wrong thx \$\endgroup\$
    – DialFrost
    11 hours ago
1
\$\begingroup\$

From code to golf

You can change the word “code” into “golf” by changing a letter at a time in four steps:

CODE
COLE
COLD
GOLD
GOLF

Today, we’ll be doing the same thing with programs.

Cops thread

Your challenge is to:

  • choose a programming language
  • write two programs / functions, one that outputs code and one that outputs golf
  • Such that you can repeatedly change a single character and get a program that outputs an English word (insert dictionary here) until you get to the golf program.
  • Share the code program and the number of times you need to change a character, but not any of the intermediate programs or the golf program, which robbers will try to discover.
  • Intermediate programs can't output code or golf.

For example, if the program abcde outputs code in a certain language, and the program abcdf outputs potato, then changing that e to an f is a valid step.

And if the program aqcdf outputs golf, then abcde -> abcdf -> aqcdf is a valid chain in which you change a character twice.

You should only share the code program and the number of programs not counting the code program, the rest is for the robbers to guess.

Your solution is cracked when your entire chain of programs is found. It does not have to be your intended solution, only one with the same initial program and same or less length. (If someone finds a longer chain, it’s not a crack.)

If your answer is not cracked after a week, you may mark it as safe.

Scoring

Your score is the number of programs not counting the code or golf ones, multiplied by the length in bytes of your code program. The safe answer with the lowest score wins.

Robbers thread

Your challenge is to crack an answer on the cops' thread. Cops will create a series of programs in which the first prints code, the last prints golf and the rest print English words (insert dictionary here) that aren't code or golf such that each program can be derived from the previous by changing a single character of its code.

The cops will only share the code program and the number of changes, your challenge is to figure out the rest. Once you discover their whole program chain, their answer is cracked.

The user with the most cracks wins the cops challenge.

\$\endgroup\$
9
  • \$\begingroup\$ Is allowed to remove letter? \$\endgroup\$
    – Fmbalbuena
    1 hour ago
  • \$\begingroup\$ @Fmbalbuena Nope. \$\endgroup\$
    – emanresu A
    1 hour ago
  • \$\begingroup\$ there will be someone say that the program are changed “239742387” times \$\endgroup\$
    – okie
    1 hour ago
  • 1
    \$\begingroup\$ @okie Then there will probably be some sort of pattern, and it'll be possible to find that. \$\endgroup\$
    – emanresu A
    59 mins ago
  • \$\begingroup\$ @emanresuA yea and that will be another interesting part of this challenge. \$\endgroup\$
    – okie
    56 mins ago
  • \$\begingroup\$ @okie Exactly!! \$\endgroup\$
    – emanresu A
    54 mins ago
  • \$\begingroup\$ @DLosc Nice! (filler) \$\endgroup\$
    – emanresu A
    40 mins ago
  • \$\begingroup\$ I'ma say no on #2, and I don't see why anyone would do #1 since you can crack with a shorter program. \$\endgroup\$
    – emanresu A
    31 mins ago
  • \$\begingroup\$ @DLosc True, I'll allow that then \$\endgroup\$
    – emanresu A
    20 mins ago
0
\$\begingroup\$

Find Maximum number of 4+ letter words from Scabble Tiles

The challenge is to find the most words with 4 or more letters you can make with one set of scrabble tiles.

The tile distribution is as follows:

2 Blank Tiles
A 9  N 6    +====+===========+
B 2  O 8    | 01 | K J X Q Z |
C 2  P 2    | 02 | B C M P F |
D 4  Q 1    | 02 | H V W Y * |
E 12 R 6    | 03 | G         |
F 2  S 4    | 04 | L S U D   |
G 3  T 6    | 06 | N R T     |
H 2  U 4    | 08 | O         |
I 9  V 2    | 09 | A I       |
J 1  W 2    | 12 | E         |
K 1  X 1    +====+===========+
L 4  Y 2
M 2  Z 1

Valid words are any words that are 4+ that are available in this file, the official scrabble dictionary.

Tiles cannot be used twice. This means you can only have 1 word with a K, J, X, Q, and/or Z unless you use a blank tile to represent one of these letters.

I'm not sure how I'd do scoring on this. I want shorter code to score better, but I don't want a short piece of code that finds a lot less words to score better than a longer piece that finds many more words.

\$\endgroup\$
11
  • \$\begingroup\$ Meh. I don't like dependency on external files; are we allowed to load it, or even embed it into the source code? \$\endgroup\$ Dec 17 '13 at 20:00
  • \$\begingroup\$ as for finding more vs. shorter code, you could demand all words be found \$\endgroup\$ Dec 17 '13 at 20:19
  • \$\begingroup\$ @JanDvorak Any way to use it. It's a text version of the official scrabble dictionary, it seemed to be the most fitting word list for the task. "All words being found" might be hard, considering there are probably many combinations of words that would deplete all the tiles. It's a maximum of 25 words, (25 words, 4 letters each, 100 tiles), but I don't know if it's possible to use all tiles with just 4 letter words. After so many words, you might not have enough tiles to make an actual word, which means you'd either have to go back or accept that you're not using all the tiles. \$\endgroup\$
    – Rob
    Dec 17 '13 at 20:23
  • 5
    \$\begingroup\$ As currently described, this is a no-input task, which means that the answer can be precomputed and then the program only needs to decompress it. Consider rewriting it to take input (either of the word list or of the tiles available). \$\endgroup\$ Dec 18 '13 at 8:01
  • \$\begingroup\$ I suggest taking a list of tiles as input, loading the list of words from a predefined file and requiring all combinations / best combination to be found. Of course, if the input is the full list of tiles, the computation is going to take ages. I might allow preprocessing the word list outside the program itself (up to a certain point; a linearithmic growth?) \$\endgroup\$ Dec 18 '13 at 8:32
  • 1
    \$\begingroup\$ I suggest modifying this so that input is a list of tiles, limited to a full rack or less (therefore 4-7 tiles, since our minimum word length is 4). Input should be assumed to be valid based on the standard set of tiles (e.g.: it wont' have something like 3 J's or 4 G's). This would have some practical use for a player in a scrabble game to figure out their next move (though it does not take into account tiles available to them which are already on the board). \$\endgroup\$
    – Iszi
    Dec 18 '13 at 21:14
  • \$\begingroup\$ Alternative mode: Input is a list of tiles, maximum 96 (so that at least 4 are remaining in the set). Output only includes words (minimum 4 letters) which can be created without those tiles. This would be interesting as it provides words that may yet be created (though, again, not taking into account usable tiles on the board) at a given point in the game. \$\endgroup\$
    – Iszi
    Dec 18 '13 at 21:15
  • \$\begingroup\$ Output needs to be decided as either a list of all possible words, or only the highest-scoring word(s). Another enhancement may be to require that the list be sorted descending in order of score (if output is all words), then ascending alphabetically. There's no reason to take each program's output into account for scoring. Since everyone is expected to use the same dictionary, all programs' outputs should be identical (except perhaps in sorting, if that's left out of the spec). So, this should be Code Golf. \$\endgroup\$
    – Iszi
    Dec 18 '13 at 21:15
  • \$\begingroup\$ It's also worth noting that, as currently written, the task could just be to filter the given dictionary down to words which have 4 or more letters. By its very nature, the Scrabble dictionary should already exclude any words that cannot be made with a Scrabble set. \$\endgroup\$
    – Iszi
    Dec 18 '13 at 21:18
  • \$\begingroup\$ @Iszi it's not "what are all the words you can make", it's "what are all the words you can make, where every letter used depletes a tile". There's a max of 25 words if you can use all 100 tiles. \$\endgroup\$
    – Rob
    Dec 19 '13 at 16:40
  • \$\begingroup\$ I think I misunderstood the problem, then. I thought it was "all the words possible using a set of tiles" not "all the words possible, using only one set of tiles". Still, my point about code golf remains. There is an absolute maximum to the number of words (each with 4 or more letters) you can make with a single Scrabble set, and a finite number of permutations which can be used to hit that maximum. Every program written with this goal should end up with the same (or nominally similar) output. \$\endgroup\$
    – Iszi
    Dec 19 '13 at 16:56
0
\$\begingroup\$

Since this question is closed, I figured I'd post it here so further issues can be hammered out in Meta instead of the main site.

Known Issues:

  • Some rules seem a bit unclear to some users.
  • Clarification may be needed on what is needed to qualify for the "win percentage" bonus.
  • Win percentage bonus may not be enough to be a real incentive. (This may just depend on the language or implementation.)
  • Perhaps the win percentage bonus should be eliminated entirely, or maybe it should just be made a mandatory part of the spec.
  • It's been suggested to use a simple 1-9 numbering system for the board positions, instead of any sort of X,Y coordinates.
  • May want to allow some flexibility on the input format. (i.e.: Input must still specify the sequence of moves thus far, using whatever addressing scheme is specified in the spec, but leave the delimiters - or lack thereof - up to the developer.)
  • Exactly what is expected of the program, such as how it can figure out whose turn it is or what the output should be, seems to need some clarification.
  • Some test cases should probably be added.
  • Clarification may be needed on the matter of what parts of the game we can assume have followed the guide already.
  • Some flaws exist in the chart. (Two already mentioned in comments on the original post.) These should be identified and addressed so that proper expectations for those conditions are clearly set.
  • Original post said we would not have to account for null input (i.e.: X asking what their first move should be) but this might be a good enhancement to add.

I personally think this is a great challenge. So far, I've had a very hard time finding a lot of room for optimization and got up to probably 400 characters in PowerShell before I gave up (not even half-way through the chart yet) due to some of the above issues. I'd really like to see what some more serious golfers could do with this, once the spec is properly hammered out.


Overview

This is the XKCD tic-tac-toe cheetsheet:

enter image description here

It's rather big, I know. But it's also your most valuable resource in your challenge.

The challenge

Create a program (in your language of choice) that uses the Optimal Move Cheatsheet (henceforth OMC) to output the optimal move when given a sequence of moves.

The input

Your program will be fed a series of moves in the following fashion:

A3 A2 B2 C2 ...

Where the first combination is always X, the second O, and so on. The letter is the Y coordinate (A-C, A at the top) and the number is the X coordinate (1-3, 1 at the left).

You may assume that the given combination is following the OMC's suggestion for each move at least for the player asking for a recommendation. You can also assume that the input will never be null (at least one move has been made). You must:

  1. Figure out whether the next move is for X or O (you don't need to output this)
  2. Use the OMC to decide the next move
  3. Print the next move in the standard format A3

Optional:

You may also include the player's chance of winning (as a percentage) for 50 character discount on your score.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I think a 1-9 system would be easier than any XY system, but not by too much. The biggest issue I think is that if you go by the chart (rather than formulating your own algorithm that plays the same way) you have a ton of data to enter (there are several hundred squares in the two charts). Perhaps limit the input to only sequences starting A1 B2 (or 1 5 if you use telephone keypad numbering)? That's the center square in the X chart and the top left square in the O chart. \$\endgroup\$
    – Blckknght
    Dec 23 '13 at 5:14
  • \$\begingroup\$ @Blckknght Limiting the scope of the challenge makes it less interesting. Part of the challenge (if not the entire challenge) here is to find ways to shortcut the flow while still putting out accurate results. As for the 1-9 system, the simplification may be relatively trivial but it does help clear out some otherwise unneeded bloat since everyone will probably build in some conversion to a 1-9 system anyway to shorten the code. It also enables some other shortcuts where the same move suggestion applies to multiple situations which are mathematically related. \$\endgroup\$
    – Iszi
    Dec 23 '13 at 19:47
  • 1
    \$\begingroup\$ My point is that the chart data so dominates the code size that winning answers will pretty much have to ignore the data in the chart and use an AI. So the challenge becomes "write a Tic-Tac-Toe AI that plays exactly like this chart", which seems less interesting to me than "use (part of) this chart to make an AI with trivial code". I already have working code for the problem and bonus in about 200 non-golfed characters of Python, but it will require many 1000s of characters of data, even if I exploit some symmetries. Even if I was willing to type all that data, an AI will beat it, I'm sure. \$\endgroup\$
    – Blckknght
    Dec 23 '13 at 20:55
  • 1
    \$\begingroup\$ @Blckknght I'm pretty sure even a fairly straightforward implementation of the chart can be fit within about 5,000 characters - especially in a proper golfing language. IRRC, I'd finished the X portion of the chart in about 400 characters with PowerShell before I gave up on my first go at it. Even then, there was still plenty of room for optimization, and that's in a language which is far from optimal for golfing. Certainly, it's nice when you can bang out a quick answer in 15 minutes. But not every challenge has to fit in 500 characters or less. \$\endgroup\$
    – Iszi
    Dec 23 '13 at 21:12
0
\$\begingroup\$

Test for Irreducible Complexity (Check for Redundant Characters)

I may need some additional help coming up with the full spec for this competition. As of right now, this is just a concept.

Many interesting questions, such as the "42" question in this sandbox, involve finding the longest program which is not reducible. This means that no set of characters can be removed and still allow the program to function as desired.

The basic idea is that your program will test a Base Program to make sure that it contains no redundant characters. The input will consist of:

  • Base Program (in the same language as your answer)
  • Expected Output

Your program will simply evaluate all possible subsequences of the Base Program and verify that none of them give the Expected Output.

This challenge actually has a utility value to several other challenges. For example, it verifies the results of a "longest non-reducible"-type challenge. In addition, it could make sure that a golfed solution cannot be golfed further.

I assume that the winning criteria will be fastest program, as cycling through all the possibilities takes a long time.

Problems

A sequence of length N has 2^N subsequences. Even if each evaluation is done very quickly, it might be unfeasible to test any program with more than 20 or so characters in a reasonable amount of time.

\$\endgroup\$
8
  • \$\begingroup\$ Problem: some subsequences of legitimate answers may be pretty dangerous to the environment. You don't want to eval just everything. \$\endgroup\$ Dec 23 '13 at 16:59
  • \$\begingroup\$ @JanDvorak Yes that actually is a serious problem. To what extent is it possible to fix that? \$\endgroup\$
    – PhiNotPi
    Dec 23 '13 at 17:04
  • 1
    \$\begingroup\$ Forbidding any program with dangerous subsequences? :-) \$\endgroup\$ Dec 23 '13 at 17:05
  • 1
    \$\begingroup\$ A more reasonable (but very difficult) solution would be the requirement to implement a sandbox. \$\endgroup\$ Dec 23 '13 at 17:07
  • 1
    \$\begingroup\$ Even without dangerous behavior, the halting problem will be an issue: it's hard to tell whether a shortened program will terminate at all, especially for every conceivable input. \$\endgroup\$
    – MvG
    Jan 7 '14 at 23:49
  • \$\begingroup\$ Are you sure this is possible? The problem of testing if two functions/programs/turing-complete things are equivalent is undecidable - I'm fairly sure it's reasonable easy to constract a brainfuck program that you can't tell if you can remove even a single character. \$\endgroup\$ May 16 '21 at 4:44
  • \$\begingroup\$ Extending on my previous comment - Let's assume you have a solution to this. Take a brainfuck program you want to test if halts. Let it reduce it, now you have an equivalent irreducible program. Add +. in the end of it, and then try to reduce it again. If the code never halts, that +. is reducible and when you'll run it again it will be removed. Otherwise it's important, so it will be kept. The halting problem is undecidable, therefor this is undecidable. \$\endgroup\$ May 16 '21 at 4:54
  • \$\begingroup\$ You can also get its undecidablility from that in Unary it will tell you if a given program is minimal, which is known to be undecidable as well \$\endgroup\$ May 16 '21 at 5:25
0
\$\begingroup\$

Wordlist detector

You are to write a program which, given a list of words, constructs a regular expression to match all these words but nothing else. Both your program and the constructed regular expressions are to be as short as possible.

Input and Output

Input comes on standard input and consists of one line giving n, the total number of words, followed by n lines with one word each. The number of words will be less than 1000, the length of each word less than 30. Words will consist only of lower case ASCII letters, i.e. a-z. You may choose to ignore the first line and use EOF instead to end the list.

Output shall be written to standard output. It consists of a single line, giving a POSIX extended regular expression to match these words and no others. Since input for this regex is not restricted to letters only, elements like . or [^…] won't make too much sense, which limits the language in a natural way. You may choose whether you want to terminate the line with a newline or not. Programs may choose to print multiple lines of output, in which case only the last one will be used for scoring. So you might print intermediate results and continue searching for improvements.

Test cases

Each submission may be accompanied by one regular expression. When scoring the submissions, I'll use this regular expression to reconstruct a word list from it. The code to do this reconstruction can be found at the end of this post. The reconstructed word list must fit the input specification above in terms of word count and length. It would be nice if your own program would be able to regenerate that regular expression from the word list, but that is not a strict requirement. But please don't paste bogus programs just to submit a challenging regular expression, though.

These test cases will be collected and fed to all programs for scoring.

Scoring

The final score of each program will be the program size plus the size of all its generated regular expressions for the inputs collected from submitted answers, including the example from this question. So short code which produces too long results might get beaten by longer code which generates shorter expressions.

Does this still qualify as ?

Submissions which generate an incorrect regular expression for one of the test cases will be disqualified, as will those which don't terminate in the allotted time. You can use the input reconstruction program below to check whether a produced regular expression does encode the correct word list.

Requirements

All submissions are welcome, but in order to include your submission in the tournament, it must be executable with reasonable effort on my Linux machine. It shouldn't depend on any exotic libraries, or any specialized ones which take too much work away from your own program. It must operate in reasonable time, say no more than five minutes per input. Your output must be reproducible, so if you use randomization at some point, please seed the randomizer, and please don't terminate an improove loop by a timer measuring execution time or some such.

Tournament times

I'll run the first major tournament two weeks after posting this question. I'll include a table of the results in this question. I'll try to run tournaments repeatedly as late submissions arrive, but I'll not promise any regular schedule.

Example

An very simple example application would be in Python 3 (53 chars):

print('|'.join(input() for i in range(int(input()))))

And here is a test case which could be posted along with the program, although this program obviously doesn't generate exactly this concise output:

bann?ana|ap(fel|ple)|s[ou]n|[hs](a|ou)nd

The expansion of that expression could be turned into the following example input, which need not be posted as part of an answer since it can be deduced from the regular expression:

10
banana
bannana
apfel
apple
son
sun
hand
hound
sand
sound

Regex expander program

And here is a program to turn regular expressions into word lists, again written in Python 3.

#!/bin/env python3
concat = set(('',))
altin = set(('',))
altout = set()
prev = None
stack = []
regex = iter(input())
for ch in regex:
    if ch == '(':
        stack.append((concat, altin, altout))
        altin = concat
        altout = set()
        prev = None
    elif ch == ')':
        concat.update(altout)
        prev, altin, altout = stack.pop()
    elif ch == '|':
        altout.update(concat)
        concat = altin
    elif ch == '[':
        ch = regex.__next__()
        cls = []
        while ch != ']':
            if ch == '-':
                crange = range(ord(cls[-1]), ord(regex.__next__()) + 1)
                cls.extend(map(chr, crange))
            else:
                cls.append(ch)
            ch = regex.__next__()
        prev = concat
        concat = set(w + c for w in prev for c in cls)
    elif ch == '?':
        concat.update(prev)
        prev = None
    elif ch >= 'a' and ch <= 'z':
        prev = concat
        concat = set(w + ch for w in prev)
    else:
        raise Exception("Illegal input")
if stack:
    raise Exception("Unclosed group")
concat.update(altout)
words = sorted(concat)
print(len(words))
print('\n'.join(words))

This is restricted to the part of regular expression syntax which I expect for this answer. If you have good reason to use something I did not consider, feel free to do so although I will likely have to update this code to cope with it. If you find a bug, please let me know.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ This is just Meta regex golf under the constraint that the two lists between them cover all possible words. Given that some people are tackling that existing question on that basis, this would qualify for closing as a duplicate. \$\endgroup\$ Jan 8 '14 at 8:45
0
\$\begingroup\$

Rhymalator

(at the point, it's just something that came to me before i wake up, so it may need some adjusting, and i'd like some feedback as to if this could be fun)


The code challenge is to write a program that takes as input a calculation in Reverse Polish Notation and outputs the result. It must at least implement + - * /. It So far so easy, but to make it fun and "artistic", the following restriction applies:

  • The source code must rhyme when read. Example in PHP

    $iterator = str_split($a);
    foreach ($iterator as $key=>$value){
        if ($key > 3){
            ++$virtue;
        }
    }
    

    (the rhyme is on value-virtue)

  • Lines whitout readable characters count as whitespace (the two lines with } in the example)

\$\endgroup\$
2
  • \$\begingroup\$ How does that example rhyme...? \$\endgroup\$
    – Doorknob Mod
    Jan 25 '14 at 12:54
  • \$\begingroup\$ @DoorknobofSnow well, i'm not really a poet, that's why i propose it as a challenge for others :p. if you have a better example i'll replace it \$\endgroup\$
    – Einacio
    Jan 27 '14 at 15:58
0
\$\begingroup\$

Implement Kalah

The game of Kalah is a two-player board game in the Mancala family. Your implementation must:

  • Identify the active player ("Player 1" or "Player 2")
  • Display board state (in format specified below)
  • Accept input to allow that player to move (using index system below)
  • Announce a winner ("Player N wins")

Overview

Each player has a line of six spaces, called houses, and one additional space called a store. Each space holds seeds, which move from house to house in a counter-clockwise direction. The objective is to fill your store with seeds.

You must represent the board in the following two-row format with stores offset, where HH is a house and SS is a store:

SS HH HH HH HH HH HH
   HH HH HH HH HH HH SS

The top row represents the number of seeds in player #1's spaces, and the bottom row represents the seeds in player #2's spaces. The S in each row is the respective player's store (player #1's is top-left, #2's is bottom right). Single-digit values should include a leading space.

In this challenge, user-input will identify each house numerically. Use a left-to-right, indexed-from-one scheme for both sides:

S 1 2 3 4 5 6
  1 2 3 4 5 6 S

Note that the players' stores are not numbered, because seeds placed in the store never move out.

Rules

Wikipedia has a good summary of the game and its rules:

  1. At the beginning of the game, three seeds are placed in each house.

  2. Each player controls the six houses and their seeds on his/her side of the board. His/her score is the number of seeds in the store to his/her right. [Clarification: from our perspective, player 1's store is to the left, player 2's store is to the right.]

  3. Players take turns sowing their seeds. On a turn, the player removes all seeds from one of the houses under his/her control. Moving counter-clockwise, the player drops one seed in each house in turn, including the player's own store but not his/her opponent's.

  4. If the last sown seed lands in the player's store, the player gets an additional move. There is no limit on the number of moves a player can make in his/her turn.

  5. If the last sown seed lands in an empty house owned by the player, and the opposite house contains seeds, both the last seed and the opposite seeds are captured and placed into the player's store. [Clarification: moves that end on an opponent's empty house end normally without a capture.]

  6. When one player no longer has any seeds in any of his/her houses, the game ends. The other player moves all remaining seeds to his/her store, and the player with the most seeds in his/her store wins.

Example

(Parenthetical text should not appear in actual output.)

Player 1
 0  3  3  3  3  3  3
    3  3  3  3  3  3  0
> 2                      (prompt arrow and line break
                          are purely optional)
 Player 2
 1  1  0  3  3  3  3
    4  3  3  3  3  3  0
> 4

Player 2  (P2 gets a bonus turn from rule #4)
 1  0  3  3  3  3  3
    4  3  3  0  4  4  1
> 5

Player 1  
 1  0  3  3  3  4  4
    4  3  3  0  0  5  2
> 4

Player 1  (P1 captures P2's seeds in space 1)
 6  0  4  4  0  4  4
    0  3  3  0  0  5  2
...

Player 2
12  0  0 10  0  1  0
    0  0  0  0  0  1 13
 > 6

Player 1 wins            (because the non-finishing players gets
                          all remaining seeds on their side, it's 23-14)

Meta question: Would this be improved by removing some of the rules?

\$\endgroup\$
1
  • \$\begingroup\$ Do the players run the game once and then take it in turns to take moves, with the process ending only when the game ends? Or do they run the program once per move? \$\endgroup\$ Jan 30 '14 at 10:06
1
62 63
64
65 66
121

You must log in to answer this question.

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