577
\$\begingroup\$

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

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29 at 13:27

4830 Answers 4830

1
111 112
113
114 115
161
0
\$\begingroup\$

Count bytes like a Java golfer

Java is verbose, everybody knows that. Sometimes, here on PPCG, it happens that a Java answer is shorter than 60 characters, but most of the time it's longer, way longer! And the Java golfers here often post improvement suggestions in comments.

Alas, the PPCG website is based on the stack software, which invisibly cuts <code> comments according to an obscure rule, which I shall name the "Java golfer's bane", making it impossible to get an accurate byte-count by copy-pasting.

The rule in question is the following:

  • in a <code> tag, insert two invisible characters
    • the first time after 60 non-whitespace consecutive characters
    • then subsequently ever 20 non-whitespace consecutive characters

Challenge

Your goal is to help us, poor Java golfers, to get the byte-count straight from when we copy/paste code from comments.

SE software rules are, I'm sure, complex, so we will simplify a bit, but not that much.

  • Your input:
    • is mappable to UTF-8;
    • must support codepoints until at least U+FFFF;
    • will contain only characters with codepoints greater than or equal to U+0020;
    • must be a string or a characters array/list if those accept unicode characters, or else must be an integer (16 bits minimum) array/list. Unless I forgot anything obvious, no other input format is allowed.
  • If a sequence of non-whitespace characters in the input contains more than 60 characters:
    • keep the 60 first characters, then skip the next 2 characters;
    • then until you meet a whitespace, keep the next 20 characters and skip the next 2.
    • We don't care which are the two stripped characters.
  • Your output is the size of the string after being sanitized, in bytes as encoded in UTF-8! You must support very long Java answers, up to 500 characters (not bytes).
    • You don't need to map to UTF-8 since I give the rule on how to count without mapping, but in some languages it might be easier to actually map!
  • The standard loopholes are naturally forbidden.
  • This is codegolf, so the shortest answer in bytes wins!

You may assume the following:

  • the only whitespace character you will ever get is the space (U+0020). I abuse the term whitespace by including the start of the string as well in its meaning.
  • no whitespace will be at positions 62, 94, 116, (+22) ... after the previous whitespace

You may not assume the following:

  • The skippable characters will exclusively be the ones SE actually uses (U+200C U+200B);
  • you will get only ASCII characters;
  • you will not get any diacritics.

Bonus

  • if your code supports Unicode code points up to U+1FFFFF, you can remove 10% off your byte count, do not round the resut.

How to count the number of UTF-8 bytes?

If you haven't a builtin for that, Wikipedia gives us the rule, based on code points:

first code point  |  last code point  |  # bytes
U+0000            |  U+007F           |  1
U+0080            |  U+07FF           |  2
U+0800            |  U+FFFF           |  3
U+10000           |  U+1FFFFF         |  4

Wikipedia goes beyond those number, but the RFC 3629 capped this mapping to 4 bytes, so we thank it!

Test cases

Work in progress!


Notes for review:

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

What feedback do you have for me?

Challenge

Convert and print out a time in a 12-hour format. HH:MM AM/PM

Examples

Input:

  • 'Fri Jun 30 2017 21:14:20 GMT-0700 (PDT)'
  • 'Sat Jun 31 2018 08:06:20 GMT-0700 (PDT)'
  • 'Fri Jul 01 2017 01:14:20 GMT-0700 (PDT)'
  • 'Sat Apr 10 2020 09:06:20 GMT-0700 (PDT)'

Ouput:

  • 09:14 PM
  • 08:06 AM
  • 01:14 AM
  • 09:06 AM

Rules

\$\endgroup\$
9
  • \$\begingroup\$ I think this question has been covered pretty thoroughly by this challenge and this one, and would probably be closed as a dupe. \$\endgroup\$ Commented Jul 1, 2017 at 1:20
  • \$\begingroup\$ did not realize it had already been done :( \$\endgroup\$
    – zoecarver
    Commented Jul 1, 2017 at 1:22
  • \$\begingroup\$ It's not exactly the same question, but I think that area has been pretty much covered. Now, what you could do is use this question as a model, but go from 24-hour time to 12-hour time :) \$\endgroup\$ Commented Jul 1, 2017 at 1:28
  • 1
    \$\begingroup\$ I like that Idea! in fact I could take it a step further and convert a string in the following format: 2017-07-01T02:58:38.799Z to 12 hour time \$\endgroup\$
    – zoecarver
    Commented Jul 1, 2017 at 2:58
  • \$\begingroup\$ @musicman523 I made an edit to the question, what do you think? \$\endgroup\$
    – zoecarver
    Commented Jul 1, 2017 at 4:16
  • \$\begingroup\$ I definitely like this better. You should add more test cases with different days (for example, does 1 come out as 1 or 01?), months, days of the week, etc. so there is no confusion about the input format \$\endgroup\$ Commented Jul 1, 2017 at 4:27
  • \$\begingroup\$ ok, sounds good. Is that enough test cases? feel free to edit and add more details. \$\endgroup\$
    – zoecarver
    Commented Jul 1, 2017 at 4:28
  • \$\begingroup\$ I feel like the testcases should be formatted like input -> output\ninput -> output. What about the midday and midnight? \$\endgroup\$
    – Maya
    Commented Jul 2, 2017 at 17:53
  • \$\begingroup\$ Ok, Sounds good. I am posting it. \$\endgroup\$
    – zoecarver
    Commented Jul 2, 2017 at 23:12
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\$
5
  • \$\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
    Commented Jul 1, 2017 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
    Commented Jul 1, 2017 at 20:13
  • \$\begingroup\$ @Shelvacu That seems like a really cool idea, yeah. Will change my question. \$\endgroup\$
    – clismique
    Commented Jul 1, 2017 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
    Commented Jul 3, 2017 at 8:26
  • \$\begingroup\$ If you don't want to post it I will. Keep me posted. \$\endgroup\$
    – Shelvacu
    Commented Jul 3, 2017 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\$
2
  • \$\begingroup\$ This is code-golf I suppose, you should mention the winning condition. \$\endgroup\$
    – 0xffcourse
    Commented Jul 3, 2017 at 17:42
  • \$\begingroup\$ Is there any reason to believe that there's any way to compress this other than base conversion? \$\endgroup\$ Commented Jul 4, 2017 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\$
4
  • 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\$ Commented Jul 4, 2017 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 Mod
    Commented Jul 4, 2017 at 9:52
  • \$\begingroup\$ @PeterTaylor Thank you, updated \$\endgroup\$ Commented Jul 4, 2017 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\$ Commented Jul 4, 2017 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\$
3
  • \$\begingroup\$ I'm mainly looking at feedback for what people think of this challenge before developing it further. \$\endgroup\$ Commented Jul 5, 2017 at 10:16
  • \$\begingroup\$ I think you should include other operating systems with different paths separators in the challenge itself. \$\endgroup\$
    – user41805
    Commented Jul 6, 2017 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\$ Commented Jul 6, 2017 at 9:02
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\$
2
  • \$\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
    Commented Jul 6, 2017 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\$ Commented Jul 6, 2017 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\$
6
  • \$\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\$ Commented Apr 11, 2017 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\$ Commented Apr 11, 2017 at 8:56
  • \$\begingroup\$ Which is why need to get some code to do it for us :) \$\endgroup\$
    – Notts90
    Commented Apr 11, 2017 at 8:58
  • \$\begingroup\$ Will file names only ever contain a .? \$\endgroup\$
    – Shaggy
    Commented Jul 6, 2017 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
    Commented Jul 6, 2017 at 11:26
  • \$\begingroup\$ Test case: c:\foo? \$\endgroup\$ Commented Jul 6, 2017 at 13:32
0
\$\begingroup\$

Let's simplify polynomials

In many situations we have to expand mathematical expressions containing variables, for example, calculating characteristic polynomials, expanding products of polynomials, etc. It is trivial if the variables are known (in this case, we just substitute the variables with the corresponding values and evaluate the expression by a calculator), but not so simple if we need to manually expand the expression.

Motivation

Consider the cases with only one variable (say, x). Suppose the coefficients are sufficiently small. Then, a simple way is to take x to be some number (e.g. 1000), evaluate the expression and convert the numerical answer back to a polynomial.

Here is an example. Suppose we need to expand

Put and evaluate it using a dumb calculator. The answer is .

By running the program/function with input -984982000, one should get

[-1, 15, 18, 0] (descending order)

, and so the expanded polynomial is .

The task

Write a program or function which satisfies the following:

  • The input is an integer, which is calculated by substituting x = 1000 in a polynomial (which you have to find out).
  • Output the coefficients, guaranteed to be in the range [-499,499] (inclusive), and to be integers. You can represent the polynomial in either ascending or descending order, so long as it is consistent across different runs. You can return a list of integers, print to standard output (with non-numeric separators), etc.

Examples

Input         Output (descending power)
1003005007    1 3 5 7
1001          1 1
999           1 -1
998994        1 -1 -6
-998994       -1 1 6
1000001       1 0 1
0             0


Input
1003005007

Valid outputs                     Invalid outputs
[1 3 5 7] (descending order)      1357 (coefficients are not separated)
[7 5 3 1] (ascending order)       7531 (coefficients are not separated)
"1 3 5 7" (descending order)      "1357" (coefficients are not separated)
"7, 5, 3, 1" (ascending order)    [1 5 3 7] (neither ascending nor descending order)
7                                 "10305070" (numeric separator "0")
5
3
1 (ascending order)

Rules

  1. Standard loophole applies.
  2. Your program/function should be able to at least handle polynomials of degree 3. Also, the input might be negative. Therefore, using a suitable data type is necessary.
  3. You can take the input in integer or string format. It is guaranteed that the input is a valid integer.
  4. The shortest program/function (in bytes) wins. Good luck!
\$\endgroup\$
6
  • \$\begingroup\$ I think this input-output pair violates the order-criterion: 1000001 1 0 1 \$\endgroup\$
    – flawr
    Commented Jul 11, 2017 at 9:09
  • \$\begingroup\$ What do you mean with "consistent across different runs"? Why don't you restrict this challenge to just have ascending coefficients? (Also please include wheter e.g. 1 3 5 7 means x^3 + 3x^2+5x+7 or 1+3x+5x^2+7x^3. \$\endgroup\$
    – flawr
    Commented Jul 11, 2017 at 9:12
  • \$\begingroup\$ @flawr To avoid confusion, a program or function should not output in different orders when different inputs are given (e.g. 1003005007 -> [1 3 5 7] and 999 -> [-1 1]). So 1 3 5 7 can mean both, but it has to be specified. To solve the problem one way is to find out and remove the leading/trailing coefficient recursively, and it probably costs extra bytes to reverse the list of coefficients. \$\endgroup\$ Commented Jul 11, 2017 at 9:15
  • \$\begingroup\$ Ah so the order has nothing to do with the challenge but just with the input/output? (I first thought we have to find polynomiasl where the coefficients are in are in ascending order.) Perhpas clarify that this is not about the coefficients but about the representation of the polynomials. And as I said before please specify that in your examples the constant monomial comes first, and the coefficients of the larger powers come after. \$\endgroup\$
    – flawr
    Commented Jul 11, 2017 at 9:51
  • \$\begingroup\$ I don't understand what the question has to do with the title. \$\endgroup\$ Commented Jul 11, 2017 at 10:07
  • \$\begingroup\$ @PeterTaylor see my edit \$\endgroup\$ Commented Jul 11, 2017 at 10:33
0
\$\begingroup\$

Fighting a Land War

In this KoTH, you need to earn as much money as you can while fighting over tiles to take over.

The board is a large hexagon made up of 91 smaller hexagonal tiles (A 6x6 hexagon)

Each tile is either:

  1. An impassable mountain
  2. Hills that generate production. They start out with a random value (between 2 to 4)
  3. Valleys that generate money. Their starting value is the distance from the nearest corner multiplied by 2 (between 2 and 10)

Board

There are 6 players in each game, each starting in a different corner of the hexagon. The corner will always be a hill(4). Turn order is randomized at the start of the game.

Each turn, the following happens:

  1. Each tile that you have owned for N^2 turns (where N is an integer) increases in value by 1
  2. You earn money/production. (Equal to the sum of the valley/hill values)
  3. You can spend production on defenses or capturing tiles.
    • Adding N TileDefense costs N Production
    • Capturing a tile with N TileDefense costs 1 + 2*N Production
    • You can only capture a tile if it is a non-mountain tile that is adjacent to your current tiles.

Notes:

  • Tiles lose all defense on capture.
  • Multiple players can upgrade a single tile
    • The turn counter for tile upgrades is player-specific. This means that if you capture a tile from another player, the turn counter starts at 0.
    • If you capture a tile you've owned before, it starts off where you left it.

And that's it. The player with the most money after 500? turns wins.

\$\endgroup\$
2
  • \$\begingroup\$ 1. "Each tile is either" determined how? Randomly or in a fixed pattern? 2. How does step 3 work? As many rounds of capture and defence as you like? Or do you declare all of your attacks and defences at the start of the round? This has implications both for defending a tile on the turn you capture it and for blitzkrieg captures. \$\endgroup\$ Commented Jul 16, 2017 at 6:56
  • \$\begingroup\$ 1. I'm still thinking about this. I think I'm going to randomly generate a triangular segment, and then mirror it across to the other 5 segments. 2. Oooh...I haven't thought about this. Thanks, I'll give it some thought. \$\endgroup\$ Commented Jul 16, 2017 at 12:06
0
\$\begingroup\$

Rock Paper Scissors, but it's a big, custom tournament

We all know "Rock, Paper, Scissors", and it's pretty variated.

A world tournament is held every year, and it's dang popular.

However, the contestants are able to bring their own ways of play to the plate, and they play with them.

The challenge:

Create a program that, by process of elimination through RPS, determines the winner of the tournament.

The tournament rules:

  • No slackers. (Let the amount of players be an integer equally divisible by 2. [In other words, an even number.])

  • You can bring 2 of either of the 4 variants:

    None: Play regular RPS.

    RPSLV: Play "Rock, Paper, Scissors, Lizard, Spock" (play diagram shown here).

    Best out of three: Play 3 rounds; if by round 2, a player wins the round and has two points, they auto win. Else, winner of the next round wins.

    Double RPS: Play with four hands (two hands used by each player).

  • You cannot bring two of the same variant.

  • In order to use a variant, the two players must have the same type of variant. If there are no matching variants, the gameplay is automatically None.

  • However, if there are more than one variant matches, a game of mode None will be played. The winner of the game mentioned decides what mode they play for the match they will play to see who goes to the next round.

  • In the case of a tie, replay until a win occurs (for all modes)

  • There can be only one winner.

The coding rules:

  • All choices must be randomized (no strategies, to make this simple.).

  • No standard loopholes.

  • Give an explanation as much as you can. (If possible, include a "Try it out online" sample.)

Sample Input/Output:

You must make a table variable with all the player numbers, from 1 to n, with two variants for each player.

n = the amount of players you intend to enter.

Example Input:

Player # | Var 1 | Var 2
1        | RSPLV | None
2        | None  | x2 RPS
3        | x2 RPS| Boo3
4        | Boo3  | x2 RPS
...      |...    | ...

Make a func() that:

1: Checks the variants of the next two availible players on the list, starting at player 1, then does the second to third last rules depending on what happens.

2: Makes the pair engage in battle, gameplay depending on the chosen variant.

3: Finally, boot the loser off the game and add the winner to the next list (round). (The "boot the loser" part isn't that required, but I recommend so as to not make the program add a player to the next table.)

Output (uses table from input):

 Round 1:
 1 vs. 2 // None, since the None variant matches both of them
 ["Rock"/*1*/,"Scissors"/*2*/]
 1 wins

 3 vs. 4 // They have more than one match, so they fight for who decides
 ["P"/*3*/,"S"/*4*/]
 4 wins, and chooses Best out of 3 
 Match 1:
 ["P"/*3*/,"R"/*4*/] // 1(3) - 0(4)

 Match 2:
 ["P"/*3*/,"S"/*4*/] // 1(3) - 1(4)

 Match 3:
 ["P"/*3*/,"R"/*4*/] // 2(3) - 1(4)
 3 wins

 Round 2:
 1 vs. 4 //No matches, defaults to None
 ["R"/*1*/,"R"/*4*/] // No-one wins
 ["R"/*1*/,"S"/*4*/]
 1 wins the tournament

Misc. requirements (some optional):

A {!} means it is required.

  • {!} Print each match, and who wins.

  • {!} Print the tournament winner.

  • {!} The number of players must be flexible.

  • Print the table for each round.

Scenarios:

None:

a vs. b //Either they have no matches, or they have both None matches
["R"/*a*/,"S"/*b*/]
a wins

RPSLV (will make this one quick):

a vs. b //RPSLV chosen
["V"/*a*/,"L"/*b*/]
b wins

Best out of Three:

Scenario 1: (a tie occurs at match 2)

a vs. b //Boo3 chosen
Match 1:
["P"/*a*/,"S"/*b*/] // 0(a) - 1(b)

Match 2:
["P"/*a*/,"P"/*b*/] // tie
["P"/*a*/,"S"/*b*/] // 1(a) - 1(b)

Match 3:
["R"/*a*/,"S"/*4*/] // 2(a) - 1(b)
a wins

Scenario 2: (a player has two points by the end of match 2)

a vs. b //Boo3 chosen
Match 1:
["P"/*a*/,"S"/*b*/] // 0(a) - 1(b)

Match 2:
["S"/*a*/,"P"/*b*/] // 0(a) - 2(b)
b automatically wins

Double RPS:

a vs. b //x2 RPS chosen
[("R", "P")/*a*/, ("S", "S")/*b*/] // lock
[("P", "P")/*a*/, ("S", "S")/*b*/]
b wins

Both the coding and tournament rules apply to your code.

For sandbox use only (won't be included in real question)

I don't know if this kind of problem is suitable for code golf, it could be a programming puzzle, I'm not sure. Go ahead in the comments and tell me what mode it should be, and if I should improve it. (Also, sorry for the mix of Python lists and C++ comments, if it confuses you.) A ** means the choice is random.

\$\endgroup\$
4
  • \$\begingroup\$ Hi and welcome to PPCG, and thanks for using the sandbox! I had a hard time following what you intended from this challenge. The rules are rather disorganised with many points early on not making sense until later. For example, you say: "No slackers. (Let p be a number equally divisible by 2.)" before it is clear that you intend for us to implement a single elimination tournament. I had no idea what "p" was supposed to mean, or why this should matter. I'd recommend trying to explain this to someone verbally, perhaps, to try to organise your thoughts better. Good luck! \$\endgroup\$ Commented Jul 15, 2017 at 21:50
  • \$\begingroup\$ Ah, thanks. I will edit the problem. \$\endgroup\$ Commented Jul 15, 2017 at 22:03
  • \$\begingroup\$ I'm not quite sure what we're supposed to implement. The controller for the tournament and what else? Do we also implement the players, so that we're simulating the entire thing? Or do we have to provide some kind of API for the players? In the first case, how does "The winner decides what mode they play" work? \$\endgroup\$ Commented Jul 16, 2017 at 7:14
  • \$\begingroup\$ Again, any multi-choice is random. \$\endgroup\$ Commented Jul 16, 2017 at 19:29
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\$
8
  • \$\begingroup\$ Is the sample output for input X? \$\endgroup\$
    – 0xffcourse
    Commented Jul 3, 2017 at 12:27
  • \$\begingroup\$ @officialaimm The characters can be of your choosing, there's no input currently \$\endgroup\$
    – dzaima
    Commented Jul 3, 2017 at 12:27
  • \$\begingroup\$ So, all the positions marked by X should have same character or can have different characters? \$\endgroup\$
    – 0xffcourse
    Commented Jul 3, 2017 at 12:40
  • \$\begingroup\$ @officialaimm They can have any characters \$\endgroup\$
    – dzaima
    Commented Jul 3, 2017 at 12:42
  • 1
    \$\begingroup\$ I think its better if you showcase sample output with different characters then. \$\endgroup\$
    – 0xffcourse
    Commented Jul 3, 2017 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\$ Commented Jul 17, 2017 at 14:12
  • \$\begingroup\$ @trichoplax good idea \$\endgroup\$
    – dzaima
    Commented Jul 17, 2017 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\$ Commented Jul 17, 2017 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\$
1
  • \$\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\$ Commented Jul 17, 2017 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\$
11
  • 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\$ Commented Jul 17, 2017 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
    Commented Jul 17, 2017 at 19:37
  • \$\begingroup\$ Will edit the question. \$\endgroup\$ Commented Jul 17, 2017 at 19:37
  • \$\begingroup\$ Are caught errors allowed? \$\endgroup\$
    – wrymug
    Commented Jul 17, 2017 at 20:38
  • \$\begingroup\$ You mean stuff like try? \$\endgroup\$ Commented Jul 17, 2017 at 20:57
  • \$\begingroup\$ Who wins? What's the criterion for deciding that? \$\endgroup\$
    – Riker
    Commented Jul 17, 2017 at 21:32
  • \$\begingroup\$ @Riker I am currently thinking about that. \$\endgroup\$ Commented Jul 17, 2017 at 23:07
  • \$\begingroup\$ @S.G.Harmonia yeah \$\endgroup\$
    – wrymug
    Commented Jul 18, 2017 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
    Commented Jul 18, 2017 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\$ Commented Jul 18, 2017 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\$ Commented Jul 18, 2017 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\$
9
  • \$\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\$ Commented Jul 15, 2017 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
    Commented Jul 15, 2017 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\$ Commented Jul 15, 2017 at 23:46
  • \$\begingroup\$ I think .1M should be 100K and we should allow up to 4 digits (or under 5). \$\endgroup\$
    – zoecarver
    Commented Jul 15, 2017 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\$ Commented Jul 15, 2017 at 23:49
  • \$\begingroup\$ Ok, I will specify. thanks for the help! \$\endgroup\$
    – zoecarver
    Commented Jul 16, 2017 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\$ Commented Jul 16, 2017 at 7:05
  • \$\begingroup\$ Thank you for your feedback! I have applied your edits, anything else? \$\endgroup\$
    – zoecarver
    Commented Jul 18, 2017 at 3:29
  • \$\begingroup\$ I am going to post this unless anyone has any other feedback. \$\endgroup\$
    – zoecarver
    Commented Jul 19, 2017 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\$
3
  • \$\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\$ Commented Jun 29, 2017 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\$ Commented Jun 29, 2017 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
    Commented Jun 29, 2017 at 15:31
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\$

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\$
5
  • \$\begingroup\$ is the input guaranteed to be rectangular? will the _ be on one line \$\endgroup\$ Commented May 24, 2017 at 4:45
  • \$\begingroup\$ @DestructibleLemon I will edit to clarify. \$\endgroup\$
    – sporkl
    Commented May 24, 2017 at 12:11
  • \$\begingroup\$ If its padded its very trivial to just replace all the spaces with # \$\endgroup\$
    – Notts90
    Commented May 25, 2017 at 8:30
  • \$\begingroup\$ @Notts90 Not all the spaces, only the ones below the line. \$\endgroup\$
    – sporkl
    Commented May 25, 2017 at 12:08
  • \$\begingroup\$ Ah ok, might want to make it clearer the bit above the line are included in the input. \$\endgroup\$
    – Notts90
    Commented May 25, 2017 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\$
28
  • \$\begingroup\$ This is the canonical string equal question, but it does not allow you to use string comparison. \$\endgroup\$
    – Stephen
    Commented Aug 1, 2017 at 21:37
  • 4
    \$\begingroup\$ Bro... Come on, at least 3 sentences. \$\endgroup\$ Commented Aug 1, 2017 at 21:39
  • \$\begingroup\$ Do you need to handle strings with new lines or spaces in them? \$\endgroup\$
    – geokavel
    Commented Aug 2, 2017 at 0:08
  • \$\begingroup\$ @MagicOctopusUrn added a bit more clarification :P what else is there to say? \$\endgroup\$
    – Stephen
    Commented Aug 2, 2017 at 1:21
  • \$\begingroup\$ @geokavel clarified \$\endgroup\$
    – Stephen
    Commented Aug 2, 2017 at 1:21
  • \$\begingroup\$ This needs more information, test cases and to actually be made into a challenge. \$\endgroup\$ Commented Aug 2, 2017 at 8:59
  • \$\begingroup\$ @TheLethalCoder I forgot testcases - thank you. However, what else would I add to make it a challenge? \$\endgroup\$
    – Stephen
    Commented Aug 2, 2017 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\$ Commented Aug 2, 2017 at 11:05
  • \$\begingroup\$ @TheLethalCoder OK, how's that? and thanks for the feedback. \$\endgroup\$
    – Stephen
    Commented Aug 2, 2017 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\$ Commented Aug 2, 2017 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
    Commented Aug 2, 2017 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\$ Commented Aug 2, 2017 at 11:21
  • \$\begingroup\$ @TheLethalCoder ok how's that? \$\endgroup\$
    – Stephen
    Commented Aug 2, 2017 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\$ Commented Aug 2, 2017 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
    Commented Aug 2, 2017 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\$
2
  • \$\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\$ Commented Aug 3, 2017 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
    Commented Aug 3, 2017 at 8:22
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\$
16
  • \$\begingroup\$ how to deal with the sun... \$\endgroup\$ Commented Aug 10, 2017 at 4:30
  • \$\begingroup\$ @HelkaHomba This URL is invalid or has expired. \$\endgroup\$
    – Oliver Ni
    Commented Aug 10, 2017 at 5:50
  • \$\begingroup\$ @DestructibleLemon Not sure, I'll think about it. \$\endgroup\$
    – Oliver Ni
    Commented Aug 10, 2017 at 5:51
  • \$\begingroup\$ What would i.sstatic.net/nkx4V.jpg become? \$\endgroup\$ Commented Aug 10, 2017 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
    Commented Aug 10, 2017 at 6:41
  • \$\begingroup\$ Won't this fall under the usual "No objective winning criteria" that pop cons have been falling under lately? \$\endgroup\$ Commented Aug 10, 2017 at 7:58
  • \$\begingroup\$ @TheLethalCoder Fixed. \$\endgroup\$
    – Oliver Ni
    Commented Aug 10, 2017 at 9:14
  • \$\begingroup\$ @OliverNi How? The voting criteria is still subjective and that's why recent ones have been closed. \$\endgroup\$ Commented Aug 10, 2017 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
    Commented Aug 10, 2017 at 9:25
  • \$\begingroup\$ @OliverNi Yeah you're winning criteria is fine. It's the subjective voting criteria I'm questioning. \$\endgroup\$ Commented Aug 10, 2017 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
    Commented Aug 10, 2017 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\$ Commented Aug 10, 2017 at 9:39
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$
    – Oliver Ni
    Commented Aug 10, 2017 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\$
    – 0xffcourse
    Commented Aug 10, 2017 at 12:28
  • \$\begingroup\$ So... if you vertically flip any of those images your algorithm would fail? \$\endgroup\$ Commented Aug 11, 2017 at 20:38
0
\$\begingroup\$

Intertwined Polyglot

Write a program which when executed as language A, produces a different program in language B, which in turn produces the name of language A. And the other way round (B to A to B).

+-----------+   Lang. A    +-----------+   Lang. B
| Program 1 | -----------> | Program 2 | -----------> "<Lang. A>"
|           |              +-----------+
|   Your    |              +-----------+
|  Program  | -----------> | Program 3 | -----------> "<Lang. B>"
+-----------+   Lang. B    +-----------+   Lang. A

Rules

  • The produced programs must be unique both from each other, and from the original program.
  • Uniqueness is defined as at least one modified or moved printing character. Example: a bc => ab c would not be considered unique, whereas a bc=> a cb would.
  • The output may contain leading and/or trailing whitespace and/or newlines, so long as the language name is intact.
  • Your program(s) may not take any input.
  • This is , so fewest bytes wins.
\$\endgroup\$
9
  • \$\begingroup\$ I couldn't find a matching question... but I really think this might be a dupe.. \$\endgroup\$
    – 0xffcourse
    Commented Aug 10, 2017 at 12:20
  • \$\begingroup\$ You should define "unique". Does 1 character difference count? Can it be a hidden character (CR,...)? \$\endgroup\$
    – Goufalite
    Commented Aug 10, 2017 at 12:49
  • \$\begingroup\$ @officialaimm That's what I thought too, but I had no luck finding it either \$\endgroup\$
    – MTCoster
    Commented Aug 10, 2017 at 13:03
  • \$\begingroup\$ @Goufalite I would say yes to a single character, but I'm not sure about whitespace. For some languages it's integral, but others will ignore it \$\endgroup\$
    – MTCoster
    Commented Aug 10, 2017 at 13:05
  • \$\begingroup\$ I believe this is the duplicate you guys are thinking of. cc @officialaimm \$\endgroup\$ Commented Aug 11, 2017 at 21:01
  • \$\begingroup\$ @ETHproductions Nope, not that one... I don't even know if there is a dupe, I just doubt there might be one.. \$\endgroup\$
    – 0xffcourse
    Commented Aug 12, 2017 at 3:25
  • \$\begingroup\$ The "And the other way round" should be emphasized more. On my first read, I though only A to B to A was necessary. An example would solve this and make the challenge easier to understand overall. \$\endgroup\$ Commented Aug 14, 2017 at 1:31
  • \$\begingroup\$ @fireflame241 Does the diagram I've added help to ease understanding? \$\endgroup\$
    – MTCoster
    Commented Aug 14, 2017 at 8:42
  • \$\begingroup\$ @MTCoster absolutely. However, it looks like Program 1 and Your Answer are different. Remove the dividing line? \$\endgroup\$ Commented Aug 14, 2017 at 13:55
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\$
3
  • \$\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\$ Commented Aug 20, 2017 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
    Commented Aug 20, 2017 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
    Commented Aug 20, 2017 at 21:39
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
  • 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
    Commented Aug 23, 2017 at 18:53
0
\$\begingroup\$

Numbers to Algorithms

Another horrible part of Cubically is attempting to print numbers when the notepad is occupied. Since you can't add up existing faces, the integer (or ASCII value) you have to print needs to be on one single face.

The maximum value you can store on one Cubically face is 45. This isn't great, but it's better than nothing. Your challenge is to write a program that automates the process of getting the values 0-45 onto the top face.

Your program will take an input number n and produce a Cubically code snippet as output. This Cubically snippet should achieve the task of getting all integers on the top face to sum up to n. If you don't yet know how Cubically works, go check out the repo. Here's a run-down of all you need to know.

Cubically is my esolang based on a Rubik's Cube. Its 3x3x3 memory cube is initialized like this (without the comments on the right):

   000
   000          top face
   000
111222333444    left, front, right, and back faces, respectively
111222333444
111222333444
   555
   555          down face
   555

It uses quarter turn notation, so RRLL turns the cube to look like this:

   505
   505
   505
111424333242
111424333242
111424333242
   050
   050
   050

Now the sum of the top face is 30. So if n is 30, RRLL would be a valid output.

In addition to quarter turn notation, you can send a subscript number to face turns to mean "turn the xth layer inwards from the [face] face, where x is the subscript number". So R1 would turn the cube to look like this:

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

Arbitrary base conversion

Given an integer n of any sign, output a list of digits of its representation in a given base b not in -1, 0, 1. If b is positive, n will be non-negative.

Rules:

  • You may not use arbitrary base conversion built-ins like Jelly's b or 05AB1E's в.
  • You may assume the input is valid, as above.
  • All digits must be greater than or equal to 0 and strictly less than b.
  • For zero you must return [].

Test cases

256, 10 -> [2, 5, 6]
256, -10 -> [3, 5, 6]
1000, 25 -> [1, 15, 0]
1000, -30 -> [2, 27, 10]
0, 300 -> [0]
1000, 1000 -> [1, 0]
18446744073709551615, 4 -> [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
18446744073709551615, -5 -> [3, 3, 2, 1, 3, 3, 1, 2, 1, 2, 2, 3, 0, 1, 1, 4, 0, 2, 0, 4, 3, 4, 2, 3, 3, 1, 4, 4]

Sandbox

Is this a dupe?

\$\endgroup\$
4
  • \$\begingroup\$ I'd suggest 0 in any base be the empty array, so it doesn't need special handling from recursive solutions and the like. \$\endgroup\$ Commented Aug 6, 2017 at 21:57
  • \$\begingroup\$ @ETHproductions Let's see...well, [0] shouldn't actually need special-case handling if you put the sum check before the special cases...but otherwise I did consider []. \$\endgroup\$ Commented Aug 7, 2017 at 8:47
  • \$\begingroup\$ We had this challenge which was closed as dupe of that challange. \$\endgroup\$
    – nimi
    Commented Aug 20, 2017 at 18:10
  • \$\begingroup\$ @nimi Hmm...from the title you would guess that it's about converting to bases 2..36 although that doesn't seem to be the case so not sure if this is a dupe or something. \$\endgroup\$ Commented Aug 20, 2017 at 18:29
0
\$\begingroup\$

Bomberman

Given an input Bomberman board b, use the following characters to define the different bomberman tiles:

  • X denotes the outer boundary of the board.
    • X is always in each of the four corners of the board.
    • X may only be on the boundaries of the board.
  • - denotes an empty space.
    • When a bomb blows up over an empty space, it replaces it with *; and may continue.
  • o denotes a blocker that is breakable.
    • When a bomb blows up over a breakable blocker, it replaces it with *; and stops.
  • O denotes an impenetrable blocker.
    • When a bomb reaches an impenetrable blocker, it stops prior to it.
  • 0-9 describes a bomb of n power.
    • When a bomb explodes it explodes in a plus pattern.
    • A bomb of 0 strength would be: *.
    • A bomb of 1 strength would be: * \n***\n *
    • And so on... 1-indexing is not okay because that would make the 9 bomb a 10 bomb.

Worked Example

An example board would be (without bombs):

XXXXXXXXXXXX
X----------X
X-oo---O---X
X--------O-X
X--OoO-----X
X----------X
X--O-------X
X-------O--X
-----o------
X---------OX
X--O---o---X
XXXXXXXXXXXX

If we were to add some randomized bombs to this board we would see:

XXXXXXXXXXXX
X----------X
X-oo-1-O---X
X--------O-X
X--OoO--0--X
X---1------X
X--O-3-----X
X-------O--X
--4--o------
X---------OX
X--O-2-o---X
XXXXXXXXXXXX

This should, when input to your program, output the following explosion pattern:

XXXXXXXXXXXX
X----*-----X
X-oo***O---X # This didn't get blocked, it's just a small explosion.
X----*---O-X
X-*O*O--*--X # This destroyed a brittle block.
X-****-----X
X-*O*****--X # This got hard blocked.
X-*--*--O--X
*******---** # Notice how it wraps, because there's no boundary.
X-*--*----OX
X-*O****---X # This got hard-blocked.
XXXXXXXXXXXX

Example 1:

Input:

XX
XX

Output:

XX
XX

Example 2:

Input:

X-O--X
-o2-o-
-1--1-
-o-2o-
X--O-X

Output:

X-O--X
-****-
******
-****-
X--O-X

Example 3:

Input:

X     X
 OOOO
  1114


X     X

Output:

X    *X
 OOOO*
*******
  ****
     *
X    *X

Rules

More examples, soon. Is this good? Sandbox? What should I change?

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

Is Effort Inversely Correlated with Upvotes?

Inspired by this chat message and the subsequent conversation

Introduction

PPCG is infamous (famous?) for it's short golfing language answers that are showered with upvotes. But, are these short answers full of hard-core golfing, or are they just a few builtins that work? Do these answers take effort, and deserve upvotes, or are upvotes and effort inversely correlated?

The Challenge

To get some variables out of the way, x=effort, and y=votes

Your challenge is, given a question ID, output A if the question has a strong positive correlation between effort and votes, B if it has a weak correlation between efforts and votes, or C if it has a strong negative correlation between effort and votes. A may be any value never given as B or C, B may be any value never given as A or C, and C may be any value never given as A or B (You doubt have to have consistent values across runs, but the set of values for A must not intersect with B or C, etc.).

Defining Effort

Effort is an awfully complex concept, but for this challenge we will grossly simplify it to the number of significant edits. significant edits, in this context, will be the number of edits, by the question author, that occurred more than 1 minute after the previous edit (initial posting, in this case, counts as an edit).

Defining Votes

Votes is upVotes - downVotes.

Defining Correlation

For the sake of simplicity, will we use the least-squares regression line as our correlation model. If R^2 (the determination coefficient) is less than .3 (e.g. < 30% of the variation is explained by the model), we will say that there is weak correlation. If R^2 is greater than or equal to .3, we will say that the correlation is strong. Negative vs. positive correlation must be determined from the sign of R (the correlation coefficient).

What Points?

The data points that should be included in your regression are points of the form (votes, effort) for each answer in the given question.

Test Cases

//TODO

Specifics

  • For the purposes of this challenge, you may access the api.stackexchange.com website. You may not shorten the URL with any out-of-language utilities (e.g. tinyurl, but you can still compress it if your language supports compression)
  • You may not violate any standard loopholes
  • You may take input and give output in any reasonable format
  • You should exclude community wikis from your calculations

Meta

\$\endgroup\$
4
  • \$\begingroup\$ @programmer5000 okay \$\endgroup\$ Commented Aug 22, 2017 at 20:32
  • \$\begingroup\$ "number of edits greater than 5 characters" counted how? Levenshtein distance with substitution counted as 1? (This is a terrible proxy for effort: apart from anything else, adding strikeout to record a one-byte improvement would take you past the threshold, even if the improvement was suggested in comments and required no effort on the OP's part). \$\endgroup\$ Commented Aug 23, 2017 at 21:23
  • \$\begingroup\$ @PeterTaylor that's intentional (the strikeout), but I agree that's it's a bad proxy for effort.. I'll try and create a better one... \$\endgroup\$ Commented Aug 23, 2017 at 21:39
  • \$\begingroup\$ @PeterTaylor updated definition of effort, is it better or worse? \$\endgroup\$ Commented Aug 24, 2017 at 18:03
0
\$\begingroup\$

Word Problem Generator

Already exists here!

Word problems can be a great way to test comprehension of concepts, but they are pain to write. That's why you need to make a program that takes an equation (or set of equations), and makes a word problem out of them. For example, if the input is x+3=8, you can output, Mary has 3 more apples than Johnny. If Mary has 8 apples, how many does Johnny have?

The best answers for this challenge will be able to handle many different types of equations and randomly generate a variety of unique word problems. It might be o.k. if your program creates non-sensical word problems, as long as they describe the input equation/equation set and people like them.

Rules

  • Submission must be no longer than 2000 bytes
  • External files and URL's may be used to access word lists not specifically made for this challenge. You can also use libraries for parsing mathematical equations and sentence generation that were not specifically made for this challenge (WolframAlpha is acceptable). Inquire about other acceptable usage of external sources.
  • Golfing is encouraged. Most popularity contests ask for readable code, but with a tight 2000 byte limit, I encourage golfing as much as possible (even using a golfing language), so that you'll have enough bytes remaining to create interesting word problems.

Examples

  • atan(x) = 5/4 => "At what angle should Jan hit the soccer ball to hit a target 5 feet high and 4 feet away?"
  • x+5 = y, 2(x-1) = y-1 => "Paul is 5 years older than Sally. Last year Paul was twice Sally's age. How old are Paul and Sally?"
  • x = 6^2/4^2 => "How much more pizza is there in a 12 inch pizza than an 8 inch pizza?"

Submission

With your submission, you include the types of equations/equation sets it can handle (we'll assume that a,b,c,d,e,f,g refer to constants and t,u,v,w,x,y,z refer to variables).

As an example, let's say your program can only make 1 type of word problem: "How long will it take for a boat with speed a to catch up to a boat with speed b that is distance c ahead of the first boat?" In that case, you write that your program only handles equations of the form at = bt + c, so people will know to only test it with things like 5t = 3t + 2 or 4t = 2t + 1.

Furthermore, you should mention if your program can make multiple types of word problems for one type of equation/equation set. For example, an equation of the form a + bx = c could lead to word problems about the time it takes to get from one point to another, or the amount of a particular coin you need to reach a certain amount of money.

Likewise, mention other ways your program creates variety in generating word problems.

Finally, you can include some sample word problems your program has generated, and the equations they were for.

Minimum Requirements

The most basic acceptable solution should handle at least 1 equation/equation set with at least 1 variable, 1 constant, and 1 mathematical operation. Such a minimal program might only handle equations of the form x = a + 1. It might output word problems like, "If Jerry has a apples, and he picks 1 more, how many does he have now?" Obviously, you should not strive for the bare minimum.


All suggestions welcome!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ In case you haven't seen it yet: Tag Wiki for popularity contest. As noted there, you should include an objective validity criterion. You already have some useful rules, but it's still not clear me what the minimum requirement for an answer is. E.g. would handling only equations x=1+2 suffice? What about only x=3. \$\endgroup\$
    – Laikoni
    Commented Jul 21, 2017 at 8:51
  • \$\begingroup\$ @Laikoni ty, updated. \$\endgroup\$
    – geokavel
    Commented Jul 21, 2017 at 15:35
  • \$\begingroup\$ Personally, I dislike the scoring. Having a hard byte count limit discourages more verbose languages, but at the same time, byte count is not a factor in scoring. Also, I'm not sure popularity-contest is the right choice here. I would either 1) Make it a code-golf and impose strict requirements on what the program should be able to do, or 2) Make it a test-battery, where the score is the percentage of inputs that result in coherent output \$\endgroup\$ Commented Jul 21, 2017 at 20:59
  • \$\begingroup\$ @musicman523 I've thought about other formats than pop-con, but I think they all significantly reduce creativity. I don't have a perfect answer for byte count limit, but I think it is needed, otherwise people can spend forever hardcoding all sorts of words problems, which is not really what I'm looking for. Also, one tradeoff is the languages that are usually more verbose are the more established ones that also have more library access. \$\endgroup\$
    – geokavel
    Commented Jul 21, 2017 at 21:55
1
111 112
113
114 115
161

You must log in to answer this question.

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