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

4479 Answers 4479

1
34 35
36
37 38
150
2
\$\begingroup\$

A Picture is Worth a Thousand Words

The average word is four characters/bytes long. So a picture, according to the old saying, is worth 4 kilobytes. But how complicated can that picture get?

Using any language or length of code you want, generate an image exactly 4,000 bytes in size with the highest possible entropy. You may use any standard image format. Your score will be the compression ratio when your image is compressed as a .zip file. For example, an image that compresses to 2,000 bytes will score 2, but if it expands to 4,100 bytes it will score 0.9756. Lowest score wins.

\$\endgroup\$
8
  • \$\begingroup\$ What image formats are allowed? \$\endgroup\$
    – wastl
    Aug 13, 2019 at 2:41
  • \$\begingroup\$ @wastl All of them. \$\endgroup\$
    – Purple P
    Aug 13, 2019 at 3:19
  • \$\begingroup\$ should the program output to a file or can it print a list of bytes? \$\endgroup\$ Aug 13, 2019 at 12:20
  • 3
    \$\begingroup\$ Interesting challenge. .zip is a file format, not a compression method, though. You'll need to specify what compression method is used -- DEFLATE, LZMA, etc. -- because that could drastically affect the scoring. \$\endgroup\$ Aug 13, 2019 at 12:51
  • \$\begingroup\$ @SuperStormer It shouldn't matter as long as you upload the image file. \$\endgroup\$
    – Purple P
    Aug 13, 2019 at 15:03
  • \$\begingroup\$ @AdmBorkBork How about gzip? I would specify version 1.6 because that's what I have. \$\endgroup\$
    – Purple P
    Aug 13, 2019 at 15:04
  • \$\begingroup\$ If you say something like gzip 1.6 using DEFLATE with default settings that should probably suffice. \$\endgroup\$ Aug 13, 2019 at 15:58
  • \$\begingroup\$ I didn't test this but I feel that any uncommon image format of raw data will have the optimal score (assume the compressor is smart enough to store without compression) \$\endgroup\$
    – DELETE_ME
    Aug 16, 2019 at 4:42
2
\$\begingroup\$

Black Hole Evaporation

Background: In empty space, occurring all the time, there are pairs of particles that appear and then, usually soon after, cancel each other out. At a certain distance from a Black Hole, it's possible that a pair of particles might spontaneously appear and, if the distance is just right, one of the particles will fall into the Event Horizon while the other escapes off into space, never getting a chance to cancel each other out. The exit of those particles is Hawking Radiation. Eventually, this process causes the entire Black Hole to evaporate away.

Challenge

Given a string of numbers, emit the negative of the single digit number closest to, in front of, the infinity symbol ∞ (the event horizon), and continue emiting it until there are no digits left in front of the infinity symbol. Then print the rest of the string masking each character uniquely and different from the masked character (burst of energy that might take place at the final instant), excluding any infinity symbols.

Test cases

Input:                      Output:
111∞4567                    -1 -1 -1 jkl;
3∞                          -3
3-145∞962                   -5 -4 1 -3 ™©®
4-567-9∞1-23                 9 -7 -6 5 -4 😐😈😎😻
2-1∞                        1 -2
34∞67∞89                    -4 -3 9876
-123∞456                    -3 -2 1 ♫♪#
6-6∞6                       6 -6 ä
48120∞                      0 (or -0) -2 -1 -8 -4
---5∞555                    5 オゼヰ

Challenge rules

  • Anything after the first infinity symbol can be ignored as it has fallen into the Black Hole and we know nothing more about it anyway until after evaporation, where the information is a bit scrambled.
  • The code should only expect numbers, negations, and infinity symbols. No decimal points or other symbols. The input can be an array, list, etc..., but each character must be separate, including the negation and infinity characters.
  • A negation only applies to the single digit immediately after it. See the test cases above.
  • You may mask the remaining characters after evaporation with any character set of your choice, as long as the resulting character is different from the masked character, and each character in the resulting output is unique. For languages limited to smaller character sets (or type constraints), characters may repeat after each possible unique character has already been utilized in the output.
  • You may use the '_' symbol instead of the '∞' symbol.

General rules

  • This is , so shortest code in bytes in its respective language wins.

  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN (with the specification above)/STDOUT, functions/method with the proper parameters and return-type, full programs.

  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (TIO).
\$\endgroup\$
19
  • \$\begingroup\$ I'm thinking of expanding this to all alpha numeric characters. \$\endgroup\$
    – ouflak
    Aug 7, 2019 at 19:04
  • \$\begingroup\$ What does it do if there is a single number after the infinity symbol? \$\endgroup\$ Aug 8, 2019 at 6:53
  • \$\begingroup\$ I'll update the rules and the test cases. Curiously, I already sort of demonstrated that case by having nothing after the infinity symbol. Nice catch. \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 6:55
  • \$\begingroup\$ If 121 remains after evaporation, is reversing that string an acceptable scrambling? \$\endgroup\$
    – Adám
    Aug 8, 2019 at 7:21
  • 2
    \$\begingroup\$ Any particular reason to use ? Adding Unicode into the mix is an unnecessary complication for many languages. Maybe allow substituting _? \$\endgroup\$
    – Adám
    Aug 8, 2019 at 7:22
  • \$\begingroup\$ @Adam, "If 121 remains after evaporation, is reversing that string an acceptable scrambling" Absolutey! Our understanding of what happens to the information after Black Hole evaporation is still under much debate. It is entirely possible that the result of scrambling might result in the same information. We just don't know. \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 7:46
  • \$\begingroup\$ @Adam, "Any particular reason to use ∞? Adding Unicode into the mix is an unnecessary complication for many languages." Yeah I thought about that. It can even be excluding factor, which I don't like. I really want that infinity symbol though.... I'll have a think about it, but any suggestions like yours are welcome. \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 7:49
  • \$\begingroup\$ @Adam, "If 121 remains after evaporation, is reversing that string an acceptable scrambling?". After re-reading through the Information Paradox, I think the answer is 'no'. '121' should definitely end up different. I'll have to find some way to re-word the challenge, and I can be talked out of this. This requirement seemed rather innocent, but as I'm trying to code this up in my head, it can get complicated. \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 8:01
  • 2
    \$\begingroup\$ The connection between the background and the task is not very clear. The comment about information suggests that you have a much clearer idea which you haven't included in the question. There's no need to overload the question with back story, but a link to a more detailed explanation might make it feel less arbitrary. \$\endgroup\$ Aug 8, 2019 at 8:23
  • \$\begingroup\$ @PeterTaylor, I've been mulling over your comment and I'm not sure what to include. Links to the Information Paradox or Hawking Radiation, or both? \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 8:41
  • \$\begingroup\$ Probably both. AIUI, the infinity symbol represents the event horizon, the symbols to the left represent virtual pairs which become Hawking radiation, the symbols to the right represent the captured information, the emission of the inverted symbols to the left corresponds to the emission of Hawking radiation, and the shuffling of the symbols to the right corresponds to the information paradox. (I'm not sure without checking some reference why there's anything left to the right after evaporation). It would be good to sketch the correspondences and have some "Further reading". \$\endgroup\$ Aug 8, 2019 at 8:46
  • \$\begingroup\$ @PeterTaylor, Ok thanks. The final stage of evaporation might release a detectable packet of energy (which has yet to be seen or is even theoretically certain), so that's kind of what that represents. There might be something left over afterwords, or maybe not. When I get the chance, I'll edit some links in and parenthesize some metaphors in there as well. \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 8:55
  • 1
    \$\begingroup\$ @ouflak Regarding you can use it but allow substitution. Btw, _ is the infinity symbol in the J language. \$\endgroup\$
    – Adám
    Aug 8, 2019 at 9:27
  • \$\begingroup\$ @Adám, What about, "If your language has a built-in substitute for ∞, you may use that. If your language can't use Unicode, or use it efficiently, you may use the '_' symbol instead." Does that sound fair and inclusive enough? \$\endgroup\$
    – ouflak
    Aug 8, 2019 at 10:03
  • 1
    \$\begingroup\$ @ouflak What if your language's infinity is inf? That's three symbols, so it complicates matters a lot. "use it efficiently" is unclear? Does that include causing higher byte count? How about just: You may use the _ symbol instead of . \$\endgroup\$
    – Adám
    Aug 8, 2019 at 10:06
2
\$\begingroup\$

caN it be acrOnymised?

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I shall hereby refer to Code Golf and Coding Challenges as DANGLE \$\endgroup\$
    – Quinn
    Aug 19, 2019 at 18:32
  • 1
    \$\begingroup\$ Can the acronym contain lowercase letters? (For an example of that, see BSoD.) \$\endgroup\$
    – user85052
    Aug 20, 2019 at 4:58
  • \$\begingroup\$ @A__ While actual acronyms can, I'm going to say that the acronym will always be in complete uppercase, for simplicity's sake. And I've added in constraints on the length of the inputs. \$\endgroup\$ Aug 20, 2019 at 9:13
2
\$\begingroup\$

BotNets KotH

Controller, Example and Submission Template now added


flavor text not yet written

This is a web-based JS KotH where submissions have 2 parts, a Worker Bot and a Controller Bot. The goal is to have the most gold at the end of the game, by killing other bots and collecting gold found on the grid, while navigating the grid and surviving.

Worker Bots

A Worker Bot is a class(ES6 or ES5) based on this format:

class YourWorkerBot extends WorkerBot {
    performAction(message) {}
    sendMessage(x, y, surroundings) {}
}

Each botnet has 20 Worker Bots. For every botnet, its worker bots are

Method Descriptions:

  • constructor(index): sets the color that the controller displays the bot as
  • performAction(message): returns an action(described below).
  • sendMessage(x,y,surroundings): x and y are zero-indexed coordinates. surroundings is a flat array of the 5x5 area around the bot. returns message(string) to send to controller bot

Actions

Each move is formatted as a 2 element list([action, param]) where action is a string

  • Movement: formatted as ["move", square] where square is an integer that represents the square you want to move to, using the same index as the surroundings object. You can only move one square orthogonally or diagonally. Moving onto a square with a coin will collect the coin.
  • Kill: formatted as ["kill", square] where square is an integer that represents the square you want to attack, using the same index as the surroundings object. You can only kill a bot one square orthogonally or diagonally. If you kill a square with no bot, you do nothing. You get half the coins(rounded down) of the bot you attacked.
  • EMP: formatted as ["emp",undefined]. It causes all bots including itself in the 7x7 surrounding area can't move next turn. This costs 3 coins.
  • Any invalid action is treated as you doing nothing.

Surroundings

The surroundings object will be a flat array of the 5x5 area around you, starting from the top left corner and going left to right and top to bottom. The grid below shows how the indexes of the array map to the actual grid area. Each square will be either a string, where "B" is a bot, "C" is a coin, "E" is an edge(not a valid move target) and "" is empty.

 0  1  2  3  4
 5  6  7  8  9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24

Controller Bot

A Controller Bot is a class(ES6 or ES5) that extends the following class:

class YourControllerBot extends ControllerBot{
    constructor(locations){
         super(locations)    
         this.storage=""
    }
    sendMessage(messages,index){
         return ""
    }
}

Each botnet has only 1 Controller Bot.

Method Descriptions

  • constructor(locations): locations is an array of the initial locations([x,y]) of the worker bots.sets initial storage value
  • sendMessage(messages,index): messages is a list of lists of the messages sent by all the worker bots(not just your own), always in the same order and grouped by botnet. returns message to its worker bots whose index is index.

The Game

The arena will be a 100x100 grid with 100 random coins scattered around it. Each game will have 1000 rounds and will have up to 15 randomly selected botnets. Every round, 10 coins will spawn at a random unoccupied spot. Every worker bot will get 1 turn per round. Each botnet's worker bots will perform an action in the same order for the entire game, but the order in which botnets take turns is randomized every round. Every turn, all the worker bots' sendMessage methods will be called(not just the worker bot taking the turn). After that, the controller bot's sendMessage method will be called. Finally, the worker bot's performAction method will be called and the action will be executed. This will repeat for every worker bot in a round.

Scoring

Each botnet's score is the sum of the coins collected by each of the worker bots. Botnets are ranked by most score.

Controller(WIP)

https://botnets-koth.firebaseapp.com

Example

function sampleBotnet() {
    class SampleControllerBot extends ControllerBot {
        constructor(locations) {
            super(locations);
            this.storage = "";
        }
        sendMessage(messages, index) {
            let surrondings = messages.find(message => message[0] === index)[1];
            let otherBot = surrondings.findIndex(
                (square, i) =>
                    square === "B" && [6, 7, 8, 11, 13, 16, 17, 18].includes(i)
            );
            if (otherBot !== -1) {
                return ["kill", otherBot];
            }
            let coin = surrondings.findIndex(
                (square, i) =>
                    square === "C" && [6, 7, 8, 11, 13, 16, 17, 18].includes(i)
            );
            if (coin !== -1) {
                return ["move", coin];
            }
            let validMoves = [6, 7, 8, 11, 13, 16, 17, 18].filter(
                x => surrondings[x] === ""
            );
            return [
                "move",
                validMoves[Math.floor(Math.random() * validMoves.length)]
            ];
        }
    }
    class SampleWorkerBot extends WorkerBot {
        performAction(message) {
            return message;
        }
        sendMessage(x, y, surroundings) {
            return [this.index, surroundings];
        }
    }
    return {
        name: "SampleBotnet",
        color: "red",
        controllerBot: SampleControllerBot,
        workerBot: SampleWorkerBot
    };
}

#Submission Template
```javascript
/* eslint constructor-super:0,no-this-before-super:0,no-unused-vars:0*/
import ControllerBot from "./src/scripts/ControllerBot.js";
import WorkerBot from "./src/scripts/WorkerBot.js";

//copy the part below
function yourBotnet() {
    class YourControllerBot extends ControllerBot {
        constructor(locations) {
            super(locations);
            this.storage = "";
        }
        sendMessage(messages, index) {
            return [];
        }
    }
    class YourWorkerBot extends WorkerBot {
        performAction(message) {}
        sendMessage(x, y, surroundings) {}
    }
    return {
        name: "YourBotnet",
        color: "",
        controllerBot: YourControllerBot,
        workerBot: YourWorkerBot
    };
}

Rules

  • Standard Loopholes apply
  • Bots cannot modify or add global variables
  • Bots cannot call controller functions or other bots' methods
  • Bots cannot read or modify other bots storage
  • Bots may not access the internet
  • I may disqualify any bot which does anything I deem to be cheating.

Sandbox

  • Is the bar to entry too high?
  • Can the current turn/round system be improved?
  • Any better names for the 2 bots/title?
  • Is there enough room for creativity?
  • Would it be better if I merged the 2 classes into one class?
  • Is there anything broken with the spec?
\$\endgroup\$
7
  • \$\begingroup\$ How many workers per controller, and how many controllers per game? Also, are controllers supposed to be able to message to all workers, or just their own? \$\endgroup\$ Aug 12, 2019 at 4:05
  • \$\begingroup\$ @UnrelatedString should be fixed \$\endgroup\$ Aug 12, 2019 at 13:25
  • 1
    \$\begingroup\$ performAction(surroundings, message) { return eval(message); } sendMessage(surroundings) { return JSON.stringify(surroundings); } There are, of course, countless other ways to circumvent the size restrictions. I also find said restrictions quite brutal. Additionally, I don't see the point of worker-side storage. Finally, the whole document is difficult to read - giving a short summary of the goal at the beginning would go a long way. Nitpick: it's "surroundings", not "surrondings". \$\endgroup\$
    – Alion
    Aug 16, 2019 at 10:46
  • \$\begingroup\$ Since your latest revision is "fixed spec": a) The WorkerBot class is invalid - calling super there is a syntax error. Do you want to show the base class that should be extended, or a template of how to extend said class? The second option makes more sense in my opinion, although the text right above seems to indicate otherwise. b.1) Under "Controller Bot", what is index? How is it chosen? b.2) What do bots that don't have the specified index receive as the message? b.3) Are there duplicate worker bot indexes possible? If not, please fix sendMessages descripiton. \$\endgroup\$
    – Alion
    Aug 18, 2019 at 8:21
  • \$\begingroup\$ c) Under 'The Game', sendMessages instead of sendMessage for controller bot. d) I'm worried about the split between worker bot and controller bot. I don't see how it would be anything but a minor nuisance under the current rules. Previously it was code-golf, but that's gone now. I'm also aware that it is supposed to be the essence of this challenge, so I'm hoping there's just a big misunderstanding somewhere. Perhaps it'll become clear once (b) is addressed. \$\endgroup\$
    – Alion
    Aug 18, 2019 at 8:24
  • \$\begingroup\$ I really like this idea! I think the combat could be improved (kill seems like it would just give too much power to the bots that go first in a turn), but the EMP is really creative (you might want to reduce it's range to what a worker can see, to reduce unintentional friendly fire). So that you don't need to order based on randomness, you can use a sort of "two pass" system where you first create a list of all the moves workers make, then apply them in a way that doesn't give any advantage to the worker who goes first (continued) \$\endgroup\$ Aug 19, 2020 at 21:47
  • \$\begingroup\$ (continuation) For example, all EMPs would be applied, then all kills, then all movement. If two bots attempted to move into the same spot or kill each other, you could base it off of some secondary factor like number of coins/gold or most friendly workers in the vicinity. Good luck with the challenge, it seems really cool! \$\endgroup\$ Aug 19, 2020 at 21:49
2
\$\begingroup\$

Up side down keyboard

Jono 2906 wants you to create a translator from plain Australian to up-side-down text after inventing a keyboard dedicated to typing up-side-down text, since they still want to demonstrate that their keyboard is powerful after failing to program in their keyboard.

However, they want your implementation to be typed with their own keyboard, since they also want to get used to programming using their keyboard.

Input/Output

The whole ASCII character set mapped to their up-side down variation (the up-side down " is a double ,):

 !"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~

 ¡,,#$%⅋,)(*+'-˙/
0ƖᄅƐㄣϛ9ㄥ86:;>=<¿
@∀qƆpƎℲפHIſʞ˥WNO
ԀQɹS┴∩ΛMX⅄Z]\[^‾
,ɐqɔpǝɟƃɥᴉɾʞlɯuo
dbɹsʇnʌʍxʎz}|{~

The rest of the characters are kept as-is(yes, the unprintable characters are in the ASCII character set). The characters that are larger than 0x7f will be mapped back by subtracting the character code by 128.

If you are using a character that is larger than 256, modulo the character's character code by 128 before checking the availability.

Rules

  • No standard loopholes, please.
  • Input and output will be taken with our standard input methods.
  • If you force Jono 2906 to change a key on their keyboard (allowing typing your specified character), you will get a penalty of +2 bytes for every key you add.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ I don't think I quite follow. Are we given a character as input and need to output the upside-down version? \$\endgroup\$ Aug 27, 2019 at 14:06
  • 1
    \$\begingroup\$ (1) I still find the question confusing even as to the basic functionality required. The "Input/Output" section seems to me to say that it's a Kolmogorov problem, but the "Rules" section talks about input. (2) If a character remapping is involved, the question should list Unicode codepoints for the characters in question, and should list test cases with Unicode codepoints. (3) Is the last rule saying that the program must work as is and after mangling? Or is it just a gimmick ("Post your code upside down, but it only has to work the right way up")? \$\endgroup\$ Aug 28, 2019 at 8:39
  • 1
    \$\begingroup\$ "The rest of the characters are not kept as-is(yes, the unprintable characters in the ASCII character set)." should this not be there? As for that entire paragraph, if I understand correctly: unprintable characters < 33 (as well as 127) will be kept as is; printable ASCII characters displayed will be converted to upside down; other printable ASCII characters and any character above 127 will be modulo-128 before doing the same check. \$\endgroup\$ Aug 28, 2019 at 9:24
  • 1
    \$\begingroup\$ As for the last rule: we can only use those upside down characters in our source code, and when converting it to regular it should also work? So both programs ABC and ∀qƆ should work exactly the same? \$\endgroup\$ Aug 28, 2019 at 9:25
2
\$\begingroup\$

Wrong position

I typr re;atively accuratrly, but so,etimes I made a whole nlock of text illegible by shifting a key right. So I need a program that corrects my text back to its original meaning.

Rules

  • You have to left shift on a standard English QWERTY keyboard.
  • Whitespace do not count for the procedure before left-shifting and are kept as-is in a standard left-shifting procedure. If the key is the leftmost letter/symbol on a keyboard(i.e. The ~key, Q key, A key, Z key.), the key is kept as-is. If you reach a control character while left-shifting (Caps lock and Shift), their effects will not be triggered and the character before left-shifting is kept.
  • This is a contest; the shortest answer wins.
  • Both the input and the output shall be given via our default methods.

Representation of a subset of the QWERTY keyboard that you will need

The two lines connected are possible values of the key: shifted/unshifted.

~!@#$%^&*()_+
`1234567890-=

QWERTYUIOP{}|
qwertyuiop[]\

ASDFGHJKL:"
asdfghjkl;'

ZXCVBNM<>?
zxcvbnm,./

(Space)
(Space)

Input

The input will always be a non-empty string conforming the rules above.

Output

The output will be the input string corrected to the originally intended meaning.

Examples:

Yjod ,sfr yjr, imjsppu/ -> This made them unhappy.
vpfr hp;g -> code golf

Feedback

I think this is not a duplicate; however, is any part of this challenge unclear or needs improvements?


\$\endgroup\$
4
  • 1
    \$\begingroup\$ I think you are mixing up left and right. Clearly, ~, Q, A and Z are leftmost keys, NOT rightmost. And your examples appear to be left-shifting, not right-shifting. \$\endgroup\$
    – wastl
    Sep 7, 2019 at 11:27
  • \$\begingroup\$ "I think this is a duplicate" - so why sandbox it? Or did a not go missing in editing? \$\endgroup\$ Sep 9, 2019 at 8:36
  • \$\begingroup\$ Thank you. Predominantly my mouse was not working again, I didn't get around to fix this. \$\endgroup\$
    – user85052
    Sep 9, 2019 at 8:56
  • \$\begingroup\$ "sonetimes" and "vlock" are shifted the wrong way. \$\endgroup\$
    – Hiatsu
    Sep 9, 2019 at 16:20
2
\$\begingroup\$

Path to Path Rearrangement

In the xkcd comic "Map of the Internet", a special fractal path was used, similar to this:

0  1  14 15
3  2  13 12
4  7  8  11
5  6  9  10

Ascii art version:

-0---1  14---15--16 19--20---21
     |   |       |   |       |
 3---2  13---12 17---18 23---22
 |           |           |
 4   7---8   11 30---29 24---25
 |   |   |   |   |   |       |
 5---6   9---10 31  28--27---26
                 |
58---57 54---53 32  35--36---37
 |   |   |   |   |   |       |
59  56---55  52 33---34 39---38
 |           |           |
60---61 50---51 46---45 40---41
     |   |       |   |       |
63---62 49---+---47 44--43---42
\|/

This path, known as the Hilbert curve, has some interesting properties. Among other things, it can be flipped diagonally without changing most of those properties.

-0   3---4---5  58--59---60  63->
 |   |       |   |       |   |
 1---2   7---6  57---56 61---62
         |           | 
14---13  8---9  54---55 50---49
 |   |       |   |       |   |
15  12--11---10 53--52---51   48
 |                           |
16---17 30---31--32--33 46---47
     |   |           |   |
19---18 29---28 35---34 45---44
 |           |   |           |
20  23---24  27 36  39---40  43
 |   |   |   |   |   |   |   |
21---22 25---26 37---38 41---42

Your task is to apply this transformation. Given a space on one path, find the corresponding location on the other. For example, the fourth space in the top path is located at (0, 2), which is the 14th space along the second path, so the correct output for 4 is 14.

As with similar challenges, this can be done as:

  • An infinite sequence along the second path of the corresponding locations along the first path
  • A function/program that takes a numbered position on the first path and returns the distance to that point on the second path.
  • A function/program that takes a numbered position on the first path and returns all path 1 positions along path 2 to the point specified.

The first 64 terms of this sequence (zero indexed, add one to each for one indexed) are:

0 3 2 1 14 15 12 13 8 11 10 9 6 7 4 5 58 57 56 59 60 63 62 61 50 49 48 51 52 55 54 53 32 35 34 33 46 47 44 45 40 43 42 41 38 39 36 37 26 25 24 27 28 31 30 29 18 17 16 19 20 23 22 21

This is code golf, so shortest code in bytes wins.

Meta Questions

  • Do I need a better description of the paths?
  • Is the challenge itself clear?
  • Any other issues I should fix before posting?
\$\endgroup\$
2
  • \$\begingroup\$ The default output formats for sequence challenges can be found in the tag wiki \$\endgroup\$
    – Jo King Mod
    Sep 10, 2019 at 4:03
  • 1
    \$\begingroup\$ (1) Related. (2) I don't find "Find the location along the second path of a point on the first path" at all clear. It seems to be talking about output in 2D. I think it would be clearer to say "Given an index on the first path, output the index of the same coordinate on the second path". And then give a worked example (e.g. 4 vs 14). \$\endgroup\$ Sep 10, 2019 at 10:53
2
\$\begingroup\$

Maximize the Hello, world's in code permutations

In this task you should output this exact string: hi orb (because Earth is a sphere). However, here is the catch: you must output as many hi orb's as possible in all of your code permutations. Identical permutations do not count(e.g. aa's permutations count as one permutation)

Say you have a program abc that outputs this string. You should try your best to make acb, bac, bca, cab, and cba (i.e. the permutations of abc) also output this exact string.

Rules

  • No standard loopholes, please.
  • Input/output must obey our standard methods.
  • Your score is simply the factorial of the length of your code. You shall also present the following score: The score is counted in the negative of the length of your source code divided by the number of permutations that your code generates; (expression: -(source length/permutations).) Of course you want to keep your score as low as possible.
  • All comment characters in your language are disallowed, in order to avoid collapsing into a radiation-hardening challenge.
  • If you are using the filename as data, the filename must also count in the permutations.
  • The source code length should be <1000. (Don't ask why, it's just an attempt of avoiding abusing the source code length.)

Feedback

  • Is it detailed enough?
  • Is the input/output rules clear enough?
  • Do I need any more information?

I don't think this is a duplicate because nobody has asked a question tagged with both permutation and hello-world. However, I worry that this challenge will collapse into a radiation-hardening challenge if you comment out a single character and then make sure that this will produce the same result, therefore making it a flavored version of this question and close to a duplicate.


\$\endgroup\$
10
  • \$\begingroup\$ Can't you just extend your score by increasing your byte counnt, as long as you have some commented out part or no-op? \$\endgroup\$
    – Jo King Mod
    Sep 19, 2019 at 8:50
  • \$\begingroup\$ Unneccecary NOPs are disallowed, and at least 1 permutation of your code must only contain relevant code and nops. is rather vague, since no-ops aren't really defined, nor is this challenge really that possible to increase score if you don't have no-ops, otherwise it will turn into a duplicate of the normal Hello World question \$\endgroup\$
    – Jo King Mod
    Sep 19, 2019 at 9:25
  • \$\begingroup\$ This reminds me of a challenge I sandboxed a while ago, but deleted since it was clear it would produce only trivial answers \$\endgroup\$
    – Jo King Mod
    Sep 19, 2019 at 9:27
  • \$\begingroup\$ code-golf scoring usually has lowest score (=code length) wins. If you break with that convention, you should mention it in the rules. I think a big problem with this is that for any non-trivial answer (Like H in HQ9+), the proof of correctness of the score is almost impossible, because unlike radiation-hardening, the amount of variants increases factorially instead of linearly with the code length. \$\endgroup\$ Sep 19, 2019 at 11:52
  • \$\begingroup\$ Hmm, it is okay, I will make the score negative then. I believe a program running the permutations of a string (not counting repeated ones) and evaluating them to check the result will be sufficient. Hmm, that's why the submittor needs to golf their code: to allow others to check their answers. \$\endgroup\$
    – user85052
    Sep 19, 2019 at 12:09
  • \$\begingroup\$ That's where it's unfeasible: The highest-scoring answer in the challenge you linked has 96 bytes. That's 9.9*10^149 permutations to check if they output the correct result. Even assuming your implementation is the fastest possible, that would take years, just for that single answer. You can't brute-force determine the score, but using mathematical trickery to try and calculate the score by hand will be arduous and prone to errors. \$\endgroup\$ Sep 19, 2019 at 13:10
  • \$\begingroup\$ I don't think the limitations you have put are going to prevent this from falling apart. For example, this Pyth program works for any permutation of the code where only characters after the third " are permuted. Completely filling up the code allowed will achieve a score exceedingly close to zero. I don't think that is what you want, but I'm not really sure you can fix it (like what happened to Jo King), sorry. \$\endgroup\$ Sep 19, 2019 at 18:38
  • \$\begingroup\$ @FryAmTheEggman this particular snippet fails the rule that all code needs to be relevant. However, even if we tighten the rule to all code being life and necessary, that is, in one permutation, all code is executed, and a deletion of any statement resulting in the code not outputting "Hello World" any more, you can still cheese the challenge by bloating the code. The only way to stop that would be to change the scoring method to also use the factorial of the byte count, but then A) HQ9+ is unbeatable and B) It's a math challenge because you have to calculate the amount of viable permutations \$\endgroup\$ Sep 20, 2019 at 10:06
  • 2
    \$\begingroup\$ Instead of helo word, wouldn't it make more sense to just use a different phrase like greeting earthlings or something along those lines? I agree with @AdmBorkBork that helo just looks weird. I do think it shouldn't be hello world to prevent builtins, so helo word is already better, but it still looks weird and will raise questions for sure.. \$\endgroup\$ Sep 20, 2019 at 12:38
  • \$\begingroup\$ I don't understand the scoring. If we're scored only on the factorial of the length of code, why does it matter how many permutations output hi orb? I would figure that the number of ways that is output should factor into the scoring somehow... \$\endgroup\$ Sep 20, 2019 at 14:11
2
\$\begingroup\$

The Celestial Bureaucracy

Posted

\$\endgroup\$
2
  • \$\begingroup\$ This sounds like a lot of fun. When the exam is asked, is it possible to know which bot gave the exam? \$\endgroup\$ Sep 18, 2019 at 11:58
  • 2
    \$\begingroup\$ You are given the ID of the bot via the parameter for ask, which allows you to identify if you've interacted with that bot before and if it's the Jade Emperor (because his ID is always -1). You won't get the name - if you want to identify the bot, you'll have to analyse its question and answer pattern. \$\endgroup\$ Sep 18, 2019 at 12:08
2
\$\begingroup\$

Creep Spread Territorial Control (WIP)

(probably)


Blah blah blah flavor blah blah blah something about Starcraft blah blah blah

Gameplay

Initial State

There is a 150x150 grid of square cells with approximately 7500 random cells missing in a symmetric Perlin noise pattern. There are four creep spread factions competing for dominance of this territory beginning as a single cell 10 cells in from a corner of the grid (one faction per corner). Each faction starts with 50 energy. The board does not wrap around at the edges.

Expansion

Each turn, each faction earns 1 point of energy for each controlled cell plus 20 base energy. This energy is used for expansion. How much a cell costs to expand to depends on how many cells controlled by the same faction are in the Moore neighborhood of the target cell.

  • 0 neighbors: cannot expand to this cell
  • 1 neighbor: 50 energy
  • 2 neighbors: 20 energy
  • 3 neighbors: 12 energy
  • 4 neighbors: 8 energy
  • 5 neighbors: 5 energy
  • 6 neighbors: 3 energy
  • 7 neighbors: 2 energy
  • 8 neighbors: 1 energy

There is no limit to how many cells can be expanded to in one turn other than energy costs. All expansions occur simultaneously. If two or more factions attempt to claim the same cell on the same turn, the one with the most neighbors of its own faction will claim the cell. If there is a tie, none of the factions claim that cell. Players whose expansions failed due to competition will not be refunded. Factions may expand onto each other's territory, stealing ownership of the cell.

Game End

The game lasts 10,000 turns or until there is only one faction remaining, whichever happens first. The winner is the faction with the most owned cells. Ties are broken by remaining energy.

The overall winner will be resolved with a randomized pool where each bot plays an equal number of games followed by 12 games of the top 4 contenders. (one for each possible corner positioning)

Coding

Write a bot that plays this game

  • Bots must be deterministic. As a way to provide localized pseudorandomness, a random integer between \$0\$ and \$2^{32}-1\$ will be passed to the bot, which will be seedable in the controller.
  • Bots have perfect information of the current state of the board, which turn it is, and their own energy, but not the energy of other players.
  • Bots may not remember anything between turns, but may initialize constants and utility functions at the beginning of each game.

The list of desired expansions is ordered. As soon as an invalid expansion target cell is encountered (whether by cost or lack of same-faction neighbors) in this list, the rest of the list will be ignored and a warning will be logged.

\$\endgroup\$
11
  • \$\begingroup\$ So if I build at 0,1 and 1,0 on the same turn while having a cell at 0,0, the cost would be 2000, yeah? Are failed expansions refunded? Also, I think having a source of randomness would be good. \$\endgroup\$
    – Veskah
    Sep 13, 2019 at 17:40
  • \$\begingroup\$ @Veskah, that would cost 2000, correct. I'll add some rules about when failed expansions are refunded. \$\endgroup\$
    – Beefster
    Sep 13, 2019 at 19:38
  • \$\begingroup\$ Suggestions: 1. Maybe allow expanding to own territory too? Could be used as a defensive mechanism when you can predict that you are going to be attacked. (should be thought about, could be bad) 2. Maybe set a limit on how many cell expansions can happen per turn to avoid exponentially expansion? I'm thinking that a bot which gains some advantage might get unstoppable when it is unlimited. \$\endgroup\$
    – Night2
    Sep 14, 2019 at 7:33
  • \$\begingroup\$ 3. More clarification in rules about expansions, for example if player 1 and 2 have a tie on this turn for cell X and they both go for it, but player 1 also goes for a neighbor of cell X in same turn, will player 1 win? (@Veskah mentioned another scenario too) 4. I would suggest using JavaScript so more people can write and run the code (anyone with a browser can do it), also a controller with some helper functions could be nice, for example a function which returns expansion cost for a cell in an optimized way to avoid tens of different implementations for same common action. \$\endgroup\$
    – Night2
    Sep 14, 2019 at 7:39
  • \$\begingroup\$ 5. "Bots have perfect information of the current state of the board.", does this include current energy value of other players? \$\endgroup\$
    – Night2
    Sep 14, 2019 at 7:45
  • \$\begingroup\$ @Night2 1 Interesting. It seems a bit fiddly. 2 This should actually come out to a quadratic expansion rate since where you can expand to is derived from perimeter, which grows linearly. 3 All expansions are resolved simultaneously (as in Conway's Game of Life), so player 1 does not win that tie. 4 Javascript is the likely plan since I intend to have a significant graphical component. 5 I'll have to think about it. That could be rather interesting as 'private' information. \$\endgroup\$
    – Beefster
    Sep 15, 2019 at 3:00
  • \$\begingroup\$ 6. Proposal to spice things up: board is randomly generated, with some cells being unavailable for expansion. Uniform random, Perlin/Simplex noise, cellular automaton-based cave generation, etc. 7. Will the bots have access to the turn counter? 8. Maybe rotate and/or mirror the board provided to the bots so that each bot starts at, for example, the top-left corner from its perspective? \$\endgroup\$
    – Alion
    Sep 15, 2019 at 10:36
  • \$\begingroup\$ 9. Allow bots to pre-calculate some data on load or game start. This will allow people to speed up their bots. Especially useful if you end up implementing 6. \$\endgroup\$
    – Alion
    Sep 15, 2019 at 10:47
  • \$\begingroup\$ @Alion 6 That sounds pretty interesting. I'll probably expand the board slightly in that case. 7 Yes, they'll know what turn it is. 8 I don't think that adds much. I'm probably going to have to make copies of the board every turn anyway to make it impossible to cheat on accident though... 9 Seems reasonable. \$\endgroup\$
    – Beefster
    Sep 16, 2019 at 0:39
  • \$\begingroup\$ "Bots must be deterministic. As a way to provide localized pseudorandomness, a random integer ... will be passed to the bot, which will be seedable in the controller.". Why not make a custom random function available or override the default random generator and make the controller generate and handle the seeds? For example in JavaScript users can still use the normal Math.random(), but you can use this to make it deterministic: davidbau.com/archives/2010/01/30/… \$\endgroup\$
    – Night2
    Sep 21, 2019 at 11:21
  • \$\begingroup\$ @Night2, yeah. I'll probably do that since I'm going to have to use an RNG library anyway. \$\endgroup\$
    – Beefster
    Sep 22, 2019 at 2:32
2
\$\begingroup\$

Turing-complete regex subset

It's widely known that a programming language is one iff it's capable of addition of natural numbers and primality testing. In practice, this criterion has a high accuracy for distinguishing Turing-complete languages too.[citation needed]

Cops' challenge

Choose any of the programming languages available on tio.run. Write a regex that will define a subset of this programming language. The subset must still match the definition, though ideally this should be far from obvious.

Write two programs in this language that match this regex:

  1. Take two natural numbers, a and b, as input. Output a + b. The program must work for 0 ≤ a + b < 215.
  2. Take a natural number n as input. Output whether the number is prime. The program must work for 0 ≤ n < 215.

The behavior outside of this range is undefined. This means that you can output the correct answer, a cute cat ASCII art, an error, an invalid answer, invoke nasal demons, or anything else you can, or cannot, imagine.

Regex come in multiple flavors. Choose one. You can choose any flavor available on regex101, or Retina.

In your answer, include:

  • the programming language and regex flavor you chose
  • the regex delimiter and flags you chose (for example: //gm; does not apply to Retina)
  • the regex you wrote and its byte count
  • the byte counts of your two programs

Keep the programs hidden. If 7 days pass without anyone cracking your answer, you may reveal your two programs by editing them into your answer. This will make your answer safe. Your score then becomes your regex's bytecount (lower is better). Before your answer is safe, your score is positive infinity.

Robbers' challenge

Write two programs that prove the subset to be a valid programming language. The rules that apply here are the same that apply to the cops. Additionally, your programs must not exceed the cops' in length.

When you crack an answer, post your programs to the robbers' thread.

Meta questions

The above will be posted as the cops' thread, with the robbers' thread simply linking to it.

  • Any improvements to challenge structure? I've never done this before.
  • Do you see any loopholes that need addressing?
  • Are the allowed regex flavors reasonable?
  • Duplicates?
\$\endgroup\$
9
  • \$\begingroup\$ I think this is a duplicate of codegolf.stackexchange.com/questions/136150/… \$\endgroup\$ Sep 22, 2019 at 18:11
  • 1
    \$\begingroup\$ @pppery Hmm. These are definitely pretty similar. On the other hand, regexes might allow more interesting answers. \$\endgroup\$
    – Maya
    Sep 22, 2019 at 18:25
  • 1
    \$\begingroup\$ I'm not convinced this is a dupe since most of the interesting work here is in selecting the regex rather than in choosing a sequence, though I think the other challenge is cleaner. I think the optimal scoring regex will usually be to make an "unhash" that produces the appropriate programs. Unfortunately I don't have any suggestions at the moment to help fix that, but if you can then I think this is alright. \$\endgroup\$ Sep 22, 2019 at 18:32
  • \$\begingroup\$ @FryAmTheEggman I can't see what you mean by "unhash" here. Could you elaborate? \$\endgroup\$
    – Maya
    Sep 22, 2019 at 18:36
  • \$\begingroup\$ Consider this program which performs the first task. The regex that matches only programs like this would be short but but not very informative. I think doing this but making guessing the magic number arbitrarily hard would usually be the best approach in a given language. \$\endgroup\$ Sep 22, 2019 at 18:43
  • \$\begingroup\$ @FryAmTheEggman Like, /^\.vC\d+$/? I think that making it complicated enough would take quite a lot of bytes. \$\endgroup\$
    – Maya
    Sep 22, 2019 at 19:02
  • \$\begingroup\$ The point is that the number could be manipulated, so I could pad my program arbitrarily until I got a number that let me write a regex like ^...(2|10|76|345?)*$. That's neither very long nor easy to crack. \$\endgroup\$ Sep 22, 2019 at 19:06
  • \$\begingroup\$ I like the idea of the challenge but I feel including the bit about Turing completeness is a bit of a red herring, it only really distracts from the challenge. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 22, 2019 at 21:30
  • \$\begingroup\$ To elaborate the particular part I like is regex selection part. I do agree that my challenge is a bit cleaner otherwise. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 22, 2019 at 21:31
2
\$\begingroup\$

Calculate the Ultraradical

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I'd recommend removing the text with a strikethrough; I think it is just confusing. "Accurate to 6 significant digits" isn't a very good validity criterion since it would require testing each and every possible input the program could handle. I'd recommend saying it has to be that accurate for your test cases but not be hardcoded for them, or something like that. \$\endgroup\$ Sep 19, 2019 at 19:33
2
\$\begingroup\$

Moved.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ For the tiebreak, what does code with the fewest bytes mean, given that we're outputting a county assignment? \$\endgroup\$
    – xnor
    Oct 7, 2019 at 22:24
  • \$\begingroup\$ @xnor - I modified the scoring mechanism to not require tie breaks. Thanks to this modification, I expect the code submissions to be much more interesting. \$\endgroup\$ Oct 8, 2019 at 17:06
  • \$\begingroup\$ I like your new assignment score and no longer having a code golf tiebreak.The leave-one-out looks kind-of complicated and might take a long time to run-- is there a way to simplify it? The challenge looks a lot more intimidating that when I last commented, though the idea looks the same. I guess you want to make sure people actually write code that kind-of generalizes rather than possible finding an assignment by hand. Maybe also consider something with the standard deviation in assignment place of the max-min ratio so there's also an incentive to try to balance populations in the middle? \$\endgroup\$
    – xnor
    Oct 8, 2019 at 22:48
  • \$\begingroup\$ @xnor - Great points, thanks! I simplified things by cutting the number of leave-one-out instances by a factor of 10. (I selected these 10 counties based on political geography considerations.) I also toned down the math speak to make the challenge less intimidating. I thought about standard deviation instead of max-min, but max-min is closer to how we enforce one person, one vote in practice. \$\endgroup\$ Oct 9, 2019 at 2:20
2
\$\begingroup\$

I came across this little web game Drench Its a fairly mindless game , I wrote a small JS snippet to play this game for me in the background of my browser, it cycles through and clicks on the 6 possible moves

let ind =0;
let games =0;
let wins =0;
let lastMoves = "";
setInterval(function(){
  if (jQuery('.moveNum').text() != lastMoves) {
    lastMoves = jQuery('.moveNum').text();
    ind++;
    ind = ind%6;
    jQuery('.pbutton:nth('+ind+')').click();
  } else {
    games++;
    if ((jQuery('.moveNum').text()*1)) {wins++;}
    jQuery('#myCanvas').click();
  }
},200);

This Strategy wins about 3% of the time My question is, is there a more optimal strategy that will allow me to win a greater % of the time (without looking at the board)?

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Hi and thanks for using the sandbox! Though this is a bit unusual for this site, I think your question is on-topic, just far too broad. "Can I do better" just isn't something you can really ask on the SE network. I think the best way for you to move forward is to fully explain the game in the body of your post, and then score submissions based on their win percentage. \$\endgroup\$ Sep 21, 2019 at 19:37
  • 1
    \$\begingroup\$ I really like the idea though - I think win% is the way to go \$\endgroup\$ Sep 23, 2019 at 15:20
  • 1
    \$\begingroup\$ Make this a code-challenge? To verify, you can run it for, for example, 500 times and calculate the winning percent? \$\endgroup\$ Oct 13, 2019 at 8:49
  • \$\begingroup\$ Coded this up in p5.js, you can play it here hoppingmad9.github.io/dench Happy to convert it to pure js if needed and could add an interface to get the board state and input moves. \$\endgroup\$
    – Sam Dean
    Oct 18, 2019 at 12:14
  • \$\begingroup\$ oops, well I guess the code golf version can be called "Dench" not "Drench". I thought "Dench" was a weird name \$\endgroup\$
    – Sam Dean
    Oct 18, 2019 at 15:29
  • \$\begingroup\$ Probably needs a time limit for each turn to prevent people trying every single possibility of moves \$\endgroup\$
    – Sam Dean
    Oct 25, 2019 at 15:39
2
\$\begingroup\$

Create a safe crossing.


Given a string/number/array of any two distinct characters make the "squarest" 2D array that allows "someone" to cross from left to right or top to bottom "stepping" only on whichever character you have chosen as your stepping stone

or

Make the "squarest" array possible that contains a complete row or column of stepping stone characters. (clearer but takes away the fun story-ness)


"squarest" meaning smallest difference between the dimensions of the 2D array.

Input

  • A string/number/array of your choosing consisting only of your two chosen distinct characters. So no error checking needed. Allow true/false values if input is array?
  • input will have at least 1 stepping stone character so that a valid solution is always possible 1 by x or x by 1
  • a minimum length of x? needed? might make it easier if there's some weirdness with very short arrays in the algorithms people come up with
  • the last row can be incomplete to allow for prime number length inputs and to more easily allow non trivial 1xX/Xx1 answers

Output

The output should be the dimensions of the array

  • and specify the row or column to use?
  • print your 2D array so that the path can be seen graphically?

Test Cases

100100100 -> 3x3 array

100
100
100

11111000 -> 4x2 or 3x3 - 3x3 is squarer so is correct

1111    111
1000    110
        00

11000011000101001001 -> 5x4

11000
01100
01010
01001

1000000000000 -> 12x1 - trivial as only 1 stepping stone

100000000000

010111 -> 3x2 or 2x3 - either acceptable as both are only "1" away from square

010    01
111    01
       11

This is code-golf so the shortest code in bytes wins.

Issues

  • allow diagonal crossings? does that make it a lot harder?
  • need a lot more test cases I think?
  • input spec
  • output spec
  • better/more tags?
\$\endgroup\$
2
\$\begingroup\$

ASCII Sum of your code

Encoding is nice, adding things is also nice. Let's do both !

Your task will be to create a program that read itself, convert every of its character into ASCII values and return the sum of those numbers.

Example

Let's say your program is Hello, world !. Convert every character into ascii values

H  e   l   l   o   ,  (space) w   o   r   l   d   (space) !
72 101 108 108 111 44 32      119 111 114 108 100 32      33

Now, sum everything into a meaningless very useful value

72 + 101 + 108 + 108 + 111 + 44 + 32 + 119 + 111 + 114 + 108 + 100 + 32 + 33
= 1193

Here it is, Hello, world! returns 1193 !

Rules

  • The code have to read itself and calculate the result
  • Standard loopholes are not allowed
  • This is codegolf, so the fewer bytes wins.
  • Non-standard languages with non-ASCII characters should use their own codepage's encodings (Thanks for @Veskah for this rule)

Feedback

  • Is the challenge clear enouth ?
  • Is there an already existing challenge like this one ?
  • is this considered as a duplicate of this challenge ?
\$\endgroup\$
5
  • 2
    \$\begingroup\$ I would probably have non-standard languages use their codepage's encodings (pretty much all of them should be 8 bytes) to crunch their output. The big hammer approach would be to ban non-ASCII languages but I would not recommend that. \$\endgroup\$
    – Veskah
    Oct 23, 2019 at 14:06
  • 3
    \$\begingroup\$ Requiting the code to read itself and do the calculation is a non-observable requirement. Since it seems you don't want programs that just hardcode the value, I think the best way to be just to require the program take in an input string to use. Regardless, I don't really see room for interesting golfing in the challenge, since pretty much any normal-ish language has built-ins to take ASCII values and compute sums, and weird languages that don't have already done these as subtasks for many many challenges. \$\endgroup\$
    – xnor
    Oct 25, 2019 at 0:52
  • \$\begingroup\$ @xnor Does this challenge with string input already exist ? \$\endgroup\$ Oct 25, 2019 at 7:06
  • 2
    \$\begingroup\$ I don't remember an exact one, but I'm finding very close ones: averaging ASCII values and summing then counting binary 1's, which was closed as a duplicate of one without the character adding. I also found an unrestricted quine challenge with the same task as yours. So I think there's a good chance this would be closed as a duplicate either way. \$\endgroup\$
    – xnor
    Oct 25, 2019 at 7:11
  • 1
    \$\begingroup\$ Yup, the last one is quite the same as mine. Duplicate it is then. \$\endgroup\$ Oct 25, 2019 at 7:13
2
\$\begingroup\$

It's slashing time

(Inspired by Seven Slash Display)

You're lying in bed, awake. Sleepily, you turn your head to the alarm clock and read what time it is. Since you're lying down, the clock is facing diagonally, making it difficult to read. You decide to write a program to help you out (hey, you're awake anyway).

Given a "slashed" seven-segment display, output what time it is in 24-hour format.

      /\
       /\
    /\  /
    \ \
   . \/
 /\ .
  /
  \/

2:03

You can choose where to place the : between the numbers (for example, evenly spaced as above or left-aligned as below, etc.), but the : must be present.

Some further examples:

       \
        \
    /\
     /\
  / . /
  \/\.
 \  /
  \

15:31

       \
      \/\
     \
      \
   \.
    \.

1:14

Here are the precise digit shapes:

/\
\ \
 \/

 \
  \


/\
 /
 \/

/\
 /\
  /

 \
\/\

/
\/\
  /

/
\/\
 \/

/\
  \

/\
\/\
 \/

/\
\/\
  /

Rules & Standard I/O boilerplate

  • The time will always be valid. For example, you'll never receive something like 30:25 or 7:99 or the like.
  • You're allowed to pad the input with whitespace however necessary (e.g., padding it to always be a rectangle with trailing spaces).
\$\endgroup\$
3
  • \$\begingroup\$ Input always a valid time? Can we shift the dots? \$\endgroup\$
    – Veskah
    Oct 29, 2019 at 19:01
  • \$\begingroup\$ 2 in 2:03 is not aligned with other digits :( \$\endgroup\$
    – tsh
    Oct 31, 2019 at 8:53
  • \$\begingroup\$ @tsh Indeed it wasn't. Thanks for the correction! \$\endgroup\$ Oct 31, 2019 at 15:11
2
\$\begingroup\$

Room volume as a function of paint on the walls/ceiling

Task: Write a function that will take in the size of a room (height, width, and length) and a number of paint layers (given that the layers are of a consistent thickness) and return the area of free space in the room after that many layers of paint are applied.

Requirements:

  • Return the final area left in the room after the paint layers are added
  • should be able to run on a room of any size
  • The answer must account for the decreasing area in the room as each layer is applied.
  • number of layers and paint layer thickness should both be inputs
  • must account for walls and ceiling
  • standard loopholes are disallowed

The winner is determined via byte count

\$\endgroup\$
1
  • 1
    \$\begingroup\$ How thick is each coat of paint? Also, do you mean return the volume of free space in the room? \$\endgroup\$
    – girobuz
    Nov 14, 2019 at 4:30
2
\$\begingroup\$

List of integers to pairs ?? Any suggestions for the title ??

Write a function or a full program taking a list of non negative integers numbers L that outputs a pair of numbers [X , Y] such that X %( Y + i ) == L [ i ] .

Output specifications

  • You can output X Y in any order, just indicate it and be consistent.
  • X Y are also unsigned integers, obviously Y must be greater than 0 to avoid modulo 0 errors.
  • If your language doesn't support 0 indexed list you can consider X %( Y + i ) == L [ i + 1 ] ?? Any suggestions how to handle this ??

Example

[ 1, 2, 3 ] => [ 11, 2 ]

 11 %( 2 + 0 ) = 1
 11 %( 2 + 1 ) = 2
 11 %( 2 + 2 ) = 3

[ 10, 2 ] => [ 98, 11 ]

 98 %( 11 + 0 ) = 10
 98 %( 11 + 1 ) = 2

Test cases

[ input ] , [ output ] pairs

[ 0, 1, 2 ] ,  [ 5, 1 ]
[ 1, 2 ] ,  [ 5, 2 ]
[ 1, 2, 3 ] ,  [ 11, 2 ]
[ 1, 2, 3, 4, 5 ] ,  [ 59, 2 ]
[ 4, 3, 2, 1, 0 ] ,  [ 9, 5 ]
[ 6, 12, 18 ] ,  [ 3318, 18 ]
[ 27, 18, 9 ] ,  [ 279, 28 ]
[ 3, 9, 27 ] ,  [ 4059, 26 ]
[ 2, 4, 8, 16 ] ,  [ 8584, 14 ]
[ 0, 0, 0, 0, 0, 0 ] ,  [ 60, 1 ]
[ 1, 1, 1, 1 ] ,  [ 61, 2 ]
[ 120, 20 ] ,  [ 12220, 121 ]
[ 10, 2 ] ,  [ 98, 11 ]
[ 9, 8, 7, 0 ] ,  [ 1339, 10 ]
[ 0, 1, 4, 9, 2, 10, 4, 15, 10, 5, 0, 16, 12, 8, 4, 0, 22, 19, 16, 13 ] ,  [ 100, 10 ]
[ 9, 99, 90, 81, 72, 63, 54, 45, 36, 27 ] ,  [ 999, 99 ]

Rules

  • Input/output can be given by any convenient method.
  • You can print it to STDOUT or return it as a function result.
  • Either a full program or a function are acceptable.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

\$\endgroup\$
7
  • \$\begingroup\$ For the testcases I think you can omit the outer parenthesis and the trailing comma. Furthermore I'd talk about nonnegative integers instead of unsigned integers. \$\endgroup\$
    – flawr
    Nov 17, 2019 at 16:44
  • \$\begingroup\$ But I have another question: Is this problem always solvable? \$\endgroup\$
    – flawr
    Nov 17, 2019 at 16:44
  • \$\begingroup\$ @flawr thanks I'll fix then. For the second question Idk.. Numbers increase extremely, I made a program for solving the problem and also a program to do the reverse(X,Y to list) I may do some test for each X,Y to a certain number.. \$\endgroup\$
    – AZTECCO
    Nov 17, 2019 at 17:48
  • \$\begingroup\$ I don't think [0,0,1,1] has a solution (consider the parity of X) cc @flawr \$\endgroup\$
    – H.PWiz
    Nov 17, 2019 at 17:53
  • \$\begingroup\$ @H.PWiz sadly yes \$\endgroup\$
    – AZTECCO
    Nov 17, 2019 at 18:45
  • \$\begingroup\$ @flawr and H.PWiz so if it's not always solvable do I have to delete this challenge? \$\endgroup\$
    – AZTECCO
    Nov 17, 2019 at 18:47
  • 1
    \$\begingroup\$ I dunno, you could guarantee that the input is solvable. Or you could ask a different (harder) question instead: "Is there a solution?" \$\endgroup\$
    – H.PWiz
    Nov 17, 2019 at 19:06
2
\$\begingroup\$

Create a block maze solver AI

A block maze is a maze in which goal is to complete a pathway by adding blocks.

It starts like this :

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

# is a block (which can be crossed). . is empty space (which cannot be crossed).

The goal is to connect top-left corner S to the bottom-right corner E. Diagonals are not allowed.

S....
.....
.....
.....
....E

One possible solution for the example above is to add three blocks like this :

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

Think about a man who want to cross a river with crocodiles . using huge stone blocks #.

The task is to create a program that take a grid as input and return a solution as output.

Scoring

The sum of all blocks required to solve all solutions in a 1.000 test case file I will provide.

The winning program is the one that use the fewest blocks to solve all mazes.

Rules

  • All grids are 25 x 25.
  • Start / end points are always top-left / bottom-right corners. There is always a block on those points.
  • There is always one guaranteed solution (which can be found by filling all empty spaces)
  • Program must be entirely deterministic; pseudorandom solutions are allowed, but the program must generate the same output for the same test case every time. If two programs take the same number of steps (e.g. they both found the optimal solutions), the shorter program will win.

The program should return the solution as a sequence of blocks x-y coordinates (the coordinates of blocks to add to solve maze) in the format of your choosing :

11-3;15-6;19-12   

Meta

  • I cannot think of a simple algorithm that returns an optimal (best possible) solution in a reasonable time. I expect programs to use some heuristics to get non-optimal/near-optimal solutions. I made the grids 25 x 25 to make it challenging enough and prevent simple solutions like brute force.
  • Is this a duplicate? There is lot of related questions but I couldn't find anything related to block maze.
  • The tags are . Anything else?

EDIT : as AlienAtSystem pointed out in comments, there is an optimal algorithm for all cases. I made some tests: even a slightly modified Dijkstra's algorithm will work (it will find shortest path in a short time). I will not post this challenge as it is trivial. I leave it here in case someone else would have same idea.

\$\endgroup\$
11
  • \$\begingroup\$ By fewest total steps, do you mean cumulatively? \$\endgroup\$
    – Corsaka
    Nov 20, 2019 at 10:07
  • \$\begingroup\$ I mean the sum of all blocks. If solution for maze01 use 4 blocks and solution for maze02 use 5 blocks, it is 4+5 = 9 blocks in total. The lowest is the best. Someone who has 7+1=8 blocks will win. I have edited answer. \$\endgroup\$
    – tigrou
    Nov 20, 2019 at 10:37
  • \$\begingroup\$ You should allow people to have any output format as long as it has x first, y second. None of the mazes are duplicate. I can't think of any other tags. This should be good to post. \$\endgroup\$
    – Corsaka
    Nov 20, 2019 at 10:49
  • \$\begingroup\$ Should we add a test suite of some sort? Or how are you going to verify the score of a submission? But in general the challenge looks clear. A few questions: I assume there are some test cases among the 1000 requiring us to go right/up for the optimal solution, instead of only going left/down? Are the input-characters strict, or could we also use for example 012 for @.x respectively as integer-matrix? One other relevant tag: [path-finding] \$\endgroup\$ Nov 20, 2019 at 13:25
  • \$\begingroup\$ @KevinCruijssen I am planning to provide a program to validate solutions. right/up : some mazes might be shorter to solve that way but it is not allowed. The goal is go from top-left to bottom-right (not to cross from left to right). character set : programs should use the same characters as the test file. Anyway, using 012 might be a good idea (I might update the test file with such chars). There is no @ character in the test file since the start / end position are always the same. \$\endgroup\$
    – tigrou
    Nov 20, 2019 at 14:31
  • \$\begingroup\$ @tigrou Ah ok, so @ is not part of the input. In that case a binary-matrix with just 0s and 1s would be a suitable input format I guess. As for the right/up: I meant it for an input like this pastebin. With this maze you could walk from the top-left to bottom-right with just 2 x insertions (at the _ positions), but you'd have to travel up and left in the path from the top-left to bottom-right. But if I understand correctly we only travel right and down, so this would be the solution (with 4 insertions at _) instead? \$\endgroup\$ Nov 20, 2019 at 18:38
  • 1
    \$\begingroup\$ @KevinCruijssen : both solutions you posted are valid. You can go up / down / left right at any moment. \$\endgroup\$
    – tigrou
    Nov 20, 2019 at 18:42
  • \$\begingroup\$ I can think of an algorithm that should be optimal for all test cases. This could result in the tie-breaker problem if other people realize it, too. \$\endgroup\$ Nov 22, 2019 at 6:32
  • \$\begingroup\$ @AlienAtSystem : optimal algo : is it because of my test cases (which have some flaws) or the maze challenge in general ? \$\endgroup\$
    – tigrou
    Nov 22, 2019 at 8:20
  • 1
    \$\begingroup\$ @tigrou In general. It can be translated into a shortest path challenge over a considerably smaller graph. While A* wouldn't work on that one, other algorithms will. This wouldn't be short in terms of bytes, although I suspect not that much compared to other approaches, given that some part tasks need to be done by everyone. \$\endgroup\$ Nov 22, 2019 at 9:35
  • 2
    \$\begingroup\$ I think you don't need to give up entirely right away. While this doesn't work as test-battery challenge because it's too easy to get everything right, it should be good for posting as generic code golf. \$\endgroup\$ Nov 22, 2019 at 13:36
2
\$\begingroup\$

OEIS A125959

https://oeis.org/A125959 is a sequence I submitted. It is the following array, which then repeats:

1 2 3 4 5 6 7 8 9    
2 4 6 8 1 3 5 7 9    
3 6 9 3 6 9 3 6 9    
4 8 3 7 2 6 1 5 9    
5 1 6 2 7 3 8 4 9    
6 3 9 6 3 9 6 3 9    
7 5 3 1 8 6 4 2 9    
8 7 6 5 4 3 2 1 9    
9 9 9 9 9 9 9 9 9

This is a rather useful array for quickly calculating the digital root of the product of any two numbers (i.e the iterative sum of the digits of the product). See the OEIS link if you're interested in the details.

The challenge is to print the array in the shortest number of bytes.

Input

None

Output

The above array. It can be output as strings with new lines, or as a nested array, or an array of strings; but not as a single-line sequence (i.e. the 2d-nature of the array must be reflected in your output).

\$\endgroup\$
4
  • 4
    \$\begingroup\$ So it's the multiplication table mod 9, except 0s are 9's? \$\endgroup\$
    – xnor
    Nov 25, 2019 at 12:58
  • \$\begingroup\$ @xnor is it? I hadn't spotted that before. Does that stop it being an interesting challenge? \$\endgroup\$ Nov 25, 2019 at 13:49
  • 1
    \$\begingroup\$ I believe it does (because it is "create a 10x10 table of the function (-~a*-~b-1)%9+1" now). \$\endgroup\$ Nov 25, 2019 at 14:05
  • 2
    \$\begingroup\$ I think it makes it too similar to generic print-a-multiplication table challenges, but others might disagree. \$\endgroup\$
    – xnor
    Nov 26, 2019 at 2:10
2
\$\begingroup\$

Times have changed!

(pun intended)


Preface

As mathematics progressed, mathematicians agreed upon the 'order of operations', to prevent mathematical expressions from becoming ambiguous.

Given the expression \$7 \times 6 + 5 \times 3\$ we know to first evalulate multiplication, giving \$ 42 + 15\$, which is equal to \$57\$.

But what if another group of mathematicians had agreed to evaluate addition before multiplication? This expression would become \$ 7 \times 11 \times 3\ = 231\$: which is different from our answer by an error of \$305\%\$!


The Challenge

Given a mathematical expression containing + (addition), * (multiplication), and the digits 0123456789, we can find:

  • \$E_1\$ - the 'real' value of the expression, when multiplication takes precendence.
  • \$E_2\$ - the 'alternate' value of the expression, when addition takes precedence.

Your task is to write a program or function which, given a string representing an expression, calculates and outputs the percentage error, \$\frac{|E_1 - E_2|}{E_1} \times 100\$.


Rules

  • WIP.
\$\endgroup\$
2
  • \$\begingroup\$ Related \$\endgroup\$
    – Chas Brown
    Dec 1, 2019 at 22:33
  • \$\begingroup\$ @ChasBrown do you think it's similar enough to call this challenge a dupe? \$\endgroup\$
    – FlipTack
    Dec 27, 2019 at 14:14
2
\$\begingroup\$

Bake the cookie

Quick intro

So i was playing cookie clicker yesterday, and I thought about something. We keep producing cookies, without any loss. What if your cookies failed? This is where I thought about a clicker that would cook a cookie. Don't click too much, or the cookie will be overcooked!

Task

Your task will be to create a function that will "bake" a cookie :

  • Your function will have to randomly select a number between 5 and 10 : it will establish the cooking duration of your cookie (and so, the number of time you'll have to call the function to cook your delicious cookie).
  • Each time you call that function, it will iterate the baking process of your cookie.
  • Your function should return "Undercooked" if your cookie is not fully cooked, "Overcooked" if you ... overcooked it, and "Cooked" when the cookie is baked just right.

Example

Since I'm bad at explaining things, an example will show you more clearly what needs to be done. Let's call my function bake() :

bake()    // The random number generated is 6, so i need to call my function 6 times
Undercooked

bake()
Undercooked

bake()
Undercooked

bake()
Undercooked

bake()
Undercooked

bake()    // We hit the 6th function call, the cookie is baked.
Cooked

bake()    // The 7th call overcooked the cookie. Congratulation, you ruined it.
Overcooked

Rules

  • The random number of iterations has to be set the first time you call the function. It has to be between 5 and 10 (inclusive).
  • A cookie has to be undercooked before being cooked, and has to be cooked before being overcooked. The 3 steps have to be reachable. A cookie can't uncook itself, therefore you can't go from cooked to undercooked, or from overcooked to cooked (it's too late, you ruined the cookie anyway).
  • The function can have as many parameters as you please.
  • Classic rules apply, no standard loopholes
  • This is codegolf, so the shortest code wins.

Meta

  • Is the challenge clear enough ?
  • Should I go with this method to iterate the "baking" process ?
  • Are there some rules I could add to make it more exciting ?
  • Does this challenge exist already ?
  • Should we bake pies instead ?
\$\endgroup\$
3
  • \$\begingroup\$ I'm assuming bake() will take no parameters and will have to store the count somehow, which means you might want to include some rules about file and global variable I/O. I also did a small editing pass. \$\endgroup\$
    – Veskah
    Dec 2, 2019 at 16:14
  • \$\begingroup\$ @Veskah I never thout about restricting bake()'s parameters, gonna edit the rules to include this particulatiry. Also, thanks for the edits. \$\endgroup\$ Dec 3, 2019 at 8:12
  • \$\begingroup\$ I don't think I understand what you are trying to accomplish. Why do you refer to the submission always as a function? Could it not be a program? Similarly, your edit to allow arbitrarily many parameters conflicts with the general tone that seems to imply that we should be storing state between calls. I think you will want to try explaining the task simply, perhaps even to the level of a non-programmer. \$\endgroup\$ Dec 8, 2019 at 19:47
2
\$\begingroup\$

Posted

\$\endgroup\$
3
  • \$\begingroup\$ I don't think this is possible? Surely you can't tell what direction is involved with the mirrors, e.g. /1, can you tell if the pointer started on 1 going east vs / going north? \$\endgroup\$
    – Jo King Mod
    Dec 18, 2019 at 9:10
  • \$\begingroup\$ @JoKing Hm yeah I think your right. I will try a little more but you are right that mirrors can't be used. \$\endgroup\$
    – Wheat Wizard Mod
    Dec 18, 2019 at 15:06
  • \$\begingroup\$ @JoKing I actually do think this is possible. \$\endgroup\$
    – Wheat Wizard Mod
    Dec 18, 2019 at 15:15
2
\$\begingroup\$

Title: When is Hannukah?

Input

The input will be a year between 1583 and 2250.

Output

The Gregorian date of the first evening of Hannukah that year. That is the day before the first full day of Hannukah. Your code should output the month and day of the month in any easy to understand human readable form of your choice.

Examples

2013    November 27 
2014    December 16
2015    December 6  
2016    December 24 
2017    December 12 
2018    December 2  
2019    December 22
2020    December 10 
2021    November 28 
2022    December 18
2023    December 7  
2024    December 25 
2025    December 14 
2026    December 4  
2027    December 24
2028    December 12 
2029    December 1  
2030    December 20 
2031    December 9  
2032    November 27 
2033    December 16

How do you do this?

It could hardly be simpler. We start with a couple of definitions:

We define a new inline notation for the division remainder of \$x\$ when divided by \$y\$: $$(x|y)=x \bmod y$$

For any year Gregorian year \$y\$, the Golden Number, $$G(y) = (y|19) + 1$$ For example, \$G(1996)=2\$ because \$(1996|19)=1\$.

To find \$H(y)\$, the first evening of Hannukah in the year \$y\$, we need to find \$R(y)\$ and \$R(y+1)\$, the day of September where Rosh Hashanah falls in \$y\$ and in \$y+1\$. Note that September \$n\$ where \$n≥31\$ is actually October \$n-30\$.

$$R(y)=⌊N(y)⌋ + P(y)$$ where \$⌊x⌋\$ denotes \$x-(x|1)\$, the integer part of \$x\$, and

$$N(y)= \Bigl \lfloor \frac{y}{100} \Bigr \rfloor - \Bigl \lfloor \frac{y}{400} \Bigr \rfloor - 2 + \frac{765433}{492480}\big(12G(y)|19\big) + \frac{(y|4)}4 - \frac{313y+89081}{98496}$$

We define \$D_y(n)\$ as the day of the week (with Sunday being \$0\$) that September \$n\$ falls on in the year \$y\$. Further, Rosh Hashanah has to be postponed by a number of days which is

$$P(y)=\begin{cases} 1, & \text{if } D_y\big(\lfloor N(y)\rfloor \big)\in\{0,3,5\} & (1)\\ 1, & \text{if } D_y\big(\lfloor N(y)\rfloor\big)=1 \text{ and } (N(y)|1)≥\frac{23269}{25920} \text{ and } \big(12G(y)|19\big)>11 & (2)\\ 2, & \text{if } D_y\big(\lfloor N(y)\rfloor \big)=2 \text{ and } (N(y)|1)≥\frac{1367}{2160} \text{ and } (12G(y)|19)>6 & (3)\\ 0, & \text{otherwise} & (4) \end{cases}$$

For example, in \$y=1996\$, \$G(y)=2\$, so the \$N(y)\approx13.5239\$. However, since September 13 in 1996 was a Friday, by Rule \$(1)\$, we must postpone by \$P(y)=1\$ day, so Rosh Hashanah falls on Saturday, September 14.

Let \$L(y)\$ be the number of days between September \$R(y)\$ in the year \$y\$ and September \$R(y+1)\$ in year \$y+1\$.

The first evening of Hannukah is:

$$ H(y)=\begin{cases} 83\text{ days after }R(y) & \text{if } L(y)\in\{355,385\}\\ 82\text{ days after }R(y) & \text{otherwise} \end{cases} $$

Notes and thanks

Thank you to @Adám for pointing me to the rules. To keep things simple, this challenge assumes the location to be Jerusalem.

\$\endgroup\$
22
  • \$\begingroup\$ Please type out the rules on that image into actual text. Challenges are supposed to be self-contained, while that image will be subject to link rot. Also, it's lacking an explanation how the Golden Number G is calculated. \$\endgroup\$ Dec 29, 2019 at 20:26
  • \$\begingroup\$ What if the given year has no Hannukah? Or there are two "first day of Hannukah"s in the given year? \$\endgroup\$
    – Adám
    Dec 30, 2019 at 10:56
  • \$\begingroup\$ @Adam. Now you have confused me! For which years between 1900 and 2100 were there 0 or 2 Hannukahs? \$\endgroup\$
    – user9207
    Dec 30, 2019 at 11:01
  • \$\begingroup\$ @Anush Ah, I didn't notice the range. 3031 will have 0 and 3032 will have 2. \$\endgroup\$
    – Adám
    Dec 30, 2019 at 11:17
  • \$\begingroup\$ Hold on, the first evening? That'd be the day before before the "first day of Hannukah". You should be very clear about this. \$\endgroup\$
    – Adám
    Dec 30, 2019 at 11:26
  • \$\begingroup\$ Hm, I just noticed that there's a risk of people actually not implementing the algorithms, but instead relying on a built-in calendar conversion. Though you don't state it, the answer is always the 24th day of the month Kislev in the Hebrew year CivilYear+3761. \$\endgroup\$
    – Adám
    Dec 30, 2019 at 11:47
  • \$\begingroup\$ Also, you may want to extend the valid input range. Otherwise it will often be shortest to hard-code the dates, e.g. in base 30. \$\endgroup\$
    – Adám
    Dec 31, 2019 at 14:31
  • \$\begingroup\$ @Adam Could you please double check the formula in the question actually matches the example dates I have given. If so, I will post the question. \$\endgroup\$
    – user9207
    Dec 31, 2019 at 14:43
  • 1
    \$\begingroup\$ Working on it... \$\endgroup\$
    – Adám
    Dec 31, 2019 at 15:00
  • 1
    \$\begingroup\$ OK, I've tried it now and it works. It actually works. However, don't go ahead and post yet; There are a few issues to address. \$\endgroup\$
    – Adám
    Dec 31, 2019 at 15:39
  • \$\begingroup\$ The first day of Hannukah day 84 if Rosh Hashanah is day 1, so you need to add 83 to get the first day of Hannukah, but 82 to get the evening before. \$\endgroup\$
    – Adám
    Dec 31, 2019 at 15:40
  • \$\begingroup\$ The last three paragraphs are superfluous as your range is bigger. However, I also suggest adjusting the range somewhat. If you go above 2239 then .NET won't help (which may be good or bad depending on whether you want to push people to implement the actual algorithm instead of just converting the Hebrew date using the built-in. In any case, the Hebrew calendar isn't really defined beyond 2250. \$\endgroup\$
    – Adám
    Dec 31, 2019 at 15:47
  • \$\begingroup\$ You can however pull back the earliest year to 1583, but not earlier, as that's the first year of the civil calendar. \$\endgroup\$
    – Adám
    Dec 31, 2019 at 15:49
  • \$\begingroup\$ The mathematical formulas are really awkwardly written. Maybe MathJax those? I can do it if you want. \$\endgroup\$
    – Adám
    Dec 31, 2019 at 15:50
  • 2
    \$\begingroup\$ I would adjust the output requirements to read "The Gregorian date of the first evening of Hannukah." to pre-empt people just submitting print("24 Kislev"). \$\endgroup\$ Jan 1, 2020 at 8:24
2
\$\begingroup\$

Decode the password

Given a printable ASCII string separated with spaces, output the specified index of every word. E.g.

"are turbas unsafe ?!", 1

will yield run!

  • When the index is out of bounds, this index should yield the null string (which can be joined with other strings).

More test cases

"Is Pascal truly unloyal to users?",3 -> "sure"
"I'd pass kittens to anyone stopping by!!",4 -> "stop!"
\$\endgroup\$
5
  • 1
    \$\begingroup\$ The definitive answer here is yes. \$\endgroup\$
    – lyxal
    Feb 3, 2020 at 6:58
  • \$\begingroup\$ I assume this was just meant to be laying out the idea not to forget about it. But just in case I figured I should say that you definitely need to specify what happens when the index is too large for one of the substrings, and that the rest of the string will be printable ascii / whatever you choose. \$\endgroup\$ Feb 5, 2020 at 17:19
  • 1
    \$\begingroup\$ The first test case in the more test cases section seem wrong should it not yield "sule" and not "sure"? \$\endgroup\$ Feb 11, 2020 at 15:56
  • 2
    \$\begingroup\$ And the last test case only works for 1-indexing, while all others are 0-indexed. \$\endgroup\$ Feb 11, 2020 at 16:10
  • \$\begingroup\$ What happened to this user? \$\endgroup\$
    – S.S. Anne
    Feb 11, 2020 at 23:58
2
\$\begingroup\$

Is this entire list likewise-modulus-aligned?

A pair of numbers are aligned in a modulus when they all share the same remainder when they can be put under the modulus function against an integer greater than or equal to 2 and less than or equal to the absolute value of both.

For example,

13 and 22 are aligned numbers under 3 because
13%3 = 1
22%3 = 1

3<=13, 3<=22, and 3>=2

All our requirements are met.

A list is likewise-modulus-aligned when all the elements are aligned under the same modulus base.

Challenge

Take in a list (not necessarily non-empty) of non-zero integers (not necessarily positive nor unique), and check if all the elements are likewise-modulus-aligned. Output is a truthy or falsy value.

Note; This is a "true-until-proven-otherwise" problem, meaning a single value in the list or an empty list will return TRUE.

Example I/O

      In      | Out | Why
--------------|-----|---------
         [5 7]|TRUE |1 mod 2
     [7 12 18]|FALSE|(7,18) are not mod-aligned
     [7 11 19]|TRUE |1 mod 2
  [5 13 28 44]|FALSE|(5,28) are not mod-aligned
[10 13 37 108]|FALSE|(37,108) aren't aligned in any base below 10
            []|TRUE |No disproven pairs
          [42]|TRUE |No disproven pairs
    [-5 13 16]|TRUE |1 mod 3
      [1 9 18]|FALSE|Arrays of size 2 or greater with 1 or -1 will always be false
    [14 17 19]|FALSE|Every pair is modulus-aligned, but not under the same base
[17,22,32,107]|TRUE |2 mod 5
      [4,8,12]|TRUE |0 mod 2
        [-1,1]|FALSE|No mod 1 allowed
           [1]|TRUE |No disproven pairs
       [7,7,7]|TRUE |Numbers >=2 are always mod-aligned with themselves
     [2,2,8,8]|TRUE |0 mod 2
   [3 9 22 22]|FALSE|Pairs don't suddenly make (9,22) mod-aligned.

Sandbox Questions

I'm gauging the interest to this question and seeing if this is an acceptable and unique challenge, just want to make sure I haven't missed another post doing a similar thing.

I changed the rules to be a lot more lenient on the comparisons, might do the pairwise comparison as a bonus or follow-up challenge later. But this is a compromise I can live with.

Extra Hints/Tips

For all non-1 derivations, a number will be aligned with its negative self.
1 is never aligned with any other number, nor will -1.
A number that is a multiple of another will be aligned with that number in all its factors.
Numbers that share factors will always align, but numbers that don't share factors also may.
All odd numbers are aligned with each other, as are all even numbers.

\$\endgroup\$
30
  • 1
    \$\begingroup\$ I'm not clear on why this challenge asks to compare all pairs of a list, rather than just a single pair. The condition covers pairs of numbers, so it would be more natural to just receive a pair of numbers as input. \$\endgroup\$
    – isaacg
    Feb 19, 2020 at 18:21
  • \$\begingroup\$ Because it's a combination of that function and a list-pair function with interesting shortcuts that can overlap. Asking for a pair could take X bits, and pushing all pairs to a function could take Y, but the combination of the two isn't necessarily X+Y. In my going at it, I saved like 8 bytes in the mix by being clever. This way, there are several ways to solve while still being a challenge. \$\endgroup\$
    – Mathgeek
    Feb 19, 2020 at 18:24
  • 2
    \$\begingroup\$ Some test cases that are not 1 mod x would be good \$\endgroup\$
    – Jo King Mod
    Feb 20, 2020 at 5:21
  • \$\begingroup\$ Good suggestion, Jo. I just added one, and I'll add a few more in a bit - I hadn't even caught that! \$\endgroup\$
    – Mathgeek
    Feb 20, 2020 at 13:32
  • 2
    \$\begingroup\$ While what you observed can be true, in my experience it is not usually a source of interest in golfing to combine tasks unnecessarily. Similarly, does including negative numbers make this task more interesting? In most languages this will not make a difference, but it will make answering in some languages (consider Retina) substantially more difficult - to the point where people probably won't answer. I always try to recommend making a challenge as simple as possible - just like writing a proof. \$\endgroup\$ Feb 20, 2020 at 18:59
  • \$\begingroup\$ I made negative numbers allowed because negative modulus is still a valid application of modulus - but that argument of "combining two things" is applicable to like literally every other code golf question. The string-wise calculus question could have just been "print out which of two characters is the largest", but then there was added difficulty to comparing pairs and assigning those values to distinct characters. This isn't just an arbitrary expansion, it's a setwise comparison of several elements applied over a function; You see these "expansions" all the time, so why is this one an issue? \$\endgroup\$
    – Mathgeek
    Feb 20, 2020 at 19:24
  • \$\begingroup\$ I agree that the part of the challenge where you check every pair seems unnecessary, and was going to comment on this independently. I think just having two numbers as inputs would make a better challenge overall. Or, have all numbers in the list need to be aligned by the same modulus, which seems like a more natural extension. \$\endgroup\$
    – xnor
    Feb 20, 2020 at 19:33
  • 2
    \$\begingroup\$ Okay, what about a fairer follow-up instead - instead of checking if all pairs are modulus-aligned, a list is modulus-aligned if all the entries share an identical mod-point. ie: They all have to be n mod m together for the list to be valid. Think that's still a more fair question? I think submitting pairs only is a very low-level simple problem that doesn't have any real puzzle or golfing elements to it, so I'd like it to be slightly more complex somehow. \$\endgroup\$
    – Mathgeek
    Feb 20, 2020 at 19:37
  • 2
    \$\begingroup\$ What you and xnor propose sounds good to me. I tried to phrase what I said as suggestions and opinions, because that is all they are. There isn't anything wrong with what you have, but I know I'd be more likely to answer if you changed some things about it. The same is true for many challenges on this site (including my own). Over time, I've come to see that including requirements that are technically valid but aren't necessary rarely adds interest to a challenge. \$\endgroup\$ Feb 20, 2020 at 20:29
  • 1
    \$\begingroup\$ Doesn't [10 13 37 109] satisfy 1 mod 3 (and therefore it is modulus-aligned)? \$\endgroup\$
    – Bubbler
    Feb 20, 2020 at 23:45
  • \$\begingroup\$ You're correct fixed! \$\endgroup\$
    – Mathgeek
    Feb 21, 2020 at 13:14
  • 1
    \$\begingroup\$ @KevinCruijssen But that's fine. If I have a list [7, 14], they are aligned under Base 7. \$\endgroup\$
    – Mathgeek
    Feb 21, 2020 at 14:40
  • 1
    \$\begingroup\$ I also just read the "(not necessarily positive nor unique)" part of your challenge, so you might want to add a few test cases containing multiple of the same number in that case. \$\endgroup\$ Feb 21, 2020 at 14:46
  • 1
    \$\begingroup\$ Nice challenge btw. And good choice on explicitly mentioning "Note; This is a "true-until-proven-otherwise" problem, meaning a single value in the list or an empty list will return TRUE.", since those [1]/[-1] test cases are really annoying in my approach. ;) I had a prepared solution which worked for all initial test cases in 10 bytes, but now it's 50% larger to 15 bytes just to fix those two test cases, haha. Looking forward to when it goes live. I would leave it in the sandbox for a little while longer for others to give feedback though, just in case. Oh, and welcome to CGCC! \$\endgroup\$ Feb 21, 2020 at 15:05
  • 1
    \$\begingroup\$ @xnor yes, the question then dissolves to finding whether the gcd of the differences of consecutive elements is >1. \$\endgroup\$ Feb 21, 2020 at 16:09
2
\$\begingroup\$

Square-Cube Digit Usage

\$\endgroup\$
3
  • \$\begingroup\$ In response to the first sentence: nice. \$\endgroup\$
    – lyxal
    Feb 20, 2020 at 0:43
  • \$\begingroup\$ I'm not exactly sure how your title relates to the challenge. Obviously "Square-Cube Digit Usage" won't exactly roll off the tongue, but what you have now seems misleading. \$\endgroup\$ Feb 20, 2020 at 20:22
  • \$\begingroup\$ Nice challenge. I prepared a solution for when it goes live. I would add a few more test cases first, though. One suggestion: 1333 (or 3133/3313/3331) -> 111 (first positive integer as input that has a 3-digit number as output). Here the results for the first 10,000 inputs. \$\endgroup\$ Feb 21, 2020 at 10:53
2
\$\begingroup\$

Draw an American flag for any amount of states

The flag of the United States of America goes by many names. The Stars and Stripes. Old Glory. The Last Known Non-Erotic Usage Of The Verb 'To Spangle'.

It is also one of the few flags semi-regularly updated. The red and white stripes represent the 13 original states, but one more star has been added to the blue canton for every state that joined the union later. This last happened in 1960, when Hawaii got in. Flag designs with 51 stars are already waiting for when Puerto Rico or Washington D.C. are made states, but this vexillologist is lazy. You are to make a program that can draw the flag with any number of stars desired!

Specification

Here's a neat image of the official, government-standardised design for the current U.S. flag: flag design

Disregard the contents of the canton for now. Your program must draw a flag that adheres to only the ratios I give here:

  • A (the height of the flag) = 1
  • B (the width of the flag) = 19/10
  • C (the height of the canton) = 7/13
  • D (the width of the canton) = 19/25
  • L (the height of any stripe) = 1/13

Because raster solutions are not exact and this flag is commonly misdrawn anyway, there's tolerance of 2% for every ratio, taking the flag height as the base.

Furthermore, the correct colours must be used.

  • Every odd-numbered stripe must be this shade (hex): #B22234
  • The blue canton must be in this shade: #3C3B6E
  • Every even-numbered stripe, and every star, must be in this shade: #FFFFFF

Conversions to other colour coordinate systems can be found on the wiki page as well.

Stars

Your program must takes as input any integer between 0 and 200, and draw that number of stars within the canton. The following rules apply.

  • Each star must have five outer points and be five-fold rotationally symmetrical.
  • Each star must be the same size.
  • The bounding circles of stars may overlap, but the surface of the stars itself may not overlap.
  • The bounding circles of the stars may go outside the canton, but the surface of the stars itself may not go outside the canton.
  • I don't want solutions that just place every star on the same line; that would leave a lot of blue canton untouched, which would be a waste. So, as a rule, the combined surface area of the bounding circles of every star in the canton must be at least 20% of the surface area of the canton.

    Since overlapping bounding circles still count, you get a formula for the minimum width w of the star, where a is the area of the canton and n the number of stars: formula. See here for how it's derived.

Other specifications

There's no minimum or maximum size for your output image, though I recommend something that will allow 200 stars to fit but still be demonstrably star-shaped. When they are only a few pixels high, it becomes hard to argue that they have the required amount of points. Obviously, for vector solutions any size is permissible.

This is , so the smallest program wins!

Test cases

Because I gave no specific arrangement of the stars (you may arrange them however you want), there is an infinite number of correct and incorrect solutions for each number of stars. These are just examples of valid and invalid solutions:

Valid:

valid1

Invalid (stars too small):

invalid1

Valid:

valid2

Invalid (stars of unequal size, going out of the canton):

invalid2

Invalid (stars have too many points, stripes have wrong colours, colours are the wrong hue, proportions are wrong):

invalid3

Sandbox

Do I need more test cases? Any other feedback?

\$\endgroup\$
2
  • 2
    \$\begingroup\$ If you really want to allow 0 as an input, you'll need an exception to the rule that the combined areas of the bounding circle must be at least 20% of the area of the canton. (If there aren't any stars, there aren't any bounding circles, so the combined areas would be 0.) \$\endgroup\$ Mar 7, 2020 at 2:19
  • 4
    \$\begingroup\$ I know it's less thematic, but maybe the task could be just to draw the canton? Arranging and drawing the stars is the interesting part, whereas the stripes aren't changing, so in terms of golfing the stripes seem somewhat extraneous. I guess you could also have the number of stripes be variable. \$\endgroup\$
    – xnor
    Mar 7, 2020 at 17:40
2
\$\begingroup\$

Excessively complicated Game of Life

In the excessively complicated version of the Game of Life, the world is a \$W \times H\$ square torus with a grid of squares. Each square has a rulestring attached to it - by default, B/S. Each square has a dead or alive cell in it. Each alive cell is controlled by a player. Every turn, if there is not an alive cell in a square, it is born iff the part between B and / contains the number of alive neighbours. Every turn, if there is an alive cell in a square, it survives iff the part after S contains the number of alive neighbours. Cells are considered adjacent if they have a common edge or a corner. A cell is not adjacent with itself. Cells controlled by other players also count as alive neighbours.

For example, normal Conway's Game of Life cells have the B3/S23 rulestring: cells are born if they have exactly 3 alive neighbours, and survive if they have 2 or 3.

Each player starts with a B/S012345678 cell, placed uniformly randomly.

Each cell knows a 3x3 array of numbers from \$-1\$ to \$1\$, representing adjacent cells (including self). \$1\$ in it means an ally cell, \$0\$ means a dead cell, and \$-1\$ means an enemy cell, and a 3x3 array of rulestrings for adjacent cells.

Every turn, every cell can alter one bit of the rulestring of any adjacent square (including its own) - that is, remove or add a number from it (or, alternatively, it can do nothing).

When cells are born, the player they belong to is chosen semi-randomly: the odds of the cell being assigned to a player are proportional to the number of cells they contributed to the cell's birth.

A player is eliminated when all their cells die. When \$N\$ turns passed, or when only one player remains, the game ends. A full point is distributed between all remaining players proportionally to the number of cells they control (dead cells don't count).

Clarifications

  • Rulestrings are attached to squares, not to cells. When a cell dies, the rulestring on its square is not changed.
  • No cell can be born with zero alive adjacent cells (that is, rulestrings cannot start with B0).
  • When multiple cells attempt to alter the same bit in a rulestring, it is only affected once.

Challenge

Define a pure function \$(nearbyStates, nearbyRules)\to(\Delta x, \Delta y, index)\$ to be used as the algorithm for your cells. To do nothing, output an index of 0.

Otherwise, an index of 1 corresponds to toggling B1, 2 to B2 and so on until B8, the index 9 is skipped, then an index of 10 corresponds to toggling S0, 11 to S1 and so on until S8.

Winning criterion

\$X\$ games are run, and the leaderboard is formed by sorting participants by the total number of points.

This is , so whoever wins wins!

Sandbox stuff

  • Is this a good idea?
  • Is the description of the game clear?

I think I decided that the language for submissions will be Javascript. Now I have to write a controller.

Besides the obvious Javascript option, I am considering C++ with a Javascript engine (probably V8). This can multiply the performance by \$\%NUMBER\_OF\_PROCESSORS\% \cdot \frac{cppPerformance}{jsPerformance} \cdot \frac{myC++skill}{myJSskill}\$, which can be quite large. Unfortunately, that might also muptiply the challenge's popularity by \$\frac{webBrowserLoadingSpeed}{programInstallationSpeed}\$, which can be quite small! Would that be a good idea?

\$\endgroup\$
6
  • \$\begingroup\$ Disclaimer: I'm biased in both categories. Language: Leaning towards JS, especially since this challenge seems to be of the "hack around and see what works" type, and I believe browser-based ones shine here the most. Python seems to be popular as well, but AFAIK it's usually used for challenges that don't need rich visualization. Other languages, like Java, .NET, C++, etc., can also be considered, of course (higher performance)... Orientation: Removing orientation does seem to be a good fit. It increases the amount of interactions that can happen between any two entries. \$\endgroup\$
    – Alion
    Mar 26, 2020 at 18:31
  • \$\begingroup\$ Regarding C++: You can have your cake and eat it too. Have you heard of Wasm and Web Workers? This combination lets you get near-native peformance along with multithreading all in the browser. \$\endgroup\$
    – Alion
    Mar 29, 2020 at 13:40
  • \$\begingroup\$ Note that improving controller performance only gets you so far. You're gonna have to go the Formic route and cache entry responses in some smart way to extract all the potential of C++. \$\endgroup\$
    – Alion
    Mar 29, 2020 at 13:48
  • \$\begingroup\$ @Alion I include "caching in some smart way" in "improving controller performance". I have also considered using Emscripten (and started using it, starting with the renderer first, because I randomly decided so) but then I got worried because I thought calling JS from WASM and WASM from JS is going to be too slow. After reading the comment, I googled and it turned out Emscripten has multithreading. I guess I'll continue now. \$\endgroup\$ Mar 29, 2020 at 13:50
  • \$\begingroup\$ I'd like to see a good C/C++ KoTH. I'm always excluded from them because I don't know any languages that they're in. \$\endgroup\$
    – S.S. Anne
    Apr 1, 2020 at 20:15
  • \$\begingroup\$ @SSAnne I do not understand your comment. Are you proposing a C/C++ KoTH, or are you stating that they cannot be good because you don't know these languages? \$\endgroup\$ Apr 2, 2020 at 0:09
1
34 35
36
37 38
150

You must log in to answer this question.

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