460
\$\begingroup\$

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.

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, 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. 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, replace the post here with a link to the challenge and delete it.

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

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

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]

\$\endgroup\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – JL2210 Sep 26 at 15:57
  • 1
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 at 13:43

2589 Answers 2589

0
\$\begingroup\$

Help! My code has exploded!

Insert backstory here

Task:

Your task is to create a program, which must follow these rules:

  • It must be able to be split exactly into pieces of the same length in bytes.
  • Once you have separated your program into pieces, your program must print 1 if the first "piece" is removed from your code, 2 if the second "piece" is removed, etc., until the program prints n if the nth piece is removed.

For example, if your program was the following:

aabbccdd

And it could be split into 4 equal parts of length 2, then these programs must result in the following outputs:

bbccdd -> 1 (aa is removed)
aaccdd -> 2 (bb is removed)
aabbdd -> 3 (cc is removed)
aabbcc -> 4 (dd is removed)

Scoring requirements:

Your program is scored based on the number of parts that it can be split into, with each part following the rules defined above. The more parts, the higher the score.

In the event of a tie, there is a "hierarchy" of scoring methods (with the next method in the list being used when there is a tie):

  • Number of parts the program can be split equally into
  • Size of the full program, in bytes (shortest byte-count wins)
  • Time posted (first poster wins)

Rules:

  • Each byte in the program must belong to one part.
  • Each part in the program must be of equal length.
\$\endgroup\$
  • \$\begingroup\$ You can make arbitrarily long programs that do this. I suggest instead that each answer should describe a pattern that can go to infinity (with possibly a starting piece). However scoring is difficult, since I forsee that some answers will have the segment number within each segment, meaning that going from 99 segments to 100 segments may require more characters per segment. \$\endgroup\$ – Shelvacu Jul 1 '17 at 20:02
  • \$\begingroup\$ Proof of concept for arbitrary number of segments: gist.github.com/shelvacu/e04c237ad8d1c066a7fd8b5170261e25 However, that was still fun to make so I definitely think there's potential here. \$\endgroup\$ – Shelvacu Jul 1 '17 at 20:13
  • \$\begingroup\$ @Shelvacu That seems like a really cool idea, yeah. Will change my question. \$\endgroup\$ – clismique Jul 1 '17 at 23:12
  • \$\begingroup\$ @Shelvacu Hmmm, I'm not sure how to properly make this into a challenge, TBH. I might scrap it. EDIT: I might have an idea, but I need to completely rewrite it. I might just delete this whole thing. \$\endgroup\$ – clismique Jul 3 '17 at 8:26
  • \$\begingroup\$ If you don't want to post it I will. Keep me posted. \$\endgroup\$ – Shelvacu Jul 3 '17 at 22:14
0
\$\begingroup\$

Introduction

Ten years ago, a secret encryption key used by DVD players was published online. When the industry tried to censor it, the internet reacted by republishing it widely—creatively incorporating the key onto shirts, a flag and even in song.

If this code golf community had existed, I'm sure we would have joined in.

Challenge

Output the number 13256278887989457651018865901401704640.

Example input and output

Input:

Not applicable.

Output:

13256278887989457651018865901401704640

\$\endgroup\$
  • \$\begingroup\$ This is code-golf I suppose, you should mention the winning condition. \$\endgroup\$ – officialaimm Jul 3 '17 at 17:42
  • \$\begingroup\$ Is there any reason to believe that there's any way to compress this other than base conversion? \$\endgroup\$ – Peter Taylor Jul 4 '17 at 7:40
0
\$\begingroup\$

Decode Reddit's Voting System

Background

Users with a high enough reputation on Stack Exchange can see the number of upvotes and downvotes on each question and answer. On Reddit, however, the net vote count and percentage of upvotes are displayed. Unfortunately due to rounding errors, it is impossible to determine exactly how many upvotes and downvotes occurred.

Challenge

Given a nonzero net vote count and a percentage of upvotes, return all possible pairs of the numbers of upvotes and downvotes.

Constraints

The net vote count can be any integer in the range [-2^31, 2^31).

The percentage can be a whole number in the range [0, 100], or a floating point number in the range [0, 1] with no more than two digits; you may decide which format to accept.

The percentage represents the percentage of votes which are upvotes, rounded to the nearest integer. So a value of 93% could be anywhere in the range [92.5%, 93.5%) that would result

The maximum numbers of upvotes and downvotes will not fall outside the range [-2^31, 2^31); that is, you should be safe using 32-bit signed integers.

You may not return two ranges representing all possible amounts of downvotes and upvotes; you must specify which numbers of upvotes correspond to which numbers of downvotes; hence you must return all possible pairs.

Test Cases

1, 67%  -> [(2, 1)]
1, 100% -> [(1, 0)]
1, 60%  -> [(3, 2)]
0, 50%  -> [(0, 0), (1, 1), (2, 2), ...]; cases like this will not be valid input
More involved ones to come...

Meta

Anything I can do to make this more clear or more fun?

\$\endgroup\$
  • 2
    \$\begingroup\$ 1. Does "net vote count" mean upvotes minus downvotes? 2. The listed input 0, 100% is a special case ((0-0)/(0+0) = NaN% or a division by zero exception) so it should be mentioned explicitly in the spec, not just added as a test case. 3. Input 0, 50% would have 2^31 valid outputs, so that should also get an explicit mention because of the potential for answers to fail due to array size limits etc. Combined with point 2, I would suggest editing the question to guarantee that the net vote count will never be 0. \$\endgroup\$ – Peter Taylor Jul 4 '17 at 7:38
  • \$\begingroup\$ "Unfortunately due to rounding errors, it is impossible to determine exactly how many upvotes and downvotes occurred." I was under the impression that reddit adds some random noise to the net votes (not sure about the percentage) to throw off bots or something. \$\endgroup\$ – Martin Ender Jul 4 '17 at 9:52
  • \$\begingroup\$ @PeterTaylor Thank you, updated \$\endgroup\$ – musicman523 Jul 4 '17 at 19:33
  • \$\begingroup\$ @MartinEnder I believe they simply stop reporting exact values after it reaches a certain threshold, but I'm not sure. For this challenge we'll assume they don't add any noise \$\endgroup\$ – musicman523 Jul 4 '17 at 19:34
0
\$\begingroup\$

Create The Correct Path

Which would be better code golf with shortest code and being able to run on at least two operating systems or code challenge and scoring by how many operating systems it can run on?

( OR )

Given an input create a program that when ran on different operating systems creates a path for each one. For example, when ran on Windows:

[ "folder1", "folder2" ] -> folder1\folder2

Input

An array of strings or any suitable alternative. The input can be empty, in which case you would just return an empty string.

Output

The correct path for the operating system the program has been ran on.

\$\endgroup\$
  • \$\begingroup\$ I'm mainly looking at feedback for what people think of this challenge before developing it further. \$\endgroup\$ – TheLethalCoder Jul 5 '17 at 10:16
  • \$\begingroup\$ I think you should include other operating systems with different paths separators in the challenge itself. \$\endgroup\$ – Kritixi Lithos Jul 6 '17 at 8:45
  • \$\begingroup\$ @KritixiLithos I was going to, was waiting to see if I should go with code-golf or code-challenge before writing up the formatting for all the examples. \$\endgroup\$ – TheLethalCoder Jul 6 '17 at 9:02
0
\$\begingroup\$

Draw a Probability Road

Background

I'm conducting a probability experiment. I have a collection of live rats, and I'm going to assign each rat a probability as a percentage integer from 1 to 99 (inclusive). The experiment will last 10 weeks, and at the end of each week, I'll roll a 100-sided die. Any rats who have a higher or equal probability than the number I roll, I kill.

Now of course I'd rather not go actually killing rats, so I want to write a program to create a probability road to show the probability of a rat surviving, when given that rat's probability number.

Unfortunately my lab is full of rats, so I don't have much room to write this program. As a result it needs to be as short as possible in order to fit in my cramped room.

The Challenge

Given an integer 0 < x < 100, output an ASCII Art probability road that shows the rat's chances of surviving.

Input can be taken as an integer, a string, an array of digits or an array of characters.

Output (detailed below) should be either printed/outputted, or returned as a single string (not an array of strings)

But what is a probability road?

A probability road is a type of probability chart used for displaying all possible outcomes of a given event. It consists of a series of lanes, each lane being one possible outcome, and the vertical axis representing time.

For our ASCII art challenge, we want each lane to be a space with a pipe on either side, like so:

| |
| |
| |

However 2 neighbouring lanes should share a pipe, like so:

| | | |
| | | |
| | | |

Every 2 lines of ASCII art represents one week of the experiment, and at each week, a number of lanes corresponding to the probability given should be terminated. A terminated lane ends in an X like so:

| | |
| | |X
| | | |

The lanes should be ordered with the longest lanes on the left, in descending order to the right, and the number of lanes in your probability road should be the fewest possible to accurately represent the given probability, for example given a probability of 50 (50%), the road would look like this:

| | | | | | | | | | |X - Week 10
| | | | | | | | | | | |
| | | | | | | | | | | |X - Week 9
| | | | | | | | | | | | |
| | | | | | | | | | | | |X - Week 8
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |X - Week 7
| | | | | | | | | | | | | | |
| | | | | | | | | | | | | | |X - Week 6
| | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | |X - Week 5
| | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | |X - Week 4
| | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | |X - Week 3
| | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | |X - Week 2
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |X - Week 1
| | | | | | | | | | | | | | | | | | | | |

Given the probability of 50%, half of the lanes should succeed past week 10, while each week, 5% of the total lanes should be eliminated. This could be displayed using 1000 lanes (as could every probability from 1-99), by terminating 50 each week and having 500 reach the end, however this is not the most simplified form of the chart, so doing so would not be valid for this challenge.

Note that the Week X labels are not necessary

Another example, this time for the input 80:

| | | | | |X X
| | | | | | | |
| | | | | | | |X X
| | | | | | | | | |
| | | | | | | | | |X X
| | | | | | | | | | | |
| | | | | | | | | | | |X X
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | | | | | | | |

This time, there are 25 lanes. Each week, 2 (8%) are terminated, and 5 (20%) make it to the end.

Rules

Standard loopholes apply, shortest code (in bytes, per language) wins.

As per usual, trailing whitespace is allowed. You may have trailing spaces at the end of lines, and one or more trailing newlines at the end of the output.

Meta

How can I make the explanation clearer? It seems difficult to understand currently.

Also is there anything else that needs specifying or clarifying?

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

If you've come here, you probably know what is, and that's what I'm going to assume.

Story

(I guess)


Keyboards are input devices we use all the time. They existed before mice and touch screen, etc.

Their fundamentals have not changed: when you press a key down, a signal is sent to the computer. When you release it, another signal is sent.

So here's the challenge: calculate the minimum number of signals(length of a signal does not matter) depending on the input string.

Example:

Input:

test

Output:

8

Explanation: All keys have to be pressed down and released


Input2:

TEst

Output2:

10

Explanation: Shift has to be pressed, then T, down, up, E, down, up, then release shift, then s down, up, then t down, up, totalling up to 10.


Rules

Any language is accepted.
This is , so shortest code in bytes wins.
Programs with incorrect outputs will be disqualified.

Happy golfing!

Edit:

The keyboard layout used should be this: http://dry.sailingissues.com/keyboard-US-International.png

Only characters in this keyboard layout will be used (+lowercase letters).

Using Caps-Lock is ok, since it DOES have an advantage: numbers remain numbers while letters become uppercase.

Thanks for the feedback so far.

\$\endgroup\$
  • \$\begingroup\$ I think this might be a dupe, lemme see if I can find the original. EDIT: Ah, it's your challenege. I suggest deleting it from main while you work on it here; you can edit and then undelete it when it's ready. \$\endgroup\$ – Shaggy Jul 6 '17 at 9:10
  • \$\begingroup\$ Test cases? Your comment about caps lock is a good example of an edge case which should be explicitly covered by the test cases, and implies another where a shift covers a substring which mixes upper-case letters and symbols. \$\endgroup\$ – Peter Taylor Jul 6 '17 at 10:24
0
\$\begingroup\$

Abbreviate a rename

After you commit a rename, git reminds you but tries to avoid showing the full source and target path. It does this by splitting the path into components, extracting identical leading and trailing components, then using them to abbreviate the rename. (Other output that git produces is not relevant here.) Here is an example:

foo/bar/baz/quux.c => foo/baz/bar/quux.c

The leading component foo and trailing component quux.c is the same, so this becomes

foo/{bar/baz => baz/bar}/quux.c

This also works when one of the components is empty, e.g.:

foo/{bar/baz => }/quux.c
foo/{ => baz/bar}/quux.c

Please write a program or function that abbreviates a rename. The input can be a pair of strings or a single string with a delimiter which can be => or newline or something else not typically found in a file name. The output should be a single string containing a => as shown. You can assume that neither string is a prefix of the other (git doesn't abbreviate the rename in that case for some reason.)

This is , so the shortest program wins!

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

Lazy programmers need help versioning!

So here's a question, which is related to a recent problem I had while doing some data processing. I think it is good practice to include version numbers in file names to prevent data being overwritten and so you can see how things have changed with each version but I'm lazy so want it automating!

Your challenge

Take a full Windows file path and either increment the file version, or if there is no version, make it version 1.

Input

A full Windows file path, that includes the file extension.

Output

The original file path with the file version, incremented appropriately.

Rules

  • The version is determined by an underscore followed by a single digit, i.e _1 for version 1.
  • For a file that already have a version, it will only be in the range 1-8, so you only ever have to deal with single digit file versions.
  • Standard rules apply
  • Default Loopholes are forbidden.
  • Please provide explanations of your code so others can learn form it and if possible, links to an online interpreter such as TIO
  • This is so shortest code in bytes wins!

Test cases

Case 1
Input:  C:\Foo\Bar.txt
Output: C:\Foo\Bar_1.txt

Case 2
Input:  C:\notsortedfile_version_1_new_5.docx
Output: C:\notsortedfile_version_1_new_6.docx

Case 3
Input:  D:\a\very\deep\file\567234.pdf
Output: D:\a\very\deep\file\567234_1.pdf

Case 4
Input:  Z:\Storage\Somefile_2017-04-11.txt
Output: Z:\Storage\Somefile_2017-04-11_1.txt

Case 5
Input:  Z:\Storage\I.Like.Dots.txt
Output: Z:\Storage\I.Like.Dots_1.txt

Sandbox Questions

Not sure if this is dupe of Please release me!

Any feedback welcome.

\$\endgroup\$
  • \$\begingroup\$ I don't think it's a dupe. My opinions: You shouldn't let the test cases be dependent on OS. Just stick with one, the challenge is to modify a string, it doesn't really depend on which OS you're on. Personlly, I'd skip the 1-8 limitation. I think it would be more fun to go from file_9 to file_10. People (including you) might disagree with me though. \$\endgroup\$ – Stewie Griffin Apr 11 '17 at 8:51
  • 1
    \$\begingroup\$ Also, I though version control was handled this way: filename.xyz -> filename_new.xyz -> filename_new_1.xyz (remember to rename the previous to: filename_new_OLD.xyz). And of course versions such as filename_new_2_backup.xyz, filename_final_version.xyz -> filename_final_version_2.xyz. \$\endgroup\$ – Stewie Griffin Apr 11 '17 at 8:56
  • \$\begingroup\$ Which is why need to get some code to do it for us :) \$\endgroup\$ – Notts90 Apr 11 '17 at 8:58
  • \$\begingroup\$ Will file names only ever contain a .? \$\endgroup\$ – Shaggy Jul 6 '17 at 11:19
  • \$\begingroup\$ @Shaggy It could be any valid windows file path so yes, I've added a test case to cover it. \$\endgroup\$ – Notts90 Jul 6 '17 at 11:26
  • \$\begingroup\$ Test case: c:\foo? \$\endgroup\$ – Peter Taylor Jul 6 '17 at 13:32
0
\$\begingroup\$

The task

Your code should take in an integer 0 < x < 1965593254291461501637330902918203684832716283083 and output the smallest integer m such that x^m mod 1965593254291461501637330902918203684832716283083 = 1. This long number is the next prime after 2^100 so can be encoded efficiently.

You may take the input in any format that is convenient and output in any convenient form too.

Your code should take less then one minute to run on a standard desktop no matter what the input.

Examples

2, 4235851503548771316711413838489497242205033676
3, 16943406014195085266845655353957988968820134704
169434060141950852668456553539579889688, 16943406014195085266845655353957988968820134704

Those with python or similar can check the answers with e.g. pow(3,16943406014195085266845655353957988968820134704, 1965593254291461501637330902918203684832716283083) which equals 1.

You may not use any builtin or library function which solves this problem for you.

\$\endgroup\$
  • \$\begingroup\$ Is there a reason you picked that specific number? \$\endgroup\$ – Pavel Jul 6 '17 at 20:07
  • \$\begingroup\$ I think that unless there's a simple formula that gets that number, hardcoding that value would take more bytes than the rest of the code. \$\endgroup\$ – Pavel Jul 6 '17 at 20:07
  • \$\begingroup\$ @Phoenix I added a simple formula. \$\endgroup\$ – user9206 Jul 6 '17 at 20:13
  • \$\begingroup\$ I don't think it's a great idea to use nubmers that are so large that many languages require special constructs to represent them, it gives an unfair advantage to languages with arbitrary precision integers, which already tend to be shorter. \$\endgroup\$ – Pavel Jul 6 '17 at 20:19
  • \$\begingroup\$ @Phoenix I take your point but the point of this challenge is to devise efficient code for large inputs. Languages with builtin large number support tend to be quite slow (e.g. python) compared to e.g. C. I would like to leave it like this. \$\endgroup\$ – user9206 Jul 6 '17 at 20:22
  • \$\begingroup\$ Is there an efficient way to find the multiplicative order modulo a prime of a number, short of factoring p-1? \$\endgroup\$ – xnor Jul 7 '17 at 4:59
  • \$\begingroup\$ @xnor, none known. \$\endgroup\$ – Peter Taylor Jul 7 '17 at 7:35
  • \$\begingroup\$ @PeterTaylor Is 100 bits too big to factorize without calling library code to do it for you? Or could the question allow you to factorize the number beforehand? (Wolfram alpha will do that for free for example for the number in my question minus 1.) \$\endgroup\$ – user9206 Jul 7 '17 at 7:52
  • \$\begingroup\$ @PeterTaylor I am just wondering how much I need to reduce the number by. Currently it is 160 bits. \$\endgroup\$ – user9206 Jul 7 '17 at 8:37
  • \$\begingroup\$ @PeterTaylor Actually even the command line tool factor can handle the 160 bit number it turns out \$\endgroup\$ – user9206 Jul 7 '17 at 8:52
0
\$\begingroup\$

Escape the Labyrinth!


Introduction

You are stuck in a labyrinth. You only have your brain and a map. Now you need to find a way out, of course your brain doesn't have much memory (or else you wouldn't be stuck!) so you need to optimize your mental code for size. Of course we can't trivially program in the brain-language, so your brain will also accept any other language.

Specification

Input

Your input will be a Matrix. You may encode it however serves your language best as long as the format doesn't encode additional information. For the purpose of this challenge I will use a list of lists for representation and explanation.

Said matrix will contain four distinct values:

  • 0: This marks a spot you can move onto
  • 1: This marks a wall
  • 2: This marks the starting point
  • 3: This marks the target point

It is guaranteed that there will be exactly one occurence of type-3 and type-2. You may also change the above values / data-types to your liking as long as you don't encode additional information.

It is guaranteed that you will get an input that has a solution. If the input doesn't have a valid solution, the behavior is left undefined. Your program may not terminate, it may error out, it may simply return nothing, it may blow up, it may become a political activist or it may do something else.

You may assume that the input labyrinth is walled-off, that is you can't actually "leave" the labyrinth.

Output

Your output will be sequence of four different values:

  1. L: Stands for left
  2. R: Stands for right
  3. U: Stands for Up
  4. D: Stands for Down

You may change the values and data types of the above constants to your liking, as long as you document these changes and you can uniquely infer the path.

What to do?

Given the labyrinth, start your virtual character at the position tagged 2 and find a way to the position tagged 3. You may not pass through walls (1 cells) and you may only go one step up, left, right or down in each step. You also need to document your action of course in each step, ie output it as described above.

Note: You do not have to find the shortest path, but rather a path.

Who wins?

This is , so the shortest solution in bytes wins! Standard loophole rules apply of course. Standard I/O rules also apply.

Example

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

might result in:

Going right.
Going down.
Going down.
Going right.
Going down.
Going down.
Going down.
Going right.
Going right.
Going up.
Going right.
Going right.
Going down.
Going down.
\$\endgroup\$
  • \$\begingroup\$ Potential questions: What other tags to use? Should it be allowed to receive position information of 2 and 3 in the input as well? \$\endgroup\$ – SEJPM Jul 7 '17 at 20:15
  • 1
    \$\begingroup\$ I'd be very surprised if this wasn't a duplicate. I'm stuck on mobile for quite a while, but My car only turns right is very similar except you have to manage orientation. I'd look closely at other maze challenges to see that this adds to the site. \$\endgroup\$ – FryAmTheEggman Jul 9 '17 at 21:33
  • \$\begingroup\$ I agree with FryAmTheEggman. This is very likely a dupe. \$\endgroup\$ – Gryphon - Reinstate Monica Jul 9 '17 at 23:50
0
\$\begingroup\$

Combine RGBA colors

The function Combine input a list of RGBA colors. Shapes with given color was drawn on the same position one by one. The first color was drawn on the top, and the last one drawn on the bottom. You need calculate what color the shape is when all these shapes was drawn.

Formula

Colors are represented in Red, Green, Blue, and, Alpha components:

  • Red, Green, Blue are numbers in range 0 ~ 255 (inclusive).
  • Alpha is a number in range 0 ~ 1 (inclusive).

If there are only one color, the following formula applied:

Combine(color) = color

If there are exactly two colors, the following formula applied:

Combine(top, bottom) = {
    r = (top.r * top.a + bottom.r * (1 - top.a) * bottom.a) / (1 - (1 - top.a) * (1 - bottom.a)),
    g = (top.g * top.a + bottom.g * (1 - top.a) * bottom.a) / (1 - (1 - top.a) * (1 - bottom.a)),
    b = (top.b * top.a + bottom.b * (1 - top.a) * bottom.a) / (1 - (1 - top.a) * (1 - bottom.a)),
    a = 1 - (1 - top.a) * (1 - bottom.a)
}

* if top.a = bottom.a = 0 then r, g, b may be any numbers in range 0 ~ 255

If there are more than two colors, the following formula applied:

Combine(first, second, third, ..., (n-1)th, nth)
    = Combine(Combine(first, second), third, ..., (n-1)th, nth)
    = Combine(first, Combine(second, third), ..., (n-1)th, nth)
    = ...
    = Combine(first, second, third, ..., Combine((n-1)th, nth))

Since this function is associative, you may chose the order you prefer.

Input format

You may take input from stdin, or function parameter, or other acceptable input format.

If you are taking input from an single string or stdin, colors should in following format:

  • In red green blue alpha format (e.g. 10 20 30 0.4, 100 200 250 0.5)

colors are separated by a single whitespace character (space, tab, cr, lf, ...).

You may also take input in anything which can express an ordered list (e.g. array, list, tuple, multiple function parameters, or maybe something else...) of colors. And colors may be represented as a string described above or an ordered list with 4 number values.

Red, green, blue components inputted are guaranteed to be integer. But you are allowed to output them as real number.

An optional integer number for count of colors at the beginning or ending of the input or as an parameter is allowed.

Input should not contain other values which does not described above.

Input always has at least one color.

Output format

You should output a single color in any format described above and the format should also be accepted by your code.

If output color meets alpha = 0, red, green, blue component may be any valid number in range 0 to 255.

Output value should in the range described above (rgb should in 0 ~ 255, a should in 0 ~ 1).

Floating point precision

When calculate Combine function with only one parameter, any floating point error is not allowed.

When calculate Combine function with two parameters, red, green, blue component should not have an error greater than (0.5 + ε); alpha component should not have an error greater than (0.005 + ε).

When calculate Combine function with more than two parameters, the formula first convert it to an sequence of calling Combine multiple times with two parameters, the errors allowed in each call is described above, and the error may be accumulated.

Sample testcases

[[0, 0, 0, 0.5]] -> [0, 0, 0, 0.5]
[[0, 0, 0, 1], [1, 1, 1, 1]] -> [0, 0, 0, 1]
[[0, 0, 0, 0], [1, 1, 1, 0.5]] -> [1, 1, 1, 0.5]
[[50, 100, 200, 0.5], [100, 200, 0, 0]] -> [50, 100, 200, 0.5]
[[10, 20, 30, 0.5], [10, 20, 30, 0.5]] -> [10, 20, 30, 0.75]
[[120, 240, 33, 0.5], [0, 0, 0, 0.5]] -> [80, 160, 22, 0.75]
[[0, 0, 0, 0], [0, 0, 0, 0]] -> [r, g, b, 0]*
    * r, g, b may be any numbers in range 0 ~ 255
[[20, 70, 20, 0.5], [140, 110, 80, 0.5], [200, 200, 110, 0.5]] -> [80, 100, 50, 0.88]
[[251, 140, 20, 0.19], [182, 161, 148, 0.28], [27, 99, 33, 0.05], [154, 107, 234, 0.55], [112, 142, 9, 0.26], [136, 225, 243, 0.39], [57, 157, 208, 0.54], [214, 252, 4, 0.96], [152, 183, 38, 0.13], [140, 242, 83, 0.73]] ->[168, 146, 140, 1]*
    * floating errors are allowed

Winner

This is code golf, code shortest in bytes win.

\$\endgroup\$
  • \$\begingroup\$ Is there an upper limit to the number of colours we'd need to be able to handle? Can you explain your reasoning for allowing the number of colours to be taken as an additional input? \$\endgroup\$ – Shaggy Jul 7 '17 at 9:00
  • \$\begingroup\$ Oh, and a few test cases and a worked through example would be handy, too. \$\endgroup\$ – Shaggy Jul 7 '17 at 9:06
  • \$\begingroup\$ @Shaggy for languages do not support the EOF concept in stdin (I do not know but maybe), or languages need an mark to indicate array length (like C). \$\endgroup\$ – tsh Jul 7 '17 at 9:21
  • \$\begingroup\$ @Shaggy Is an upper limit should be included? Will it simply be "any finite number"? Although program may not be able to handle large input due to memory limitation. But that should not be considered generally, IMO. \$\endgroup\$ – tsh Jul 7 '17 at 9:38
  • \$\begingroup\$ No, I don't think and upper limit is needed, it was just a query. Whether you do have an upper limit or not, you should probably specify it in the challenge somewhere. See my opinion on allowing C to take list length as an extra argument here. For the test cases (when you add them), I'd suggest providing both the expected output and the allowed ranges when taking floating point precision errors into consideration. \$\endgroup\$ – Shaggy Jul 7 '17 at 10:02
  • \$\begingroup\$ Ooops, the formula was wrong. fixed. \$\endgroup\$ – tsh Jul 7 '17 at 10:25
  • \$\begingroup\$ @Shaggy test cases had been added, should there be some more? \$\endgroup\$ – tsh Jul 7 '17 at 10:25
  • \$\begingroup\$ @Shaggy but question itself may override these default rules, right? also, I don't think add another optional parameter would make the question any easier. \$\endgroup\$ – tsh Jul 7 '17 at 10:29
  • \$\begingroup\$ I'd suggest adding test cases that have 3 or more colours and also a greater range of colours and alphas. \$\endgroup\$ – Shaggy Jul 7 '17 at 10:46
  • \$\begingroup\$ @Shaggy two more testcases are added. \$\endgroup\$ – tsh Jul 7 '17 at 11:34
  • \$\begingroup\$ I still think specifying the range of acceptable results for the test cases (the last one in particular) could help add some clarity. My rough tests without any rounding gave RGB values of 168.1342541694134,146.5053458267826,140.72902296732062for the last test case but, depending on when and how I rounded, they could end up being as low as 163,143,136 or as high as 171,151,143. \$\endgroup\$ – Shaggy Jul 10 '17 at 10:32
  • \$\begingroup\$ @Shaggy Since the operation is not a linear one, it is very difficult to calculate the range allowed. Maybe if the final answer has an error greater than (0.5, 0.005), the proving of the error should be left to the respondent. \$\endgroup\$ – tsh Jul 11 '17 at 1:11
0
\$\begingroup\$

Stitch the Genome

Introduction

As you probably know DNA (deoxyribonucleic acid) is made up of bases, often denoted as A T C and G. One of the coolest things we can do with DNA is sequence it, or figure out what sequence of base pairs make up the molecule. Sequencing small molecules of DNA is easy, but it is hard to sequence long strands without error. Instead, the long strands are copied many times, then cut up into many little pieces. Those pieces are then fed through the sequencer. What we end up getting are many, many sets of pieces of the strand. In each set, we are near-guaranteed to get every base in the strand, but they aren't in any order. The solution, then, is to compare all of the different sets of strand pieces we have, and try and figure out how to put them together.

Challenge

Your challenge is, given a set of strand pieces, output a possible sequence of the original strand. To simplify real life a bit, you can expect that each set will always contain the entire strand sequence (not in order, mind you), and that there will be at least one possible sequence. Observe a simple example:

Input:
 - [ATC, G]
 - [CG, AT]
Output: ATCG

From the first input, we deduce two possibilities: ATCG and GATC. From the second input, we deduce another two possibilities: CGAT and ATCG. As you can see, the only common possibility is ATCG, and thus that is our answer. Let's look at another example:

Input:
 - [AT, G, C]
 - [A, TG, C]
Output: ATGC or CATG

Here, we deduce six possibilities from the first input: ATGC, ATCG, GATC, GCAT, CATG and CGAT. Then, from the second input, we deduce another six possibilities: ATGC, ACTG, TGAC, TGCA, CTGA and CATG. Since there are two common possibilities, ATGC and CATG, we can output either one.

Essentially, this problem can be reduced to: find a common permutation of the input.

Specifics

  • You may write a program or function
  • You may input in any acceptable format (array of arrays, list of lists, separated string, etc.). Furthermore, you may substitute A T C and G in your input with any other unique values, as long as you're consistent
  • You may output in any acceptable format
  • Standard loopholes apply

Test Cases

Format:

Input:
 - Pieces 1
 - Pieces 2
 - Etc.
Possible Outputs: [Possible output 1, possible output 2, etc.]

Input: 
 - [G, A, C, C, T, A, G]
 - [GAC, C, TAG]
 - [G, AC, CT, AG]
 - [GA, CC, T, A, G]
Possible Outputs: [GACCTAG]

Input: 
 - [G, C, G, C]
 - [G, C, GC]
 - [G, CG, C]
Possible Outputs: [GCCG, CGCG, GCGC, CGGC]

Input: 
 - [TA, A]
 - [TA, A]
 - [T, AA]
Possible Outputs: [TAA]

Input: 
 - [CC, T, A]
 - [CC, T, A]
 - [C, CT, A]
Possible Outputs: [CCTA, ACCT]

Input: 
 - [GAG, C, T, C]
 - [GA, G, C, TC]
 - [GA, G, C, T, C]
 - [G, A, G, C, T, C]
 - [G, AGC, TC]
Possible Outputs: [GAGCTC, TCGAGC]

Input: 
 - [AG, A, C, A, T, G]
 - [AG, A, C, A, T, G]
 - [AGAC, A, TG]
 - [AGA, CA, T, G]
 - [A, G, AC, A, T, G]
 - [A, G, A, C, ATG]
Possible Outputs: [AGACATG]

Input: 
 - [C, A, A, C, T]
 - [CA, A, C, T]
 - [CA, A, C, T]
 - [C, A, AC, T]
 - [C, A, A, C, T]
 - [C, AA, C, T]
Possible Outputs: [CAACT, TCAAC]

Input: 
 - [CA, G, C]
 - [CAG, C]
Possible Outputs: [CAGC, CCAG]

Input: 
 - [A, GT]
 - [A, G, T]
 - [AG, T]
Possible Outputs: [AGT]

There is a set of 100 random test cases here, or you can check out the java program that generated them.

\$\endgroup\$
  • \$\begingroup\$ Too much intro, IMHO. \$\endgroup\$ – Adám Jul 12 '17 at 17:50
  • \$\begingroup\$ @Adám that was fast! I'll look into cutting down at that! Got to go do a thing now though, so it may be a while.... \$\endgroup\$ – Socratic Phoenix Jul 12 '17 at 17:51
  • \$\begingroup\$ any other unique characters or numbers? \$\endgroup\$ – Adám Jul 12 '17 at 17:53
  • \$\begingroup\$ @Adám hmm... unique values i guess... I'll update it now \$\endgroup\$ – Socratic Phoenix Jul 12 '17 at 18:31
0
\$\begingroup\$

What's Underneath the Sine Wave?

Task

Your task is to output a part of the sine wave out of any characterss of your choosing and on any background of your choosing. The wave can start and end either on the highest or the lowest point of the wave if both are the same.

The challenges main part is what happens below the wave (or above if you chose to start at the peaks of the wave). For each column, looking top-to-down it should repeat until the bottom the segment of spaces until the wave.

Or a visual explanation:

Start with a sine wave of your choosing (this is not a valid one as it isn't 50x20, but smaller to save space):

             ####             
           ##    ##           
          #        #          
         #          #         
        #            #        
       #              #       
      #                #      
     #                  #     
    #                    #    
  ##                      ##  
##                          ##

and then, look top-down and until the 1st encounter of a non-background character record the characters and then repeat them:

        ↓   ↓####             
        ↓  ##  P ##           
      4x↓ # ↓  P   #          
        ↓#  P  P    #         
        X   ↓  P     #        
       #↓   P  P      #       
      # ↓4x ↓  P       #      
     #  ↓   P  P        #     
    #   ↓   ↓  P         #    
  ##    P   P  P          ##  
##      ↓   ↓  P            ##

so for this the output would be

             ####             
           ########           
          #  ####  #          
         # ######## #         
        #    ####    #        
       #  ##########  #       
      #      ####      #      
     #   # ######## #   #     
    #     #  ####  #     #    
  ##    #  ########  #    ##  
##           ####           ##

Clarifications

  • There can be any amount of leading/trailing lines with any amount of whitespace
  • On each line there can be extra leading whitespace, as long as the amount is equal on all lines
  • The width should be at least 50 characters total (excluding columns of only whitespace)
  • The height should be at least 20 characters total (excluding lines of whitespace only)
  • The repeating bottom parts must be cut from the bottom (or top) of the wave
  • Inaccuracies due to rounding or floating-point errors can be dismissed
  • The background character has to be constant
  • The wave characters can be different, as long as they aren't ever equal to the background
  • This is , the shortest code per language wins!

Sample outputs

                         XXXXXX
                       XXXXXXXXXX
                     XX  XXXXXX  XX
                    X  XXXXXXXXXX  X
                   X     XXXXXX     X
                  X  XXXXXXXXXXXXXX  X
                XX       XXXXXX       XX
               X    X  XXXXXXXXXX  X    X
              X      XX  XXXXXX  XX      X
             X     X   XXXXXXXXXX   X     X
            X            XXXXXX            X
           X      X XXXXXXXXXXXXXXXX X      X
          X              XXXXXX              X
         X      XX     XXXXXXXXXX     XX      X
        X          X XX  XXXXXX  XX X          X
       X       X    X  XXXXXXXXXX  X    X       X
      X                  XXXXXX                  X
    XX        X   X  XXXXXXXXXXXXXX  X   X        XX
   X                     XXXXXX                     X
XXX          X     XX  XXXXXXXXXX  XX     X          XXX

..................................................
DCB....................QPONM....................10
...A9........0.......SRQPONMLK.......C........32
.....8..........X...T..QPONM..J...F..........4
......7.......Z...VU.SRQPONMLK.IH...D.......5
.......6...............QPONM...............6
........5......Y.W..TSRQPONMLKJ..G.E......7
.........4.............QPONM.............8
...................U.SRQPONMLK.I
..........3.......V.T..QPONM..J.H.......9
...........2....X....SRQPONMLK....F....A
............1..........QPONM..........B
.................W.UTSRQPONMLKJI.G
.............0.........QPONM.........C
..............Z...V..SRQPONMLK..H...D
...............Y....T..QPONM..J....E
...................U.SRQPONMLK.I
................X......QPONM......F
.................W..TSRQPONMLKJ..G
..................V....QPONM....H
...................U.SRQPONMLK.I
....................T..QPONM..J
.....................SRQPONMLK
.......................QPONM..................................
...
.
....

sandbox

  • please suggest (or just edit in) ways of making this clearer
  • Anything missing?
  • Should I make this challenge take input, rather than being an broad kolmogorov-complexity challenge?
\$\endgroup\$
  • \$\begingroup\$ Is the sample output for input X? \$\endgroup\$ – officialaimm Jul 3 '17 at 12:27
  • \$\begingroup\$ @officialaimm The characters can be of your choosing, there's no input currently \$\endgroup\$ – dzaima Jul 3 '17 at 12:27
  • \$\begingroup\$ So, all the positions marked by X should have same character or can have different characters? \$\endgroup\$ – officialaimm Jul 3 '17 at 12:40
  • \$\begingroup\$ @officialaimm They can have any characters \$\endgroup\$ – dzaima Jul 3 '17 at 12:42
  • 1
    \$\begingroup\$ I think its better if you showcase sample output with different characters then. \$\endgroup\$ – officialaimm Jul 3 '17 at 12:53
  • \$\begingroup\$ I can't tell what the task is from reading the description, or from looking at the example. It might help to walk through a few example columns to make it clear, then follow up with the full wave examples after that. \$\endgroup\$ – trichoplax Jul 17 '17 at 14:12
  • \$\begingroup\$ @trichoplax good idea \$\endgroup\$ – dzaima Jul 17 '17 at 14:12
  • \$\begingroup\$ Thanks. A second look at the examples was enough for me to grasp the pattern, but a step by step example would probably have got it across quicker. \$\endgroup\$ – trichoplax Jul 17 '17 at 14:14
0
\$\begingroup\$

Pristine Pristige

A pristine program, as defined by Calvin'sHobbies, is

a program that does not have any errors itself but will error if you modify it by removing any contiguous substring of N characters, where 0 < N < program length.

Pristige is a language I designed in which all syntactically valid programs are pristine.

Pristige works just like Brain-Flak, except every function requires a airity declaration at the beginning. An airity of n is declared with n .s followed by a |. For example the Brain-Flak program

({}())

Is equivalent to the Pristige Program

(..|{|}(|))

In addition Pristige requires that there is only one function at the top level of the program. Meaning that

(.|{|}){.|(..|{|}[.|(|)])}

Is an invalid program.

To be absolutely concrete here is a grammar that spans all syntactically valid Pristige programs:

S → (A) : <A> : {A} : [A]
A → .AS : |

Task

You must write a compiler from Pristige to Brain-Flak, that is itself a pristine program.

This is a question so answers will be scored in bytes, with less bytes being better.

Rules

  • You must either throw an error (or print error if your language cannot do so) if the inputted program is syntactically invalid.

  • If the input is syntactically valid you must output an equivalent Brain-Flak program. The simplest way to do this is to remove all instances of . and |, but you are not required to do so.

  • You may use any default IO format.

  • Your program must be a pristine program. That means deleting any continuous substring must cause an error

Reference Implementation

Here will go an implementation I have not yet completed

Test Cases

Here will go test cases

\$\endgroup\$
  • \$\begingroup\$ Surely we should print error if the program is syntactically invalid? Sort of unrelated, but is Pristige a mix of the words pristine and prestige? \$\endgroup\$ – FryAmTheEggman Jul 17 '17 at 19:25
0
\$\begingroup\$

Write a code poem

It is said that Larry Wall, creator of Perl, wrote a poem titled "Black Perl" in said language, as shown here.

The poem is fully functional (working syntax, no runtime errors, etc. [no errors in general]).

The challenge:

In any language (practical languages recommended), write a haiku (example of one at https://en.wikipedia.org/wiki/Haiku).

Coding rules:

  • The poem must be able to function properly (no errors).
  • Unlike Wall's poem, you must run through the whole program (exits only at the end).
  • If you define a function to act as a word, it will count towards your poem.
  • Caught errors and other error-handling tricks are valid.

Misc rules:

  • You cannot use multi-line strings or line continue symbols, etc. (No multi-line functions/tricks).
  • Brackets, parentheses, and other grouping symbols (with the exception of < and > as operators are ignored unless as a string.

Example lines (written in Python, not the best, probably):

while i_love ....: # i_love counts as two words

i_am > than_you # read symbols/operators as words

"""my love for ...
is ....... by ...""" # Invalid, as stated by one of the misc. rules

me(,"john", "abby",
    "and liz") # invalid, line continuation

Winning:

This is a , so submission with the highest amount of votes wins.

For sandbox only:

How can I improve on this challenge? Is there anything else I should add? Let me know in the comments.

\$\endgroup\$
  • 1
    \$\begingroup\$ This is currently both too broad and unclear. What does "work" mean? What is a "script"? What is allowed besides "words" (whatever those are)? How do we measure answers against each other? Try to look at some of the challenges on this site to get a better feel for what we do here - I'm afraid this is very far off the mark. You can try asking other users in chat, once you get some reputation, about ways to make this fit better, but personally I don't think this kind of challenge is a good fit for this site. \$\endgroup\$ – FryAmTheEggman Jul 17 '17 at 19:35
  • \$\begingroup\$ I like the idea, but I think you need to be more specific in what is valid and invalid. If my script is just one giant multi-line string, it satisfies your requirement, but obviously that's not what you're going for. \$\endgroup\$ – wrymug Jul 17 '17 at 19:37
  • \$\begingroup\$ Will edit the question. \$\endgroup\$ – S.G. Harmonia Jul 17 '17 at 19:37
  • \$\begingroup\$ Are caught errors allowed? \$\endgroup\$ – wrymug Jul 17 '17 at 20:38
  • \$\begingroup\$ You mean stuff like try? \$\endgroup\$ – S.G. Harmonia Jul 17 '17 at 20:57
  • \$\begingroup\$ Who wins? What's the criterion for deciding that? \$\endgroup\$ – Rɪᴋᴇʀ Jul 17 '17 at 21:32
  • \$\begingroup\$ @Riker I am currently thinking about that. \$\endgroup\$ – S.G. Harmonia Jul 17 '17 at 23:07
  • \$\begingroup\$ @S.G.Harmonia yeah \$\endgroup\$ – wrymug Jul 18 '17 at 0:05
  • \$\begingroup\$ I do think this question might be too broad. Maybe make it so it has to be a haiku? And then score by popularity contest \$\endgroup\$ – wrymug Jul 18 '17 at 0:07
  • \$\begingroup\$ 1. I have no idea where to close the parenthesis in "Brackets, parentheses, and other grouping symbols (with the exception of < and > as operators are ignored unless as a string.". 2. A popularity contest should have a clear spec to identify valid answers, and an indication of what aspect of the answers makes them good. It's a hack to judge subjective contests like codegolf.stackexchange.com/q/33172 . I don't think this has a clear spec ("Don't produce an error" is far too broad), and it's not clear what makes a haiku program a good haiku program? \$\endgroup\$ – Peter Taylor Jul 18 '17 at 7:35
  • \$\begingroup\$ As an illustration of the problems raised in point 2, consider that I can take any haiku I want, remove the characters ,.+-<>[] (of which only the first two are likely to be present anyway) and claim it's a brainfuck program which does nothing. And before you edit to add a rule to prohibit that directly, let me emphasise the word illustration. The problem is far deeper, and I don't think it can be fixed. It certainly can't be papered over. \$\endgroup\$ – Peter Taylor Jul 18 '17 at 7:37
0
\$\begingroup\$

Challenge

Take a number and output it with 4 digits or less using letters and numbers. For example; 270,030 would turn into 2.7K.

Key

Billion -> B

Million -> M

Thousand -> K

Rules

  • You may choose to accept input numbers that include commas delimiting every three decimal places (such as 123,456,789).
  • Round to nearest, half-up.
  • Numbers will only go up to a trillion.
  • The mantissa part of the answer should be at least 1.
  • All letters must be uppercase and as specified below.
  • Outputs must be 4 or less characters wide.
  • Outputs must be as mathematically precise as possible. Example:
    • 154,893 -> 100K NOT OK
    • 154,893 -> 155K GOOD
  • If there are multiple outputs with the same mathematical precision, return the shortest one. (If they are the same length, you may return either.) Example:
    • 1000 -> 1000 NOT OK
    • 1000 -> 1K GOOD

Examples:

1,234,567 -> 1.2M
102 -> 102
1000 -> 1K
1001 -> 1001
100,000 -> .1M
12,345,678,912 -> 12B
1,452,815,612 -> 1.5B

Submissions

\$\endgroup\$
  • \$\begingroup\$ I made a bunch of edits, feel free to roll back any changes you dislike. For the case of 100,000, should you return .1M, 0.1M, or 100K? \$\endgroup\$ – musicman523 Jul 15 '17 at 23:39
  • \$\begingroup\$ I like 100K best, maybe we should change it to 5 or less characters. Also thanks for the edits. \$\endgroup\$ – zoecarver Jul 15 '17 at 23:41
  • \$\begingroup\$ Personally I think 4 characters is fine. To further elaborate on my question: If you are outputting a decimal, do you require a leading 0 or would you allow .1M? \$\endgroup\$ – musicman523 Jul 15 '17 at 23:46
  • \$\begingroup\$ I think .1M should be 100K and we should allow up to 4 digits (or under 5). \$\endgroup\$ – zoecarver Jul 15 '17 at 23:47
  • \$\begingroup\$ Oh, I thought it was 4 digits or less. My misunderstanding. If .1M is not allowed then you should clarify in the question that the "number" part of the answer should be at least 1. However this seems rather arbitrary to me, when your original goal was to get the number as short as possible \$\endgroup\$ – musicman523 Jul 15 '17 at 23:49
  • \$\begingroup\$ Ok, I will specify. thanks for the help! \$\endgroup\$ – zoecarver Jul 16 '17 at 0:36
  • 2
    \$\begingroup\$ 1. The ""number"" part is called the mantissa. 2. I think "as specified below" should be "as specified above". 3. 154,894 -> 1.5K is not GOOD. It should be 155K. 4. Or should it? I don't see any rules specifying how to round. 5. 1K has less precision than 1000 because it gives fewer significant figures. \$\endgroup\$ – Peter Taylor Jul 16 '17 at 7:05
  • \$\begingroup\$ Thank you for your feedback! I have applied your edits, anything else? \$\endgroup\$ – zoecarver Jul 18 '17 at 3:29
  • \$\begingroup\$ I am going to post this unless anyone has any other feedback. \$\endgroup\$ – zoecarver Jul 19 '17 at 19:32
0
\$\begingroup\$

Bastion Breach

Stolen with permission from the minigame with the same title from Angels with Scaly Wings

Introduction and rules

  • There are two players
  • Both players receive a suit of cards (2-9, ace and face cards) and another is randomly shuffled into a public zone.
  • The players then proceed to choose one of the cards in their hand to bid for the card. Once they've used a card, it can't be used again.
  • The owner of the card with the highest value then gets a point.
  • If the highest scoring card was in the middle or if the value of the highest cards is equal, nobody gets a point. That point then goes onto the next round and is awarded to the winner of that round.
  • The ace is special: it wins against a face card, ties with another ace, and loses against a number card. Effectively the scoring system is reversed for the ace card.
  • The player with the most points at the end of the game wins.

Input/Output format for bots:

At the beginning of each round, your bot will be called as a whole program and will receive input in the form cards-in-middle your-played-cards opponents-played-cards as command line arguments.

Example: 23456789JKQA 24 56 - The cards in the middle are 23456789JKQA, your played cards are 24 and your opponents are 56. Your opponent won both of the previous games and what you're bidding for is the card 4.

You will output a single character representing a card that you haven't already played. If it is invalid or you've already played it, you automatically forfeit the round. Valid outputs are the following characters: 23456789JQKA

Example scoring

Middle card: 2
Bot 1 card: 4
Bot 2 card: 5
Winner: Bot 2
----
Middle card: Q
Bot 1 card: K
Bot 2 card: 5
Winner: Bot 1
----
Middle card: Q
Bot 1 card: K
Bot 2 card: A
Winner: Bot 2
----
Middle card: Q
Bot 1 card: 6
Bot 2 card: 5
Winner: None, next round scores another point
----
Middle card: A
Bot 1 card: 2
Bot 2 card: J
Winner: Bot 1
----
Middle card: 5
Bot 1 card: K
Bot 2 card: 5
Winner: Bot 1
----
Middle card: 5
Bot 1 card: 2
Bot 2 card: 5
Winner: None, next round scores another point
----
Middle card: A
Bot 1 card: 9
Bot 2 card: J
Winner: None, next round scores another point

Scoring for regular cards: 23456789JQK

Scoring for the ace:

wins: JQK
draw: A
lose: 23456789

Submission

You should write your entry as

Bot Name, Language

Insert
Code
Here

Explanation/Random stuff here

Running the tournament yourself

The controller is available here (Sandbox: Not written yet). It can be ran with python3 controller.py or python controller.py depending on your path. It expects all the bots to be in the bots directory. You can get all the bots already entered with python get_answers.py or python3 get_answers.py

Other rules and information

  • Bots are not allowed to use file storage.
  • The competition will be Round Robin, all bots will play against all others and they will be ranked by the number of other bots they've won against.

    • A loss counts as nothing
    • A draw counts as one point
    • A win counts as two points
  • The bot with the most points wins the game.

  • The bot that wins the final game, to be ran on wins the tournament.

Sandbox notes:

  • I have yet to create a controller for this though I'll probably be basing it off the one I did for the cake cutting contest
  • I hope I've explained it well enough, it's a simple game and I want the barrier for entry as low as possible. I've tried fixing what I believe went wrong with the GOL challenge and feel that KOTHs work better when they have lots of bots.
  • I have permission to post this from the developer of the game in question, see first line.
  • Feedback on readability is very much appreciated and welcome
\$\endgroup\$
  • \$\begingroup\$ "Both players receive a suit of cards (2-9, ace and face cards) and another is randomly shuffled into a public zone. The players then proceed to choose one of the cards in their hand to bid for the card." Which card? Reverse engineering from the example, I think that what's meant is that the third suit is uniformly shuffled and dealt face up in a line, such that both players can see the entire sequence of auctions, and then the cards are auctioned off one by one from left to right. Future references to "the middle" are presumably references to the same "public zone"? \$\endgroup\$ – Peter Taylor Jun 29 '17 at 11:34
  • \$\begingroup\$ "The ace is special: it wins against a face card, ties with another ace, and loses against a number card." Unless I'm missing something, there's nothing special there: just an overcomplicated abstraction. On the basis of KISS I would suggest making the cards be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 or A, B, C, D, E, F, G, H, I, J, K, L, M. \$\endgroup\$ – Peter Taylor Jun 29 '17 at 11:36
  • \$\begingroup\$ The ace card is different in that it's scored in reverse compared to the other cards. And your first comment is correct, how would you suggest rewording for it to be more clear? \$\endgroup\$ – Blue Jun 29 '17 at 15:31
0
\$\begingroup\$

What's that character? (Part 1)

Recently I ran a command on my laptop that returned a bunch of characters - some printable, some non-printable. I'm having trouble figuring out what those characters are, so I could use some help. Unfortunately, I'm running low on disk space, so you'll have to write me the shortest program you can that I can run.

Challenge

Given a list of ASCII characters, return their names as written on www.asciitable.com, my go-to site for looking up character points.

Input

You may take a string, a list of characters, or a list of ASCII code points (e.g. 'a' -> 97).

You may optionally take the length of the string/list as well. Note that for C, you must take this parameter, since the string could contain NUL bytes, so strlen won't work here.

Output

Output is flexible as usual; you may print or return from a function as you see fit. You should output a list of strings.

The Table

0 NUL
1 SOH
2 STX
3 ETX
4 EOT
5 ENQ
6 ACK
7 BEL
8 BS
9 TAB
10 LF
11 VT
12 FF
13 CR
14 SO
15 SI
16 DLE
17 DC1
18 DC2
19 DC3
20 DC4
21 NAK
22 SYN
23 ETB
24 CAN
25 EM
26 SUB
27 ESC
28 FS
29 GS
30 RS
31 US
32 Space
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127 DEL

Test Cases

[0, 97, 7, 22] -> [NUL, a, BEL, SYN]

More to come...

Meta

  • Would it be more interesting to use the UTF-8 names for the printable characters (0x20 - 0x7E), and the ASCII names for the control characters?
\$\endgroup\$
  • \$\begingroup\$ hand copy the table from the website please dont. Try a Google search: theasciicode.com.ar/ascii-codes.txt \$\endgroup\$ – Stephen Jul 23 '17 at 22:39
  • \$\begingroup\$ @StepHen good call, thanks \$\endgroup\$ – musicman523 Jul 23 '17 at 23:24
  • \$\begingroup\$ Downvoter: I would much like your feedback rather than just your vote \$\endgroup\$ – musicman523 Jul 24 '17 at 1:39
  • 1
    \$\begingroup\$ IMO just have take a letter and output the code. Since that part is boilerplate str.chars.map( real program ). Also for ASCII char names NUL is it ok is we output them in lower case? e.g. nul (obviously ascii letters would have fixed case) \$\endgroup\$ – Downgoat Jul 24 '17 at 1:42
0
\$\begingroup\$

How good is my mahjong hand?

Your goal is to calculate the shanten (minimal number of tiles needed for your hand to be a "waiting hand") of a Riichi mahjong hand.

What is Japanese Mahjong (or Riichi)

The goal of the game is to build a 14 tiles valid hand. Your hand is 13 tiles long, and each turn, you draw a 14th. If it doesn't make you win, you discard a tile. The tiles are grouped by colors : man, numbers, let's call them m; pin, circles, p; sou, bamboos, s; and honor tiles, z.

For p,m, and s : tiles are numbered from 1 to 9, with 4 examples each (1m 1m 1m 1m 2m 2m 2m 2m 3m 3m 3m 3m... 9m 9m 9m 9m).
z contains winds : ton for east, e; nan for south, s; sha or xia for west, w; and pei for north, n.
z contains dragons too : chun for red, r; haku for white, h; and hatsu for green, g.
Same rule, 4 examples each.
Honor tiles cannot be sequenced in a chii, they can only combine with themselves, by matching for a pair or for a pon. Don't worry, I will define terms pon and chii in the next part.

So a random hand can look like 1s 1s 1s 2s 2s 2s 3s 9p 9p 4m ez ez nz.

What is a "waiting hand"

What is called a tenpai hand, or hand that is one tile left before winning, is a hand respecting a winning shape. In general, a winning hand is composed of 4 sets of 3 sequenced (chii, like 1s 2s 3s) or matching (pon, like 1s 1s 1s) tiles, plus a pair (like 1p 1p). An example of a winning hand (14 tiles) can be : 1s 2s 3s 4s 5s 6s 6s 7s 8s 3p 3p 3p ez ez
So a "waiting hand" can be : 1s 2s 3s 4s 5s 6s 6s 7s 8s 3p 3p 3p ez where you need only ezto win.

The goal

To output a positive integer (between 0 and 7, inclusive) representing the shanten as defined above. For instance, a hand like 1s 1s 1s 2s 2s 2s 3s 9p 9p 4m ez ez nz is 2 shanten, because :
- you have a set of three 1s (a pon)
- you have a pon of 2s
- you have a pair of 9p (your pair)
- you have another pair of ez (that needs a third one to become a pon)
- you have 3 "isolated" tiles, 3s,4m,nz.

So drawing ez, and creating the pon of ez, makes you discard nz for example. Then let's imagine you draw 2s : you discard 4m, and you are now with a "waiting hand", with :
1s 1s 1s 2s 2s 2s 2s 3s 9p 9p ez ez ez, waiting on 1s or 4s. You drew two "useful tiles" to come to this hand, so you were 2 shanten.

@Sandbox : Is it on-purpose to put two detailed examples? (pro : clarifies what you have to do / con : challenge's wall of text is even bigger)

Another example

Let's see your hand looks like 4p 5p 7p 1m 1m 1m 2s 4s 6s ez sz hz hz.
- you have a pon of 1m
- you have 4p and 5p sequenced, requiring 3p or 6p to be a chii
- you have 2s 4s 6s, requiring 3s or 5s to create a chii
- you have a pair of hz
- you have 3 "isolated" tiles, 7p, ez and sz.

So, as for the first example, we have 3 isolated tiles. But are we 2 shanten? No, because 2s 4s 6s is not complete. So in fact, we have 4 useless tiles, the 4th being 2s or 6s depending on what we draw.
Proof : if we draw 3p, 3s and hz, our hand looks like that :
3p 4p 5p 1m 1m 1m 2s 3s 4s sz hz hz hz
and is waiting on the second sz to form the pair and win. We drew 3 useful tiles, so we were 3 shanten.

Test cases

3m 6m 9m 3p 5p 8p 1s 5s 8s ez sz nz gz -> 7 shanten
3m 6m 9m 3p 4p 5p 8p 1s 5s 8s ez sz nz -> 6 shanten
3m 6m 9m 3p 4p 5p 8p 1s 5s 8s ez nz nz -> 5 shanten
3m 6m 9m 3p 4p 5p 8p 8p 5s 8s ez nz nz -> 4 shanten
3m 5m 6m 9m 3p 4p 5p 8p 8p 5s 8s nz nz -> 4 shanten
3m 4m 5m 6m 3p 4p 5p 8p 8p 5s 8s nz nz -> 3 shanten
3m 4m 5m 6m 3p 4p 5p 8p 8p 5s 5s nz nz -> 2 shanten
3m 4m 5m 6m 7m 3p 4p 5p 8p 5s 5s nz nz -> 1 shanten
3m 4m 5m 6m 7m 3p 4p 5p 5s 5s nz nz nz -> 0 shanten
6s 7s 8s 1p 1p 1p 3p 4p 5p 6p 7p 7p 7p -> 0 shanten
3s 4s 5s 6s 7s 2p 4p 6p ez nz nz hz gz -> 3 shanten
3s 4s 5s 6s 7s 7s 1p 2p 4p 6p nz nz hz -> 2 shanten
3s 3s 4s 5s 6s 7s 7s 2p 4p sz sz nz nz -> 2 shanten
3s 3s 4s 5s 5s 6s 7s 7s 4p nz nz sz sz -> 2 shanten
3s 3s 3s 4s 5s 5s 7s 8s 2p 3p 4p 6p 6p -> 1 shanten
1m 1m 1m 2s 7s 7s 1p 3p 4p 9p sz hz cz -> 4 shanten
3m 6m 9m 3p 8p 1s 5s 8s ez sz nz gz cz -> 8 shanten

Protip

Calculating shanten can be complex, so here is a link that can help you doing so. You can refer to this site if you need any other information on riichi mahjong. Good luck!

Scoring and extra rules

This is code-golf, so shortest answer in bytes wins for its language. Standard loopholes apply.

NB : If you know mahjong, or were curious and dug deeper into the rules, don't mind with specific shapes like seven pairs or thirteen orphans.

tags :
@Sandbox : should I create some sort of in a pastebin or something?
Related
Related too
Something that can help if you speak japanese <- you can copypaste in the field the output from this program :)
Another protip

SANDBOX

Feel free to comment and tell me if this is on-purpose in PPCG, if there is any way to improve the way I say things, if I'm unclear anywhere ...

\$\endgroup\$
  • \$\begingroup\$ If you downvote, please explain why (by commenting or suggesting edit) so I can improve. If you don't, then don't downvote, this makes just the post less visible for no reason. \$\endgroup\$ – V. Courtois Jul 24 '17 at 6:17
  • \$\begingroup\$ Didn't downvote this, nor have I read through it yet. But that may be the reason it just appears to be a wall of text. Maybe try splitting it up into multiple posts or breaking the text down into easier read chunks. Or even take bits out that might not be needed. \$\endgroup\$ – TheLethalCoder Jul 24 '17 at 8:28
  • \$\begingroup\$ @TheLethalCoder in fact I'd like to explain clearly what is mahjong (to put some context in the challenge). Though you're right, it is a wall of text, that's what it looks like to me too. And I can't really "split it" into multiple posts, because it is what the challenge will look like in the end. TL;DR I want to be as clear as possible since this challenge is gonna be hard. \$\endgroup\$ – V. Courtois Jul 24 '17 at 8:32
  • 1
    \$\begingroup\$ I think you should be able to make it clearer by tidying the post up and formatting it more. The problem is a lot of people will open the question see all the text and move on without giving it a chance \$\endgroup\$ – TheLethalCoder Jul 24 '17 at 8:45
  • \$\begingroup\$ @TheLethalCoder I do know about this. How do you think I can make it tidier without removing content? \$\endgroup\$ – V. Courtois Jul 24 '17 at 8:46
  • \$\begingroup\$ To be honest I have no clue, if I knew more on the subject I'd be able to help more \$\endgroup\$ – TheLethalCoder Jul 24 '17 at 8:49
  • \$\begingroup\$ @TheLethalCoder mmh okay. Japanese mahjong is a well documented topic (I already linked some docs in the post). So maybe I shouldn't define the rules myself and let a link do the job? \$\endgroup\$ – V. Courtois Jul 24 '17 at 8:52
  • 1
    \$\begingroup\$ Well you'd want the important information in the post so it is self contained. Maybe the "fluff" can be trimmed down. \$\endgroup\$ – TheLethalCoder Jul 24 '17 at 8:53
0
\$\begingroup\$

I'm sort of brainstorming a challenge. I'm not really paying attention to question format at the moment.

The challenge would be to generate and populate a Golf Scorecard.

The output would look something like this:

Hole    Par     Strokes Score
1       3       3       0
2       5       4       -1
3       4       5       1
4       3       4       1
5       4       4       0
6       5       3       -2
7       4       3       -1
8       3       5       2
9       5       5       0
Totals  36      36      0

A Par value would be generated by choosing a random number in [3, 4, 5].

A Stroke value would be generated by choosing a random number within some range (say -2/+2 or -3/+3) of Par. A Stroke can be no lower than 1.

Score = Stroke - Par

Total is adding up all the values in that column (not including Hole).

I'm wondering if it would be too much to ask to have the generated values be somewhat realistic (unlike my example output), in that Par values tend to be mostly 4, with about the same number between 3 and 5, and Stroke values tend to be close to or above Par, with it being very unlikely to be 1.

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

Proposed Question

Triskaidekaphobic Primes

It is known that a certain number, which lies between 12 and 14, brings bad luck. The Church of Triskaidekaphobia (CoTDP) asserts that the key to salvation is avoiding this number in all situations, such as numbering floors, license plates, space shuttle missions and more.

The IT department of CoTDP is looking for talented developers. Candidates must prove their ability to program in accordance with Triskaidekaphobic dogma. Can you get this prestigious job?

Your Mission

Write a program that prints all prime numbers below 1000, excluding the unlucky one. the program must obey the CoTDP programming rules.

Rules

  1. Numbers whose absolute value is greater than 12 and smaller than 14 are considered unlucky and must be avoided.
  2. Unlucky numbers must not be used in the program:
    • Must not appear in the program, in any representation/base.
    • Must not be the value of an expression or calculation (e.g. 5 + 8).
    • Must not be an intermediate value in an expression (e.g. 5 + 8 + 3, 35 % 22 == 0).
    • Must not be stored in a variable, register, memory etc (e.g. for i in xrange(20):).
    • Must not be passed to a function or returned from one.
    • The above applies to any complex type which contains an unlucky number (e.g. range(20) in Python 2).
    • The above applies to all expressions, not just constant expressions (e.g. x+1 is invalid if x happens to be 12).
  3. No calculation, or intermediate value of a calculation, may yield an unlucky number. For example, and for i in xrange(20): are forbidden.
  4. Output lines bust be separated by line-feed only (no carriage return).
  5. You must find primes using basic mathematical operations. If your language provides tools to find primes or test primality, you must not use them.
  6. Standard Loopholes apply.

Scoring

This is code-golf, the shortest solution (in bytes) wins.

Questions for Meta

  • Do the limitations make sense for all sorts of languages? I think they cover languages such as C/Python/Java that use expressions, and also languages such as BrainFuck that manipulate memory (I think it's obvious that you must not write 13 in a memory cell).
  • Is there a trivial solution that makes it uninteresting?
  • Would it be better as a popularity contest?
  • Or maybe, accept the shortest, but give a bounty for the most interesting/creative answer?
  • Can the expression "Church of Triskaidekaphobia" be considered offensive to followers of some churches?
\$\endgroup\$
  • \$\begingroup\$ Should we treat numbers such as 39 (13 * 3) as prime, or not prime for the sake of this calculation? If 13 is not a prime, then 39 is, but it's up to you. (I did something kind of similar to this here) \$\endgroup\$ – Stephen Jul 29 '17 at 19:15
  • \$\begingroup\$ @StepHen, IMO, an unlucky divisor is still a divisor. I think asking for "primes below 1000, excluding the unlucky one" makes it clear. Your interpretation might make it more challenging, but I'm not sure how it would work - 39 is a multiple of 3 (though you shouldn't actually do this division), so how can it be prime? Maybe 169. \$\endgroup\$ – ugoren Jul 29 '17 at 19:23
  • \$\begingroup\$ Related: we are not allowed to store 13, right? \$\endgroup\$ – Stephen Jul 29 '17 at 19:37
  • \$\begingroup\$ @StepHen, I'm not sure what you mean by "store". My intention is that 13 won't be used in any way. I write that it can't be used in the program and can't be derived by calculation, so how can it be stored? \$\endgroup\$ – ugoren Jul 29 '17 at 20:12
  • \$\begingroup\$ Well you could store it with x = ord("\r"), although if you can't use it there's not much point. \$\endgroup\$ – Stephen Jul 29 '17 at 20:25
  • \$\begingroup\$ ord("\r") is an expression that yields 13, and is therefore invalid. But it's worth clarifying. \$\endgroup\$ – ugoren Jul 29 '17 at 20:27
  • \$\begingroup\$ Your post (as it stands) says no calculation, not no expression. \$\endgroup\$ – Stephen Jul 29 '17 at 20:28
  • 1
    \$\begingroup\$ Numbers whose absolute value is greater than 12 and smaller than 14 are considered unlucky and must be avoided. is 12.5 allowed? \$\endgroup\$ – l4m2 Apr 2 '18 at 19:09
0
\$\begingroup\$

Fill to the line!

Given input consisting of the characters _, , and newline, fill the empty space up to the line!

Example:

I will use # as the filler character in the example.

1. Input


________



2. Fill up to the line, but not above.


________
########
########
########
  • You may assume that the input either is rectangular (is padded), or consists only of the line and newlines.
  • You may assume that there is only one straight, unbroken line.
  • The whitespace above the line is part of the input. Do not fill above the line.

Test cases:

"
Input
"
"
Output
"
**********

"



----




"
"



----
####
####
####
####
"

**********

"


________



"
"


________
########
########
########
"
\$\endgroup\$
  • \$\begingroup\$ is the input guaranteed to be rectangular? will the _ be on one line \$\endgroup\$ – Destructible Lemon May 24 '17 at 4:45
  • \$\begingroup\$ @DestructibleLemon I will edit to clarify. \$\endgroup\$ – Comrade SparklePony May 24 '17 at 12:11
  • \$\begingroup\$ If its padded its very trivial to just replace all the spaces with # \$\endgroup\$ – Notts90 May 25 '17 at 8:30
  • \$\begingroup\$ @Notts90 Not all the spaces, only the ones below the line. \$\endgroup\$ – Comrade SparklePony May 25 '17 at 12:08
  • \$\begingroup\$ Ah ok, might want to make it clearer the bit above the line are included in the input. \$\endgroup\$ – Notts90 May 25 '17 at 12:23
0
\$\begingroup\$

Comparing Strings

You will be given two non-empty strings containing printable ASCII. If their contents are exactly the same, output their contents. If their contents are different, output a third string. This third string cannot be a substring of either string, and neither string can be a substring of it.

Test Cases

Test cases are quoted to show they are strings. Outputs marked with * indicate they are one of infinitely many possible outputs.

input, input -> output

"test", "test" -> "test"
"do", "don't" -> "dnut"*
"ye s", "yes" -> "false"*
"yes", "yes" -> "yes"
"maybe", "mayue" -> "false"*
"false", "false" -> "false"
"false", "true" -> "fatr"*

Rules

  • The inputs will be composed of only printable ASCII - that is, space to tilde. Your output should also be composed of only printable ASCII, but a trailing newline is allowed.
  • Your algorithm may not make any assumption about the length of the inputs, except that they will not be empty.
  • The output must be valid with probability 1; that is, you may generate random strings until one is valid, but you can't just output a random string and hope it's valid. Source
  • Trailing newlines in output allowed (otherwise there will be no newlines - newlines are not in printable ASCII).

This is , so shortest answer in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ This is the canonical string equal question, but it does not allow you to use string comparison. \$\endgroup\$ – Stephen Aug 1 '17 at 21:37
  • 4
    \$\begingroup\$ Bro... Come on, at least 3 sentences. \$\endgroup\$ – Magic Octopus Urn Aug 1 '17 at 21:39
  • \$\begingroup\$ Do you need to handle strings with new lines or spaces in them? \$\endgroup\$ – geokavel Aug 2 '17 at 0:08
  • \$\begingroup\$ @MagicOctopusUrn added a bit more clarification :P what else is there to say? \$\endgroup\$ – Stephen Aug 2 '17 at 1:21
  • \$\begingroup\$ @geokavel clarified \$\endgroup\$ – Stephen Aug 2 '17 at 1:21
  • \$\begingroup\$ This needs more information, test cases and to actually be made into a challenge. \$\endgroup\$ – TheLethalCoder Aug 2 '17 at 8:59
  • \$\begingroup\$ @TheLethalCoder I forgot testcases - thank you. However, what else would I add to make it a challenge? \$\endgroup\$ – Stephen Aug 2 '17 at 11:03
  • \$\begingroup\$ Usual boilerplate stuff, I'm sure something like this has been posted before too but I'm having trouble finding it. \$\endgroup\$ – TheLethalCoder Aug 2 '17 at 11:05
  • \$\begingroup\$ @TheLethalCoder OK, how's that? and thanks for the feedback. \$\endgroup\$ – Stephen Aug 2 '17 at 11:15
  • \$\begingroup\$ Better. I still don't like the challenge though it'll just lead to solutions like s=>t=>s==t?s:s+t Block ways of doing that and it'll be better \$\endgroup\$ – TheLethalCoder Aug 2 '17 at 11:18
  • \$\begingroup\$ @TheLethalCoder hm, that was my idea for the harder challenge - that was why this says easy in the title. Do you think this is too trivial? I can just skip the easy one and go straight to the harder one. \$\endgroup\$ – Stephen Aug 2 '17 at 11:20
  • \$\begingroup\$ I personally would. The easy one just leads to lots of FGITW answers. Yeah it'll probably be popular but boring. \$\endgroup\$ – TheLethalCoder Aug 2 '17 at 11:21
  • \$\begingroup\$ @TheLethalCoder ok how's that? \$\endgroup\$ – Stephen Aug 2 '17 at 11:26
  • \$\begingroup\$ Better but again I think you need to defend against the trivial cases i.e. ab, cd -> bc seems to be allowed and so does ab, cd -> bb yet they're both trivial changes to the inputs. \$\endgroup\$ – TheLethalCoder Aug 2 '17 at 11:30
  • \$\begingroup\$ @TheLethalCoder I think I can only go so far in blocking those, and with what you have, for the your first case, entering aa, ab, and for your second case, entering aa, bc would result in invalid output. Half the fun here will be "cracking" them. \$\endgroup\$ – Stephen Aug 2 '17 at 11:37
0
\$\begingroup\$

Can you generate this random sequence for me?

Inspired by this question on Retrocomputing

I want to create a random generator that always returns a desired word. I desperately need this so I can hide some easter eggs. For science easter!

Input

A word, either in string format or an array or vector of characters. You can assume all lowercase and only the regular characters a-z.

Task

Write a full program or function that finds a seed such that when taking a random sample of letters, the desired word is output. The function then should return or save another full program or function that does the generating of this desired word.

Rules

  • The returned function of program should use random sampling to create the output, so it is not allowed to hardcode (obligatory XKCD)
  • The output can be written to file in the case of a full program or returned.
  • Hiding an easter eggs is easiest when there is little code, so the shortest code wins.
  • If there is no seed that generates the required output, your program is allowed to run forever.
  • Standard codegolf rules and loopholes apply.

Example implementation:

> f <- function(string){
+     seed <- 1
+     set.seed(seed)
+     repeat{
+         seed <- seed + 1
+         set.seed(seed)
+         if(all(sample(letters, length(string), replace = TRUE) == string)){
+             break
+         }
+     }
+     generator <- function(){
+         set.seed(seed)
+         sample(letters, length(string), replace = TRUE)
+     }
+     return(generator)
+ }
> f("a")
function(){
        set.seed(seed)
        sample(letters, length(string), replace = TRUE)
    }
<bytecode: 0x000000001c83f2d8>
<environment: 0x000000001f906c20>
> g=f("a")
> g()
[1] "a"
> g()
[1] "a"
> g()
[1] "a"
\$\endgroup\$
  • \$\begingroup\$ So we're finding the seed to a pRNG that produces the correct output from a scrambled input? Have you actually managed to do this with any two none-trivial inputs? i.e. not just a few letters long? \$\endgroup\$ – TheLethalCoder Aug 3 '17 at 7:58
  • \$\begingroup\$ @TheLethalCoder I was initially thinking of doing dicerolls instead of words, since those should be easier, but I liked words better because they fit the related question better. The sample code did work for 5 letter words. \$\endgroup\$ – JAD Aug 3 '17 at 8:22
0
\$\begingroup\$

Complicating Simple Maths

We do know what 1 + 1 is, or 2 - 1. How about we turn those and other really simple operations into complex numbers?

Goal:

As stated in the intro, taking an operation that can be done within the range of the following operators ( +, -, /, *, ^ and () ), print out a complex number operation that is pretty much a transformed version, and when done using the order of operations, results in the same answer as the inputted operation.

Examples:

Input: 5 - 1
Output: 5 + 2i

Input: 4 * (7 ^ 2)
Output: (4 * 4i) * (7 ^ 2) 

Rules:

  • It is recommended you print out the sector(s) that holds your complex number(s) as a + bi, e.g. (a + bi) - (ci * (di ^ f)). (NOTE: If you are doing non-communicative operations, such as ^, /, or -, the recommendation doesn't apply to the sub-operation).

  • No standard loopholes.

  • If you want to, feel free to use operations/functions other than the set mentioned in the Goal, but your input operation must have at least one of them.

  • You can format your operators in any way, e.g. x or • instead of *, ÷ instead of /, etc.

  • Input and output is allowed in any format as long as it fits within the standard I/O rules.

  • Input must also be flexible (as in to return any input from a simple operation to a complex number operation.

  • This is , so shortest answer wins.

Sandbox use only:

Is there any way I can improve this challenge? Are there any other loopholes to be covered in the rules?

\$\endgroup\$
  • \$\begingroup\$ Can you relax output to standard IO too? At the moment it seems you can only print the result. Also isn't this essentially calculate the result of the inputted expression then work out a complex expression that gives the same answer seeing as you don't need to keep anything in the input the same. \$\endgroup\$ – TheLethalCoder Aug 7 '17 at 10:32
  • 3
    \$\begingroup\$ And if that is the case isn't this challenge just return input + (1 + i^2)? \$\endgroup\$ – TheLethalCoder Aug 7 '17 at 10:33
  • \$\begingroup\$ No, the challenge is to transform parts of the input into complex numbers and output that. \$\endgroup\$ – S.G. Harmonia Aug 7 '17 at 13:13
  • 1
    \$\begingroup\$ But 5 - 1 becomes 5 + 2i You are removing two stages - and 1 and adding 2 + and 2i. It's not entirely clear how much you can remove and how much you can add. \$\endgroup\$ – TheLethalCoder Aug 7 '17 at 13:15
  • \$\begingroup\$ At least one sub-operation should be transformed from simple to complex (which could take two steps). \$\endgroup\$ – S.G. Harmonia Aug 7 '17 at 13:16
0
\$\begingroup\$

Make it night!

You just went on vacation to see some scenery in the beautiful night. Unfortunately, your alarm clock malfunctions and when you wake up, it's daytime.

Your mother would like to see some photos, but you can only take pictures in the day. You would like to be able to convert these daytime pictures to pictures in the nighttime.

Challenge

Given an image taken in the daytime, process it and turn it into night time as best as you can.

Sometimes it might be hard to do, like images that have a sun, but you can write your algorithm to remove the sun or do something else.

Example

(I did this by hand, so it might not be that good)

Original

Result

Voting

Please vote accordingly to how well the algorithms perform.

  • Is the sky dark like a night sky?
  • Does the picture look photoshopped/edited?
  • Are there vivid colors that shouldn't appear in the night?
  • If you were showed both images, would you believe that there was no processing?

(If you have a suggestion, please comment.)

Test Cases

Test case 1

Test case 2

Test case 3

Winning

Since this is a , the answer with the highest score (upvotes minus downvotes) wins.

\$\endgroup\$
  • \$\begingroup\$ how to deal with the sun... \$\endgroup\$ – Destructible Lemon Aug 10 '17 at 4:30
  • \$\begingroup\$ @HelkaHomba This URL is invalid or has expired. \$\endgroup\$ – Oliver Ni Aug 10 '17 at 5:50
  • \$\begingroup\$ @DestructibleLemon Not sure, I'll think about it. \$\endgroup\$ – Oliver Ni Aug 10 '17 at 5:51
  • \$\begingroup\$ What would i.stack.imgur.com/nkx4V.jpg become? \$\endgroup\$ – Calvin's Hobbies Aug 10 '17 at 6:39
  • \$\begingroup\$ @HelkaHomba This is a popularity-contest, so that depends on how your algorithm handles it. The better it does, the more votes you will probably get.. \$\endgroup\$ – Oliver Ni Aug 10 '17 at 6:41
  • \$\begingroup\$ Won't this fall under the usual "No objective winning criteria" that pop cons have been falling under lately? \$\endgroup\$ – TheLethalCoder Aug 10 '17 at 7:58
  • \$\begingroup\$ @TheLethalCoder Fixed. \$\endgroup\$ – Oliver Ni Aug 10 '17 at 9:14
  • \$\begingroup\$ @OliverNi How? The voting criteria is still subjective and that's why recent ones have been closed. \$\endgroup\$ – TheLethalCoder Aug 10 '17 at 9:17
  • \$\begingroup\$ @TheLethalCoder as I know, "highest score (upvotes minus downvotes)" is exactly the defaults for popularity-contest, at least it is written in the tag description: "A popularity contest is a competition where the answer with the highest vote tally (upvotes minus downvotes) wins." \$\endgroup\$ – Oliver Ni Aug 10 '17 at 9:25
  • \$\begingroup\$ @OliverNi Yeah you're winning criteria is fine. It's the subjective voting criteria I'm questioning. \$\endgroup\$ – TheLethalCoder Aug 10 '17 at 9:34
  • \$\begingroup\$ @TheLethalCoder Voting is subjective. You can't just tell someone to 'downvote if the answer has x pixels that are y units apart from all the four neighboring pixels' or something like that. \$\endgroup\$ – Oliver Ni Aug 10 '17 at 9:37
  • \$\begingroup\$ @OliverNi I know and isn't that the whole reason recent pop cons have been closed? Because the criteria people should vote on is subjective. \$\endgroup\$ – TheLethalCoder Aug 10 '17 at 9:39
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – Oliver Ni Aug 10 '17 at 9:39
  • 1
    \$\begingroup\$ Provided you explicitly say what to do with the "dangerous" cases like the 'images with sun', this imo is a nice pop-contest but... you surely know well enough that pop-contests, almost always, don't garner much love here. \$\endgroup\$ – officialaimm Aug 10 '17 at 12:28
  • \$\begingroup\$ So... if you vertically flip any of those images your algorithm would fail? \$\endgroup\$ – Magic Octopus Urn Aug 11 '17 at 20:38
0
\$\begingroup\$

Multiplicity of a Curve

Given an polynomial p in two variables x and y as well as a point (u,v), determine the multiplicity m of the curve C = { (x,y) | p(x,y) = 0} at the point (u,v).

Details

  • The degree of a monomial a * x^i * y^j in two variables is d = i+j.
  • A polynomial is homogeneous if all its monomials have the same degree d.
  • Any polynomial p (where d is the degree of p, i.e. the maximum of the degree of all its monomials) can uniquely be decomposed into a sum of polynomials p = p0 + p1 + ... + pd where each pk is homogeneous of degree k OR possibly zero.
  • The multiplicity of a curve C given by the polynomial p at (u,v) can be determined using the following computation:

    • First decompose the polynomial p(x-u,y-v) (this is p with x,y replaced with x-u,y-v) into a sum of homogeneous polynomials as described above:

      p(x-u,y-v) = q0 + q1 + ... + qd
      
    • Then determine the minimal k such that qk is nonzero. Then the multiplicity is defined as m := k.

Example

Let us consider the polynomial p(x,y) = -x^2 - 4x + y^2 - 2y -3 and the point (u,v) = (-2,1).

p(x-u,y-v) = y^2 - x^3

So the decomposition is

p(x-u,y-v) = [0] + [0] + [y^2] + [-x^3]

Here the brackets are just used to highlight the homogeneous polynomials of each degree.

We see that y^2 is the nonzero polynomial of least degree, so m = 2

TODO

  • add more testcases
\$\endgroup\$
  • \$\begingroup\$ 1. My interpretation is that the multiplicity is just the minimum degree of all nonzero terms in the polynomial p(x-u, y-v). If this is true, stating so would simplify reading. 2. What input formats are permitted? Few languages have Polynomial as a type, so an input such as [[0,1],[2,3]] could be taken to represent 0x⁰y⁰ + 1x¹y⁰ + 2x⁰y¹ + 3x¹y¹. \$\endgroup\$ – fireflame241 Aug 20 '17 at 18:43
  • \$\begingroup\$ I did not add the formats yet, but these are the two I had in mind, as we did it in previous challenges. \$\endgroup\$ – flawr Aug 20 '17 at 19:51
  • \$\begingroup\$ Regarding the degree: Yes that is essentially what I wrote down, just a little bit more detailed for people who are not familiar with the topic. \$\endgroup\$ – flawr Aug 20 '17 at 21:39
0
\$\begingroup\$

Golf Cubically code

Your task is to optimize Cubically source code using one or more optimizations in this post.

How this challenge works:

  • You will choose one or more optimizations below and write a program (in the language of your choice) that performs those optimizations on a Cubically program.
  • Your program will take a Cubically program as input using any allowed input methods, and output a Cubically program using any allowed output methods.
  • The first answer to successfully perform all optimizations wins!

Optimizations

1. Face turn arguments

Before a face turn is performed, the interpreter calculates turns = turns mod 4. So R5 would be equivalent to R1 which is equivalent to R, R7 is equivalent to R3 which is equivalent to R', etc. Also note that R11111 is equivalent to R5, and R22 is equivalent to nothing at all.

Performing this optimization will mean evaluating all arguments to an R, L, U, D, M, E, or S command and shortening them as much as possible.

Test cases:

Relevant code -> Optimization
R11           -> R2
R1            -> R
L33           -> L2
U22           ->
D222          -> D2
M11111        -> M
E00001        -> E
S9            -> S

2. Repeated face turn

When multiple calls to the same face turn command are present right next to each other, they can clearly be golfed. For example, R2R1 is equivalent to R3. UUU is equivalent to U3. F2F2F2F2 is equivalent F8.

Test cases:

Relevant code -> optimization
R2R2R2        -> R6            (R2 if you also choose optimization 1)
LLL           -> L3
UU            -> UU or U2
D3D2D1        -> D6            (D2 if you also choose optimization 1)

3. "Set notepad to" commands

There are some commands that, instead of adding to/subtracting from/multiplying by/dividing by the notepad, just assign to it. Here are all such commands:

_^=<>⊕«»·|:

When called with multiple arguments, since each argument calls the command separately, only the final argument is relevant. So =123 is equivalent to =3, _00000 is equivalent to _0, and :12345678987654321 is equivalent to 1.

Test cases:

Relevant code -> Optimization
_333          -> _3
=12321        -> =1
+54321        -> +54321
:55           -> :5
/55           -> /55

4. Repeated non-face-turn commands

When multiple face turn commands are present right by each other, their arguments can simply be added together. Commands do not act this way. While R2 calls R with 2, =2 calls = with the face sum of the front face (face index 2).

To perform this optimization, when multiple commands outside of RLUDFBMES appear next to each other, simply remove the duplicated commands without removing the arguments.

Relevant code -> Optimization
_1_1_1_1      -> _1111         (_1 if you also choose optimization 3)
%11%22%33     -> %112233       (%3 if you also choose optimization 3)
+12345+67+8   -> +12345678

5. Nonexistent commands

Go check out the Cubically commands page and you'll see that there are plenty of characters that are not commands. For example, there are no commands that are lowercase letters.

To perform this optimization, remove all nonexistent commands and their arguments from the Cubically source. If the commands also have arguments, you must remove the arguments so that they are not passed to the previous command.

Test cases:

Relevant code -> Optimization
moo cow moo   -> 
moo2cow2moo   -> 
misteR2 FOO   -> R2F
FEAR ME.      -> ERME
u1U2u3U4u5U6  -> U2U4U6   (nothing if you also choose optimization 1, U12 if you also choose optimization 2)

6. Non-implicit commands

There are lots of implicit commands in Cubically (RLUDFBMES()$~&E!), but there are plenty that need to be called with arguments. So %%%% is equivalent to nothing at all while %%2%% is equivalent to %2.

Test cases:

Relevant code -> Optimization
%%%%          -> 
$$$$          -> $$$$
++2++2++2     -> +2+2+2                 (+222 if you also choose optimization 4)
+++>--<-      -> Not Brainf**k, sorry!  (:P)

Sandbox

I'll add more optimizations later.

\$\endgroup\$
  • \$\begingroup\$ Clarification on R123: That's the same as R6 and R2, not R3, right? Digits are summed, there are multidigit numbers? That would be better to specify \$\endgroup\$ – isaacg Aug 17 '17 at 20:13
  • \$\begingroup\$ A few things: first, I can't find the tag "fgitw", is there a typo? Second, does optimization 1 require handling F and B as well, or just the currently listed ones? Third, in optimization 3 most of the listed commands seem invalid because the notepad is used in calculation and then overwritten with the output; for example =11 is not the same as =1 in most circumstances. In fact, I think only _: are valid. Fourth, is the winning answer one which performs all optimizations in a single program, or one which contains a separate program for each optimization? \$\endgroup\$ – Kamil Drakari Aug 18 '17 at 18:03
0
\$\begingroup\$

Hungry for Apples?

enter image description here

This challenge is simple, given an integer 0 <= n or 0 < n, output an ASCII-apple with that many bites taken out of it.


No bites (0):

         //
     .-.:|.-.
   .'   ''   '.
   ;          ;
  :            :
  :            :
  :            :
   :          ;
   '.        :
     '-_.._-'

Bite 1:

         //
     .-.:|.-.
   .'   ''   '.
   ;          ;
   '-.         :
     }         :
   .-'         :
   :          ;
   '.        :
     '-_.._-'

Bite 2:

         //
     .-.:|.-.
   .'   ''   '.
   '-.        ;
     }         :
     }         :
     }         :
   .-'        ;
   '.        :
     '-_.._-'

Bite 3:

         //
     .-.:|.-.
   .'   ''   '.
   '-.        ;
     }      .-'
     }      {
     }      '-.
   .-'        ;
   '.        :
     '-_.._-'

Bite 4:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }      {
     }      {
     }      {
   .-'      '.
   '.        :
     '-_.._-'

Bite 5:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }".    {
     } }    {
     } }    {
   .-'"     '.
   '.        :
     '-_.._-'

Bite 6:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }"~".  {
     } } }  {
     } } }  {
   .-'"~"   '.
   '.        :
     '-_.._-'

Bite 7:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }"~"~".{
     } } } }{
     } } } }{
   .-'"~"~" '.
   '.        :
     '-_.._-'

Bite >7:

[empty output]

Rules

  • You may have trailing spaces, make it consistent though.
  • You may have exactly 1 trailing newline.
  • You are NOT doing an animation here, you are taking in n and outputting an apple.
  • You may error on integers less than 0, as the spec provides n > 0.
  • You must have empty output (no error) on n > 7/8.
    • You threw out the core; you didn't error the core into non-existence.

This is

\$\endgroup\$
  • 3
    \$\begingroup\$ I feel this would be better if there was some more symmetry in the 5, 6, and 7 bytes so that people could possibly make better compression. \$\endgroup\$ – AdmBorkBork Aug 4 '17 at 18:26
  • \$\begingroup\$ @AdmBorkBork better? \$\endgroup\$ – Magic Octopus Urn Aug 22 '17 at 21:26
  • 1
    \$\begingroup\$ Yes, much better. \$\endgroup\$ – AdmBorkBork Aug 23 '17 at 12:33
0
\$\begingroup\$

Code the beach on the beach (heavily WIP)

The Gods of the Sea have seen your coding ability and asked you to rewrite their beach-generating program.

Code the beach

This program will take no input and, in this order:

  • Print sand (.)
  • Print ocean waves (~)
  • Print crabs (>.<)
  • Print seagulls (-v-)

This program will be run by the Gods of the Sea. They will run it once a day and will want a different beach every time they run it, so the beach items should be generated (pseudo)randomly.

To avoid this beach becoming overloaded, there should be:

  • Between five and eight crabs
  • Between three and seven seagulls
  • Between eighty and one hundred grains of sand
  • Eighty ocean waves

Your program should create the beach just as the Gods' existing program does. It will first draw the sand at the bottom of the screen, in the last three lines. Example sand:

. .. .. . . ... . ... ..  . ..  .... .. . ... . .. . .. . . .. . .. . . .... ...
  .. . .. .. .. .. ... .   ..  .. ... ...  .   .   ....... .... ...... ... .
. . . .. .. ...... ... .. ......... .  .... .. . . . . ... .. .. . . . ...

Then the waves will be printed, starting from the leftmost character in the fourth-to-last line. The point where the waves meet the sand should vary by at most one character, and waves should never go off the screen. All water that is not curling in a wave will cover the sand, so there can be no sand under the water. Example waves:

TODO: Add example waves

Crabs should be spawned in the last four lines and cannot be spawned on waves, because if they were, they would be quickly sucked under and disappear.

Seagulls may be spawned anywhere, and should be evenly distributed to the best of your pRNG's ability.

On the beach

The Gods were born in ancient times, so they're still using VGA; their terminal has 80x25 characters for output, as does their text editor - which is so old it does not support scrolling. Your program will have to fit in this text editor, so it will need to be small.

The Gods do not yet have the internet, so you'll have to write your program on the beach in a location they can see it. Unfortunately, the only convenient place at the moment is a very small sandbar on the Oregon coast. Waves occasionally reach this spot. To make sure you have enough time write the entire program before it's washed away, it will need to be as small as possible.

Furthermore, since the Gods are so far away, some characters written in the sand are indistinguishable. Gods are good at guessing, so if they see a character that looks like another they'll get it right, but another character that looks similar to the character they guessed will be assumed to be said previous character. So if a l is present in the source before an I, the Gods will see two ls.

Here are the lookalikes:

  • o and O
  • l and I and |
  • : and ;
  • " and '

The Gods don't have the technology to easily use Unicode characters, so you'll have to give them a lot of help. Each non-ASCII character you use will cost 5 bytes to describe it to them.

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm not sure if the lookalike characters and penalty for non-ASCII characters is necessary. Drawing the beach, random placement and number of objects, and constrained placement of objects sounds like enough to me. The 80x25 hard constraint also seems superfluous. A line width limit of 80 keeps the idea, but would still allow for golfing in more verbose languages. \$\endgroup\$ – Andrew says Reinstate Monica Aug 23 '17 at 18:53

You must log in to answer this question.

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