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

2867 Answers 2867

1
52 53
54
55 56
96
0
\$\begingroup\$

Create a basic spell checker

In this challenge, you have to implement a basic spell checker. Your program will use the first input as a source.

Specifications

  • You will receive two inputs, one is a sentence/paragraph you use as a source for your spell checker, and the other includes wrong words (they can be correct too) which you have to correct using the first input.
  • Possible mistakes: Missing one letter (e.g. helo), one extra letter (e.g. heello), substitution of one character (e.g. hilp instead of help), transposition of two adjacent characters (e.g. hlep instead of help).
  • In other words, the mistake and the original word have to have a Damerau–Levenshtein distance of one.
  • You can separate the inputs in any reasonable format. For example, instead of using a newline, you can use a pipe sign to separate them. (|) However, watch out so you don't use something like letters because they are used in the 1st input.
  • It's possible for a word to have neither an identical word nor a word with 1 distance from the first input. You will have to leave them unchanged.
  • You don't need to do anything with punctuation. That is, I won't test words that are followed by a punctuation. (E.g. From the first example, I won't ask the correction of 'blod')
  • Challenge is case insensitive, both the input and output. Meaning that if 'The' is used in the 1st input and the 2nd input is 'teh' you can change it to 'The', 'teh', 'teH', and similar cases.
  • If a word is in the first input, but also has a distance of 1 with one of the other words, do not correct it.
  • If there are two words with the same distance, you can output either of them. (E.g. 'en' can change into 'on' and 'in' if the words are both in the first input.) You can also output both of them, but you'll have to use a slash between them. (E.g. 'en' can be corrected into 'in/on')
  • You can assume words are just sequences of letters separated by spaces.
  • You can use STDIN or the closest alternative in your language.
  • Standard loophole rules apply.
  • This is , so the shortest code wins.

Examples

Input:

A criminal strain ran in his blood, which, instead of being modified, was increased and rendered infinitely more dangerous by his extraordinary mental powers. 

increasd mnetal

Output:

increased mental

Input:

The fact is that upon his entrance I had instantly recognized the extreme personal danger in which I lay.

I recognizi dnger en

Output:

I recognize danger in    
| |
\$\endgroup\$
  • \$\begingroup\$ There are several definitions of "distance". Since the most common one is probably Levenshtein, you might want to specifically say that original and mistake have to have Damerau–Levenshtein distance of one. Other questions: what is a word? Only sequences of letters? What about "doesn't" or "up-to-date"? (It's probably simplest to rule those out.) What do we output if there are two different words with distance one? E.g. does en become in or on if both are in the first string? \$\endgroup\$ – Martin Ender Jun 3 '15 at 20:33
  • \$\begingroup\$ Is the input case insensitive? If so, is case of the output arbitrary too or do we have to preserve the input capitalisation? And are we guaranteed that every word in the second string has a word in the first string that is no more than distance 1 away? \$\endgroup\$ – Martin Ender Jun 3 '15 at 20:34
  • \$\begingroup\$ @MartinBüttner I clarified it in the bullet point above it. Only transposition of adjacent letters, one missing letter, one extra letter and a wrong letter. I guess that's Damerau-Levenshtein distance. Regarding the two words problem, I guess you could output either of them. I'm not really sure about this. I'm open for ideas. \$\endgroup\$ – JNV Jun 4 '15 at 4:49
  • \$\begingroup\$ @MartinBüttner Good point. It's case insensitive, and the output can be in any case. (e.g. If the first input includes 'The' and there's 'teh' in the second input, it should output 'the' or 'THE' or 'tHE' or ...). No, you're not guaranteed that there's a word with a distance of 1 in the first input. Take a look at the example #2, 'I' was not changed. Also, in your previous post, you asked what counts as a word. I already said it in the post 'You can assume all words in the 2nd input are separated by spaces.' I'll edit it for clarity. \$\endgroup\$ – JNV Jun 4 '15 at 4:56
  • \$\begingroup\$ I was asking for distance "no more than 1 away". That is, could there be a word that has neither a word with distance 1 nor an identical word in the first input? "You can assume words are just sequences of letters separated by spaces." Yet in the first input, there is punctuation. What sort of punctuation should we expect? The rest looks good. \$\endgroup\$ – Martin Ender Jun 4 '15 at 12:43
  • \$\begingroup\$ @MartinBüttner Yes, it's possible for a word to have neither an identical word nor a word with 1 distance from the 1st input. You can ignore the words that are followed by a punctuation, like blood in the 1st input. They won't be in the test cases. (E.g. I won't ask for the correction of 'blod') Thank you for your help. \$\endgroup\$ – JNV Jun 4 '15 at 13:10
  • \$\begingroup\$ As for the 'lay' in the first example, I'll fix it now, thanks. \$\endgroup\$ – JNV Jun 4 '15 at 13:19
  • \$\begingroup\$ Right, but the question is what do we do with words that have neither an identical word nor a word with 1 distance from the 1st input. Remove them? Leave them changed? Also, that second point might be worth mentioning in the spec. \$\endgroup\$ – Martin Ender Jun 4 '15 at 13:19
  • \$\begingroup\$ @MartinBüttner Leave them unchanged. Thank you for your support. \$\endgroup\$ – JNV Jun 4 '15 at 13:26
0
\$\begingroup\$

Multiply with restricted operations: Best lower bound

Multiply with restricted operations is a challenge to multiply two variables using as few as possible of four allowed operations: addition, reciprocal, negation, and variable assignment. The current best is 22 operations.

Your goal is to prove a lower bound L, a number for which you demonstrate that there are no solutions with fewer that L operations. The highest L wins.

You must explain why your code demonstrates the lower bound, and I must be able verify your code by running it. There is a time limit of 30 minutes. The natural approach is to search the space of possible solutions, perhaps shrinking it via mathematical arguments, but any method is allowed. Purely mathematical proofs without code are also valid.

Your code is limited to 30 minutes and 3GB of memory on my machine (Windows 7 with a Intel Core i5-460M processor). I may be satisfied with someone else running your code to confirm with a conservative adjustment for different machine speeds.

Your code needs to run on easily-available free software. Please include instructions on how to run your code.

The winner will be the highest lower-bound proven by [date]. Tiebreak is fastest runtime on my computer. I will give a bounty of 500 rep to the winner.

If your lower bound matches a solution, narrowing down the optimum to a single value, I will award you an additional bounty of 300 rep.


For Sandbox:

  • I haven't done a fastest code before. Anything I'm missing? Any machine specs I should add?
  • When to have deadline?
| |
\$\endgroup\$
  • \$\begingroup\$ Maybe you should require the program to be able to prove lower bounds for arbitrary expressions, rather than only a*b. Otherwise, it will be impossible to tell if a brute-forcing program is doing anything correctly, for any bound too low to find an answer. \$\endgroup\$ – feersum Jun 8 '15 at 17:35
  • \$\begingroup\$ @feersum I'd really like to let people optimize for just multiplication since that's the function I care about. Is it really impractical to verify that code is doing the search correctly if the user is required to give a detailed explanation of their method and why it works? I trust people to be honest as to what the code does. \$\endgroup\$ – xnor Jun 12 '15 at 17:49
  • \$\begingroup\$ I do believe it is impractical. How can you really tell that someone is not randomly twiddling bits and then printing 19? It seems that (innocently) bugged answers are more likely than correct ones in an environment where there is no testing. \$\endgroup\$ – feersum Jun 12 '15 at 18:01
0
\$\begingroup\$

Date-A-List!

Introduction

The year is 20XX. Lists of integers are now members of society with a full set of rights. Like humans, lists like to have dates and get married. In this challenge, we'll produce a program "Date-A-List!" that will get as many lists as possible on happy and compatible dates. Lists tend to prefer using programs that use as little bytes as possible, so this program will be golfed.

Lists are compatible (that is, you can assign them to a date together) if they share 2 or more integers in the same order. For instance, the lists (1 2 3) and (2 3 5) would be compatible. The lists (1 2 3) and (3 2 5) would not be compatible because they do not share 2 or more integers that are in the same order.

Lists are also always monogamous -- they will never go on a date with more than one list. For instance, consider the lists (1 2 3), (2 3 5) and (5 1 2) -- although the first list is compatible with both of the others, it may only date one of them.

Input Description

Input is a list of lists in brackets, space separated:

(1 2 3) (2 3 5) (5 1 2)

That input would indicate three lists to be assigned to dates: [1, 2, 3], [2, 3, 5], and [5, 1, 2].

Output Description

If n is the maximum number of dates possible, output n lines, each line consisting of two space separated lists which are to be matched up. For instance, on the example input there are two possible outputs:

(1 2 3) (2 3 5)

or:

(1 2 3) (5 1 2)

[TODO: More complex inputs and outputs]

| |
\$\endgroup\$
  • \$\begingroup\$ It would be nice to include the word "matching" somewhere in the text, for searchability. It would also be nice to have the basic examples use slightly more variety: at present they're all 3-element lists which overlap on adjacent pairs, but neither of those are stated as constraints. How about using (1 2 3) and (2 5 4 3) as the example of compatibility? \$\endgroup\$ – Peter Taylor Jun 6 '15 at 13:43
0
\$\begingroup\$

5-a-side Toroidal Bot Soccer

Randomised teams

This is a team game. Rather than being assigned permanently to one team or the other, each bot will play in a number of games, each for a different randomly composed team of 5 players ("5-a-side"), and score a point for each game in which its team wins. This means every game requires team work, but there is still a single overall winner after all games are played.

Rules

There are no rules for the players (no referee, no penalties, no off-side rule). The movement of the ball defines the score and the players can do as they see fit.

Scoring

There are no goal posts. If the ball moves off the right hand edge of the field, it reappears at the left hand edge of the field and team 1 scores a goal. Similarly team 2 score if it moves off the left hand edge and reappears at the right. The score will be represented by a single integer, that is increased by one when team 1 scores, and decreased by one when team 2 scores. At the end of a game, team 1 wins if the score is positive, team 2 wins if the score is negative, and a zero score is a draw/tie.

Movement over the top and bottom edges has no effect on the score.

The game lasts for 2000 time steps (each bot provides 2000 moves). If there is no winner by the end of the game it is extended by up to a further 1000 moves, with the game ending if either team scores.

Physics

Physics is the main obstacle to real world toroidal soccer, and will not be respected in this game. The physics have been simplified as much as possible to hopefully allow games to be viewed live.

This is a non-contact sport. Bots pass straight through other bots (of either team) with no interaction. Each bot can only interact with the ball.

The playing field is a continuous rectangle of width 100 and height 50. The bots and the ball have radius 1. Bots and ball can move freely in any direction without meeting a boundary - the edges of the field wrap. The ball will rebound from any bot if their circumferences overlap.

Turning and acceleration

Due to the use of simplified physics this is quick to explain:

A bot has a facing angle and a velocity. A constant acceleration applies in the direction specified by the facing angle. Drag is a deceleration proportional to the velocity (an acceleration in the opposite direction to the velocity, proportional to the size of the velocity). This means a bot that does not turn will accelerate to a maximum velocity where the drag matches the acceleration.

A bot can turn any angle instantaneously, but the velocity (and hence direction) will only change gradually. For example, a bot changing direction by 180 degrees will continue travelling backwards while it slows down to zero velocity, and then accelerate in its new direction.

The ball has no acceleration of its own, so other than collisions, its only change in velocity is due to drag. There is no spin.

Collisions

Only the ball can be involved in a collision with a bot - bots pass straight through each other.

Although the radius of both bots and ball will be displayed visually as 1, I believe the results are the same if collision calculations are based on the bots having radius 2 and the ball being a point.

To keep calculation simple, the ball will be tested for collision with each bot by considering the bot to be a circle moving with constant velocity and the ball to be a point moving with constant velocity (that is, the acceleration will occur at instants, rather than continuously over time). Since this is also how the motion will be modelled generally, the collisions should be consistent with the motion of objects in the game.

This allows the exact point of collision to be calculated so the rebound can occur with no overlap.

Communication

There is no communication between bots. Each bot communicates solely with the controller.

The communication method will depend on the controller type (language agnostic/specific). Players will either be functions/objects in a specific language, or separate programs that communicate through STDIN/STDOUT.

Each step all bots will be supplied with the same information, and will provide a facing angle which will be a float in the range [0, 360).

The information supplied to bots will be as follows.

  • Team direction (1 for team 1 or -1 for team 2)
  • Current score (positive if team 1 is winning, negative if team 2 is winning)
  • Facing angle and velocity of itself
  • Facing angle and velocity of 4 team mates
  • Facing angle and velocity of 5 opponents

Facing angle will be given as a float. Velocity will be given as x and y components, so two floats.

The information will therefore be received as two integers followed by 15 floats.


Sandbox questions

  • Are any terms not familiar that would be worth linking or further explaining?
  • Are there any further simplifications that could be made, without detracting from the game?
  • Are any of the simplifications too much? Am I overlooking some way in which the game could become trivial?
  • Is it correct to model the bots as radius 2 and the ball as a point? Does this give identical results to modelling the bots as radius 1 and the ball as radius 1?
  • Are there any problems likely to arise from basing collision detection on constant velocity bots and ball? (Acceleration being applied instantaneously each step, rather than spread out over continuous time.)
| |
\$\endgroup\$
  • \$\begingroup\$ How long does each game last for? I like your idea of randomising the teams. How many bots are in each team? \$\endgroup\$ – euanjt Jun 16 '15 at 7:55
  • \$\begingroup\$ @TheE The "5-a-side" in the title refers to 5 players per team - I wasn't sure how widely known that was so I'll edit that in. \$\endgroup\$ – trichoplax Jun 16 '15 at 12:41
  • \$\begingroup\$ @TheE I'm not sure how long each game should last yet - I'll have to test with some example players once the controller is written. For now I'll say 2000 steps in order to have something that people can comment on. I guess it will depend on what acceleration and drag figures I settle on too - as that affects how far each bot can move per time step. \$\endgroup\$ – trichoplax Jun 16 '15 at 12:45
  • \$\begingroup\$ If a player of the right team stays on the left part of the field, he could counter score every goal it's team take, right? \$\endgroup\$ – Katenkyo Jun 16 '15 at 13:26
  • \$\begingroup\$ Yeah I didn't read the title :) oops \$\endgroup\$ – euanjt Jun 16 '15 at 14:00
  • \$\begingroup\$ @TheE no problem - and thanks for the other feedback :) \$\endgroup\$ – trichoplax Jun 16 '15 at 15:17
  • \$\begingroup\$ @Katenkyo all the players can move freely over the edges of the field, so if the left team can get the ball past the right team's players then it shouldn't matter which side of the field they are on. The left team can reappear at the left side of the field and keep kicking the ball further right. \$\endgroup\$ – trichoplax Jun 16 '15 at 16:06
  • \$\begingroup\$ @Katenkyo also all players can see all other players, so a bot from team 1 kicking the ball past the right hand edge of the field can see any team 2 bots waiting at the left hand edge of the field. It can therefore aim to avoid them so they cannot simply kick it back. \$\endgroup\$ – trichoplax Jun 16 '15 at 16:08
0
\$\begingroup\$

Build a Rorschach Generator

2 possible challenges:

1.

Help a poor struggling game dev write some code to quickly and efficiently generate a Rorschach inkblot.

Using your language of choice, generate a Rorschach inkblot. You may use any method of generating a random seed.

The generated image must be in black and white and reflect down the middle of the image. This is a code golf so the shortest submission will win.

OR

2.

Help a poor struggling game dev write some code to quickly and efficiently generate a Rorschach inkblot.

Given 2 input images (a source image and an image of a template inkblot), convert the first into the Rorschach inkblot of the second without changing the colours of the image.

You may assume that the images are the same size, however you may not display the original image unaltered. Anywhere in the template where the RGB values of the pixel are (255,255,255), you may not display the original image. The produced image must be vertically mirrored, so you will have 2 copies of the source image distorted and reflected in the result.

Then I'd provide source images some of which would probably be shamelessly stolen from either the Voroni Map or the Mona Lisa Colour Palette questions because those questions are awesome.

My thoughts:

I'm essentially hoping to get the source image in a twisted demented fragmented form, similar to if you gave a small child red cordial then the source image and a blur tool and said go nuts. I feel like my second challenge has potential, but I feel like I need to improve the challenge description and detail exactly what I want to be produced, but I'm not sure how to do that without a wall of text and without unnecessarily restricting the challenge.

| |
\$\endgroup\$
  • \$\begingroup\$ Your suggestions aren't code-golf. Code-golf means that the shortest code in byte/char wins. First of all, you should determine what will be the winning criterion. It will be hard to determine some if you want to keep it as a code-golf AND a pop-con. The first one is more designed to be a pop-con, as submissions can be creative. The second one is too restrictive to be a pop-con : for the same images, ouput will always be the same. It would go as a code-golf. Be aware that image-processing is language retrictive by essence, and that could be badly welcomed as a code-golf :) \$\endgroup\$ – Katenkyo Jun 23 '15 at 14:31
  • \$\begingroup\$ Not necessarily a duplicate, but something to look over to make sure yours differs sufficiently Make a Rorschach image \$\endgroup\$ – trichoplax Jun 23 '15 at 16:48
0
\$\begingroup\$

[Insert] Nerd Sniping Pattern (Series)

Having learned from Prime Nerd Sniping Pattern that hoping an optimal solution will not be spotted too quickly is not a good idea, I'd like to judge how much interest there is in a series of similar contests that have been demonstrated to not have an achievable optimal solution, allowing long term open ended competition.

Each one would need work to demonstrate this lack of an achievable optimal solution, and I'll put that work in if there is suffficient interest here.

For example, there could be a Fibonacci Nerd Sniping Pattern, Factorial Nerd Sniping Pattern, and so on. Each one would need to have a different method of defining the scoring pattern, so that different optimisation techniques and algorithms would be required for each one. This is what would ensure they are distinguished from each other as separate challenges in a series, rather than near duplicates.

What I've learned from my mistake with the primes

The prime scoring pattern had a checkerboard optimal solution because all of the scoring pixels were on opposite coloured checkerboard squares to the pixel being scored. I need to avoid this in any future scoring patterns, and more generally avoid any pattern that divides the image into two regions for scoring (where all of one region are scored by combinations of pixels from the other). Intuitively, there should be plenty of mixing.

As I think about it more, I'll add ideas here on things to rule out and things to ensure I have before considering a pattern scoring rule ready for posting.

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

Build a Mahjong AI

Mahjong is a traditional Chinese gambling game played throughout Asia in which four players draw and discard tiles in order to try to complete a hand of 14 tiles.

In this problem, a specification for a simplified version of Mahjong called "PPCG Mahjong" was given. Your task in this problem is to build a program that will play a version defined here called "Full PPCG Mahjong" (hereafter known as the FPM rules).

Your program will be an online program, taking input as it plays the game. (that does not necessarily mean it needs networking capabilities, but it means that it will output in reaction to ongoing input, not just all input at once.)

Tiles

There are 34 types of tiles in FPM.

  1. The “bǐng”/“pin” (餅) tiles, also known as the circle tiles / dot tiles. These will be represented in text with a number from 1 to 9 and then the letter b, as in 1b, 2b, up to 9b.

  2. The “suǒ”/“sou” (索) tiles, also known as the bamboo tiles. These will be represented in text with a number from 1 to 9 and then the letter s, as in 1s, 2s, up to 9s.

  3. The “wàn”/“man” (萬) tiles, also known as the character tiles. These will be represented in text with a number from 1 to 9 and then the letter w, as in 1w, 2w, up to 9w.

The three tile types totalling 27 tiles above are called the number tiles.

  1. The “fēng”/”fuu” (風) tiles, also known as the wind tiles. There is one wind tile for each cardinal direction. These will be represented in text with the letter of the wind's cardinal direction in capitals, repeated twice, as in: EE, SS, WW, or NN.

  2. The “yuán”/“gen” (元) tiles, also known as the dragon tiles. There is one red, one green, and one white dragon, represented as ZZ (for zhōng 中/center), FF (for 發/fortune), and BB (for bái 白/white) respectively.

The two tile types above are called the honour tiles. There are four of each type of tile, for a total of 136 tiles.

Objective

The goal of Mahjong is to form a complete hand, which consists of four sets and a pair.

A set is one of:

  • A sequence of number tiles. (e.g. 5w 6w 7w or 3s 4s 5s)

  • A triplet of any tile (number or honour tile). (e.g. 3b 3b 3b or EE EE EE)

  • A quadruplet of any tile. (e.g. 3b 3b 3b 3b or EE EE EE EE)

A complete hand will have 14 tiles if there are no quadruplets present; each quadruplet adds one tile to the hand's size, up to a possible 18.

Gameplay

Mahjong is a game played in several hands (局, ).

At the beginning of each hand, each player receives a text input of START [Wind] [Round number]. Each player is then given an input of 13 tiles, represented as a set of 13 space-separated strings (e.g. 1b 9s BB 3w 6w 4b ZZ 3w 5w 2s 6b NN NN) and assigned a different seat wind depending on where they "sit" at the virtual table (given as a single letter out of NESW).

Starting with the player at position East and moving clockwise around the compass, each player takes a turn in which:

  • The player whose turn it is will be given a tile (自摸牌, zìmōpái) from the "wall" (the collection of tiles that have not been drawn or dealt yet) as a two-character input.

  • The player can take actions during the standby phase:

    • If the player has four of the same tile in his hand, it can call kong (槓, gàng) and draw an extra tile. Those tiles must stay as a quadruplet from then on and cannot be used for anything else. The program does this by outputting kong [quadruplet tile] as text.

    • If the player previously called pung on a triplet and has a fourth of the tile, it can call kong as well.

    • If the player's hand is complete with this drawn tile, it may declare hu in which case the hand ends.

  • The player will then produce an output of whatever tile it decides to discard. The tile that was discarded will be propagated as output to the other players in the form [seat] [discarded tile] (e.g. E 8w). The players can then call that tile if it will complete a set:

    • The player immediately after the discarding player may call chi (吃, chī) by outputting chi as text during the call phase, to complete a sequence.

    • Any other player can call pung (碰, pèng) to complete a triplet, similarly by outputting pung as text. Pung overrides chi when it happens.

    • Any player can also call kong (槓, gàng) to complete a quadruplet, also by outputting text, in which case they are given an extra tile as text input.

    • Any player can also call hu (胡, ) to complete their hand regardless of whether they are completing a sequence, triplet, or pair. Hu overrides both pung/kong and chi.

    • If a player does not want to call tiles, it must output pass.

The turn immediately goes to the player who called the tile, and they skip their draw phase, discarding another tile immediately. If nobody called a tile, the next player draws one. At any point if a player calls, the other three players will receive an input indicating that the player in that seat made a call and what was called.

  • For chi, the input will be in the form of [seat] chi [other two tiles] (e.g. S chi 6w 7w).

  • For pung and kong, the input will be in the form of [seat] pung/kong. This is because all the tiles are identical to the called tile anyway.

  • For hu, the input will be in the form of [seat] hu [all other tiles in hand].

In the above three cases, the tile being called is always the previously discarded tile.

  • For a kong during the standby phase, the input will be in the form of [seat] kong [kong tile], because the kong tile is not implied to be the previously discarded tile.

  • For a hu during the standby phase, the input will be in the form of [seat] hu [tile drawn]

Once a tile is called, the set that it makes is locked in place and cannot change for the rest of the hand. So if two tiles would make use of a tile in a called set, they may not use that tile.

A hand ends when either somebody calls hu validly or there are no more tiles to draw. (There is no dead wall in this game.) At that point, all players will receive an input of END to signal that the round has ended, and a summary of their points.

If somebody other than the dealer won, then the deal rotates. If the dealer or nobody won, then the deal stays the same. After four deal rotations, the prevailing wind also rotates.

A game of FPM consists of 16 such deal-rotations (rounds), such that each player gets to play one round with each combination of seat wind and table wind. Each player starts with a bank of 500 points. At the end of 16 rounds, the player with the most points is the winner of the game.

Example gameplay interaction

> START HAND EAST 1
> 1b 4b 6b 2s 9s 3w 3w 5w 6w NN NN ZZ BB
> E       // The player is East (dealer)
> NN      // East drew the north-wind first.
BB        // East decides to discard the white-dragon.
> S 3w    // Nobody called it, and South discards a 3-character.
pung      // East wants to pung the 3w tile.
ZZ        // East discards the red-dragon
> S pung  // South pungs the red-dragon.
> S 6w    // South discards a 6-character instead.
pass      // East has no use for this tile, so it passes.
> W kong 2s    // West declares a standby kong on 2-bamboo.
> W 3b    // West discards a 3-circle.
pass      // East passes again.
> N chi 2b 4b  // North chi-s it with a 2b and 4b.
> N 7s    // North discards a 7-bamboo.
pass
> 2w      // East's hand: 1b 4b 6b 2s 9s 2w 5w 6w NN NN NN -- 3w 3w 3w
2w        // East doesn't need the 2w, so he discards it.
> S hu 2b 3b 4b 7s 8s 9s 2w 6w 7w 8w ZZ ZZ ZZ 
          // South wins on that tile. The 2w completed his pair.
> END
> 496 506 499 499  // Their current point counts. South's hand was worth
                   // 2 points, so East pays 4 while the others pay 1.
> START EAST 2
> [13 more tiles]
> N       // The deal rotated, and this player is now North.

Brackets

Your program can participate in one of three levels of gameplay:

  • Level 1, where every hand is worth exactly 8 points, and the only thing that matters is completing hands.

  • Level 2, where every hand is worth the number of points in the points table section below, but any hand can still win.

  • Level 3, where every hand is worth the number of points in the points table, but a hand must have at least 8 points total with that system to win.

Points

(TBD)

Penalties

The following are invalid moves:

  • Failing to produce an output when required.

  • Discarding a tile that is not in your hand, or when it is not your turn.

  • Calling chi on any player other than the one immediately before you, or calling any tile that does not actually complete a set in your hand.

  • Calling hu when your hand is not complete, or when your hand value does not meet the minimum point requirement in level 3 gameplay.

If your program makes an invalid move, the move will be rejected, your program will pay 20 points to each of the three other players, and for the rest of that round, it will be a "forced tsumogiri" player, which automatically discards every tile it draws and never calls anything.

Special Rules

There are no special rules such as dora or furiten in FPM. Any person may complete a hand at any time as long as it is a valid complete hand.

| |
\$\endgroup\$
  • \$\begingroup\$ Sounds fun :) I hope there'll be enough entries to actually play a game though \$\endgroup\$ – Sp3000 Jun 24 '15 at 4:34
0
\$\begingroup\$

Team Gun Battle


This is an individual competition, where the goal is to be the last player surviving. Fighting always takes place between two teams. At the beginning, every player is randomly assigned to one of two teams and placed randomly on the board.*

Each turn, a player can move north, south, east or west or stay. In addition to moving, they can also shoot a bullet north, south, east, or west. Note that players won't know about other players' movements when they move, but the shoot() method is called after all moving has taken place. The player can choose to shoot a light bullet, which travels 4 squares per frame and does 1 damage, or a heavy bullet, which travels 2 squares per frame and does 3 damage. The bullets do move on the same step they were shot in, so if a target is less than 4 units away, you can shoot a light bullet without any chance of the target dodging.

Every player has a starting health of 30 and 30 bullets to shoot.

After 1000** or so steps, the round will end. Whichever team has more players alive will be considered the winners. Ties will be broken by whichever team has the highest total health.*** Every player not on the winning team will die, and the winning team will be split up into two new teams. This means that half of those who were originally on your side are now your enemies. Another 1000 steps are executed and another winning team is chosen. This process repeats until there is only one player left.

This has some interesting strategic consequences. For example, if your team is winning, it is in your interest to start shooting players on your own team because they may not expect it and you will have to fight them eventually. Similarly, you don't want to waste all of your bullets on the first few rounds because your bullets and your health is not replenished after each round. I like trichoplax's suggestion where ammunition and health could be slightly restored after each round. You want to get your teammates to do as much work as possible before killing them.

The controller almost ready. This is the spec:

public class Player1 extends Player {
  public Direction move(World w, int stepsLeft) {
    // stepsLeft = # of steps left in round
    // List of players: w.getPlayers()
    // List of bullets: w.getBullets()
    Player p1 = w.getPlayers().get(0);
    // Check health: p1.getHealth()
    // Check # of bullets left: p1.getBullets()
    // Check team: p1.isOnSameTeam(this)
    // Check position: p1.getPosition()
    return Direction.NORTH; // always move north
  }
  public Bullet shoot(World w, int stepsLeft) {
    // similar to above
    return new Bullet(Direction.NORTH, true); // heavy bullet shot north
  }
}

*I think the board should be a square with side length 3*(# of players). Hopefully this would make to not too sparsely populated.

**Exact number to be determined. It may be based on the number of players (higher # of players = more steps until the end of the round). 1000 seems like a good number.

*** I'm working on a system that's somewhat more fair. Currently, if there was originally an odd number of players, they were split with one random team getting an extra player. Obviously, that team has a significant advantage under this system. Perhaps it could be percentage of surviving players?

| |
\$\endgroup\$
  • \$\begingroup\$ It sounds like it would be easy to forever avoid opponents by just staying off their orthogonal lines. What happens if it never gets down to one player for that reason (or everyone runs out of bullets)? \$\endgroup\$ – Geobits Jun 25 '15 at 16:37
  • \$\begingroup\$ @Geobits If everyone runs out of bullets, then I have two options I'm considering: a) Nothing happens, and when the 1000 frames ends at the end of the round, one team is randomly chosen to proceed (that is the default when teams tie exactly; if one team has higher total health than the other, then that team wins) b) everyone's bullets are replenished. Which is better? \$\endgroup\$ – soktinpk Jun 25 '15 at 17:06
  • \$\begingroup\$ Would it help to give everyone some extra ammunition at the start of each round, but also let them carry over whatever ammunition they saved from the last round? \$\endgroup\$ – trichoplax Jun 25 '15 at 17:21
  • 1
    \$\begingroup\$ If you were feeling mean you could make the arena wrap and have bullets not stop until they hit someone. So dodged bullets will keep looping across the arena, slowly filling it up until there's no way for everyone to avoid them. \$\endgroup\$ – trichoplax Jun 25 '15 at 17:22
  • \$\begingroup\$ @trichoplax I like your first idea. The second seems like a little harsh since you have a lot less control of who your bullets hit. \$\endgroup\$ – soktinpk Jun 25 '15 at 17:30
  • \$\begingroup\$ I did think it might be a little too mean :) \$\endgroup\$ – trichoplax Jun 25 '15 at 17:31
  • \$\begingroup\$ If everyone runs out of bullets, then there is obviously a knife fight. \$\endgroup\$ – feersum Jun 25 '15 at 21:40
0
\$\begingroup\$

A few minutes ago, I posted this question as a popularity-contest which was quickly put on hold as too broad. Specifically, the "there are no restrictions on what the programs/functions do" was apparently not quite right. A commenter also suggested that an empty program would be a possible answer which I knew, but didn't necessarily want to restrict as I think the popularity contest would have taken care of that. I'd be interested in any suggestions people have to make the question more appropriate for PPCG.

Also, I plan on asking with the tags popularity-contest and restricted-source. Does that seem right?

Here is the question:

Inspired by the bonus in this question

Write some code that can be run in multiple directions. In each direction, the code must be a complete program or a function. The code must be written in one language (so for example, you cannot have a python program that is also a whitespace program when run backwards).

Explanation of "multiple directions"

If your code is

abcd efgh
 ijklm
nop

Then backwards is

hgfe dcba
mlkji 
pon

And sideways is

a n
bio
cjp
dk
 l
em
f
g
h

Trivial example

Brainfuck

 .
.+++++++++
 +++++++++
 +++++++++
 +++++++++
 +++++++++
 +++++++++
 +++++++++
 +++++++++
 +++++++++.
         .

Notes

  • there are no restrictions on what the functions/programs do
  • your code must be able to run in at least two directions, but more is better
  • abuse of comments is frowned upon but allowed
| |
\$\endgroup\$
  • \$\begingroup\$ Welcome to the sandbox! You deleted your post before I could add another comment, so here's what I wanted to say: What makes an answer "good" in this question? If we go by the criteria "your code must be able to run in at least two directions, but more is better", which the empty program satisfies, that seems a little contradictory. Thus I think it's good to place some sort of restriction on the programs. I think source-layout is better than restricted-source - take a look at the questions there and see what you think :) \$\endgroup\$ – Sp3000 Jun 27 '15 at 6:17
  • 2
    \$\begingroup\$ Also, as is even if the question wasn't closed as too broad, it'd probably be closed as a duplicate of this question, which you might want to also take a look at. \$\endgroup\$ – Sp3000 Jun 27 '15 at 6:18
  • \$\begingroup\$ Thanks, I'll look through those questions. And I think you're right. That other question is pretty similar. I might just let it go. \$\endgroup\$ – sudo rm -rf slash Jun 27 '15 at 13:40
0
\$\begingroup\$

Allongiator


There are a lot of acronyms on the internet -- ROTFL, RTFM, NSA, laser, taser, and so on. Your job is to write code that, given an acronym, can figure out what that acronym might stand for. You'll be given an alphabetically-sorted list of words that you can use, to be provided in the format of your choice.

Note that if you're given an actual acronym, you don't have to provide what it really stands for. As an example, given ROTFL, you could output "rolling on the floor laughing", or you could output "rearrange orange thrice free language".

Input

  1. A dictionary of all of the words you're allowed to use. This is guaranteed to have at least one word for each letter; your program is allowed to do anything it wants if it encounters a letter that it can't find a word for.
    • Not necessarily in alphabetical order
    • All in lowercase
  2. A string of lowercase letters, with no whitespace, punctuation, or non-letter characters.

They can be given in any format you want. For example, the acronym could be the first command line argument and the dictionary the rest of them, or they could be arguments to a function, or given via standard input, or whatever.

The dictionary contents can be found [here].

Output

  1. A string containing a space-delimited list of words that form the acronym given as input, from the dictionary given.
    • No trailing whitespace except for a single optional newline
    • The words must be chosen (pseudo-)randomly from the dictionary -- that is, if I run it twice with identical inputs, I should get different outputs1.
    • It doesn't have to make sense or be plausible or grammatically correct. Any words that start with the right letters will do; however, bonus points2 to anyone who manages that.

Since this is , the shortest answer wins.

All the standard prohibitions apply here, though with the note that accessing the dictionary from the web is acceptable, so long as it's the unmodified dictionary and nothing else.

1: Barring practically impossible situations.
2: That is, a browser cookie


Sandbox (foot)notes:

This may very well be a duplicate. I looked around as much as I could, but I don't even know what this is called, so I didn't find much. Apologies if it is.

Would they be acronyms or initialisms? I'm not sure.

I'll add the actual dictionary once I've found a nice one that isn't massive.

| |
\$\endgroup\$
  • \$\begingroup\$ A quick search for acronyms turned up this \$\endgroup\$ – Sp3000 Jun 27 '15 at 6:31
  • \$\begingroup\$ @Sp3000 ...I even upvoted that question and I forgot about it. Should I delete this post? \$\endgroup\$ – Fund Monica's Lawsuit Jun 27 '15 at 6:32
  • \$\begingroup\$ I'm not sure tbh... might be good to get a second opinion, since I'm not sure whether that one being a popcon changes anything \$\endgroup\$ – Sp3000 Jun 27 '15 at 6:33
  • \$\begingroup\$ @Sp3000 Alrighty. I'll leave this up. (Thanks for replying so quickly, by the way) \$\endgroup\$ – Fund Monica's Lawsuit Jun 27 '15 at 6:51
  • \$\begingroup\$ Eww, CR..... =) \$\endgroup\$ – Faraz Masroor Jun 28 '15 at 3:42
  • \$\begingroup\$ @FarazMasroor Nooo my secret is revealed (I recognize you from that meta question! Hi!) \$\endgroup\$ – Fund Monica's Lawsuit Jun 28 '15 at 3:42
0
\$\begingroup\$

Gimme your best shot

Introduction

You're fed up. You've tried to sell your car but failed, not knowing whether your price is too high, too low or people are just too picky. Then a programmer decides to take a look at your car and makes you an offer using a program that he had written for judging a car's worth.

Challenge

Given a car's make, model and mileage, you have to find how much a car is worth using the method below. The shortest program to do so wins.

If the make or model of the car is incorrect, you must output "Error: [input make/model] is invalid".

Method

First of all, you should scrape all of the prices and mileages of all of the listings on AutoTrader.com of the specified car. Next, plot these on a graph (this graph is not needed to be shown) of mileage against prices.

On the graph you should draw a line of best fit. Now you can read the price on the line of best fit for the specified mileage of the car. Now output this with a dollar sign before the price.

Example

None of these prices are correct output

Ford Fiesta, 200 miles

Input: ford, fiesta, 200
Output: $15000

Subaru Outback, 0 miles

Input: subaru, outback, 0
Output: $27000

Example script

Here's my example test script in Python 2.7 (uses autotrader.co.uk though, not .com):

from BeautifulSoup import BeautifulSoup
import urllib2, sys, re, pylab

model, make, mileage, postcode = sys.argv[1:]
mileage = int(mileage)

page = urllib2.urlopen("http://www.autotrader.co.uk/search/used/cars/%s/%s/postcode/%s/"%(model.replace(" ","%20"), make.replace(" ","%20"), postcode)).read()
soup = BeautifulSoup(page)

results = soup.findAll("div", {"class":"search-result__content"})

cars = []

for j in results:
    pricetag = j.findAll(text=re.compile(r"£.*"))
    price = int(pricetag[0].replace(',','').replace('£',''))

    mileages = j.findAll(text=re.compile(r".+ miles"))
    mileagecar = int(mileages[1].replace(" miles","").replace(",",""))

    cars.append([mileagecar, price])

x = [k[0] for k in cars]
y = [i[1] for i in cars]

poly = pylab.polyfit(x, y, 2)

print("£"+str(int(pylab.poly1d(poly)(mileage)+0.5)))
| |
\$\endgroup\$
  • \$\begingroup\$ I believe scraping autotrader.com violates their visitor agreement. Section 5 seems to imply that it's illegal as well (though that may well depend on the jurisdiction). \$\endgroup\$ – Geobits Jul 1 '15 at 20:00
  • \$\begingroup\$ @Geobits Damn it haha... I'll look for some kind of API for another online car sales site... \$\endgroup\$ – Beta Decay Jul 1 '15 at 20:01
  • \$\begingroup\$ I'm also not sure where the pounds/dollars difference comes in. Both of those cars are available in the US, for example, but output is in pounds. I don't see anything in the input to say which to use. \$\endgroup\$ – Geobits Jul 1 '15 at 20:05
  • \$\begingroup\$ @Geobits It was based on whether the program used AutoTrader**.com** or .co.uk \$\endgroup\$ – Beta Decay Jul 1 '15 at 20:07
  • \$\begingroup\$ Well... I mean I got that. But it's a code golf; why would you use the longer one? I assumed there had to be some reason you made the choice, not just because you felt patriotic ;) \$\endgroup\$ – Geobits Jul 1 '15 at 20:09
  • \$\begingroup\$ For instance, what if I decide to use the US site, and there are no matches for a particular make/model (even if there may be on the UK site)? Is my output "wrong"? \$\endgroup\$ – Geobits Jul 1 '15 at 20:10
  • \$\begingroup\$ @Geobits I see... Well I'll limit it to an American site when/if I find one \$\endgroup\$ – Beta Decay Jul 1 '15 at 20:14
  • \$\begingroup\$ Doesn't really matter where the site is from, really, as long as it's one site. Or there's something in the input to determine that. If the input was, say ford fiesta 200 dollars (or us/uk, gbp/usd, etc) then that part wouldn't be an issue. \$\endgroup\$ – Geobits Jul 1 '15 at 20:15
0
\$\begingroup\$

Meta-Manufactoria

Manufactoria is a pretty great programming game. However, instead of writing machines to solve the problems, your goal is to write a program that creates the machines for you. If you are already familiar with Manufactoria, then for the next section, you only need to read the italicized phrases.

The Rules of Manufactoria

In this version of Manufactoria, you are placed in a 9x9 world. The input generator is in the center top square (4, 0), and the output acceptor is in the center bottom square (4, 8). When input is generated, it moves immediately down.

Input is represented by a robot that has a queue of colors. Output will be the same robot, but the queue may contain a different sequence of colors. Robots must always eventually end up in the output square. There are 2 colors available, Red and Blue.

Each tick, the robot moves 1 square. The direction the robot moves, and any modifications to the queue is determined by the square it is on. There are 3 types of squares:

  1. Movement square. This square either moves the robot North, East, South, or West and does not affect the queue. You cannot have two movement squares on the same tile

  2. Choice square. This square moves the robot based on the top color in the queue. The general Choice square moves the robot east if red, west if blue, south if empty, and never north. This square can be rotated or reflected to change the directions traveled.

  3. Writer square. This square writes a color to the back of the queue, and moves the robot in a given direction.

STDIO and Scoring

Your program will be passed two lists of the same length, one containing the inputs, and the other containing the outputs. Each item of each list contains only the R and B characters, representing the input queue.

Your output is the board that solves the Manufactoria puzzle. Each square is represented by two characters. The first character represents the square type, the second represents the direction. The square types can be:

  • Movement
  • Choice
  • Red writer
  • Blue writer.
  • .. Empty square
  • II Input
  • OO Output

The directions are: - North - East - South - West.

The direction listed for a choice tile represents the direction traveled if the queue is empty. If the direction is lowercase, the tile is reflected (which swaps the colors).

The program which solves more puzzles than any other program wins. In the event of a tie, the tiebreaker is the program that produces the most efficient solutions. Efficiency is measured by the number of times the robot moves across all of the solutions.

Your program should be a general solver. I may add puzzles to the ones listed below at any time.

Sample Puzzles

The solutions given below don't necessarily have to do what the title indicates. Your program's solution also doesn't have to match the ones listed below. It only needs to solve the inputs given. The format below is

[Inputs] [Outputs]
Solution Map

Example 1: Don't do anything

["","R","B","RRBR","BRRBRB"] ["","R","B","RRBR","BRRBRB"]

........II........
........MS........
........MS........
........MS........
........MS........
........MS........
........MS........
........MS........
........OO........

Manufactoria 1

Example 2: Print second R and anything after:

["","R","B","RR","BRB","RBRBBB"] ["","","","R","","RBBB"]

........II........
..MSCSMWCSMW......
..RSMEMEMS........
BECsMEMEMS........
........MS........
........MS........
........MS........
........MS........
........OO........

Manufactoria 2

Example 3: Reverse String (This doesn't reverse any string, it only works for the examples listed)

["","BBR","B","RRB","BRRRB","BBRB"] ["","RBB","B","BRR","BRRRB","BRBB"]

........IICsMERS..
......CECSCEMSBS..
......RSMSCEMSMW..
......REMSCEMS....
........MSRSMS....
........MSRSMS....
........MSRSMS....
........MSBWMW....
........OO........

Manufactoria 3

Example 4: Only include Rs

["R","","BBR","BRR","B","RBRBRBBR","BBBBBBRRR","RBBBRBRBBB","RRRR"] ["R","","R","RR","","RRRR","RRR","RRR","RRRR"]

........II........
........MEMEMEMS..
MSCSMWCSMWCSMWCSMW
REREMERERSMW..MS..
........MSMWMWMW..
........MS........
........MS........
........MS........
........OO........

Manufactoria 4

| |
\$\endgroup\$
  • \$\begingroup\$ Sounds extremely difficult. \$\endgroup\$ – feersum Jul 7 '15 at 3:07
  • \$\begingroup\$ I enjoyed playing that game...Hard indeed. :-) \$\endgroup\$ – Spikatrix Jul 7 '15 at 12:39
0
\$\begingroup\$

(Need a title.)

Write two programs (or functions) in the same language for these two tasks:

  1. Given a list of integers, split at every non-negative integer. If there are two or more consecutive non-negative integers, your program should preserve the empty list between them.
  2. Given a list of lists of negative integers, concatenate the lists and insert non-negative integers between them. The inserted integer after the nth list (zero-based) should be n.

Alternatively, you can increment every integer by one for both tasks. So you split at positive integers, accept non-positive integers in task 2 and the inserted integers start at 1.

The input for task 1 and the output for task 2 should have the same format, with the exception that one can be the string representation of the other in your programming language. The same goes for the output for task 1 and the input for task 2.

Your score is the total length of your two programs times (30 + their Levenshtein distance). Lowest score wins.

Example for task 1

Input:  [-5 7 8 -5 2 -6 -3 -3 8]
Output: [[-5] [] [-5] [-6 -3 -3] []]

Example for task 2

Input:  [[-5] [] [-5] [-6 -3 -3] []]
Output: [-5 0 1 -5 2 -6 -3 -3 3]
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ if(1>2){code1}else{code2}. There's no need to ever have the edit distance any greater than 1 or 2. \$\endgroup\$ – John Dvorak Jul 12 '15 at 6:03
  • \$\begingroup\$ better yet: if(input[0] instanceof Array<int>){code1}else{code2}. Haskell might be able to pull this off even more cleanly because the typeclasses are resolved at compile time, meaning that even empty arrays have the proper type. \$\endgroup\$ – John Dvorak Jul 12 '15 at 6:06
  • \$\begingroup\$ The first task description is extremely unclear. What does it mean to split? How can one preserve something that didn't exist in the first place? \$\endgroup\$ – Peter Taylor Jul 12 '15 at 16:55
  • \$\begingroup\$ @JanDvorak If the answer is less than 30 bytes, it is beneficial to remove a byte while increase the edit distance by one. But maybe I should change it to the length plus the edit distance. \$\endgroup\$ – jimmy23013 Jul 12 '15 at 19:48
  • \$\begingroup\$ @PeterTaylor It just works like the CJam and GolfScript /. I'll try to reword it later if I get the scoring method working. \$\endgroup\$ – jimmy23013 Jul 12 '15 at 19:50
0
\$\begingroup\$

Return of the 5318008

Introduction

A week or so ago, I posted the challenge 5318008, with a massive reaction. Now, I want you to do the same again but with musical chords.

Challenge

Given a word list, you must output a list of words which can be formed using musical chords. However, the word must also sound good too.

The chords which you may use are:

A B C D E F G

These are all the major chords without the flat/sharp chords.

A word will sound good if all of its letters are within the same key. All the chord progressions which you must concern are listed below:

  • A major: A D E G
  • B minor: D G A
  • D major: D G A
  • E major: E A B D

Other progressions such as G or C major could not make any word because all of the major chords (which were not sharps or flats) were consonants.

For my tests, I used the UNIX wordlist, gathered by typing:

ln -s /usr/dict/words w.txt

Or alternatively, get it here.

There are some uppercase letters in the dictionary, so make all of the letters in all of the words in the dictionary lowercase.

Winning

The shortest code to output a list of words wins.

| |
\$\endgroup\$
  • \$\begingroup\$ What about A minor? \$\endgroup\$ – Nathan Merrill Jul 13 '15 at 17:03
  • \$\begingroup\$ @NathanMerrill No vowels in Am, just C F and G \$\endgroup\$ – Beta Decay Jul 13 '15 at 17:05
  • \$\begingroup\$ I don't understand then. A minor includes "a" and "e" \$\endgroup\$ – Nathan Merrill Jul 13 '15 at 17:09
  • \$\begingroup\$ What about case sensitivity? Also I'm expecting this to end up as a regex challenge, if I've understood the problem correctly \$\endgroup\$ – Sp3000 Jul 13 '15 at 17:10
  • \$\begingroup\$ @Sp3000 Edited to say that all words should be converted to lowercase \$\endgroup\$ – Beta Decay Jul 13 '15 at 17:13
  • \$\begingroup\$ @Nathan Sorry, I was talking about chords instead of notes :/ \$\endgroup\$ – Beta Decay Jul 13 '15 at 17:14
  • \$\begingroup\$ So I'm to assume that A would only be included if A major is a subset of the key? \$\endgroup\$ – Nathan Merrill Jul 13 '15 at 17:18
  • \$\begingroup\$ @Nathan Uhh yes \$\endgroup\$ – Beta Decay Jul 13 '15 at 17:22
  • 1
    \$\begingroup\$ Ok. Also, B minor and D major include the same notes, so the notes listed should be the same. D major shouldn't have the C, as it has a C#. \$\endgroup\$ – Nathan Merrill Jul 13 '15 at 17:24
  • \$\begingroup\$ I don't know much about music theory, but from what little I do know I find this question very confusing. A B C D E F G doesn't look like a list of chords, but like the scale of C major. If by the "key of C major" you mean the tonic chord of the scale of C major, that would be C E G, which is not all consonants. I also promise to downvote any question which allows people from one specified nation to answer a different question to people from the rest of the world. \$\endgroup\$ – Peter Taylor Jul 13 '15 at 19:25
  • \$\begingroup\$ @PeterTaylor Refer to this: The chord chart...lists all the common traids and four note extended chords belonging to the key of C major. \$\endgroup\$ – Beta Decay Jul 13 '15 at 19:35
  • \$\begingroup\$ Yes, but that doesn't clear anything up. Unless... are you sure you're not confusing chords with chord progressions? \$\endgroup\$ – Peter Taylor Jul 13 '15 at 20:55
  • \$\begingroup\$ @PeterTaylor Yes, that's exactly what I meant. I didn't know the word for it \$\endgroup\$ – Beta Decay Jul 13 '15 at 20:58
  • \$\begingroup\$ You are definitely confusing notes and chords here. B minor and D major both contain the notes B C# D E F# G A, The possible chords are Bm Em F#m Dmaj Gmaj Amaj and C#dim, with F#m and Em often subsituted for Fmaj and Emaj. One valid interepretation is that both keys contain all these chords, another is that the minor is just B E (F#) and the major is just D G A. Under no circumstance can Bm be considered D G A. You are also misusing the word progression. This refers to the sequence of chords in a particular song and has nothing to do with the chords available in a particular key. \$\endgroup\$ – Level River St Aug 8 '15 at 12:32
  • \$\begingroup\$ A major contains A B C# D E F# G# so the only natural notes are ABDE,which is what you have written for E major. E major contains one additional sharp E F# G# A B C# D# so the only natural notes are E A B. \$\endgroup\$ – Level River St Aug 8 '15 at 12:35
0
\$\begingroup\$

Break out of the digital world!

Note: The tag is just something I knocked up quickly, if anyone has any better ideas please let me know.

Challenge

You must write a morse code to ASCII translator using an external device (such as a button or the spacebar on the keyboard).

Dots

A button press is a dot when it has been pressed for 0.5 seconds or longer and released.

Dashes

A button press is a dash when it has been pressed for 1 second or longer and released.

Exit

A button press is an exit when it has been pressed for 5 seconds or more. This should end the program and display the result.

Space

A space is when there has been no button input for 1 second. This should move on to the next letter.

Your code should support every character on the following:

http://zunkworks.com/images/bluetoothmorse/morsecode1.gif

Winning

The shortest code wins. You may write this in any language that allows input from an external source. For example, Arduino or Python (on a Raspberry Pi).

| |
\$\endgroup\$
  • 4
    \$\begingroup\$ Does this actually have to be able take input from hardware? Can you allow feeding in simulating data? I think a standard format like a sequence of numbers measuring current/voltage every millisecond would make it more accessible. \$\endgroup\$ – xnor Nov 18 '14 at 1:35
  • \$\begingroup\$ While I do own an arduino, I see absolutely no reason why this challenge should be limited to using an external switch. Is there anything wrong with using the space bar or a mouse button? If it HAS to be an external switch, how about I rip open my mouse and connect an old doorbell push across one of the mouse button contacts? \$\endgroup\$ – Level River St Nov 27 '14 at 20:45
0
\$\begingroup\$

VSEPR Strikes Back!

(Note: I know that the VSEPR method fails sometimes, and that there are exceptional molecules. This is addressed in the scoring system, and otherwise the challenge is about the molecules which conform.)

Most people who have taken an introductory chemistry course know about molecules, and (probably) the VSEPR theory of chemical bonding. Basically, the theory predicts the shape of a molecule given three main properties: the central atom A, the number of atoms bonded to the central atom X, and the number of lone electron pairs E on the central atom. Applying the VSEPR theory is simply a matter of finding the values of X and E (A always has an implied value of 1, as we'll see). This is called the AXE method. For example, a molecule which has 1 lone pair and 3 atoms bonded to the main atom is AX3E1, which is the trigonal pyramidal configuration.

The Challenge

Your job is, given a covalent chemical compound, to output the geometrical shape of the molecule inputted. But wait! exclaim the exasperated programmers, you can't expect us to input all of the molecular data for every element! Of course we can, but I'm not feeling particularly masochistic today, so born was the scoring system below.

The input is any molecule, such as CO2 or HgCl2, and the output should be the name of the shape and NOT the AXE form. Ions should have their charge put in parenthesis directly after the ion, such as CO3(2-) or NH4(1+). 1- and - (and 1+ and +) are all acceptable.

About the central atom A

In most cases, the central atom will be apparent. It usually has no subscript in the chemical formula: the C in CO2 is the central atom, for example. In a few cases, though, you might face compounds like ethelyne (C2O4), in which no clear atom is the central one. In this case, it is worth noting that such compounds are usually symmetrical, and considering any carbon to be the central atom will do.

Scoring System

The base score is the number of bytes the program takes.

  1. There is a minimum of 6 elements to be implemented for input; every 5 extra you add multiplies your score by 0.9.
  2. Multiply your score by 0.8 if you can make your code work for ions.
  3. Multiply your score by 0.9 if you can detect ionic compounds (VSEPR only works for covalent compounds) and reject them accordingly.
  4. Multiply your score by 0.8 if you also output the bond angles.
  5. There are certain classes of molecules which VSEPR fails to predict correctly, due to various reasons. (Check the first link in the post for the section on the exceptions.) Multiply your code by 0.9 per class if it returns those correctly.

Test Cases

The parts in brackets are optional bonuses from above.

CO2: CO2 -> linear [180*]
HgCl2: HgCl2 -> linear [180*]
H2O: H2O -> bent [104.5*]
[CO32-: CO3(2-) -> trigonal planar 120*]
BrF: BrF3 -> T-shaped [90*]
[NaCl: NaCl -> Ionic compound]
XeF4: XeF4 -> square planar [90*]

Notes:
- The bonding patterns are not valid when the central atom is a transition metal (so don't do that.).
- Standard loopholes apply.

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

One transparent colour sprite


Overview

This challenge will only involve a hex string as input and a hex string as output, but will be explained in terms of computer graphics.

Given a fixed size background image, a smaller fixed size sprite image and its location, place the sprite on the background image allowing the background to show through for one specified colour of the sprite image.


Details

  • The background image will always be 32 by 18 pixels.
  • The sprite image will always be 8 by 8 pixels.
  • The colours will always be in the range 0 to 3 inclusive.
  • There will always be exactly one transparent colour, from 0 to 3 inclusive.
  • The location (x, y) of the sprite may be outside or partially outside the background image.

Input

Since all inputs will always be the same size, there will be no separators, just a single string of hex digits.

To avoid having to define negative inputs, the top left pixel of the background image will be (128, 128), increasing left and down, and x and y will be defined by 2 hex digits each, giving a range of 0 to 255.

The input hex string will be made up of:

  • Background pixels, 2 per hex digit, a string of 32 * 18 * 0.5 = 288
  • Sprite pixels, 2 per hex digit, a string of 8 * 8 * 0.5 = 32
  • Transparent colour, a single hex digit (the most significant half of the hex digit is unused)
  • Sprite x and y, 2 hex digits each, a string of 2 * 2 = 4

The input will therefore be a string of 288 + 32 + 1 + 4 = 325 hex digits with no separators.

Output

The output is the finished 32 by 18 pixel image, as a string of 288 hex digits with no separators.

Format

Pixel order

Each image is ordered in English reading order, left to right then top to bottom. That is, the pixels are listed in rows. The first pixel listed will be the top left. This applies to both the background image and the sprite image.

Colour encoding

Pixel colours are encoded 2 per hex digit, most significant first.

For example, the hex digit B corresponds to binary 1011. This means the first pixel has value 10 = 2 and the second pixel has value 11 = 3.

Transparent colour

Since the single transparent colour is encoded in one hex digit, which normally holds 2 colours, the first 2 bits (most significant) are ignored and the last 2 bits (least significant) are used to represent the transparent colour.

For example, the hex digit D corresponds to binary 1101. The 11 is ignored and the 01 is used to indicate colour 1.

Although the first two binary digits are always ignored, you may not assume they are always 00. They may take any value and all hex inputs of the correct length should produce a valid output.

Coordinates

x and y are encoded as 2 hex digits each, most significant first.

For example, the hex string 2A corresponds to binary 00101010, and decimal 42

Case sensitivity

Your code may accept input as either upper case or lower case hex digits, or both. If it only accepts one or the other case, it must also output in the same case.

You may not choose an arbitrary 16 characters to represent hexadecimal. You must use either (or both) of the following as input:

0123456789abcdef

0123456789ABCDEF

You must choose one or other (not both/mixed) to use as output. That is, you may accept inconsistent inputs if you wish to, but the output must be either always lower case or always upper case.


Sandbox thoughts

  • I'm considering adding example inputs and outputs and maybe a snippet to verify the output of arbitrary inputs for testing.
| |
\$\endgroup\$
0
\$\begingroup\$

Live Tennis Scoreboard

In this challenge, we're going to create a tennis scoreboard that could (theoretically) be used in an actual tennis match. The tennis scoreboard will display the score while listening on STDIN. As new results come in on STDIN, the tennis scoreboard will update itself accordingly.

Description of Input

When the scoreboard is first instantiated, it will be provided input for two strings -- these are the names of the competitors. This can be via command line arguments, user input functions, etc.

After that, the scoreboard will recieve input via STDIN. These correspond to events that the scoreboard should reflect in the score.

  • 0

    The first player has scored a point.

  • 1

    The second player has scored a point.

  • U

    Undo the previous point and revert to the previous state of the scoreboard.

The scoreboard must handle games, deuces, etc. as described in the next section.

Terse Description of Tennis Scoring System

This section here describes the exact rule set to use.

A match is between two players. To win a match, a player must win three sets. To win a set, a player must win at least six games and have a two-game lead over their opponent. To win a game, a player must win at least four points and have a two-point lead over their opponent.

The number of sets and games won are displayed as is. Points are displayed as follows in order of priority:

  • 1 point = 15
  • 2 points = 30
  • 3 points = 40
  • Number of points won are equal to the opponent = 40
  • Number of points won are one greater than the opponent = Ad

Tiebreaks are optional. Implementing tiebreaks grants you -40 to your score.

Scoreboard Format

During the first set and first game:

Name | x
Name | x

where x is the point display for each player.

During the first set:

Name a | x
Name a | x

where a is the number of games won by each player.

During the second set:

Name b a | x
Name b a | x

where b is the result of the first set.

During the third set:

Name c b a | x
Name c b a | x

where c is the result of the second set.

etc. for fourth and fifth sets.

Example:

Federer 5 6 6 3 2 | 0
Murray  7 4 4 6 2 | 15
| |
\$\endgroup\$
  • \$\begingroup\$ A bit of a far stretch, but it would be cool if you could point the programs at URL which gave the scores for an actual tennis match \$\endgroup\$ – Beta Decay Jul 27 '15 at 8:04
0
\$\begingroup\$

Punch buggy?

As some of you might know, "punch buggy" is a children's(?) game that involves spotting Volkswagen Beetles and punishing other players. For reference, the car on the left is a punch buggy, while the car on the right is not:

punch-buggy-yellownot-punch-buggy

Your task is: given an image, determine whether there is a punch buggy shown in it. Entries will be scored by percent correct among all n (TBD) test images. If there is a tie, it will be broken by run time on my computer (specs will be posted on main).

Test images may contain just about anything, and come in various sizes. Most will be automobiles of various types, but I will make sure they have a maximum of one auto in them (so if you see a non-matching car, you don't need to look for more). I won't use toy cars or heavily modified cars to try to fool you. Images will be pulled from Google Image Search, and will be of varying quality (from ad-quality to candid in-the-yard).

This is not a Kolmogorov complexity challenge. The point is not to recognize specific image files, but to recognize a Beetle in any picture. If it looks like someone is cheating this, I will change to a different test set and re-score.

Spec

Input is the name of an image file in JPG or PNG format (should I restrict this to one?).

Output is Punch Buggy! if a punch buggy is present in the picture, and any other non-empty string if not.

Programs are run once per image. I will write a simple test controller for this using STDIO, so programs must be runnable from the command line, using a language that is freely available on Ubuntu.

You are allowed to read/write other files, but only in a folder with the relative path /yourProgramName. You are allowed to read files whose names are passed as input via STDIN.

Test Images

(will include link to collection when posted, probably about 100 total)

Sandbox

Yes, this seems a bit difficult to me, too. I don't see that as a problem. Is there anything that isn't clear about the task or spec? Other notes/questions/suggestions?

If it needs fluff (I'm not sure yet), it will probably be something like "help my robot become more human via children's games".

| |
\$\endgroup\$
  • \$\begingroup\$ Personally, I don't think this is that hard. You just look for a large grouping of yellow pixels around the centre of the image. I think you should limit it to a PNG. \$\endgroup\$ – Beta Decay Jul 29 '15 at 13:21
  • 1
    \$\begingroup\$ @BetaDecay That would only work if all punch buggies are yellow and all other images/cars are not. The images shown here are only representative samples. The test cases will include various cars of various colors at various angles in various lighting conditions. \$\endgroup\$ – Geobits Jul 29 '15 at 13:27
  • \$\begingroup\$ Ohh I thought Punch Buggy was when you have a yellow car, not just a Beetle \$\endgroup\$ – Beta Decay Jul 29 '15 at 13:30
  • \$\begingroup\$ Ah. That's the Yellow Car Game. Similar, but yea, that would be a different difficulty level. \$\endgroup\$ – Geobits Jul 29 '15 at 13:32
  • 3
    \$\begingroup\$ I afraid even if you people try to recognize buggies their results will come from randomness and overlearning on the provided images. Recognizing a car at all would be a difficult task itself. \$\endgroup\$ – randomra Jul 30 '15 at 11:49
  • 1
    \$\begingroup\$ If you want to avoid this being a kolmorogov challenge, would it help to provide a much larger training set and test on a small subset of this that is not announced in advance? That does introduce a deadline excluding future submissions though. \$\endgroup\$ – trichoplax Aug 1 '15 at 18:30
  • \$\begingroup\$ @trichoplax Not necessarily, because you could always test the new submissions using the subset (which is still unannounced) \$\endgroup\$ – Beta Decay Aug 5 '15 at 11:48
  • \$\begingroup\$ @BetaDecay good point. That makes this sort of challenge seem much more promising. \$\endgroup\$ – trichoplax Aug 5 '15 at 12:27
  • \$\begingroup\$ @trichoplax Though it could still be a kolmogorov complexity because a program could be programmed to recognise all pictures in the album, and choosing a subset wouldn't stop that program from getting full marks \$\endgroup\$ – Beta Decay Aug 5 '15 at 12:37
0
\$\begingroup\$

Question about symmetry in ascii grid (temp title)

Synopsis: Given a grid of ASCII characters, determine if, and in what ways, the grid is symmetrical.

Some characters are symmetrical to others. For example:

  • d is symmetrical vertically to b
  • W is symmetrical horizontally to M
  • O is symmetrical both ways to O
  • ! is symmetrical horizontally to i (takes some imagination!)
  • ^ is symmetrical horizontally to v
  • b is rotationally symmetrical 180 degrees to q (that is, if you rotate the first character 180 degrees, you get the second character)
  • (space) is symmetrical vertically, horizontally, and rotationally to

In this challenge, there are only three types of symmetry that need to be considered: vertical, horizontal, and rotational by 180 degrees. You can find a full list of which characters are considered symmetrical at the bottom of this post.

If we arrange some characters into an n by m rectangle (where n and m are both even integers), then the rectangle may be symmetrical. Here is an example:

M^^^^MM^^M
OOOOOOOOOO
OOOOOOOOOO
WvvvvWWvvW

It is symmetrical horizontally.

Here's another example.

dddbbb
dddbbb
dddbbb
ddOObb

It is symmetrical vertically.

Here's one more example:

++++++
+p++q+
++++++
++++++
+b++d+
++++++

This one has three ways it is symmetrical -- horizontally, vertically, and rotationally.

Write a program which will, when given a rectangle of characters as input, output the number of ways that rectangle is symmetrical. For the three inputs I've shown above, the outputs would be 1, 1, and 3 respectively.

[Todo: list of characters]

Sandbox Questions

  1. One thing I've been considering is allowing entrants to access the list of which characters are symmetrical (in some sort of CSV format) in a file. This would mean that entrants wouldn't have to encode the symmetries themselves. On one hand, this probably saves some frustration at having to code in all the possible symmetries. On the other, this reduces the complexity of the challenge as the aspect of encoding the symmetries with minimal characters is removed. I'd like your thoughts on this.
| |
\$\endgroup\$
  • \$\begingroup\$ Yet more symmetries: all of []{}() are vertically symmetric to themselves. | belongs in "Both". lower-case c belongs in vertical. Maybe also lower-case a depending on the font your going by (apparently not the one used on SE). Likewise t might belong in horizontal symmetry. We also forgot about digits: 08 both ways, 3 vertical. \$\endgroup\$ – Martin Ender Sep 1 '14 at 11:58
  • \$\begingroup\$ What do you think about adding rotational symmetry (by 180 degrees) to the mix? \$\endgroup\$ – Martin Ender Sep 1 '14 at 11:59
  • \$\begingroup\$ ​​​​​​​​​​​​​Like 6 and 9? I think rotational symmetry would do well as a seperate question actually. \$\endgroup\$ – absinthe Sep 1 '14 at 12:08
  • \$\begingroup\$ Yes, like 6 and 9. If a new question for that is based on the same concept, it would probably be too similar to not be a duplicate (at least the solution I have in mind would be rather easily adapted to do rotational symmetry, I think). Adding it here, might open some possibilities for interesting compression/golfing. \$\endgroup\$ – Martin Ender Sep 1 '14 at 12:11
  • \$\begingroup\$ You've convinced me. I'll edit in the rotational part when I have time. \$\endgroup\$ – absinthe Sep 1 '14 at 12:14
  • \$\begingroup\$ Since there will probably be combinations of all three symmetries on different characters, I'd recommend only having one list for each symmetry (with some pairs in multiple lists). Here are the rotational pairs I can think of: d/p, b/q, (/), [/], {/}, </>, %/%, ///, \/\, ,/,, S/S, s/s, z/z, Z/Z, W/M, !/i, ^/v, $/$, as well as all those which are symmetric both ways to themselves. \$\endgroup\$ – Martin Ender Sep 1 '14 at 12:22
  • \$\begingroup\$ Some of the characters are not visible (at least on my screen) so would benefit from being followed by a description. I think they are just spaces but markdown appears to fail to display them even in backticks. \$\endgroup\$ – trichoplax Sep 1 '14 at 14:09
  • 1
    \$\begingroup\$ Displaying a single space in an inline code tag has to be done with an actual <code> tag rather than with backticks. codegolf.stackexchange.com/questions/5194/… is a good starting point for rotational symmetries. Some digits also have linear symmetries. \$\endgroup\$ – Peter Taylor Sep 1 '14 at 14:39
  • \$\begingroup\$ Would you also consider J and L as symmetrical (also requires a little imagination...)? \$\endgroup\$ – WallyWest Sep 2 '14 at 22:41
0
\$\begingroup\$

Clarence the Fast? Typist

(Inspired by this excellent question on the original challenge.)

Introduction

Lawrence is a business manager who works at an Internet service provider. Recently, he has noticed that Clarence, the data entry clerk, has been typing a little slow lately. Since Clarence's job is entering the IP addresses manually into the database, Lawrence is starting to get worried. Especially that there is now a backlog of angry customers who are calling to ask why they are not connected to the Internet yet.

Lawrence, as you might expect from one who manages an ISP, has hit upon what he considers to be an excellent solution to the problem. He decides to optimise the layout of Clarence's keypad to make it faster for him to type in the IP addresses.

Clarence's keypad is normally laid out as follows:

123
456
789
.0E (E stands for "Enter")

The distance between the centres of each adjacent key is 1 centimetre. Clarence types using the "eagle search" system -- he uses one finger only and moves that finger from key to key to type in an address. For example, to input the number 7851, Clarence would start his finger on 7, move 1cm right to 8, move 1cm up to 5, then move √2cm to 1 -- a total of 3.41cm.

If we rearrange his keypad like this, we can get better results:

423
156
789
.0E

With this layout Clarence only needs to move his finger 3cm. This saves time!

Your task is to write a program that determines the most optimal keypad layout, given a list of IP addresses that Clarence must type in. Clarence needs to push the E after each IP address, so you also need to optimise the position of the E key.

Input Description

Input is a newline separated list of IP addresses. Each IP address is a string that will be in the form

().().().()

where each () is an integer in the range 0 - 999. I would also like to point out that addresses such as 0.42.42.42 or 999.999.999.999 in the input are still valid, despite the fact that they are invalid IP addresses. So you don't need to include any IP address verification code in your program.

Output Description

Output the layout of the keys such that the distance Clarence needs to move his finger to type them all in is as low as possible. If there are multiple layouts that are equally as low, output any one of them.

The format for the output looks like this:

123
456
789
.0E

[todo: example inputs and outputs]

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Lose the intentional confusion of the names. The point of a specification is to be easily understood, not deliberately confusing. \$\endgroup\$ – Peter Taylor Aug 5 '15 at 10:51
  • \$\begingroup\$ I don't think it affects the challenge in any way, but 999.999.999.999 makes my eyes bleed. \$\endgroup\$ – Dennis Aug 8 '15 at 5:01
0
\$\begingroup\$

Is a picture worth a thousand words?

There is an old saying that goes "A picture is worth a thousand words". For us programmers, pictures and words are actually quantifiable in bytes. (A word is worth 8 bytes on a standard 64-bit system, a thousand words is worth 8000 bytes, and an image is worth the number of bytes needed to store it in the particular format it is in.)

Write a program or function that, given the path of an image as input, determines if it is or is not worth a thousand words. Print worth it if it is, and not worth it if it is not.

This is a challenge, so the shortest answer wins!

Problems:

Too simple, maybe have the programs perform a check on the environment to determine actual word length?

No test cases (Yet)

Question is sort of short

| |
\$\endgroup\$
  • \$\begingroup\$ I love the title, but I'd agree the challenge is too simple. This is just os.path.getsize in Python, for instance. I'd suggest playing off the 'thousand words' part of the challenge more. \$\endgroup\$ – absinthe Aug 11 '15 at 22:30
  • \$\begingroup\$ @Pyrrha how would you suggest playing off of the 'thousand words' part? A thousand literal english words? Maybe have the program convert an image into words and words into images (Obviously not accurately, e.g. 'Blue' will not give a blue image, 'Blue' is just a symbol. 1000 symbols represent the image by dictionary lookup, or something. \$\endgroup\$ – rodolphito Aug 12 '15 at 2:29
  • \$\begingroup\$ If you have a good idea feel free to take over the challenge :) \$\endgroup\$ – rodolphito Aug 12 '15 at 2:30
  • 1
    \$\begingroup\$ Alternative: Find 1000 English words (i.e. letter sequences) in the image file’s source code. \$\endgroup\$ – Crissov Aug 12 '15 at 11:19
0
\$\begingroup\$

Write an Adblocker!

Introduction

You've gotten tired of reading text ads dispersed throughout your content. You've tried solving this problem using a simple find-and-replace solution, but the advertisers have wisened up! Every text ad now comes in slightly different variations to slip past your filter.

Challenge

Write an adblocker that, given a sample ad, removes all variations of it from the content. Your program must remove every sentence in the input for which 75% of its words are identical, and in the same location.

This is codegolf, shortest answer in bytes wins!

Example

Given an example sentence from an advertisement, such as

Buy my computer now with cheap free shipping.


Buy my laptop today with cheap free shipping.

is an ad because 6 out of 8 words (>= 75%) are identical and in the same locations.


The computer was expensive but shipping was free.

is not an ad because 0 out of 8 words (< 75%) are identical and in the same location. Note how computer, shipping, and free don't count as identical because they are in different positions in the sentence.

If a sentence is not the same length as the ad, it isn't an ad.

Bonus

After matching an ad, remember which words were used as replacements, and use them to match future ads.

For example, when Buy my laptop today with cheap free shipping. was matched to the given sample Buy my computer now with cheap free shipping., your program should remember that laptop and today are synonyms for computer and now, respectively.

If laptop or today are ever encountered in a future sentence, they should be matched with their synonyms in the ad.

Your program only needs to match synonyms in content that appears after the synonym was found.

So, if the sentence Purchase my laptop today with cheap free shipping. was encountered after your program found out about the aforementioned synonyms, it would match because 7 out of 8 words matched in the same location (>= 75%). Note that a program that doesn't claim the bonus would only match 5 out of 8 words (< 75%), and would not consider the sentence an ad.

Your program should then proceed to make note that Purchase is a synonym for Buy, and continue processing the content.

Programs claiming this bonus can claim a 35% reduction of their score, i.e. score_with_bonus = number_of_bytes * 0.65.

Input

Accept one sentence as a sample advertisement followed by a number of sentences of content. Only letters of the alphabet, spaces, and periods will appear in the input.

Input may be taken in any convenient format for your language. For example, accepting a string for the ad sentence and an array of strings for the content is acceptable.

Output

Output the content without the ad variations. The content must be in the same order.

The output may come in any reasonable format for your language. For example, printing to a file or stdout is acceptable. If your language makes it easier to output an array like ["Content 1", "Content 2", ...], or in a similar such format, this is acceptable.

Test Cases

Input

Two for one deal on lumber for a limited time only.
    
Make sure to pace yourself well when you run long distances.
You don't want to tire too quickly.
Three for one deal on tires for a limited time only.
Training is a must.
Two for one deal on lumber for a limited time only.
Three for one deal on tires for a short period only.

Output (with bonus)

Make sure to pace yourself well when you run long distances.
You don't want to tire too quickly.
Training is a must.

Output (no bonus)

Make sure to pace yourself well when you run long distances.
You don't want to tire too quickly.
Training is a must.
Three for one deal on tires for a short period only.

Notes

You may write a program or function.

More test cases to come!

This is my first challenge, so please give suggestions on how to improve!

In particular, comments on whether or not the bonus is appropriate would be appreciated. Also, it would be nice to know thoughts concerning the challenge as a whole (good, bad, too easy, too hard...?), so that I can better frame future ideas! Thanks!

| |
\$\endgroup\$
  • \$\begingroup\$ So the input won't have any newlines? That is, the content will be a series of one or more sentences just separated by a period and a space? Could I write a function that accepts the ad as one parameter and the content as another? \$\endgroup\$ – Alex A. Aug 14 '15 at 4:07
  • \$\begingroup\$ You many accept the input in any reasonable format. (So yes, @AlexA., that would be fine) \$\endgroup\$ – jrich Aug 14 '15 at 4:07
  • \$\begingroup\$ But what about So buy my computer now, cheap with shipping? That's just 1 out of 8, when in reality it should be 7 out of 8... \$\endgroup\$ – Beta Decay Aug 14 '15 at 7:33
  • \$\begingroup\$ You mention that commas may be included in the input, but you don't say how they affect the matching. \$\endgroup\$ – Peter Taylor Aug 14 '15 at 7:43
  • \$\begingroup\$ @BetaDecay For the purposes of the challenge, we assume that the advertisers do not get more sophisticated than a simple replacement of words, not an addition, subtraction, or rearrangement of words. Obviously this wouldn't be a very effective adblocker, but I thought it would make for a reasonable challenge. \$\endgroup\$ – jrich Aug 14 '15 at 13:32
  • \$\begingroup\$ @PeterTaylor Commas may be ignored in the input. Periods only matter for separating sentences. For matching purposes, only letters of the alphabet matter. \$\endgroup\$ – jrich Aug 14 '15 at 13:33
  • \$\begingroup\$ If commas can be ignored, you might as well remove them entirely from the spec. ',- (in CJam) isn't really where the interest lies. \$\endgroup\$ – Peter Taylor Aug 14 '15 at 15:09
  • \$\begingroup\$ @PeterTaylor You're right, commas aren't where the interest lies. I'll remove them from the challenge. \$\endgroup\$ – jrich Aug 14 '15 at 15:35
0
\$\begingroup\$

Kolmorogov image complexity


The 512 by 512 pixel image below [ to be added when posting to main ] was produced using a combination of simple methods that, if known, would allow reproducing the image with a short program. It is therefore known to have low Kolmorogov complexity. However, the original methods used will not be revealed. Instead your challenge is to produce code that outputs this image by your own best method, pixel perfect, so that the hash of your image matches the hash of this image.

Blank image to show size 512 by 512 pixels

[ Hash ]

You may use any built ins and libraries that existed publicly before the challenge was posted, including graphical libraries.

Input and output

Input

  • Your code is not required to take input.
  • Your code must be able to produce the correct output without taking input.

Output

You may use any freely available image format (free and free) or display the image to screen. Your code is not responsible for converting the image to a format that can be hashed for validation.

Winning

A valid answer is one for which the output passes the validation test. The winner is the valid answer with the shortest code in bytes.

Validator

The following code takes a PNG image as input and outputs a hash of its pixel values, announcing whether this is valid.

[ Validator to be added later ]


Sandbox questions

  • I'm considering posting a few example images here in the sandbox so people can feedback on which one would make the best candidate for posting to main. Is this acceptable if I keep the time between posting example images and posting to main reasonably short (a day or two)?

  • Would it be better to approach this from the opposite direction and say the winner is the closest to the target image in 300 bytes? I think it can work as a question with insisting on an exact match though - I'm aiming to have several aspects to be golfed down, so even if not all are golfed well the total length should still be manageable. I prefer an exact match and open ended code length, as a byte limit has very different effects on different languages.

  • Is there any general advice on what to remember/avoid when preparing the target image? Obviously this cannot be very specific advice as the exact method will not be discussed before posting to main. However, I welcome any hints at things that would make for a good challenge and things that would be trivial or too difficult. I'm definitely going to follow Peter Taylor's advice and avoid any crypto or Mandelbrot zooms. The image should be fairly easy to identify, so the emphasis can be on golfing down the components rather than solving a mystery.

  • Would it be better to say "the original method will never be revealed" or "the original method will be revealed once an answer is posted that is shorter than it" or "the original method will be revealed after a set time period"? The last one is my least favourite. I like the idea of a challenge being open ended, so I would prefer to reveal at most only what is already beaten by existing answers.

  • I like the idea of using patterns that will be recognisable so people can say "I know that pattern from somewhere" and then look it up and tweak the parameters, rather than just presenting a random looking image that happens to have a simple description. Does this sound like an interesting challenge?

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ This basically looks like a single-robber cops-and-robbers. In particular, the by now well-known issues around use of crypto in robbers should be taken into account. Guess-the-Mandlebrot-parameters is also likely to be a waste of time. \$\endgroup\$ – Peter Taylor Aug 10 '15 at 18:43
  • \$\begingroup\$ Related: codegolf.stackexchange.com/questions/24909/kolmogorov-mania . This got very mixed votes at first. Note the edit made with the clue. I say pick an image and try it. Don't say the oiginal method will never be revealed, just give more hints until someone gets it. \$\endgroup\$ – Level River St Aug 17 '15 at 14:12
  • \$\begingroup\$ @steveverrill I definitely don't want something as obscured as that - I want the pattern to be perfectly visible so it's more about golfing than guessing. I like the idea of gradual hints, but if I get mine how I'm aiming to, it won't need hints, just golfing. \$\endgroup\$ – trichoplax Aug 17 '15 at 17:15
0
\$\begingroup\$

SETI (search for extraterrestrial life)

In this code golf challenge you will search for signs of life.

Specification:

Your program takes a sequence of exactly 225 characters, each either 0 or 1. You return as output a single bit, either 0 or 1.

The goal is to distinguish between two kinds of inputs:

0 (no extraterrestrial life): Each character is zero or one independently at random, and is one with probability exactly 15%.

1 (extraterrestrial life): First, each character is zero or one independently at random, and is one with probability exactly 28%. Then, 10 rounds of the original Conway's Game of Life are played from this configuration. The 225 characters are viewed as a 15 by 15 grid, and when we apply the rules, we treat the grid as wrapping around so that it has no borders. That is, column 1 wraps around and is adjacent to column 15, and row 1 also wraps around and is adjacent to row 15. The symbol '0' is associated with 'dead' and the symbol '1' is associated with alive. After the 10 rounds the string corresponding to the state of the game is the input.

Your program does not need to give any particular output for any particular input, however it should succeed on average in the following sense. If we flip a fair coin (either 0 or 1), and choose an input from the corresponding distribution, your program should output the correct answer with probability at least 90%.

Otherwise this is code golf as usual. Enjoy!

I/O:

Your program shall accept as input a sequence of 225 characters, each either 0 or 1. You may request in your answer that the characters are space-delimited, comma-delimited, or not delimited. You may request in your answer that the input is given on standard in, or, if your answer is a program which takes command-line arguments, you may assume that the characters are passed on the command-line so that each character is an argument (assuming your shell supports passing 225 arguments to a program), or, if your language supports the concept of "global variables / values", you may write your program under the assumption that a known global variable, of the simplest "character sequence" type that your language supports, contains the input.

Your answer shall output a single bit either zero or one. You shall do this either by printing the character 0 or 1 to standard out, or by returning an integer value 0 or 1 from a designated "main" function.

| |
\$\endgroup\$
  • \$\begingroup\$ This question is going to need a fair number of test cases, soo that people can tell if their program works. Maybe a test case generator? \$\endgroup\$ – isaacg Aug 19 '15 at 14:01
  • \$\begingroup\$ I guess I assumed people would just write their own test case generator in their language of choice. I wrote one here in C++, that's what I used to pick the parameters hastebin.com/uguhapepat.avrasm \$\endgroup\$ – Chris Beck Aug 19 '15 at 14:04
  • \$\begingroup\$ added a license statement hastebin.com/sevimunolu.avrasm \$\endgroup\$ – Chris Beck Aug 19 '15 at 14:14
  • \$\begingroup\$ 8 rounds or 10 rounds? \$\endgroup\$ – Peter Taylor Aug 19 '15 at 16:19
  • \$\begingroup\$ Humm you know i'm open to suggestions, but I originally had 8 and then I made the board smaller and increased it to 10, I guess I left an 8 in there though. i'm going to edit to make it 10 everywhere \$\endgroup\$ – Chris Beck Aug 19 '15 at 16:20
  • \$\begingroup\$ So my goals for setting the parameters were like: (1) I thought there should still be some significant amount of noise in the life game, it shouldn't have enough time to entirely settle down into squares and flippers (2) I want you to have to do something more complex than "just count the number of 1's". If the same percentage is used for the random ones in both the "yes" and "no" instances, it leads to a large gap in density of ones because life tends to kill off many of the 1s after you start from random. so i made the board small and tuned the %s so that counting ones gives little info. \$\endgroup\$ – Chris Beck Aug 19 '15 at 16:27
0
\$\begingroup\$

Infinite monkeys and a broken keyboard

The infinite monkey theorem describes the probability of getting the desired result by just doing random stuff.

The task of this challenge is to calculate the minimum number of monkeys you need to get a given text on a broken keyboard. The situation is easy:

  • You have a keyboard (QWERTY-layout) that has lost some of its keys
  • Possible keys are: 1234567890abcdefghijklmnopqrstuvwxyz -=\[];',./
  • Only one button is pressed at a time and the other keys (enter, tab, numeric keypad, ...) will not be pressed/ are already lost
  • You have many many many monkeys which want to type on the keyboard!

Input

The input is a string which can only contain the possible chars. You may assume that only the characters that are in the given string aren't lost.

Task

You have to calculate how many monkeys are at least necessary to get the given input with a probability of over 50%. Afterwards just output that number.

Examples

input: aaaa
    1 key available -> P=100% to hit the right key
output: 1

input: abcd
    4 keys available -> P=25% to hit the right key
    Probability to get the desired string:
    P = 25%^4 = 0.00390625
    Number n of monkeys needed:
    (1-0.00390625)^n < 50%
    n = 178 (P=50.176%)
output: 178

Please tell me if you have ideas how to improve or clarify the question or how to optimize it.

| |
\$\endgroup\$
  • \$\begingroup\$ Similar, but I think this is a better question than mine \$\endgroup\$ – Beta Decay Aug 20 '15 at 17:58
0
\$\begingroup\$

(Possible deadlines?)

The robber and the bank (Bank managers)

(Based off 'Two makes all the difference')

A group of robbers has decided to break into a bank, but one of the members leaked the information to the bank. To stop the robbers from getting any money, they have decided to change the combination on each vault to something more complicated.

Your task

As you are a bank manager, you must figure out a new combination of rotations for the wheel lock system of the vaults. The vaults take 7 turns each, represented in degrees. You must write a program that takes 10 integers (separated in any way you like) and outputs the processed integers which have been made from the originals. This is important, as you cannot use a randomizing function to make the new combination.

Sample input:

(Note: The numbers will all be multiples of 5. The output should also be this way.)

10, 50, -230, 110, 20, -5, 50, 80, 30, -50

Sample output:

30, 110, -110, 230, 50, 115, 110, 170, 70, 70

This result is obtained by the simple (Python 3) algorithm (deliberately non-golfed)

inputlist = input('list')
for i in len(inputlist):
    if inputlist(i) > 0:
        inputlist(i) *= 2
        inputlist(i) += 10
    else:
        inputlist(i) += 120

(Note the abscence of a condition for 0 degrees, as a wheel lock would not take such a value. Also note the fact that the algorithm is a full program, not just a function that would do the same.)

Winning conditions

The shortest uncracked algorithm wins. In case there are two algorithms that have the same length and are uncracked, the one with more votes will win.

The robber and the bank (Robbers)

Your group of robbers are breaking into a bank! However, one of your members seems to have leaked the information to the bank managers. Your team manages to hack the bank's system to retrieve the original password and part of the algorithm, but your connection was cut.

Your task

You will receive 10 integers and a snippet of code (need help deciding how much) from the algorithm used to change the lock's combination. You will need to deduce what the algorithm is and finally the new combination.

Sample information:

10, 50, -230, 110, 20, -5, 50, 80, 30, -50
Part of code

Sample answer:

30, 110, -110, 230, 50, 115, 110, 170, 70, 70
Code (optional)

Winning conditions

The robber with the most vaults (algorithms/combinations) cracked wins. In the case that there are two robbers with the same number of cracked vaults, the robber with more votes will win.

(Any way to separate who wants to be a robber and who wants to be a manager? Perhaps a separate system for answering?)

| |
\$\endgroup\$
  • \$\begingroup\$ 1. It's quite confusing the way you keep talking about algorithms when you mean programs. 2. It's not at all clear what exactly the bank managers post. 3. It's not at all clear that the robbers can do anything except guess. \$\endgroup\$ – Peter Taylor Aug 24 '15 at 17:04
0
\$\begingroup\$

Buffalo buffalo buffallo buffalo buffallo buffallo buffallo parse buffalo buffalo buffallo buffalo buffallo buffallo buffallo

Write a program that can take a integer input N > 0 and then describes the syntax of a phrase in the style of "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" with N repetitions.

The wikipedia page has the parse tree and accepted syntax for phrases up to N = 8.

The sentence is unpunctuated and uses three different readings of the word "buffalo". In order of their first use, these are:

  • a. the city of Buffalo, New York, United States, which is used as a noun adjunct in the sentence and is followed by the animal;
  • n. the noun buffalo, an animal, in the plural (equivalent to "buffaloes" or "buffalos"), in order to avoid articles;
  • v. the verb "buffalo" meaning to outwit, confuse, deceive, or intimidate.

So for the first eight the output should be:

  1. Bully (meaning the imperative "[you] Buffalo!" - command someone to bully).
  2. NY bison (meaning a bison that hails from the town of Buffalo).
  3. NY bison bully (a bison from NY bullies).
  4. NY bison bully bison (NY Bison bully a bison)
  5. NY bison bully NY bison (NY bison bully NY bison)
  6. Buffalo buffalo buffallo buffalo buffallo buffallo (NY bison bully (TBC)
  7. Buffalo buffalo buffallo buffalo buffallo buffallo
  8. Buffalo buffalo buffallo buffalo buffallo buffallo buffallo

In the comments section, wikipedian Robin Johnson has it for 9 through 12 (NY stands for Buffalo, NY):

  1. (NY bison [which] bison bully) bully (bison [which] NY bison bully)
  2. (Bison) bully (NY bison [which] NY bison (NY bison bully) bully)
  3. (NY Bison) bully (NY bison [which] NY bison ([which] NY bison bully) bully)
  4. (bison [which] bison ([which] NY bison bully) bully) bully (NY bison [which] NY bison bully)

He added parenthesis for more phrase visibility, but that is not needed.

Your program should take the input and explain the gramatically correct phrase doing the following substitutions:

  • NY for the Buffalo, NY city.
  • Bison for the animal Buffalo.
  • Bully for the verb.

[code-golf] [kolmogorov-complexity]

| |
\$\endgroup\$
  • \$\begingroup\$ Are we allowed to use NLTK? \$\endgroup\$ – Beta Decay Aug 27 '15 at 10:55
  • \$\begingroup\$ The name is a little obnoxious to be honest. I would recommend removing at least a few "buffalos" from either side of "parse." \$\endgroup\$ – Alex A. Sep 4 '15 at 17:42
  • \$\begingroup\$ @AlexA. that is a good suggestion, and I think the title as is is gramatically wrong too. \$\endgroup\$ – Mindwin Sep 4 '15 at 23:48
0
\$\begingroup\$

Get home by ONLY turning right

You're finally trying to get a drivers license. About halfway during the lesson, the instructor decides that you've sufficiently mastered telling the gas- and brake pedal apart. It's time to practice the next thing: turning right.

The challenge

Your program is provided an ASCII roadmap, with your starting position, direction and home marked. You should drive home in the minimum distance required.

Your program must output route instructions for reaching your destination. The following instructions must be printed by your program whenever appropriate.

Input

Items on the map will look like this. There are only horizontal and vertical roads. (I'm open for suggestions on this one.)

  • = – A horizontal road
  • | – A vertical road
  • # – A crossroad
  • > / < / ^ / v – A one-way street
  • H – Your home
  • N / E / S / W – Your starting point and direction (North, East etc. The map is oriented north-up.)

A road segment (a signle character) is connected to another segment when:

  1. It ends at an adjacent segment that has the same alignment. E.g.: == or
    |
    |
  2. It ends at a segment with a different alignment (horizontal vs vertical). E.g.: =|, |=,
    =
    |
    or
    |
    =
  3. It ends at a crossroad. E.g.:
     |
    =#=
     |
  4. It ends at a roundabout. E.g.:
 |
=O
 |

It is not connected in (for example) these instances:

  • |
     |
  • ||
  • | =

Moving one position up, down, left and right all count as traveling the same distance.

Output

  • Turn right
  • Go straight on
  • Take the {1st/2nd/3rd} exit (at a roundabout)

You take roundabouts clockwise. Because of this, taking any exit amounts to turning right.

Rules

  • Each instruction must be on its own line.
  • No other output is permitted.
  • Your program may take no longer than a minute to run on an average home user’s computer.

Standard loopholes are forbidden, unless specified otherwise.

This is code golf. The shortest answer wins.


This is an early draft. Input is welcome, especially on the feasibility of requiring the shortest possible route, if this should be code golf, how input should be generated (randomly but the same for all programs? A few predefined maps?) and any improvements for the challenge. Any constructive feedback is welcome, even if it's just about spelling and grammar errors.

| |
\$\endgroup\$
  • \$\begingroup\$ Very related challenge \$\endgroup\$ – Sp3000 Aug 27 '15 at 11:50
  • \$\begingroup\$ @Sp3000 Not a duplicate though. \$\endgroup\$ – user2428118 Aug 27 '15 at 15:24
  • \$\begingroup\$ How are the roundabout exits numbered? \$\endgroup\$ – ASCIIThenANSI Aug 27 '15 at 17:51
  • \$\begingroup\$ @ASCIIThenANSI I've updated the text to say you take roundabouts clockwise. I hope it's sufficiently clear now. \$\endgroup\$ – user2428118 Aug 27 '15 at 18:33
0
\$\begingroup\$

Arranging Matrices

(doesn't actually require any matrix math)

While doing homework on matrix multiplication, I realized that I could avoid rewriting all of the matrices by arranging them intelligently on the page. If the problems were:

A * B = C
A * D = E
F * D = G

I could arrange the matrices like so:

 BD
ACE
 FG

This arrangement satisfies the requirement that each product (C E G) have the correct factors in the correct directions. For example, the A * D = E so E is to the right of A and below D.

The challenge is, given a list of multiplication problems (in the same format as above), output an arrangement of them that involves the fewest letters (the above solution has 7, the minimum).

| |
\$\endgroup\$
  • \$\begingroup\$ Needs a test case for an input which has conflicts. The easiest one would probably be A * B = C B * A = D. \$\endgroup\$ – Peter Taylor Sep 1 '15 at 10:31
  • 1
    \$\begingroup\$ You might want to first explain how for a single matrix multiplication you usually arrange the matrices to do the computation. I don't think everyone is familiar with the technique this challenge is based on. \$\endgroup\$ – Martin Ender Sep 1 '15 at 11:09
1
52 53
54
55 56
96

You must log in to answer this question.

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