# What is the Sandbox?

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

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

• How are tags added to questions? – guest271314 Jan 9 '19 at 7:51
• @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] – James Aug 29 '19 at 15:19
• @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary – caird coinheringaahing Sep 29 '19 at 13:43

# Mirror, Mirror, on the wall. Who's the fairest of them all?

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?

# Challenge:

Given an arbitrary number (>= 2) of possibly duplicated hexadecimal color values (ranging from #000000 to #FFFFFF) and paired strings, calculate the following:

• If #FF0800 (Candy apple red) appears in the input, return "Return to Sleeping Death"
• If #000000 appears in the input, return "Saved by Grumpy"
• If #A98AC7 or #111111 appears in the input, return "Saved by Happy"
• If #21E88E or #222222 appears in the input, return "Saved by Sleepy"
• If #32DCD5 or #333333 appears in the input, return "Saved by Bashful"
• If #43D11C or #444444 appears in the input, return "Saved by Sneezy"
• If #54C563 or #555555 appears in the input, return "Saved by Dopey"
• If #65B9AA or #666666 appears in the input, return "Saved by Doc"
• If #76ADF1 or #777777 appears in the input, return "Saved by the Seven Dwarfs"
• If #FFFAFA (Snow) appears in the input, return "Saved by Love's first kiss"
• If an F variant appears in the input, return "Press F to pay respects to Snow White"
• An F variant is any number that contains at least one F in its hexadecimal form, and is otherwise all 0s (e.g. #0FF0F0, #FFFFFF, #00000F, #F00F00)
• If multiple of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
• For all N occurrences of special color values, choose the (N-1)/2-th (truncating division) occurrence. The associated special output is the "fairest" answer.

"Appears in the input" here refers to only the hexadecimal color values, and not to the paired strings.

• If none of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
• Take the hexadecimal color value at the end of input values, write it down, and exclude that single color-string pair from consideration as the "fairest" answer
• Show its binary form to the mirror, computing a reflection of only the last 24 (#FFFFFF is the mask) bits.
• Choose the hexadecimal color with least Hamming distance from the reflection. If there are multiple (N) such colors, choose the middle ((N-1)/2-th, truncating division) instance of the color. The "fairest" answer is the associated string for the color.

# Inputs:

A sequence of hexadecimal color values and String values separated by a space. The input may also be read as two separate sequences of hexadecimal color values and String values, or a single sequence of 2-tuples (either (hexValue, stringValue) or (stringValue, hexValue) is permissible, as long as the ordering is consistent across all 2-tuples). Input order matters - for each index, the corresponding element in the supply of color values is "associated" with the corresponding element in the supply of String values, and duplicates can affect the "fairest" answer. The effect is something like Function(List(HexColorValue),List(AssociatedStrings)) -> "fairest" answer. Hexadecimal color values may be represented as either (your choice of) a String "#"+6 digits, or 6 digits alone, as long as the representation is consistent across all color values.

Here's an example input:

76ADF1 Return to Sleeping Death
2FE84E Return whence ye came!


Here's another example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return of the Jedi


Here's the third example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
7217F8 Return of the King


Here's the final sample input:

F4A52F Eating hearts and livers
F4A52F Eating apples
F4A52F Eating porridge
F4A52F Eating candy houses
F4A52F A Modest Proposal


# Outputs:

The "fairest" answer as computed by the specified logic. For example, on the first sample input, the "fairest" answer would be Saved by the Seven Dwarfs, due to the special hex color 76ADF1 appearing within the input.

In the second sample, there are no special inputs. First, we take "2FE84E Return of the Jedi", which has value #2FE84E. In binary, this is:

001011111110100001001110


We take the reflection from the mirror, getting:

011100100001011111110100


We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 18 and 12 from the reflection, respectively. Since #4FFAFC has the uniquely lowest Hamming distance from the reflection, the "fairest" answer is Return of the Obra Dinn.

In the third sample input, there are no special inputs. First, we take "7217F8 Return of the King", which has value #7217F8. In binary, this is:

011100100001011111111000


We take the reflection from the mirror, getting:

000111111110100001001110


We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 2 and 8 from the reflection, respectively. All 3 instances of hexadecimal color value #2FE84E have minimum Hamming distance from the reflection, so we take the (3-1)/2=1th instance (0-indexed) of #2FE84E. Therefore, the "fairest" answer is Return to the house immediately, young lady!.

In the last sample input, there are no special inputs. First, we take "F4A52F A Modest Proposal", which has value #F4A52F. In binary, this is:

1111010011001100101111


We take the reflection from the mirror, getting:

1111010011001100101111


We compare it against F4A52F (1111010011001100101111), which has Hamming distance 0 from the reflection. All instances of hexadecimal color value #F4A52F have minimum Hamming distance from the reflection. There are FOUR instances of #F4A52F, because we always exclude the last hexadecimal color instance from evaluation. Therefore, we take the (4-1)/2=1th instance (0-indexed) of #F4A52F, and the "fairest" answer is Eating apples. If you don't exclude the last value from consideration, you actually get the (5-1)/2=2th instance of #F4A52F (Eating porridge), which is wrong.

# Rules:

• No standard loopholes
• Input/output taken via standard input/output methods.
• The output must be exactly equal to the "fairest" answer

# Scoring:

This is code golf, so shortest program wins.

Posted~ you can see it here

• Going to need tag suggestions :) – Avi Sep 30 '19 at 20:57
• Can each entry be taken as a tuple, i.e. ("#FFFFFF","Return the Slab")? Can the label part also have a hex number in it or are we guaranteed it wont? Rules has the # but the examples do not, is either form fine? Can we get a worked example of a list containing multiple matching entries? – Veskah Oct 1 '19 at 12:33
• @Veskah You can take tuples as input. You can choose whether to keep # in your input hex colors or not, as long as you keep it the same for every single input (no sneaky stuff like putting a # before the correct answer every time). I've added more sample inputs/outputs with explanation. – Avi Oct 1 '19 at 14:28
• -1: This has way too many hardcoded input/output mappings. This challenge is more about encoding those than solving a problem. – Beefster Oct 24 '19 at 19:10

# CMC: Cross-Multiplication Calculator code-golfmatharithmetic

In this task you should create a Cross-Multiplication Calculator.

Cross-multiplication is a way of factoring an algebraic expression. This is the expression form that this way can solve:

$$x^2 + ax + b$$

$$\a\$$ and $$\b\$$ are constants here, and $$\x\$$ is a variable.

Anyway, as far as I can tell, this expression form is only solvable in this method.

# Anyway, how do I do Cross-Multiplication? (TODO)

You first take the number $$\b\$$ and factor this number into integral factors.

Okay. We are using the expression $$\x^2 + 8x + 16\$$ as an example.

(Although 16 is not a prime) let us assume that 16 only has 2 possible factors:

• $$\-1 \times -16\$$ (because $$\-x \times -x = x^2\$$)
• $$\1 \times 16\$$ (Obviously this is 16)
• And the above 2 with the factors reversed.

Now you sum these possible two factors and check this against the number $$\a\$$.

• Check 1. So $$\-1 + (-16) = -17\$$. And unfortunately -17 is not 8, we proceed to the next check.
• Check 2. So $$\1 + 16 = 17\$$. And unfortunately 17 is not 8, we proceed to the next check. There are no checks left.

Did I make a mistake? Of course, I need to change the factors.

• $$\-2 \times -8\$$ (because $$\-x \times -x = x^2\$$)
• $$\2 \times 8\$$ (Obviously this is 16)
• And the above 2 with the factors reversed.

We sum those values, and they are -10 and 10 respectively. So I should change the factors to another value:

• $$\-4 \times -4\$$ (because $$\-x \times -x = x\$$)
• $$\4 \times 4\$$ (Obviously this is 16)
• And the above 2 with the factors reversed.

Finally! $$\4+4 = 8\$$, and here is the factorization:

$$(x+4)(x+4)$$

Now you will probably realize why I desperately need a program to automate this.

# Test cases

You can assume that the input is always valid. You do not have to specify the variables, only the numbers. Therefore the expression

$$x^2 + ax + b$$

is converted into:

$$+a \, +b$$

The expected output is not:

$$(x+\alpha)(x+\beta)$$

but:

$$+\alpha \, +\beta$$

a, b => α, β
8, 16 => 4, 4
-5, -24 => 3, -8


# Scoring

This is , so shortest answer in bytes wins.

## Meta

• Is this clear enough?
• I haven't found a duplicate, but anything? (Although unlikely, I found nothing by searching "Cross Multiplication".)
• Tags are code-golf, string and interpreter. Anything else?
• Any further feedback?
• I've edited your post to use MathJax for the mathematical formula/workings. In addition, I've edited out the rather strict input/output format (leading + etc.) as it's generally recommended to allow the most natural output format. Feel free to revert these changes if you dislike them. Also, your tags bullet point in the Meta section appears to be different to the tags in the title? – caird coinheringaahing Oct 21 '19 at 17:48
• Finally, I'd vote to close this as a duplicate of this or this challenge (as it is a subset of both) – caird coinheringaahing Oct 21 '19 at 17:51

## Return the maximum value in the final List

In this challenge, start with an array initialized to zeros with indices starting at 1 and a series of operations to perform on segments of the list. Each operation will consist of a starting and ending index within the array, and a number to add to each element within that range.

Determine the maximum value in the final array.

For example, start with an array of 5 elements: list = [0, 0, 0, 0, 0]. The variables a and b represent the starting and ending indices, inclusive. Another variable, k, is the addend. The first element is at index 1.

a    b    k             list

[  0,  0,  0,  0,  0]

1    2   10    [ 10, 10,  0,  0,  0]

2    4    5    [ 10, 15,  5,  5,  0]

3    5   12    [ 10, 15, 17, 17, 12]


The maximum value in the resultant array is 17. That is the value to be determined.

Function description

The function must return a long integer that denotes the largest value in the array after all operations have been performed.

listMax has the following parameters:

n: an integer, the size of the initial array.
operations: a 2D integer array where each element contains an operation.


Constraints

$$\3 ≤ n ≤ 10^7\$$

$$\1 ≤ o ≤ 2 × 10^{5}\$$

$$\1 ≤ a ≤ b ≤ n\$$

$$\0 ≤ k ≤ 10^{9}\$$

Input Format

Allowed inputs are STDIN, function argument, System argument, file input, etc.

inputs are optional and both 0- and 1-based indexing is allowed.

Sample Case 0

Sample Input 0

5

3

3

1 2 100

2 5 100

3 4 100


Sample Output 0

200


Explanation 0

Perform the following sequence of o = 3 operations on list = [0, 0, 0, 0, 0]:

1. Add k = 100 to every element in the inclusive range [1, 2], resulting in list = [100, 100, 0, 0, 0].

2. Add k = 100 to every element in the inclusive range [2, 5], resulting in list = [100, 200, 100, 100, 100].

3. Add k = 100 to every element in the inclusive range [3, 4], resulting in list = [100, 200, 200, 200, 100].

Return the maximum value in the final list, 200, as the answer.


Sample Case 1

Sample Input 1

4

3

3

2 3 603

1 1 286

4 4 882


Sample Output 1

882


Explanation 1

Perform the following sequence of o = 3 operations on list = [0, 0, 0, 0]:

1. Add k = 603 to every element in the inclusive range [2, 3], resulting in list = [0, 603, 603, 0].

2. Add k = 286 to every element in the inclusive range [1, 1], resulting in list = [286, 603, 603, 0].

3. Add k = 882 to every element in the inclusive range [4, 4], resulting in list = [286, 603, 603, 882].

Return the maximum value in the final list, 882, as the answer.


References:

• Thanks for using the sandbox! This challenge looks a bit like one taken from another site, so I'd urge you to either put a reference or change some of the wording. Notably, the strict input format isn't a good idea, particularly input that conveys no information (i.e. the 3 after o). I strongly recommend changing the input to match what is usually done for challenges on this site: allowing the information in any convenient format. – FryAmTheEggman Nov 6 '19 at 16:48
• @FryAmTheEggman Please take a look and let me know if there are any changes need to be considered. – Pluviophile Nov 7 '19 at 6:28
• Thank you for adding a reference! I would recommend also including a link, if you can. I would also like to reiterate my suggestion to change the input format to be more lenient. – FryAmTheEggman Nov 7 '19 at 18:25
• Hi Krishna, welcome and thanks for using the sandbox! I would agree with FryAmTheEggman regarding allowing "any convenient format" for the input, as is usual on this site. So for your example, f(5,[[1,2,100],[2,5,100],[3,4,100]]) would be a valid option. – Chas Brown Nov 7 '19 at 22:50
• @FryAmTheEggman Added reference Links, and inputs are optional. – Pluviophile Nov 8 '19 at 10:36
• @ChasBrown Hi, Thank you for your time & the Suggestion. Could you please elaborate on the Convenient input format. And do I need to change the sample test cases as well? or Only "Input Format" – Pluviophile Nov 8 '19 at 10:42
• Thanks for adding the link! I've looked through the Terms of Service for hackerrank, and I couldn't figure out whether basically reusing challenges was allowed. I think it would be good if you explained why you were sure it is ok to post (this is the first time I've seen a hackerrank question posted here). The changes you made to input are good, and you can leave the test cases. However, I recommend re-wording the input part so that you don't have "first line," etc., in them anymore. – FryAmTheEggman Nov 8 '19 at 17:23

# Parse a regex

Grep is a wonderful tool. It can find stuff in files, it can help you spell stuff correctly (grep 'whatever' /usr/share/dict/words or wherever that file is), and it can even test if something is a prime number!

However, the first version was implemented back in the golden age, when FORTRAN was respected, Pascal was the language for beginners, and object orientation was just starting out in on its great adventure.

One could argue that modern developers have nowhere near that much talent or skill, what with their flashy "IDEs" and "frameworks". If they would be asked to implement something similar, they would just jump at the nearest library or cloud thingimabob and say "Done!".

At least, that is what some would say.

## Prove them wrong! Golf grep!

Parse a regular expression without calling any built-in functions or operators explicitly meant for this.

## input:

Basically the same as a simple grep: a regular expression as a command line parameter, followed by an optional filename or a dash. If the filename is not present, or it is a dash, read for stdin.

This is the recommended way to do it, but if you can write an adapter (eg: post stuff to a php form for your program via a shell script), then that is OK as well. The adapter does not contribute to your score.

## output

Lines that match the regular expression.

## Notes:

The regex dialect is PCRE (perl compatible). Files use unix line terminators if it is relevant.

• Closely related, but not quite a duplicate. – AdmBorkBork Nov 18 '19 at 20:42
• Why the downvote? – Mark Gardner Nov 20 '19 at 8:16
• You've likely been downvoted because you "ban built-in functions or operations explicitly meant for this." Consider this post for a lengthy discussion of why this has fallen out of favour. Beyond this being trivial besides parsing regular expressions, it also doesn't actually describe what a regex is or what it means to be PCRE. Challenges need to be self contained! I think your bet is to make a different matching language yourself and ask us to implement grep but with that language instead of regex. – FryAmTheEggman Nov 20 '19 at 19:09

# Predict the state of a Minecraft inventory after click events

Minecraft does inventory management over the network by sending packets describing the clicks that a player does. If you're caching these events, it can be non-trivial to predict what state the inventory is in after the clicks

## Challenge

Take an inventory of 9 slots, each with an item and a type. Assume all items can stack up to 64 and that if a slot would be "overfilled" that the cursor will continue holding onto the items. Then, take a list of the slot index, button, and mode variables for the clicks to be done (mode and button are defined at https://wiki.vg/Protocol#Click_Window). Output the inventory afterwards.

## Restrictions/Rules

You may input and output the inventory in any reasonable format. You may take click input in any reasonable format. You may ignore Mode==2, as the player inventory is not implemented correctly enough for this. You may ignore Mode==3 because this is a survival player You may ignore Mode==5 where Button==8, 9, or 10 for the same reason as Mode 3. Dropping the item is a delete. Your player won't pick it back up or anything silly like that. You may assume that input will have valid counts Don't use standard loopholes

## Examples

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
[0, 0, 0]
[0, 0, 1]
]


Output

[[],["diamond",64],[],[],[],[],[],[],[]]


Input:

[["diamond",64],["dirt", 64],[],[],[],[],[],[],[]]

[
[0, 0, 0]
[0, 0, 1]
[0, 0, 2]
]


Output

[[],["diamond",64],["dirt",64],[],[],[],[],[],[]]


Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
[0, 0, 0],
[-999, 4, 4],
[0, 4, 5],
[1, 4, 5],
[2, 4, 5],
[3, 4, 5],
[4, 4, 5],
[5, 4, 5],
[6, 4, 5],
[7, 4, 5],
[8, 4, 5],
[-999, 4, 6],
[8, 0, 0]
]


Output

[["diamond",56],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1]]


# Meta

I have no clue what I'm doing writing a question.

Tagged code golf

Critique goals:

• Improve testcases
• Improve description of problem
• Determine if the problem is too complex
• Challenges are meant to be self-contained. While information where the idea/process comes from can be nice, everything needed to solve the challenge should be in the description. This means you should write down what click does what, for all the people who don't remember what Minecraft clicks do by heart. – AlienAtSystem Nov 22 '19 at 6:43

A very-very old (maybe early 2000s) problem:

Print out a decimal number $$\n\$$ such as $$\n^2\$$ ends with $$\n\$$ with maximal length your program can compute in 60 seconds

In other words it's needed to find some long enough $$\n\$$ such as $$\10^{\lfloor\log_{10}n\rfloor+1}|(n^2-n)\$$.
A hint may be that an $$\n\$$ ending with $$\5\$$ is more easy to compute than an $$\n\$$ ending with $$\6\$$.

• How can this be king-of-the-hill? Do you mean code-challenge? And what stops us from hardcoding some extremely large number? – Jo King Nov 21 '19 at 23:36
• king-of-the-hill needs interaction between submissions. I don't see any here – Jo King Nov 22 '19 at 1:43
• @JoKing the problem becomes very simple with modular arithmetic: got 205k digits for free with ~len(n) time for each step imgur.com/ExPdwMb , so there's no need for hardcoding and it's not much interesting. ) – Alexey Burdin Nov 22 '19 at 14:11

# JavaScript: Free for All

This is a very experimental idea of mine: given a function which is provided a single function as an argument, try to run that function the most times possible in a browser environment while competing against other bots.

## Bot submissions

Each bot consists of a function. This function takes a scoring function as input. Each bot has a state consisting of three values:

• score: Number indicating score, winning criterion
• locked: Boolean which, when true, prevents further score increases
• calls: Number of times scoring function called in last 100ms (?), will set locked to true for the remainder of the round if it exceeds a certain value

The scoring function increments score and calls, as long as locked is not true.

## Restrictions

If any of these restrictions are violated, a bot will have locked set to true.

No bot or bot-defined function may:

• Run longer than 5ms
• Attempt to modify the window location (location.href, location.assign, etc.)
• Attempt to connect to the internet (AJAX, WebSockets, etc.)
• Create web workers
• Affect hardware (sound, microphone, camera, USB, gamepads, etc.)
• Leave an impact which cannot be fixed by reloading the page

## Notes

This is almost certainly a very bad idea on an assortment of levels. If you have any suggestions of restrictions or ways to make the challenge more interesting, be sure to comment.

I'm considering some sort of system to determine which bot runs first that adds to the strategy, and interesting attack angles for other bots.

To prevent this from becoming a "read the last answer and exactly cancel out its strategy" type thing, I'm open to any suggestions.

Given a digit as an English word, output its numerical value.

For example, given the input one, you should output 1 (optionally with a trailing newline).

Your program should cover all the following cases:

zero  => 0
one   => 1
two   => 2
three => 3
four  => 4
five  => 5
six   => 6
seven => 7
eight => 8
nine  => 9


# Introduction

This challenge was inspired by the 24 Game.

In the 24 Game, you are given 4 numbers and are asked to make 24 using addition, subtraction, multiplication, division, and parentheses. So...

What is the biggest number you can make given 4 numbers using the above operations?

# Challenge

For four given inputs a, b, c, d, output the biggest number you can get using addition, subtraction, multiplication, division, and parentheses.

This is code-golf, so the shortest answer wins.

# Example Input and Output

  Input  -->  Output  -->   Explanation
1,3,2,4 -->    36    --> (1 + 2) × 3 × 4
5,5,5,5 -->   625    -->  5 × 5 × 5 × 5
9,2,3,1 -->    81    --> (1 + 2) × 3 × 9



Please give feedback on this challenge and correct me if my outputs are wrong. Should I change it to the smallest number?

• – FlipTack Dec 30 '19 at 23:19
• Also the subtraction and division are surely obsolete for the challenge? – FlipTack Dec 30 '19 at 23:21
• Will positive number divide zero yield Infinity as what IEEE 754 does? – tsh Dec 31 '19 at 3:37
• Shouldn't (1+2)x3x4 greater than 1+2x3x4? – tsh Dec 31 '19 at 3:37
• @FlipTack Probably but maybe not in some circumstances. – Yousername Dec 31 '19 at 22:18
• @tsh No, infinity will not count as the solution. Thank you, that is true that (1+2)x3x4 is greater. – Yousername Dec 31 '19 at 22:19
• Does order matter? From the input it seems the order matters, i.e. we are not supposed to change the order of the input. So, for 1,3,2,4, the answer is 32, rather than 36. – Element118 Jan 1 at 5:25
• @Element118 No, order does not matter, those were just the random numbers that came from my head. – Yousername Jan 4 at 21:11

# How many ACus do I have?

Posted to main

• I'm not sure this counts as a dupe, but what it seems to be is n=floor(days_between(input, date(1,1,2020)) / 7); return n*(n-1)/2, which doesn't seem terribly interesting to golf. (Also just fyi, the 01 you used in your dates in your script is actually an octal literal i.e. 010 is 8) – FryAmTheEggman Jan 7 at 21:33
• Thanks for the feedback. I have corrected the script. Not sure how the extra 0's managed to slip in! I'll leave the challenge here for a couple more days to see if there are any more comments. – ElPedro Jan 8 at 7:43
• @ElPedro You need to wait longer. At least a month or two, but a few months is really good. – S.S. Anne Jan 11 at 21:25
• I'm sorry and no personal offence intended but I find it a bit strange that a member of 3 months is telling a member of over 4 years with lot's of experience and over 5000 rep how to use the sandbox and the main site. Maybe I am simply getting too old for this community. – ElPedro Jan 11 at 21:36
• And besides which, none of that alters my opinion that downvotes without the downvoter giving a reason are not any help to anyone. If you think differently then please feel free to give me a good reason. I am happy to listen and learn. – ElPedro Jan 11 at 21:40

# Make a Decompiler Bomb

Similar to the Make a Compiler Bomb challenge, but backwards.

The goal is to create the a 1KiB (1024 bytes) or smaller bytecode file that creates the largest output when decompiled.

# Constraints

• A binary is either an x86 binary (in the form of an ELF file, PE file (.dll/.exe), or Mach-O binary) or a virtual bytecode file (e.g. Python .pyc, Java .class, .NET CLR, etc.)

• The decompiler can be any public (preferably free) decompiler of your choice. (e.g Snowman/Hex-Rays for x86 binarys, CFR/Fernflower/etc. for java, dotPeek for .NET, uncompyle6 for Python, etc.)

• A decompiler is any tool that takes a binary and attempts to reconstruct human readable source code from it.

• The largest output byte count wins, with the smallest input size as a tie-breaker

• The binary must be executable, and print "Hello World!"

• The decompiled code must be syntactically correct

• I think you probably want to specify what a "decompiler" is, since really any file is "binary" and anything that takes that and produces some valid code probably arguable counts as a decompiler. Further, I think you might be better served by limiting the binary size, like the original challenge, as if someone finds a way that adding $n$ bytes adds more than $n^{2}$ bytes to the output they would achieve an arbitrarily large score. – FryAmTheEggman Jan 17 at 20:06
• @FryAmTheEggman I put in a basic explanation and made the scoring based on largest output rather than a formula. Explaining a decompiler is tricky though, I'll think about that more and maybe edit for it later. – famous1622 Jan 21 at 14:15
• I think the scoring change you made is good, only that kb is a tad ambiguous between being 1000 or 1024, and that it seems a tad large (but neither of those is critical and the second is just my opinion). Thinking about what to do with the problem of defining a decompiler, I realised it was probably a good idea to require that the resulting decompiled code does something. Maybe requiring that the decompiled code is a hello world variant or something will limit some problems like "this program converts to Unary source code". – FryAmTheEggman Jan 21 at 16:27
• @FryAmTheEggman Made it so the decompiled code must have correct syntax, and made the size smaller, was going to post my java example but I just realized I have to make it fit in the new restrictions so... – famous1622 Jan 21 at 16:46

# I delete the input, you delete the source code

This is a new twist on the long running series on CGCC.

Your task, if you accept it, is to write a program/function that outputs/returns the contents of an input file. The tricky part is that if I delete the input file, your program must delete itself.

## Rules

• The source code file and the input file should be in the same directory.

• The input file and source file can be named anything at all. I.e. The file names are your choice.

• The contents of the input file will be restricted to printable ASCII.

• The input file and the source file must be deletable.

• This is code-golf, so the shortest (original) code in each language wins!

• Default Loopholes apply.

## Example

If your program is jspwjxnlow8229 and the input file exists, the program must print the contents of the file. If the file doesn't exist, the program must delete itself.

## Feedback

In regards to file manipulation, have I specified the rules enough?

• What about languages in which programs don't live in files but rather in binary blobs? Is it enough for the program to delete itself from the binary blob? – Adám Jan 22 at 9:30
• Can the program and/or source file also be named anything at all? – Adám Jan 22 at 9:32
• @Adam, forgive me for not knowing, but what's a binary blob? – Lyxal Jan 22 at 9:32
• It doesn't matter what a binary blob is. I just wanted you to be aware than not all languages use the same model. – Adám Jan 22 at 9:33
• @Adam sure. I'll add a part about that to the challenge – Lyxal Jan 22 at 9:34
• Parts of this feel a bit unclear. Can the submissions know the file names in advance? (If not then the name feels a bit odd, isn't it really write a cat program that deletes itself if the input name doesn't correspond to an existing file? They aren't really tied together in that case) Similarly, why mention the recycling bin? It isn't present on many systems, and behaves differently on those that do have one (most programmatic deletions will require more work to send the file to the temporary "are you sure" location). – FryAmTheEggman Jan 22 at 17:06

# How healthy are my children?

As anyone who has twins will know, it can be hard to keep track of which child fed / was changed, and when.

That's why I've devised a system using OneNote on my phone. It's quick and easy to use.

Each entry (line) uses the following structure (note: I'm not a regex expert and the expression is more permissive than I want - see words for detail):

(ddMMyyyy )?HHmm ((1|2|B) (💧|💩|🤱){1,3}){1,3}

Or, in words:

1. For the first entry on or after midnight each day only, each line starts with the date.
2. The next component is always the time, hour and minute in 24 hour clock format
3. Next is a child identifier character - 1 or 2; or B if what follows applies to both children. All subsequent emoticons apply to the identified child, until a new child identifier is found or a newline. There is guaranteed to be at least one child identifier in a record.
4. Next comes any or all of the three emoticons (maximum one of each) representing a wet nappy (💧), a dirty nappy (💩) or a feed (🤱)
5. Repeat from step 3. until done. BUT - each emoticon will only appear once per child - so if it appears in B then it won't appear in either 1 or 2; and if it appears in either 1 or 2 it won't appear in B. It won't appear in both 1 and 2 (because then it would be in B instead). The regex doesn't show this subtlety.

Some other notes:

• Breast-Feeding (feed) emoticon 🤱 is codepoint U+1F931
• Droplet (wet) emoticon 💧 is codepoint U+1F4A7
• Pile of Poo (dirty) emoticon 💩 is codepoint U+1F4A9
• All items in the string are space-separated
• I would actually use the initials of my children's names, rather than 1 and 2 - but for the challenge I went with the numbers instead.

## Example

02022020 0005 1 💩 B 💧 🤱
0230 2 💧 🤱
0250 1 💧 💩 🤱
0330 2 🤱
0400 1 🤱
0700 B 💧 🤱
0900 2 🤱
1000 2 💧 🤱
1020 1 💧 🤱
1220 1 🤱
1420 B 💧 1 💩 2 🤱
1440 1 🤱
1600 2 💧 💩
1700 1 💧
1745 B 🤱
2100 B 💧 🤱 1 💩
2350 2 🤱 B 💩 1 💧
03022020 0015 1 🤱 B 💧
0500 1 💧 🤱
0830 1 💧 🤱
0900 2 💧 🤱
1115 B 💧 1 💩
1215 B 🤱
1330 B 🤱
1400 2 💧 💩

# The Challenge

Given the raw data, input as a single string or array of entries, containing data such as the above example, output a summary of:

• number of feeds, wet and dirty nappies, per baby, over the past 24 hours

"The past 24 hours" can be either based on system time, or the current time can be passed as an extra input.

The output format is up to you, as long as it:

a) is consistent across all runs of the program
b) shows the information required

some example outputs for the above inputs, with a current time of 14:30 on 3rd of February 2020 (hand-calculated, sorry if they're not right!):

Baby 1 had 6 wet nappies, 2 dirty nappies, and fed 8 times Baby 2 had 6 wet nappies, 3 dirty nappies and fed 6 times

{{6,6},{2,3},{8,6}}

{6,2,8},{6,3,6}

etc.

This is so lowest bytes wins. Usual exclusions apply.

• If a language can't deal with unicode input, should I allow the whole codepoint string substituted in its place? – simonalexander2005 Feb 14 at 11:59
• Should I be more explicit with the output format? – simonalexander2005 Feb 14 at 12:00
• Can someone help me make the regex more tight? – simonalexander2005 Feb 14 at 12:05

I want to ask a combined popularity / objectively scored question. Something like:

Take a string as input. Match the string to a famous painting such as "Mona Lisa" and render a cartoon version of it. 1 point per painting, 1 point per upvote. Voting closes on XX/YY/ZZZZ.

I want to reward people for including more possibilities (there will be a fixed upper limit, unlike with paintings). I also want to reward people for the quality of their renderings. The cartoon paintings should be recognisable as versions of the real paintings.

Is this a good scoring system? If not, what would be better?

• This is somewhat vague. Can you be more precise? – Don Thousand Feb 17 at 15:38

# Find the largest deletable prime with no zeros code-challengeprimes

Deletable primes (A080608) are primes such that removing some digit leaves either the empty string or another deletable prime.

Examples

415673 is a deletable prime because...
4 5673 is a deletable prime because...
4 567  is a deletable prime because...
4  67  is a deletable prime because...
67  is a deletable prime because...
7  is prime

1415673 is not a deletable prime because it is not prime

31513 is not a deletable prime because...
3151  is not prime and...
315 3 is not prime and...
31 13 is not prime and...
3 513 is not prime and...
1513 is not prime


## Challenge

Write a program to find deletable primes with no zeros. The score is the largest deletable prime with no zeros found by your program.

# Implement PSL(2,3)

Since challenge to implement Galois field already have been many, I'm writing a challenge involving a group of Lie type!

## Objective

Implement the multiplication and inversion in $$\\text{PSL}(2,3)\$$.

## The ring $$\\mathbb{Z}_3\$$

The ring $$\\mathbb{Z}_3\$$ is the set $$\\{0,1,2\}\$$ with addition, negation, subtraction, and multiplication defined as modular arithmetic:

• Addition is the usual addition with the result moduloed by 3;

• Negation, subtraction, and multiplication are also analogously defined.

Reciprocal and division is also well-defined, but that's just another detail.

## The group $$\\text{SL}(2,3)\$$

The multiplicative group $$\\text{SL}(2,3)\$$ is the set of 2-by-2 matrices whose entries are members of $$\\mathbb{Z}_3\$$ and the determinant is $$\1\$$. Note that the determinant is calculated using modular arithmetic. Matrix multiplication and matrix inversion is defined as:

• Matrix multiplication is the usual matrix multiplication, where addition and multiplication of the entries are modular;

• Matrix inversion of $$\\begin{pmatrix} a & b \\ c & d \end{pmatrix}\$$ is $$\\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}\$$. This exploits that the determinant is $$\1\$$.

As a consequence, the elements of $$\\text{SL}(2,3)\$$ are:

$$\begin{pmatrix} 0 & 1 \\ 2 & 0\end{pmatrix}, \begin{pmatrix} 0 & 1 \\ 2 & 1\end{pmatrix}, \begin{pmatrix} 0 & 1 \\ 2 & 2\end{pmatrix}, \begin{pmatrix} 0 & 2 \\ 1 & 0\end{pmatrix}, \begin{pmatrix} 0 & 2 \\ 1 & 1\end{pmatrix}, \begin{pmatrix} 0 & 2 \\ 1 & 2\end{pmatrix}, \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 1 & 0 \\ 1 & 1\end{pmatrix}, \begin{pmatrix} 1 & 0 \\ 2 & 1\end{pmatrix}, \begin{pmatrix} 1 & 1 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix}, \begin{pmatrix} 1 & 1 \\ 2 & 0\end{pmatrix}, \begin{pmatrix} 1 & 2 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 1 & 2 \\ 1 & 0\end{pmatrix}, \begin{pmatrix} 1 & 2 \\ 2 & 2\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 0 & 2\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 1 & 2\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 2 & 2\end{pmatrix}, \begin{pmatrix} 2 & 1 \\ 0 & 2\end{pmatrix}, \begin{pmatrix} 2 & 1 \\ 1 & 1\end{pmatrix}, \begin{pmatrix} 2 & 1 \\ 2 & 0\end{pmatrix}, \begin{pmatrix} 2 & 2 \\ 0 & 2\end{pmatrix}, \begin{pmatrix} 2 & 2 \\ 1 & 0\end{pmatrix}, \begin{pmatrix} 2 & 2 \\ 2 & 1\end{pmatrix}$$

## The factor group $$\\text{PSL}(2,3)\$$

$$\\text{PSL}(2,3)\$$ is defined as cosets of $$\\text{SL}(2,3)\$$ by $$\\{\begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 0 & 2\end{pmatrix}\}\$$. That is, elementwise multiplications of $$\\{\begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 0 & 2\end{pmatrix}\}\$$. They are: $$\{\begin{pmatrix} 0 & 1 \\ 2 & 0\end{pmatrix}, \begin{pmatrix} 0 & 2 \\ 1 & 0\end{pmatrix}\}, \{\begin{pmatrix} 0 & 1 \\ 2 & 1\end{pmatrix}, \begin{pmatrix} 0 & 2 \\ 1 & 2\end{pmatrix}\}, \{\begin{pmatrix} 0 & 1 \\ 2 & 2\end{pmatrix}, \begin{pmatrix} 0 & 2 \\ 1 & 1\end{pmatrix}\}, \{\begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 0 & 2\end{pmatrix}\}, \{\begin{pmatrix} 1 & 0 \\ 1 & 1\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 2 & 2\end{pmatrix}\}, \{\begin{pmatrix} 1 & 0 \\ 2 & 1\end{pmatrix}, \begin{pmatrix} 2 & 0 \\ 1 & 2\end{pmatrix}\}, \{\begin{pmatrix} 1 & 1 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 2 & 2 \\ 0 & 2\end{pmatrix}\}, \{\begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix}, \begin{pmatrix} 2 & 2 \\ 2 & 1\end{pmatrix}\}, \{\begin{pmatrix} 1 & 1 \\ 2 & 0\end{pmatrix}, \begin{pmatrix} 2 & 2 \\ 1 & 0\end{pmatrix}\}, \{\begin{pmatrix} 1 & 2 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 2 & 1 \\ 0 & 2\end{pmatrix}\}, \{\begin{pmatrix} 1 & 2 \\ 1 & 0\end{pmatrix}, \begin{pmatrix} 2 & 1 \\ 2 & 0\end{pmatrix}\}, \{\begin{pmatrix} 1 & 2 \\ 2 & 2\end{pmatrix}, \begin{pmatrix} 2 & 1 \\ 1 & 1\end{pmatrix}\},$$

You pick an element of each coset as representives, and don't care about the rest.

Multiplication/inversion of such representives is defined as multiplication/inversion in $$\\text{SL}(2,3)\$$, then taking the representive of the coset the multiplication/inversion is in. For example, $$\\begin{pmatrix} 0 & 1 \\ 2 & 0\end{pmatrix}^2 = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}\$$, if $$\\begin{pmatrix} 0 & 1 \\ 2 & 0\end{pmatrix}\$$ and $$\\begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}\$$ are representives.

## Examples

Picking the left elements as representives of the cosets above: $$\begin{pmatrix} 0 & 1 \\ 2 & 0\end{pmatrix}^2 = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}, \begin{pmatrix} 0 & 1 \\ 2 & 1\end{pmatrix}^2 = \begin{pmatrix} 1 & 2 \\ 1 & 0\end{pmatrix}, \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}\begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix} = \begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix}, \begin{pmatrix} 1 & 2 \\ 2 & 2\end{pmatrix}\begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix} = \begin{pmatrix} 0 & 1 \\ 2 & 0\end{pmatrix}, \begin{pmatrix} 1 & 2 \\ 2 & 2\end{pmatrix}^{-1} = \begin{pmatrix} 1 & 2 \\ 2 & 2\end{pmatrix}$$ To be more specific about the method of evaluation: $$\begin{pmatrix} 0 & 1 \\ 2 & 1\end{pmatrix}\begin{pmatrix} 0 & 1 \\ 2 & 2\end{pmatrix} ≡ \begin{pmatrix} 2 & 2 \\ 2 & 4\end{pmatrix} ≡ \begin{pmatrix} 2 & 2 \\ 2 & 1\end{pmatrix} ≡ \begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix}, \\ \begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix}^{-1} ≡ \begin{pmatrix} 2 & -1 \\ -1 & 1\end{pmatrix} ≡ \begin{pmatrix} 2 & 2 \\ 2 & 1\end{pmatrix} ≡ \begin{pmatrix} 1 & 1 \\ 1 & 2\end{pmatrix}$$ The steps of this algorithm is:

1. Do usual matrix multiplication/inversion;
2. Modulo the entries by 3;
3. Take the representive of the coset.

Though you can make any possible algorithm.

## Rules

• Input type and format doesn't matter, but it must be a container of integers. In C, int[2][2] and int[4] are valid examples. This restriction prevents abusing the fact that $$\\text{PSL}(2,3) \cong A_4\$$.
• Output type and format doesn't matter either, but it must be the same as the input type and format.
• Invalid inputs fall in don't care situation.
• Multiplication and inversion may be in separate codes. In this case, the score is the sum of their lengths in bytes.
• Since this is a code-golf, the code with least score wins.
• This challenge appears to heavily rely on restricted-source and thus to me does not seem too viable. – Jonathan Frech Feb 25 at 0:58
• @JonathanFrech Do you think I should lift the restriction on input type? Otherwise, "You pick an element of each coset as representives, and don't care about the rest" and "Invalid inputs fall in don't care situation" should be enough. – Dannyu NDos Feb 25 at 3:38

### Determine the Kth character in the concatenated string

You are given a list that contains $$\N\$$ strings of lowercase English alphabets. Any number of contiguous strings can be found together to form a new string. The grouping function accepts two integers $$\X\$$ and $$\Y\$$ and concatenates all strings between indices $$\X\$$ and $$\Y\$$ (inclusive) and returns a modified string in which the alphabets of the concatenated string are sorted.

You are asked $$\Q\$$ questions each containing two integers $$\L\$$ and $$\R\$$. Determine the $$\K^{th}\$$ character in the concatenated string if we pass $$\L\$$ and $$\R\$$ to the grouping function.

### Input Format

• First Line: $$\N\$$(number of strings in the list)
• Next $$\N\$$ lines: String $$\S_i\$$
• Next line $$\Q\$$(number of questions)
• Next $$\Q\$$ lines : Three space-separated integers $$\L\$$, $$\R\$$ and $$\K\$$

### Output Format

• For each question, print the $$\K^{th}\$$ character of the concatenated string in a new line.

### Test Cases

Sample Input                 Sample Output

5                                 c
aaaaa                             d
bbbbb                             e
ccccc
ddddd
eeeee
3
3 3 3
1 5 16
3 5 15


### Explanation

• Q1 Grouped String - ccccc. 3rd character is c
• Q2 Grouped String - aaaaabbbbbcccccdddddeeeee. 16th character is d
• Q3 Grouped String - cccccdddddeeeee. 15th character is e

Note: It is always guaranteed that the $$\K^{th}\$$ position is valid

This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• The challenge sounds too much like a challenge on a competitive programming site. Input format is too rigid; we usually allow any convenient I/O format for submissions (and we also allow function submissions, if you didn't notice). Also, solving Q questions of the same kind isn't the interesting part of the problem. I suggest to simply say "your program should take a list of strings S and three integers L, R, K, and output the Kth character of the output of the grouping function". – Bubbler Mar 2 at 5:26
• One more thing: I'd like to see a test case that demonstrates the "grouping function" better, specifically on the strings of different lengths and mixed-up letters, e.g. ["abx", "cedy", "zzzbbb", "q"]. If I'm understanding it correctly, the grouping function given L=R=2 should give cdey and L=2, R=3 give bbbcdeyzzz, right? – Bubbler Mar 2 at 5:32

## Very rough outline of a challenge that rewards short programs that take a long time.

Probably a no input and output can be anything except an error challenge.

Is there a nice way to exclude things like sleep(), wait() etc?

Would be required for 1 person to run all the programs for the timing to be fair.

Thinking that answers would include loops, recursion, testing of complex criteria.

• I think you would have to post your challenge as a popularity contest ... a slippery slope indeed. – Jonathan Frech Mar 15 at 23:43

## Design a Stack With Increment Operation

Design a stack that supports the following operations.

Implement the CustomStack class:

• CustomStack(int maxSize) Initializes the object with maxSize which is the maximum number of elements in the stack or do nothing if the stack reached the maxSize.
• void push(int x) Adds x to the top of the stack if the stack hasn't reached the maxSize.
• int pop() Pops and returns the top of stack or -1 if the stack is empty.
• void inc(int k, int val) Increments the bottom k elements of the stack by val. If there are less than k elements in the stack, just increment all the elements in the stack.

### Test Case:

Input

["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]
[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]

Output

[null,null,null,2,null,null,null,null,null,103,202,201,-1]

Explanation

CustomStack customStack = new CustomStack(3); // Stack is Empty []
customStack.push(1);                          // stack becomes [1]
customStack.push(2);                          // stack becomes [1, 2]
customStack.pop();                            // return 2 --> Return top of the stack 2, stack becomes [1]
customStack.push(2);                          // stack becomes [1, 2]
customStack.push(3);                          // stack becomes [1, 2, 3]
customStack.push(4);                          // stack still [1, 2, 3], Don't add another elements as size is 4
customStack.increment(5, 100);                // stack becomes [101, 102, 103]
customStack.increment(2, 100);                // stack becomes [201, 202, 103]
customStack.pop();                            // return 103 --> Return top of the stack 103, stack becomes [201, 202]
customStack.pop();                            // return 202 --> Return top of the stack 102, stack becomes [201]
customStack.pop();                            // return 201 --> Return top of the stack 101, stack becomes []
customStack.pop();                            // return -1 --> Stack is empty return -1.


This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• This would be limited to Java and C++. I could almost guarantee that this will be downvoted and closed as unclear if posted. – S.S. Anne Mar 15 at 15:45
• I agree with @S.S.Anne; terms like class, void and even the concept of operations are not existent in a majority of languages. – Jonathan Frech Mar 15 at 23:35
• One possibility of altering the challenge may be to supply a finite number of stack instructions as a series of text commands and ask how the stack looks at the end ... Kind of asking to implement an interpreter for a basic stack-based language. – Jonathan Frech Mar 15 at 23:36

## Find the longest common subsequence

Given two integer arrays. Find the longest common subsequence

Test Case:

Input:

a=[1,5,2,6,3,7]
b=[5,6,7,1,2,3]


Output:

Return
[1,2,3] or [5,6,7]


This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• Similar to this challenge. – Jonathan Frech Mar 15 at 23:29
• @JonathanFrech Yeah Similar, But not Same. Am I supposed to post the challenge?? – Pluviophile Mar 17 at 15:52
• Posting is up to you. I would not, since I think it would be righteously closed as a duplicate. – Jonathan Frech Mar 17 at 16:27

# The (All But) Quine challenge

Like a quine challenge, but the opposite. Print everything except source code

# Challenge

Write a program, which takes no input, and outputs all the strings of printable characters which are the same length as the source code of the program, except the source code of the program.

# Scoring

The shortest program (per language) to accomplish the above task, wins

• By 'printable characters' you mean printable ASCII characters (code-points [32,126])? What if I use a language that don't contain any ASCII characters in its source code? – Kevin Cruijssen Mar 20 at 13:38
• If your program is in ASCII, then you would need to print all of the ASCII characters, if the program is in Unicode, then you would have to print all of the Unicode characters – Benji Mar 20 at 14:40
• @Benji Would you consider a Python 3 source file as being "in Unicode"? – Jonathan Frech Mar 22 at 17:49
• If there are any Unicode characters that are used in the file, then no. If Unicode characters are used, then I would consider it to be Unicode – Benji Mar 23 at 14:47

## Maximum Performance of a Team

There are $$\n\$$ engineers numbered from 1 to $$\n\$$ and two arrays: speed and efficiency, where $$\speed[i]\$$ and $$\efficiency[i]\$$ represent the speed and efficiency for the i-th engineer respectively. Return the maximum performance of a team composed of at most $$\k\$$ engineers, since the answer can be a huge number, return this modulo $$\10^9 + 7.\$$

The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.

Test Case 1:

Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2

Output: 60


Explanation:

We have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = $$\(10 + 5) * min(4, 7) = 60.\$$

Test Case 2:

Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3

Output: 68


Explanation:

This is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = $$\(2 + 10 + 5) * min(5, 4, 7) = 68.\$$

Test Case 3:

Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4

Output: 72


This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• Since this is a challenge from another site, I don't think you'd be allowed to post it here without express permission. – xnor Mar 19 at 16:38

# Write an if/else statement from scratch code-golfrestricted-source

I am new to this community, so please do not hesitate to point out edits and clarifications in this post. Also note that this is just a loose draft for the question. There are several improvements to be made..

We all use if/else statements in our daily programming life (except the oldies who write Machine code). However, put your feet in a young programmer's shoes. If you wanted to write the if/else statement, what would you do?

So basically you have to re-design or recreate the if/else statement in any language of your choice.

The if/else statement should obviously not use if/else from any other language. This does not mean that we can use a statement that has some other name in other languages, no function/statement that produces if/else statement behavior can be used.

So this means that functions like case etc. which can be used in substitution with if-else cannot be used. Neither can you use while loops to simulate an if/else....

### Ideas:-

On posting this as a question there were a lot of people saying that the challenge was not clear. Can anyone edit or point the mistakes in the lines or think that they can make the question a bit more clear?

In the simplest words, it is a challenge to write the if/else statement without using any of its counterparts (like in other languages it has other names) which can be used with a syntax for general cases. For example, it should be able to compare:-

arrays
lists
dicts
other data types (heap, stack,tree)
strings


Everything a normal if/else can do.

• – S.S. Anne Apr 26 at 13:49
• 1+ have the command #, which pops a stack and jump to the nth # in the program. Is using # allowed? – HighlyRadioactive Apr 26 at 13:57
• Some languages do not have conditional statements, and some have only a while loop. Some languages may not have any of your listed data types. You don't know, so it's suggested that you don't write a challenge based on that assumption. – S.S. Anne Apr 26 at 13:57
• @HighlyRadioactive # is a kind of goto, so it's definitely allowed. – Λ̸̸ Apr 26 at 14:15
• @petStorm Okay then, but I guess we are still waiting for the OP to clarify. Is it allowed to assume there are no #s before the snippet? – HighlyRadioactive Apr 26 at 14:19
• I think that # can be allowed as long as it works for most of the data types. Atleast commmon types like string, integers, array should work with it.... – neel g Apr 26 at 14:51
• @S.S.Anne I think that languages that have only a have a while loop are automatically disqualified. So any answerer should not use them. What about making esoteric languages compulsory? I am sure it will be very tough and feel like a real challenge! – neel g Apr 26 at 14:54
• From the same page, this is also discouraged: Explicitly disallowing or disadvantaging arbitrary (classes of) languages. Going against the things to avoid guidelines will generally mean that your question will be downvoted and/or closed. Try to write a challenge that doesn't do anything that's listed there and it will be more likely that your question will get upvotes and will stay open. – S.S. Anne Apr 26 at 14:56
• How can you tell what's an if/else/switch/loop and what's not? This fulfills your requirements, for example: ,[.[-]]+[-[.]]. I could argue that this contains none of these but you'd never know if it did or not. – S.S. Anne Apr 26 at 15:03
• @S.S.Anne So what do you think is the best course of action to take? I don't want to scrap this question because it is really good at its core (but not the best in a practical scenario) Could anyone suggest a very innovative fix so that this question remains a good one? – neel g Apr 26 at 15:16
• You should also look at this. I think you should define more clearly what do you want the if-else statement to allow doing. should it allow executing code that can be substituted, given as input based on an input falsy/truthy value? – Command Master Apr 26 at 16:10
• I agree that this is far from clear. One additional question I have, is what must we be able to do within our if/else replacement. Do we have to be able to run arbitrary sequences of lines of code? Or is just producing a value enough? Note that some languages make a distinction between statements and expressions, and may have if/else constructs for one or both situations. – xnor Apr 26 at 20:15
• @neelg As far as I know most Esolangs does not have string and array (as an object). For example, there is only one type in 1+, that is, unsigned integer. – HighlyRadioactive Apr 26 at 23:58

# Make an Anti-compressor (WIP)

Create an algorithm that reversibly and losslessly makes files bigger. You must create the anti-compressor. The de-anti-compressor can be your own creation or something that already exists. The two programs do not need to be written in the same language.

### Objective Validity Criteria

• Inputs into the anti-compressor can be binary files using any or all byte values.
• All inputs into your anti-compressor must produce outputs that are at least one byte longer.
• The anti-compressor is losslessly reversible by either an existing program or your own.
• The de-anti-compressor must work on (at least) all possible outputs of the anti-compressor.
• Both the anti-compressor and de-anti-compressor can be executed on an actual computer. Keep execution time within reason (e.g. no $$\O(n!)\$$ programs, please)

This will be a unless I get a good suggestion for an objective scoring system.

My only idea so far is that the score could be based on the decompression ratio, cancelled out by how well gzip compresses the output. Unfortunately, this could be abused easily by inserting arbitrarily large amounts of random padding between significant bits of information, leading to an unbounded score that can always be beaten with trivial modification.

• Besides the usual issues with pop-cons, I'd really have no idea how to vote because the task is so broad and I don't know what's meant to be interesting in an answer. – xnor May 11 at 20:00
• @xnor that's fair. I'm not entirely sure if this challenge is a good idea in the first place, but I got an upvote earlier, so I thought it might be worth it to refine it and see where it goes. I could see the subjective criteria being along the lines of the funniest or most clever way of anti-compressing a file. Injecting filler data, random or not, is not very clever, but having it output an overly verbose java program that outputs the original file when executed is both humorous and clever- but perhaps not as much as other ideas I haven't even thought of. – Beefster May 11 at 23:09
• @Λ̸̸ The issue with that scoring system is that you can always make a file more bloated. Someone doubles every byte? I can just triple every byte. That kind of oneupmanship is not interesting. I can try to put limits on exactly what kind of bloating is allowed so that there is some sort of soft upper bound, but then the challenge becomes one of abusing the rules and finding clever interpretations and loopholes- also not very interesting. – Beefster May 12 at 15:08
• I have an idea: make the answerer choose an existing compression algorithm, and then create an anti-compression program given an input string.The anti-compressed string, when compressed with the chosen algorithm, must produce the exact same output as the input. That way, the anti-compressing method of randomly inserting characters in the input string can be avoided, since there isn't a way to un-double speak a given input character, and for a string with randomly inserted characters, the compressor will not know which characters to leave out during the compression. – Λ̸̸ May 13 at 2:36
• Given that, the scoring criterion can now be simply code-golf, since there isn't a way to create boring answers, and the only possible way to score answers left is just code-golf. – Λ̸̸ May 13 at 2:38
• @Λ̸̸ At that point, it would make more sense to make a jillion different code-golf challenges since this essentially defines an entire class of golfing challenges. – Beefster May 13 at 16:32

# Create a Drawing Guide for a Polygram

Poor old Jim, he's just terrible at drawing polygrams, and he's asked you to create a "drawing guide" for him - an ascii polygram with numbered edges, so he can follow the instructions.

## Challenge

Write a program to produce an ascii polygram with P <= 10; each edge of the polygram should be made of a single digit 0-9, showing the order in which the edges should be drawn.

## Input

Your program should receive (via STDIN, as function arguments, or some other language-appropriate method): P, the number of edges/vertices of the polygram, and Q, the spacing. In the notation as per the Wikipedia link, you'll be drawing a {p/q} polygram.

## Output

Either print to STDOUT or return (or something else language-appropriate) a multiline string showing the drawing guide for the given polygram. The string can be any size you like, as long as it's large enough to display a clear polygram.

## Notes

Your code should be able to handle compound regular polygons as well as regular regular polygons, and also inputs of q > p/2 (poor old Jim doesn't realize that the polygram for {p/q} is the same as for {p/p-q}).

## Example Output for {10,3}

              5
5 4
4
21     5        888
2 11115     8888  7
2    5111888 4    7
2     888111  4   7
2  888      111   7
8885           4117
8882               4 711
8   2 5               7  111
25               47
9   5                 7    0
9  2                 74  0
52                 7  0
9 2                 7 4
5 92                 7 04
9                 70  4
5   2                 7
5    29                7    4
6666 2 9              07   33
666              0 7333
2 696           337
2   9666     333  7
2    9  66633 0   7
2      333 666    7
2   339       666 7
2333   9    0    67
9  0
0


## Scoring

This is code-golf, so shortest in bytes wins. Tiebreaker goes to the most votes.

• I have a python solution to this which is ~600 bytes, so it's definitely doable, and it's not easy... – sirpercival Apr 27 '15 at 4:31
• I think the spec needs to be more prescriptive for this to make a good question, especially since the example seems to indicate that you're not currently even prohibiting the lines from having gaps. At a minimum I would say that you should require the lines to be equivalent to those produced by Bresenham's algorithm, and specify how overlaps should be handled; at the extreme, you could tie it down so tightly that it becomes a parameterised kolmogorov-complexity. – Peter Taylor Apr 27 '15 at 9:34

# Pointer to pointers to pointers to pointers

You should choose a language supporting pointers like C. And your task is simple: demonstrate a legitimate use of the most level of pointers.

You should justify your code by describing an algorithm that:

• Has only plain text, number or an array of those as input and output.
• You think it will make things easier to write those code as a part of the implementation of this algorithm.
• This implementation would have optimum memory usage (only declared variables and parameters, explicitly allocated space, and the return addresses for recursive functions count).

Other rules:

• They must be pointers to pointers directly, i.e. a pointer to an object containing a pointer doesn't count. It's better if nobody using this code will want to extend some pointer to an object later.
• Each pointer must have a different type (if your language can somehow make them the same type).
• You should create at least one pointer, and either dereference or compare two non-null pointers once in each level.
• Using pointers as arrays is only half as interesting.
• Iterators, etc, are considered in essence pointers and allowed in this challenge. But you can't define new types implementing iterators for this purpose.

• Could you specify "legitimate"? This sounds a bit like code bowling (and seems to have the same issues). With enough imagination I'm sure I can justify any depth of pointers. – Martin Ender Apr 30 '15 at 17:43
• @MartinBüttner Edited but, basically, it is subjective. – jimmy23013 Apr 30 '15 at 17:57
• @MartinBüttner Added a restriction to have optimum memory usage. I'm not sure whether it works. – jimmy23013 Apr 30 '15 at 18:19

# Winning Tic-Tac-Toe lines

For a given tic-tac-toe board of size N**D (for example, a normal tic-tac-toe game is 3**2), the number of winning lines of length N is given by the expression:

$$2^{D-1} + \sum_{S=1}^{D-1}2^{S-1}DN^{D-S}$$

(Basically, you are summing the number of lines in each S-dimensional slice of the board.)

# The challenge:

Given N and D, your answer should output a list of D-dimensional coordinates for each winning line. Input and output are any reasonable format. You can assume that both N and D are positive integers, with N > 1. (Degenerate cases of N=1, D>1 not included.)

• How do you intend to determine which of two answers is fastest? – Peter Taylor May 12 '15 at 19:37
• yes, @randomra made the same point on chat. i'll edit this in, but i guess... i'll put together some test cases and then time them? i dunno, i was going back and forth between this and code-golf, but i'd prefer interesting and readable algorithms. – sirpercival May 12 '15 at 20:10
• i posted this here because i really want the answer, and i hate coming up with brute force solutions... :D – sirpercival May 12 '15 at 20:16
• Um. Given that you're asking people to enumerate an exponentially large set, in what sense will the answers not be brute force? – Peter Taylor May 12 '15 at 20:28
• well, there's brute force and then there's brute force. but really it's because i don't want to do it myself, haha. – sirpercival May 12 '15 at 20:34
• also, making use of symmetry can severely reduce the computation. – sirpercival May 12 '15 at 20:40
• I imagine that the runtime in any such algorithm will be basically proportional to the number of things you print, so there won't be any good way to improve by algorithm and the speed will be very platform-dependent. – xnor May 12 '15 at 23:40

# Ayn Random number generator

Inspired by xkcd 1277:

Write a random number generator that takes no input and generates a random integer between 1 and 100. When run less than 200 times, the frequency of all numbers needs to be between 0 and 2, but when it's ran 50 000 times, the number 42 (obviously) should have a frequence that's more than 4 standard deviations higher than the mean.

• 1. I think it's difficult to decide objectively whether a PRNG appears to be fair at first sight. 2. The term more often should probably be quantified. – Dennis May 18 '15 at 21:49
• I see lots of C rand()%1000 and the like incoming... – rorlork May 18 '15 at 22:05
• @Ypnypn I have changed the criteria to have much lower numbers so they're easier to verify. – Nzall Jun 6 '15 at 13:04
• @Dennis I have rewritten the question to clarify what "being fair" is and what "more often" actually entails. – Nzall Jun 6 '15 at 13:05
• 1. Are you thinking of a standalone program that you run multiple times or a function that is allowed to keep a state? In the first case, not even a perfect RNG will, with overwhelming probability, satisfy the first condition. 2. Do you mean the mean and standard deviation of a perfect, uniform RNG or the one the code implements? – Dennis Jun 6 '15 at 23:44
• @Dennis I'm thinking of just a function AynRandom() that gets called. The frequency of numbers with a small number of iterations is subject to change, maybe from 0 to 4. The mean and Standard Deviation must be the one the code implements. – Nzall Jun 7 '15 at 9:49
• between 0 and 2 ? so print 42 would be a valid program ? – Falco Jun 11 '15 at 15:32
• @Falco No, because 42 would appear more than 2 times (unless you only run it twice). The problem is that I need a way to indicate that the RNG is fair with a low iteration count, but unfair with higher iteration counts. The only way I can make it work is by stating that with low iteration counts, all numbers should appear about equally often, which is either 0, 1 or 2 times. – Nzall Jun 11 '15 at 15:36

Please nitpick this. If there's anything that wouldn't work or would be inconvenient, however small of an issue it is, tell me about it!
Also, suggestions for [adjective] are more than welcome.

# Determine how [adjective] a number is (code-golf)

A number would be considered [adjective] if 0 is the result of multiplying its digits together, then multiplying the digits of the resulting number, then repeating until a single-digit number is produced. The more steps it takes to reach 0, the more [adjective] the number is; if the resulting number is not 0, though, the number is not [adjective] regardless of how long it took to finish.
The formula used to determine [adjective]-ness is 10-10/T where T is however many numbers it took to reach 0 (including 0 and the initial input)

Your goal is, as the title says, to write a program or function that determines how [adjective] a number is, and prints every iteration along the way. Here are some example inputs/ouputs:

in: 879
out: 879    <-       (T=1)
504    <- 8*7*9 (T=2)
0      <- 5*0*4 (T=3)
<- optional newline
6.6... <- 10-10/3 (repeating decimals can be expressed in any way you want)

in: 2468
out: 2468   <-  T=1
96     <- (T=2) 2*4*6*8
54     <- (T=3) 9*6
20     <- (T=4) 5*4
0      <- (T=5) 2*0

8      <- 10-10/5

in: -888
out: -888
-512   <- -8*-8*-8
-10    <- -5*-1*-2
0      <- -1*0

6.6... <- 10-10/3

in: 1344
out: 1344
48
32
6

0    <- did not produce 0, so the prog/func returns 0


-Takes input from STDIN.
-Throws an "error" (printed to STDOUT) and halts immediately after input if the input has one or more 0s in it or if it's less than three digits in length. The error must be a string, and as it's supposed to be printed to stdout, cannot be one generated by the language itself (eg 1/int(min(input())) to check if it's zero). Lastly, the error message has to clearly define what the error is; ERR:0 and ERR:LEN, for example, would suffice.

Bonuses/Penalties:

-25 if it properly handles decimals. For instance, an input of 99.22 would first turn into 9*9 + 0.(2*2), or 9*9 + 0.4, and so on.

This is , so the shortest answer in bytes wins.

• I don't like the +15 penalty. Whether strings are used is vague in some languages. The constant amount +15 is too little deterrent for some languages but huge for very concise ones. The fact that you've found a short solution you don't like is sign you should rethink the problem, not try to plug the hole. – xnor Jun 17 '15 at 7:48
• @xnor that's reasonable. I suppose it is a valid way of doing it, anyway, so I removed all mention of strings in that section. Should I also inc/decrease the bonus for decimals? – M. I. Wright Jun 17 '15 at 22:29
• The programming languages I know either don't allow throwing user-defined errors or print them to STDERR. Now, if you just want us to print a message and exit immediately... – Dennis Jun 17 '15 at 23:32
• ...and should be printed to STDOUT. I had a feeling that wasn't clear; I edited it, is it better now? – M. I. Wright Jun 17 '15 at 23:33
• It's the word throw that throws me off (no pun intended). To throw an error usually means something rather specific. Print an error message to STDOUT (or closest alternative) would be less confusing in my opinion. Also, since this is code golf, I think you should require specific error messages. There's no fun in losing a contest because you chose ERR:LEN and somebody else got away with EL. – Dennis Jun 18 '15 at 3:16
• Remove bonuses altogether. It's in the list of things to avoid. – mbomb007 Mar 1 '16 at 21:31
• The error if the input contains a zero seems like a separate challenge. It may be better received if there is only one challenge. There is community support for avoiding Chameleon challenges. – trichoplax Aug 10 '16 at 11:40

# Represent a Number in the Strangest Way You Can Think Of.. while staying under 8 unique characters

Your goal is to represent some numbers in the strangest way possible.

### Rules:

• The result must be a number that can be used in the programming language like any other ordinary number. For instance, <my expression> + 3 should return 3 more than the value of <my expression>.
• The code must be under 20 kilobytes. That's a rather large size for a number so you should be all set.
• The expression must have under 8 unique characters! The length of it can be as long you want, just keep it under 8 unique characters. aaaaaaaaaaaaaaaaaa is valid (if it works in the programming language) but abcdefghijklm isn't valid because it uses 8 or more unique characters.

### Guidelines:

• The goal here is to represent a number in the strangest and most interesting way possible, so if I ask you to represent the number 35 it would be a good idea to respond with something more interesting than 35 or 12 + 23.
• This isn't a ! Feel free to make your code as long as you want, so long as it's under 20 kilobytes. Fancy code can look nice!
• The code doesn't need to support decimals (floats) but if it does, it will get 10 extra points (see below).
• The code also doesn't need to support negative numbers (for instance -37) but if it does, it will get 10 extra points (see below).

# Language

Description

### 0

...


### 1

...


### 30

...


### 108

...


### 1337

...


### 1234567890

...


### 3.1415 [10 bonus points if you can get this!]

...


### -25 [10 bonus points if you can get this!]

...


## Bonus numbers:

...

The points is equivalent to the number of votes on the answer plus 10 if it supports decimals with 10 more points if it supports negative numbers. Whoever has the highest points is considered the current winner. Have fun!

This is my first go at making a popularity contest so if you have any tips those would be appreciated.. :)

• This is a great challenge... whoever downvoted this has to rethink their concept of code-restriction challenges... – WallyWest Jul 15 '15 at 22:49
• Ah, thank you. :) – Florrie Jul 15 '15 at 23:28
• Updated again with negative numbers added (-25), as well as 1 and 0. – Florrie Jul 15 '15 at 23:33
• @Sp3000 8 unique chars, not 8 total. – isaacg Jul 16 '15 at 10:04
• @isaacg Didn't I state that? – Florrie Jul 16 '15 at 11:11
• @liam_ You did, the person I was responding to who deleted their comment missed it. – isaacg Jul 16 '15 at 11:32
• TBH, I think this is such a poor popcon that it can't be rescued, but if you want to at least make it clear what you're asking then: 1. You talk about representing "a" number, but also about "support[ing] decimals" and "support[ing] negative numbers". What exactly do you want? A function which maps numbers to code? But if so, the "Post format" makes no sense. 2. What is the code which has a 20kB limitation? Total for all the numbers listed in the "Post format"? Each individual number listed in the "Post format"? Something else? 3. Are the 8 distinct characters per number or for all numbers? – Peter Taylor Jul 17 '15 at 16:19