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

2958 Answers 2958

1
51 52
53
54 55
99
0
\$\begingroup\$

Capture the flag

Basic rules

There is a rectangular map of cells, each bot has current cell. Bots compete 1 vs 1 at a time, let's call them red and blue. There are N instances of red bot and N instances of the blue bot on the map. Additionally, there is unmovable red base and blue base, both having initially the red flag and blue flag respectively. Bot instances can move around, supress enemy bot instances, capture the enemy's flag. The goal is to bring enemy's flag to the base (which should have the flag). The flag can be returned back to the base. Bots can pass the flag around.

Selectable rules (to be decided)

Map style

  • 2D, 3D or 2.5D;
  • Wrapped-around or not;
  • With walls (destructible, indestructible, buildable by bots) or without;
  • Bases positions and bots initial positions: random, selectable by player, hardcoded in a map?
  • Random-generated, pre-programmed, partially selectable by the player?

Bot capabilities

  • Moving diagonally? Dodging?
  • Seeing the entire map or only surroundings?

Intra-team bot communication

  • Uninhibited
  • Only using messages that takes a move to create or read and that travel not too fast;
  • Inhibited (only indirect by observing positions);

Prior knowledge

  • Should bots know the walls of the map from the beginning?
  • Should bots know the bases posisions from the beginning?
  • Should bots know enemy bots positions from the beginning?
  • If communication between bots is not free, should bots know initial frindly bots position from the beginning?

Attacking

  • Only nearby bots or also "shooting"?
  • Multiple weapons or not?
  • Dodge/protect move?
  • One-hit or health points?

Abandoned flag

  • Is reset to the appropriate base after timeout;
  • Is reset to the appropriate base instantly;
  • Needs to be carried by the bot manually;

Scoring

  • Reset the game after each flag score or continue the game for N moves or N scores?
  • What to do in case of stalemate?

Questions

  1. Is this challenge a good idea?
  2. Which set of proposed rule variants to choose?

My current choice is:

  • Rectangular 2D map without wraparound, with big walls pre-programmed, random single wall-lets placed randomly;
  • Bases positions are pre-defined and known in advance to all bots;
  • Bots having 10 health points, carrying chainsaw (5 damage, 1 distance) and a gun (2 damage, 10 distance);
  • Bots can stay&defend (half of received damage), move 1 cell to 8 directions, attack (without moving); build up to 8 pieces of wall in neighbouring cell, destroy 1 piece of neighbouring wall, capture the flag, score the goal, send a message.
  • Bots can cee a 11x11 rectangle, centered around them, including through walls;
  • Bots are stateful, but can't communicate with other instances directly. They can observe movements of other bots in the vision field or receive messages (if any). The message is a 4 bytes of data (i.e. a number from 0 to 2^32-1) + 1 byte of signal strength, it travels 5 cells per move, decreasing signal strength by one. Message gets received (including the current "signal strength" parameter) by all bots (including enemy ones). Bots reads the message (if any) before making a move. If there are multiple messages, only one with larger signal strength gets received. Hovewer if signal strengths differ only by 1, contect gets XORed.
  • Player choses initial positions (relative to own base) of all his bots;
  • All bots know the initial walls in the map;
  • While the bots stays close to own base, it's health gets recovered by 1 point per move, up to 10, if the flag is present.
  • Each round gets until one of the team scores 5 goals. This team wins (5-x) points, where x is number of opposin team's goals.
  • Abandoned flag can be picked up by either team. All bots know relative position of the own flag at any moment.
| |
\$\endgroup\$
0
\$\begingroup\$

A game of chance

Hello! Thought I would try out the sandbox, a rather useful tool that I haven't utilized yet! This is a game I thought up with some colleagues, basic in theory but has some deeper algorithms to win. I'm thinking of tagging this as code-challenge, any opinions welcome, especially a better name.

How to Play

Every turn, you get one number, pseudo-randomly generated, you need to put this number in a list. The list must always be in numerical order, from lowest to highest, and cannot be changed after the turn has ended. If you can no longer put the number anywhere, where it will still be in numerical order, you lose.

The list is 100 entries, which start as empty slots (seen as "-" or unique characters for your language) and slowly becomes a list of numbers (example that just lost).

Rules

  • You cannot edit the position of a value in the list.
  • The value will be inputted every turn.
  • The random numbers are X-Y. Both X and Y will always be positive and from 0 to 65535.
  • I'm willing to input the number in most ways
  • Any language that I can run! I have both Windows 7 and Linux Mint + VMs for other versions.

Scoring

You get 1 point for every round you last. There are 10 (TBD) rounds for each score, resulting in a maximum score of 1000 (which is very unlikely to ever get).

| |
\$\endgroup\$
  • \$\begingroup\$ Assuming your PRNG is uniform, how could there be a better strategy than just mapping 1 to 100 to the range the PRNG can produce and then rounding to the nearest empty cell? Or is the range of the PRNG unknown and different for each game? \$\endgroup\$ – Martin Ender Sep 4 '14 at 16:47
  • \$\begingroup\$ Assuming the PRNG has an even chance to spit out any number in the range, the challenge can be solved optimally, so scoring by rounds lasted is not a good idea. \$\endgroup\$ – Rainbolt Sep 4 '14 at 16:48
  • \$\begingroup\$ Assume you get the answer 99, would it be best to put it in the 99th slot or the 98th slot? If you put it in the 99th slot, and you get 100 twice - you lose. However if you put it in the 98th, you don't. It's not to get all 100 slots filled, it's to get as far as possible. It's a better game with the random numbers out of 1000, which I have just changed. \$\endgroup\$ – Alexander Craggs Sep 4 '14 at 16:51
  • \$\begingroup\$ @PopeyGilbert I don't think it makes sense on average to leave that extra room for a second 100, because you might as well get more numbers below 99 than you have space there. I do believe this becomes a lot more interesting, if we're talking about an unknown PRNG range though. You'd need the first few moves to decide how much you'll spread out the numbers. \$\endgroup\$ – Martin Ender Sep 4 '14 at 16:54
  • \$\begingroup\$ @MartinBüttner That's actually a very good idea. Do people suggest that I do that? \$\endgroup\$ – Alexander Craggs Sep 4 '14 at 16:55
  • \$\begingroup\$ @PopeyGilbert At the same time, in order not to make it too complicated, a good compromise might be to choose the endpoints of the range randomly from some small finite known set. \$\endgroup\$ – Martin Ender Sep 4 '14 at 17:04
  • \$\begingroup\$ @PopeyGilbert I should have said "An optimal guess exists" instead of "An optimal solution exists". This is basically just building a tree and then taking the path that gives you the best odds. Making the endpoints variable just means you have to guess at that too. It might be so hard to guess that you can't make an optimal guess in a reasonable amount of time, so you may want to add a time restriction. When you add a time restriction, things get hairy and people want to know what machine they'll be running on. \$\endgroup\$ – Rainbolt Sep 4 '14 at 17:13
  • \$\begingroup\$ @MartinBüttner I'm taking your suggestion, and I'll make the points random! RainBolt, you have some very good points, I think I do understand what your saying =) I'm already understanding how amazingly useful "The Sandbox" is. \$\endgroup\$ – Alexander Craggs Sep 4 '14 at 17:16
  • 1
    \$\begingroup\$ If the deeper problems can be fixed, there are some minor changes which I think would make it easier to understand. I would talk about an array rather than a list, because I think it has stronger connotations of being a fixed size. I would clarify whether the - in X-Y is a subtraction or giving bounds of a range. And I would ask the program to give output of the array index every time it receives an input, so that your control program can validate its moves. \$\endgroup\$ – Peter Taylor Sep 5 '14 at 22:47
  • \$\begingroup\$ You refer to both numerical order and alphabetical order. Are these meant to both say numerical order, or is there an extra challenge that I have missed? \$\endgroup\$ – trichoplax Sep 5 '14 at 23:04
  • \$\begingroup\$ @PeterTaylor Thanks for the advice! I'll fix them tomorrow. Also, GithubPhagocyte, they're both meant to be numerical order =) Will correct too :D \$\endgroup\$ – Alexander Craggs Sep 6 '14 at 21:16
0
\$\begingroup\$

Finding repeated words in a passage

This challenge is inspired by a question on the Software Recommendations website.

Write a program that outputs the repeated words in a passage on a paragraph by paragraph basis.

The program should take three text files as input:

  • passage: contains the paragraphs to be analyzed
  • blacklist: contains a list of additional pairs that should be considered as repetitions, such as: eat, ate; begin, began, begun
  • whitelist: contains a list of exceptions that should not be flagged, such as the, a, an, to, for

Specifications:

  • In each paragraph, find the repeated words that are not in the whitelist. The keywords in the whitelist file may be separated with commas or line breaks. You are free to choose the one that best suits your needs.
  • The repetitions should be allowed to differ in case, prefixes, suffixes, declension or in grammatical number. For example: allow and Allowed, friend and friends, eat and eaten should count as pairs of repetition
  • Each pair specified in the blacklist should also be considered as a repetition. You are also free to choose how the words in the blacklist are separated. Ideally, these would be copied from a table of irregularites found by a simple online search
  • It should support alternate spellings of German umlauts and the "double s" character in the list files. For example: Fränze and Fraenze, Jörg and Joerg, Müller and Mueller, Gauß and Gauss. The list need only contain one of these words, but both spellings should be searched
  • The output should write the paragraph number, then list the repeated words and their count. For example: 2: eat*3 + however*5 4: moreover*4 + despite*2 5: began/begun*3

    or any representation that is just as readable

Rules:

  • This is a code golf challenge; lowest byte count wins
  • The input file names are excluded from the byte count
| |
\$\endgroup\$
  • 2
    \$\begingroup\$ How are we supposed to deal with the grammatical variation? We can't possibly implement every single declension/conjugation of all words. Could you provide a list of words/forms which are to be treated as identical? \$\endgroup\$ – Martin Ender Sep 13 '14 at 9:03
  • \$\begingroup\$ @MartinBüttner Good idea! I should add a blacklist file \$\endgroup\$ – Tymric Sep 13 '14 at 13:43
  • \$\begingroup\$ Few people write both the "umlauted" and "non-umlauted" spellings in the same piece of text. One writes, say, "Mueller" because one's environment does not support umlauts. \$\endgroup\$ – Soham Chowdhury Sep 23 '14 at 10:23
  • \$\begingroup\$ @SohamChowdhury True, but I am assuming that the person who writes the lists is not necessarily the same as the person writing the texts (student/teacher for example). Also, some people still prefer one spelling to another even when the environment supports it (For example, "dass" is much more common than "daß", even though they are both used) \$\endgroup\$ – Tymric Sep 23 '14 at 10:31
  • \$\begingroup\$ @Timmy I agree with your first point. \$\endgroup\$ – Soham Chowdhury Sep 24 '14 at 2:17
0
\$\begingroup\$

I liked my first idea, maybe changing the game helps.

Sliding Code

A sliding puzzle, sliding block puzzle, or sliding tile puzzle is a puzzle that challenges a player to slide usually flat pieces along certain routes (usually on a board) to establish a certain end-configuration.

The fifteen puzzle is the oldest type of sliding block puzzle.

enter image description here

The challenge

Write a code that behaves as a sliding board. Given a configuration it should run when such configuration is solvable and not run (aka have compile/runtime errors) if the configuration is not solvable.

Rules

  • The board is your code. It is a 4x4 grid with a total of 15 square tiles with side length >= 1.
  • Each tile, taken alone, should output it's number in the board (from k + 1 to k + 15 with int k of your choice).

Output

Each tile should output its static value (not the actual value). The tile that outputs 13 will output 13 in every different configuration.

The whole board should output true (or 1 or whatever while it express a truthy value) if the configuration can reach the final state: ascending tile numbers on the board from left to right, up to down and the k void tile in the bottom right position.

Score

This is tile , the minimum tile side length wins, meaning a minimum score of 1 can be achieved. If a tie, the greatest k value serves as tie-breaker.

| |
\$\endgroup\$
  • \$\begingroup\$ The tiles should be squares. side*side = side^2 thus the score only depends by the side. I'll remove code-challenge tag. \$\endgroup\$ – Narmer Sep 16 '14 at 14:55
  • \$\begingroup\$ Oh okay, that makes sense then. \$\endgroup\$ – Martin Ender Sep 16 '14 at 14:56
0
\$\begingroup\$

Facing a martian fractal

Fractals are awesome.

They can be used for a very large number of pratical purposes, from antennas to self-similarity of complex networks.

One of the most fantastic uses of fractals tough remains 3D terrain landscaping.

weee! awesome

With such technique you can create awesome landscapes:

This is actually computer generated


Mars is awesome.

The red planet is surrounded in a veil of mistery for its early earth-like life.

Also, as you know, is full of martians:

enter image description here

In this photo we are facing a martian face on mars.


The Challenge

Your task is to create a fractal landscape which resembles the martian face.

  • The prospective can be the most convinient for you as long as the face and the landscape are recognizable.
  • The output should be a few frames GIF of landcape creation, to ensure that fractal approach has been used (just like the one above).
  • You don't need to use the martian face, another landscape can be used as model as long as it has a pareidolic effect of a face in it. You can also not use a model and "draw" the face yourself.
  • Colors are optional. Obviously they will give a greater chance to get more votes.

Here are some other models if you are a bit short of ideas: enter image description here enter image description here enter image description here

| |
\$\endgroup\$
  • \$\begingroup\$ While this sounds quite fun, I'm not entirely sure where the programming challenge is in that. In the end it just comes down to who finds the best parameters for the fractal they use. Moreover, it should be possible to automate this by restricting oneself to using octaves of sines and figuring out which ones to use by Fourier transforming the desired output. \$\endgroup\$ – Martin Ender Sep 18 '14 at 10:31
  • 2
    \$\begingroup\$ At the moment this is too broad and set up as an art contest. You need to define what qualifies as a "fractal approach": saying that you'll eyeball a gif is neither objective nor accurate, because I could just hard-code a mesh, run some simplification, and output the frames in reverse order. And allowing the use of any target model whatsoever means it will be judged on those models. This could be reworked into a programming contest if the program has to search a parameter space to find parameters which make a specific fractal generation technique generate the best approximation to Cydonia. \$\endgroup\$ – Peter Taylor Sep 18 '14 at 10:35
  • \$\begingroup\$ Although that does still leave an issue of hard-coding, as Martin alludes to. \$\endgroup\$ – Peter Taylor Sep 18 '14 at 10:35
  • \$\begingroup\$ I think this slips into the implementation vs output in popularity contests diatribe. In the challenge there is no input, I can't understand how restricting oneself to using octaves of sines and figuring out which ones to use by Fourier transforming the desired output is considered hard coding. Isn't it the point of the challenge? Moreover a fractal approach is self explanatory: generate random fractal terrain, explaining why is fractal and which algorithm was used is answerer's task. \$\endgroup\$ – Narmer Sep 18 '14 at 10:48
  • \$\begingroup\$ I should add that standard loopholes doesn't apply, but at this point I tought it to be paid. \$\endgroup\$ – Narmer Sep 18 '14 at 10:49
  • \$\begingroup\$ It is most certainly not self-explanatory that "a fractal approach" means that randomness is involved. Most of the best known fractals have no randomness whatsoever. The defining attribute of a fractal is debated, so if the spec requires a fractal you should give a working definition, and if you use a common one such as a non-integral Hausdorff dimension then ideally you should provide a link to some kind of tool for estimating it. \$\endgroup\$ – Peter Taylor Sep 19 '14 at 19:52
0
\$\begingroup\$

Position the Border Guard

[Currently INCOMPLETE. Posting here to save.]

You are in charge of defending an island from an invasion force. To do this, you decide to place n guard posts around the perimeter of your island. You decide that the most effective way to ensure that the whole island is equally guarded is to equally distribute your guard posts around the perimeter of the island. In other words, if someone went around the perimeter your island with a surveyor's wheel, measuring the distance between guard posts walking on the perimeter, it would be equal for every guard post. For instance, if the island were a perfect circle, and I had to place 2 guard posts, they would be placed opposite to each other.

Of course, the island is not a perfect circle. We can describe the shape of the island as sequence of arcs joined together as one cohesive shape, like the clouds in this question. The one difference is that in this question, there will never be a hole in the island. Given an input in the form

n island

Where n is the number of guard posts to place and island is a space separated list of comma separated tuples x,y,r indicating the x position, y position, and radius of the circles that construct the island, output n 2-tuples indicating the x and y positions to place the guard posts in.

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

Make a Ray Tracer

A ray tracer is a program which, for each pixel in an virtual screen, traces a path from an imaginary eye through that pixel and calculates the color of the object visible through it.

enter image description here

Ray tracers are famously small enough to fit on a business card! Code and explanation here.

Tired of seeing ray tracers that just render a spheres or a sphere and a box and, if you're lucky, a torus? This challenge addresses this.

This task is to a ray tracer that renders a true color scene specified by arguments. The arguments are:

  1. A triangle mesh, specified by the filename of an .obj mesh file
  2. The diffuse, ambient and specular (more) colors for the entire mesh
  3. A camera, specified by position, direction, up and field-of-view in degrees
  4. A point light source, specified by position and color
  5. A directional light source, specified by direction and color

The output shall be a .ppm file, which can be converted to jpg for inclusion in the answer.

There are lots of .obj files available on the Internet e.g. a teapot, cow and teddy bear and these standard test meshes.

| |
\$\endgroup\$
  • \$\begingroup\$ Very much related: codegolf.stackexchange.com/questions/17270/… ... Also you might want to include a bit more about ambient, diffuse and specular materials, or ray tracing in general. The current spec basically assumes that everyone knows how a ray tracer works. \$\endgroup\$ – Martin Ender Sep 20 '14 at 18:14
  • \$\begingroup\$ Requiring loading an obj and mtl file is a stretch for a codegolf. \$\endgroup\$ – Sparr Sep 20 '14 at 18:23
  • \$\begingroup\$ @Sparr I strip the mtl but the obj is just a few lines, at least in Python. This is codegolf but C and Java etc are going to stand a chance and, by making the input external, entrants cannot try and golf the scene itself. \$\endgroup\$ – Will Sep 20 '14 at 19:31
  • \$\begingroup\$ I don't know what the "normal" of a camera is, but to properly specify a camera takes three vectors, typically position, look, and up. (And some clipping planes, and a width of field). \$\endgroup\$ – Peter Taylor Sep 20 '14 at 20:46
  • \$\begingroup\$ @Will if you're allowing a python library that loads obj files to be used, that's even worse. that puts any language without an obj library at a debilitating disadvantage \$\endgroup\$ – Sparr Sep 20 '14 at 21:58
  • \$\begingroup\$ @Sparr no, I meant loading obj in pure python is not many lines. I picked it as the simplest mesh format out there. The key thing is, if people embed the scene in the code then this becomes an art contest, which is hated with a passion on this site. \$\endgroup\$ – Will Sep 21 '14 at 6:24
  • \$\begingroup\$ @Will You could provide a heightmap as textual input. That would be a suitably simple input case for a code golf, imho \$\endgroup\$ – Sparr Sep 21 '14 at 15:38
  • \$\begingroup\$ @Sparr to convince myself that parsing an obj file is super trivial, here's the pure Python, not even golfed: gist.github.com/williame/5799b75baf6bff3137ba ; obj is just a list of vertices and a list of faces. \$\endgroup\$ – Will Sep 21 '14 at 16:20
0
\$\begingroup\$

Well, I suppose my last suggestion was way too complex, so here's something else.

Blade Competition (Simple Card Game)

enter image description here

Certain RPG's include mini games that are quite a bit simpler than board and card games such as chess and poker, not too hard to implement and understand, but still complex enough to be interesting. So let's play Blade.

Rules

Images are better than words, so here's a short video of me playing Blade. I'm not trying to win, I'm trying to show off some interesting cases. Should be self-explanatory, the goal is to get as many points as possible.

32 cards (see below). 2 players get a deck of 16 cards each (randomly). They both draw 10 cards initially and take turns discarding cards to their field. The goal is to maximize the sum of the card's values on your side of the field.

Before they start taking turns, both players draw a card from their deck and place it on their field. The player with the lower score begins. If their scores are equal, both player a new card from their decks.

When a player discard a card to his field, he loses if his new score is still lower than his opponent's score. When the player's score is higher, the game moves on to the opponents turn. When both player's scores are equal, all cards on the field are discarded, and they draw a new card from their decks as described above.

There are 9 different card. Numbered cards from 1 to 7, whose value is 1-7. And two special cards, called Bolt and Mirror, whose value is 1 when they are used as the initial card.

When a player plays Mirror, both player's fields are exchanged with each other.

When a player plays Bolt, the last card played by the opponent gets invalidated and does not count towards the score anymore. It gets removed permanently once the opponent plays a numbered card 1-7.

A player may play a "1" and discard it to re-validate his invalidated card.

See the github for a detailed explanation of the rules. This is only for reference, the rules as implemented by the controller program are final. If you think there's a bug, leave a comment.

Input

  • stdin
  • One line, including a newline, with a json object representing the current state of the game.
  • json["file"] is the absolute path of a file you may use for storing information, it gets cleared once when the controller program is started.
  • Your program (cli) gets called once for each decision it needs to make.
  • That is, choosing a card to play, or choosing an initial card when there are no cards left in your deck.

Response

  • stdout
  • A number, including a newline, representing the card you wish to play.
  • 0 corresponds to the first card in the json["player"]["hand"] array.

Scoring

  • both players start with a score of 0
  • N (to be decided) turns, timelimit T (tbd), for each turn:
    • Draw: score +1
    • Win: score +2
    • Lose: score +0
  • Each program plays against each other program, the program with the highest score wins. I may add a few players of my own, but they won't be ranked.

Controller Program

Github

ruby controller.rb <playerfile> <timelimit> <rounds> <quiet>

See players.txt for the syntax of the playerfile. Set quiet to y to suppress debug output. Set it to n to to get a lot of information about the match, use this for debugging or if the rules are unclear. See below for a sample match with quiet set to n.

Please provide a cli line I can use to run your program on linux. I might be able to get Windows on a virtual machine.

Deck

Card_Designation Number_of_Cards (Card's Value)

1 2 (1)
2 3 (2)
3 4 (3)
4 4 (4)
5 4 (5)
6 3 (6)
7 2 (7)
B 6 (1)
M 4 (1)

(B=Bolt, M=Mirror)

Sample JSON input

  • link, sample below
  • newlines and spaces added for legibility
  • file is the absolute path of a file you may use for storing information, it gets cleared once when the controller program is started
  • lastmove is the last card played by the player / opponent, or null if no move has been made yet
  • card types 1-7 correspond to the cards 1 to 7, card type 0 is Bolt, 8 is Mirror

Everything else should be self-explanatory.

{
  "file": "/home/.../cg_blade/files/basic",
  "turn": 15,
  "player": {
    "hand": [
      {
        "type": 8,
        "value": 1,
        "valid": true
      },
      ......
    ],
    "field": [
      {
        "type": 8,
        "value": 1,
        "valid": true
      },
      ......
      {
        "type": 7,
        "value": 7,
        "valid": true
      }
    ],
    "deck": 5,
    "score": 30,
    "lastmove": {
      "type": 6,
      "value": 6,
      "valid": true
    }
  },
  "opponent": {
    "hand": 2,
    "field": [
      {
        "type": 3,
        "value": 3,
        "valid": true
      },
      ......
      {
        "type": 6,
        "value": 6,
        "valid": true
      }
    ],
    "deck": 5,
    "score": 32,
    "lastmove": {
      "type": 8,
      "value": 1,
      "valid": true
    }
  }
}

Sample match

Link, sample below.

A sample match generated with the controller program and quiet set to n. A bit long, but shows a few interesting cases.

Match between both players starts.
<basic> vs. <basic>


Initializing round 0.
Each player gets a deck of 16 cards.
Player 0: 3 6 5 3 6 7 B 5 2 4 B B 5 1 B B
Player 1: 1 2 4 4 3 3 M B M 5 2 6 7 4 2 M
Each player draws 10 cards.
Player 0: 1 2 4 5 5 B B B B B
Player 1: 2 2 4 5 6 7 B M M M
Cards remaining in each deck:
Player 0: 3 6 5 3 6 7
Player 1: 1 2 4 4 3 3


Round 0 starts.


Field initialization starts.
Player 0 draws initial card.
Player draws 7, and puts it on the field.
Player 1 draws initial card.
Player draws 3, and puts it on the field.
Player 1 gets first turn.


# Number in parentheses is the total score of the cards on the field.
Turn 0 starts.
Player 1's turn.
Player 0's field: 7 (7)
Player 1's field: 3 (3)
Player 0's hand (10): 1 2 4 5 5 B B B B B
Player 1's hand (10): 2 2 4 5 6 7 B M M M
Cards remaining in player 0's deck: 5.
Cards remaining in player 1's deck: 5.
Player 1 plays 5.
Player 1 ends his turn.
Player 0's field: 7 (7)
Player 1's field: 3 5 (8)


Turn 1 starts.
Player 0's turn.
Player 0's field: 7 (7)
Player 1's field: 3 5 (8)
Player 0's hand (10): 1 2 4 5 5 B B B B B
Player 1's hand (9): 2 2 4 6 7 B M M M
Cards remaining in player 0's deck: 5.
Cards remaining in player 1's deck: 5.
Player 0 plays 2.
Player 0 ends his turn.
Player 0's field: 7 2 (9)
Player 1's field: 3 5 (8)
......
......
| |
\$\endgroup\$
  • \$\begingroup\$ I haven't thought hard about loopholes, but one quick observation: I don't think you specify anywhere how many copies of each card are in the deck. \$\endgroup\$ – Peter Taylor Sep 20 '14 at 20:59
  • \$\begingroup\$ See the detailed rules on github. But you're right, perhaps I should add a note. \$\endgroup\$ – blutorange Sep 20 '14 at 23:38
0
\$\begingroup\$

Calculate an arbitrary linear recursive sequence

in this question given a recursive definition for a sequence we need to output a formula for the given sequence.

in this question, a linear recursive sequence is a sequence of the form:

a_0 = c_0
a_1 = c_1
...
a_{m-1} = c_{m-1}

for n >= m: a_n = x_1*a_{n-1} + x_2*a_{n-2} + ... + x_m*a_{n-m}

where m, c_1 ... c_{m-1}, x_1 ... x_m are all constants.

for example, such a definition (the fibonacci numbers):

a_0 = 0 // c_0 is 0
a_1 = 1 // c_1 is 1
for n >= 2: a_n = 1*a_{n-1} + 1*a_{n-2} // x_1 is 1 and x_2 is 1

the answer may be a function and get input as two lists, one containing a_0...a_{m-1} and one containing x_1 ... x_m, and return a string, or be a complete program and get the input as a space separated numbers.

because polynomials of degree up to 5 can be solved but polynomials of degree 5 or higher can't, the solution may assume that m is smaller than 5.

the output must be a formula that given n returns a_n. if two formulas are different but both return the same output for every index, both of them can be outputted. so, for the powers of 2, both (1+1)^n and 2*2^n - 2^n can be outputted.
in the output √5 denotes the square root of 5, as does 2√5. 3√5 denotes the third root of 5.

Example input and output:

f ([0,1],[1,1]) (fibonacci numbers) can result in ((1+√5)^n-(1-√5)^n)/√5
f ([1],[2])     (the powers of 2)   can result in 2^n
f ([1,2],[1,2]) (the powers of 2 again)   

bonus:
if your solution uses no library function which solves equations, -80 bytes.

this is code golf, so smallest byte count wins

| |
\$\endgroup\$
  • \$\begingroup\$ This seems to hinge largely on solving the polynomial equation for the characteristic roots. For the Fibonacci one, would outputting floats in place of 1+√5 and 1-√5 be valid? \$\endgroup\$ – xnor Sep 25 '14 at 17:59
  • \$\begingroup\$ @xnor what should I do? I guess allowing floats leads to an easier question, but outputting the exact formula is more mathematical. \$\endgroup\$ – proud haskeller Sep 25 '14 at 18:21
  • \$\begingroup\$ @xnor I think floats won't be allowed \$\endgroup\$ – proud haskeller Sep 25 '14 at 18:22
  • \$\begingroup\$ How then would one represent the roots of a fifth-degree polynomial? They're not generically algebraic. Maybe you can restrict to two-term recurrences to get quadratics. It would certainly make solving them and fitting to initial conditions easier, though perhaps that's less interesting. \$\endgroup\$ – xnor Sep 25 '14 at 18:39
  • \$\begingroup\$ Could you please add some {} to your first code block and be consistent with the use of _ to indicate subscripts? At present, it seems to be more work than it should be to figure out how to read the equations. \$\endgroup\$ – Peter Taylor Sep 25 '14 at 22:37
  • 1
    \$\begingroup\$ While it's true that cubics and quartics can be solved in radicals, the solutions are pretty ugly. I strongly advise you to write a reference solution so that you understand what you're asking for before you post the question. \$\endgroup\$ – Peter Taylor Sep 26 '14 at 10:42
  • \$\begingroup\$ @PeterTaylor I was searching for the formulas and found this math.vanderbilt.edu/~schectex/courses/cubic . it is possible, but i guess the best solutions would just copy-paste the variables into the formulas, which isn't very interesting \$\endgroup\$ – proud haskeller Sep 26 '14 at 11:45
  • \$\begingroup\$ @PeterTaylor Maybe restricting to qubic equations and requiring floats instead of √ would be more interesting because the solution will have to actually compute the solutions \$\endgroup\$ – proud haskeller Sep 26 '14 at 11:51
  • \$\begingroup\$ @proudhaskeller I think that allowing floats is cleaner, but there's subtleties there too. Solution might use iterative rather than exact methods to find roots, so you'd need to specify a tolerance and bounds on the coefficients of your recursion. Also, the formula is different when you have a double-root, which solutions might fail to detect due to float precision issues. \$\endgroup\$ – xnor Sep 26 '14 at 21:01
  • \$\begingroup\$ @xnor how is the formula different? I didn't get that \$\endgroup\$ – proud haskeller Sep 26 '14 at 21:04
  • \$\begingroup\$ math.stackexchange.com/questions/129849/… \$\endgroup\$ – xnor Sep 26 '14 at 21:10
  • \$\begingroup\$ @xnor I totally forgot that \$\endgroup\$ – proud haskeller Sep 26 '14 at 21:13
  • \$\begingroup\$ @xnor Maybe the input should be restricted to not include these cases \$\endgroup\$ – proud haskeller Sep 26 '14 at 21:14
0
\$\begingroup\$

Fake the forecast #2

Somewhat unfairly, your boss wasn't happy with your last attempt at forecast fakery.

She's giving you one last chance, with extra stipulations.

This time your task is to draw a map, as a grid of arrows, representing both wind speed and direction.

  • A grid is 8 tiles by 8 tiles.

  • A tile is an arrow representing a direction and a speed.

  • There are 8 potential wind directions, represented by the direction of the arrow:

    1. N N
    2. NE NE
    3. E E
    4. SE SE
    5. S S
    6. SW SW
    7. W W
    8. NW NW
  • There are 6 potential wind speeds, represented by the colour of the arrow (e.g. speeds):

    1. 00F (<20 mph)

    2. 0FF (21-30 mph)

    3. 0F0 (31-40 mph)

    4. FF0 (41-50 mph)

    5. F00 (51-60 mph)

    6. F0F (>60 mph)

There are geographical restrictions:

  • Each tile has a terrain type, land (L) or sea (S). These are:

    S L L L L L S S
    S S S L L L L S
    S S S L L L L S
    S S S S L L L L
    S S L S S L L S
    S S S S L S L L
    S S S L L S S S
    S S S S S S S S
    
  • Wind speed on land may only be between 1 and 4

  • Wind speed at sea may only be between 3 and 6

Variation must be gradual, specifically:

  • If a feature (i.e. direction or speed) differs from one of its 4 adjoining tiles (or 3 for side tiles, 2 for corner tiles) it can only differ by one increment or decrement from that neighbour. e.g. a tile whose neighbour has wind speed 4 may have a wind speed of 3, 4 or 5 (assuming it accords with other neighbours).
  • Directions can loop around, i.e. N -> NW and NW -> N. However, speeds cannot.

Because your boss is looking for believable maps, she has introduced four arbitrary restrictions:

  • There is always at least 1 tile with wind speed 6
  • There is always at least 1 tile with wind speed 1
  • A wind speed of 6 is always northeasterly
  • A wind speed of 1 is always southwesterly

Maps must be unique, don't generate the same map for different inputs.

  • Input is a positive non-zero integer corresponding to the days between now and your forecast (e.g. 1 is tomorrow's forecast, 365 is a year's time).
  • Output can be any format (e.g. image or text) but must take the form of a grid of arrows
  • Output should be reproducible — the same input will always give the same output
  • Each output must be unique from those generated using a lower input.

Because you really need to impress your boss this time, you should aim to give valid output for as many days in to the future as you can. Therefore, scoring is based on input limit:

  • Your submission's input limit is regarded as 1 less than the lowest input that gives non-unique or otherwise invalid output.
  • For instance, if valid and unique output is produced for an input of 1, 2 or 3 but not 4, your input limit is 3.

The winner is the submission with the highest input limit - i.e. the submission which continues to give valid and unique output up to the largest input.

There is a 768 byte limit on source code. If there is a draw the entry with the fewest bytes wins, so keep it short.


Here's an example of valid output (terrain shown for illustrative purposes only):

example

Some clarifications:

  • There needn't be a relation between forecasts, consecutive or otherwise (except that they must be unique).
  • Outside of a submission's 'input limit' there is no defined output.
  • There are no graphical restrictions except those specified.
  • You may supply the terrain definition grid as input - in which case it wont count towards your byte count
  • No other input or fetching of external data is permitted
  • The link to the previous question is purely in theme, no rules are carried across and previous solutions (clearly) wouldn't be valid here.
  • You don't have to draw the terrain type or any other embelishments - you can if you want but it isn't a popularity contest

Sandbox Questions

  • Would this question be marked as a duplicate?
  • Is a 768 byte limit too restrictive? Too easy?
  • Have I left any loopholes?
| |
\$\endgroup\$
  • \$\begingroup\$ 1. I think you need to come up with something more radical than your last question to stop it from being closed as a dup. 2. Why 768? It seems very specific.. \$\endgroup\$ – Beta Decay Sep 29 '14 at 15:49
0
\$\begingroup\$

Translator to Minimize the Number of Characters

With code golf you are attempting to minimize the number of characters or bytes. The languages are, however, all just ASCII characters. While I do not want to see this in other code golf challenges, can you use more exotic characters to do the job?

CJam, for example, only uses ASCII characters in its code but many other characters can be placed into the compiler as a strings. I wrote a simple translator to test this out which can be coverted to:

㉕ァײோ¸༘ݩײ౲ᖒⲫ㶚ቲ㑼ᇦ㰌⧑༘ઃ௉ⲫ௔ྭഞࠗ㒍⾺

While this is intentionally not an acceptable answer for various reasons, it shows the range of possible characters the interpreter can identify. Please note unusual things that happend as you attempt to highlight the text.

The Challenge

  1. Choose an online interpreter such as Ideone, CJam, or Golfscript and a language which can be run on that interpreter. This is so I know I am using pretty much the same resources as you are when I run your answer.
  2. Create a translator in your stated language which accepts an "original" input code from the same language. It then outputs a string which can be pasted in your answer or in a comment on this site.
  3. Create a second translator into which the previous output string can easily be incorporated. When this combined string and translator are run, it will run the original input code.

Please note:

  • The original input code to score your answer will be the same for any answers of the same language.
  • This code for scoring will be subject to change and the translator must work for any code of that language the interpreter accepts. (exceptions listed below).
  • This code for scoring will only contain ASCII characters and I will attempt to take it from existing answers on this site. At request it can exclude line breaks or specific characters for an additional 5% to your score AT MY DISCRESION (for instance Java code needs to be able to have spaces in it, I can't avoid that).
  • The input code for scoring will be roughly 500 characters long. However, you transltors need to work regardless of the length of the input code so you can't take advantage of the fact that the code is even/odd. It does not need to work for null input.
  • Any errors or anything malicious will obviously be disqualified.
  • The compressed code must be copy/pastable to codegolf SE.
  • When running the code from its translated form, the code must be able to accept input. This input is not going to be part of the code to be translated.
  • Any null case which does not compact the original code in any way is disqualified.

Scoring

  • Minimum score wins (surprise surprise)
  • Score is the number of characters you need to run the original code minus the number of characters in the original input code plus 500 (combined with any modifiers).
  • The length of the original translator does not matter.
  • 5% is added to your score for each character/symbol your language often makes use of but your translators cannot handle. I can disqualify for this if I believe that the missing character too severly cripples the programmer.
  • 5% is removed from your score if your two translators are the same piece of code (aka the translation is reversible).
  • 5% is removed from your score if all characters in the compressed output are visible (no invisible ASCII characters). White space (spaces, tabs, line breaks) are visible but ASCII character 19 (for instance) is not.
  • 3% is removed from your score if all characters are visually distinguishible (no two characters look the same but are read differently by the interpreter). The more obvious this is the better.
  • 10% if anyone provides an acceptable example input code where the score without modifiers would be longer than the original input code. This would mean the translator effectively did not compress the input code.
| |
\$\endgroup\$
  • \$\begingroup\$ What's the use of the +500? Everyone's getting it, so the differences don't change at all. \$\endgroup\$ – Soham Chowdhury Oct 4 '14 at 9:30
  • \$\begingroup\$ What happens if you remove/add 5% to a negative or zero score? \$\endgroup\$ – kaine Oct 4 '14 at 10:07
  • \$\begingroup\$ A negative number becomes smaller and zero . . . remains zero. OK, I see your point now. \$\endgroup\$ – Soham Chowdhury Oct 4 '14 at 10:20
  • \$\begingroup\$ 1. A map that is equal to its inverse is called involutive, not reversible. 2. The "input code" should be the same for all submissions. It won't be fair otherwise. 3. The first, third and fifth bonus seem rather subjective. 4. I don't understand the penultimate bullet point. 5. Am I right to assume that number of characters you need to run the original code is the number of characters of the encoded string plus the decoder? \$\endgroup\$ – Dennis Oct 12 '14 at 17:13
  • \$\begingroup\$ THANK YOU FOR THE INPUT. I will try and adress concerns. 1. Ill include involutive if I post is but the map doesnt need to be involutive if the encoder can tell if the input is encoded. That was my intention. 2) the code would need to be in the same language as the language it is programmed in. Wont work for submissions in different languages to have the same input code. 3) ill try to find a way to clarify them. Only the first has a subjective component and would be available to anyone who asks for the point fee. I dont mean look simular, I mean print exactly identical symbols. \$\endgroup\$ – kaine Oct 12 '14 at 17:27
  • \$\begingroup\$ 4) I will try and rewrite it. I meant there is a penalty if the encoder does not shorten some valid code of the appropriate length. 5) yes... These are my initial reactions. I am more than willing to remove bonuses if they complicate things too much. I think i need to include examples. I mean them there to make it easier to promote more answers. I dont want invisible characters but I would rather have answers with them than no answer. Again, thank you for the input. I like the idea and want to see it flushed out better than I probably could. Is there a good way to fix #2? \$\endgroup\$ – kaine Oct 12 '14 at 17:33
0
\$\begingroup\$

Sudden Death Rummy

with following rules: A 50 game match is played and the winner gets an average score per game. This average score is then multiplied by the bytecount of the program. The winner is the program with the lowest product of average score and bytecount.

Rummy is a card game where the objective is to get rid of all cards in your hand by forming "melds". A meld is either a consecutive series of cards in the same suit, or 3/4 cards of different suits of the same value, which is, in ascending order A(ce), 2-10, V(alet), Q(ueen) or K(ing). A meld is always at least 3 cards, and 13 cards at the most.

In my regional variant of discard rule Rummy, there are 7 rounds. the first 6 rounds require you to put down N+2 cards in 1 or more melds, then discard 1 card, then finish your turn, before you can start using existing melds or put down new melds. in the 7th round, you NEED to be able to place down your entire hand and discard the one card in 1 turn, before your opponent can do this. You start with 10 cards, and every turn you cannot empty your entire hand, you draw another card and give the turn to the opponent. The actual system involves buying cards and bidding wars, but to simplify, it's just round robbing cards until one of them finishes.


Your task: Create a Rummy bot that plays against itself.

Input: a number between 1 and 100 denoting how many games should be played.

your program needs to generate 2 random legitimate hands as the first task. The deck starts with 104 cards: 2 full decks, 4 suits per deck, 13 cards per suit. 10 cards per hand from the deck.

second task: one hand randomly starts. If the program cannot make a legitimate Sudden Death Rummy hand clear, it draws a random card and hands the turn to the other hand. If the program CAN make a legitimate hand clear, it displays 2 lines. The first line is a comma-separated list displaying the winning hand clear. The second line is the sum of the value of the cards of the other hand, with number cards being their respective value and A/V/Q/K being 10 points each. this task switches between players until one of them is the winner. If the game lasts long enough for the deck to be depleted, no victor is declared and both hands get scored according to the above rules.

3rd task: after a victor is chosen, the next game starts. task 1 and 2 are repeated until there have been as many games as the input indicates. At this point, the match ends. The victor is the side who has the lowest amount of points after the end of the last game.

[Sandbox Note: I need to: Figure out a scoring method that doesn't require multiplying or averaging average score and bytecount without encouraging high bytecounts or average scores; decide whether to include a runtime limit; Decide whether the program should also display the hand and drawn cards.]

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

Build a Version Control System [WIP]

Git, SVN, Mercurial and Bazaar are just too bloated for you. You want something simple. Something as short as possible.

Rules

  • Your program will be invoked every time an operation needs to be made to the repository.
  • Your program must take commands from command-line arguments.
  • The implementation of how the program stores its own data does not matter. Input and output format do.
  • Give your version control program a name and version numbering (so I can keep track of when you update it).

Repositories

A "repository" is a directory with files and directories in it, as well as (a) special file(s) that store settings and information for the repository. These special files may not be included in version control. All other files in that directory should be included in version control.

Features

  • 'init' command - sets up a repository in the working directory
    • [BONUS 20pts] If a repository already exists in the working directory, erase or reset it first
  • 'destroy' command - removes all of your special version control files from the repository. If you are not in the root directory of a repository, keep moving up one level until you find VCS files. If you reach the top level of the filesystem without finding your VCS files, don't do anything.
    • [BONUS 15pts] Exit with status 1 if no VCS files are found

Scoring

Your score is the length of your code in bytes, minus all bonuses. Lowest score wins.

| |
\$\endgroup\$
  • \$\begingroup\$ What should "every time you change the program" say? I'm not sure whether it should be s/change/run/ or s/program/repository/. \$\endgroup\$ – Peter Taylor Oct 5 '14 at 22:07
  • \$\begingroup\$ Do you need to generate diffs and resolve conflicts? That's a whole challenge on its own. \$\endgroup\$ – xnor Oct 6 '14 at 6:56
  • \$\begingroup\$ @PeterTaylor I mean that your entry into the competition needs to have version numbering - so I can see that you've edited your post and added features. Probably not too important \$\endgroup\$ – user16402 Oct 6 '14 at 9:41
  • \$\begingroup\$ @xnor Currently what I have in mind is a mechanism for committing changes, viewing a log of changes (diffs) and reverting to a particular commit - probably not much more (or if there is more, make it a bonus). By 'resolve conflicts' you mean when users A and B clone the same version, then both submit commits? \$\endgroup\$ – user16402 Oct 6 '14 at 9:43
  • \$\begingroup\$ Yes, usually in version control systems, when two users make parallel changes to the same file, it tries to merge the changes. If they are consistent or to different parts of the file, the changes are merged. If not, a "conflict" is presented with options on how to resolve the inconsistency. See diff3 and en.wikipedia.org/wiki/Merge_(revision_control)#Three-way_merge. This is a tricky algorithmic problem on its own, so perhaps it should be outside of the scope of your challenge. \$\endgroup\$ – xnor Oct 6 '14 at 20:08
  • \$\begingroup\$ @xnor You're right. I think I'll restrict this to a single-user system (i.e. no clone/pull/push). Should those features be available as bonuses though? Or a separate challenge? Maybe the bonus should just be "Implement a system for resolving conflicts, using an external, existing tool for conflict resolution" \$\endgroup\$ – user16402 Oct 6 '14 at 20:45
  • \$\begingroup\$ @professorfish Sounds reasonable, though perhaps you should say exactly what features it needs and what types of tools are OK, lest golfers cut too many corners. For diffs, will changes the to system be provided like "XYZ" inserted after line 1? Or will it be just be given the new file and have to produce the diff from the old file? If the second, then algorithmic alignment is also a challenge. It needs a notion of quality to prevent cheap diffs that claim the user deleted the whole file and added a new one when actually a single line was changed. \$\endgroup\$ – xnor Oct 6 '14 at 21:33
0
\$\begingroup\$

Unbreakable Wall Maria

AND ( OR )

In order to protect the last bastion of human civilisation against giant Titans, a large wall has been constructed around the perimeter of the city. It has been decided that another large wall, within the perimeter of the first one, will be erected to ensure the protection of the city. You have been assigned to design the wall to make sure it is strong and sturdy.

A wall of height p and length q is built out of identical rectangular blocks of height m and length n. A wall is considered unsecure if there is a straight line that can divide the wall into two pieces without cutting through any of the individual blocks. To illustrate, consider a wall of height 5 and length 6, constructed of blocks of 1 height and 2 length placed in either orientation. This is the test case 5 6 1 2 (a 5x6 wall composed of 1x2 blocks). There are at least two different ways of building this wall:

Image illustrating ways of presenting the walls
Diagram 1: Ways of building a wall

The first wall is an insecure wall because there is a line that divides the wall into two pieces (into a 6x4 block and a 6x2 block). Because there is only one line that divides the wall, we can call this wall an insecure-1 wall. An insecure-1 wall is more secure than an insecure-2 wall, but not as secure as a secure wall.

The second wall is a secure wall because there is no line that can divide the wall into two pieces without going through any of the blocks. You could also think of it as insecure-0 if you wanted to.

A secure wall is essential to the integrity of the wall. If it is an insecure wall it will be easily breached by the Titans. Your task is to design the wall. To do this, you will write a program that takes in the height and length of the wall and the blocks as input, and output (a graphical representation / an ASCII art representation) of the most secure wall that can be created using the blocks given.

Input

Input consists of four space seperated integers p, q, m, and n, which represents the height of the wall, the length of the wall, the height of the blocks, and the length of the blocks.

Output

This is the part I'm not sure about. I've got two possibilities: either I can make the question graphical output (i.e. I would expect the program to output an actual image), or ASCII art.

Possibility 1:

Output a graphical image (not ASCII art) of the wall. The overall appearance of the wall (e.g. line thickness, colours used, size, etc.) is up to you, but the lines that form the individual blocks must be clearly visible, and differentiated from the rest of the wall. This means you can't pull something like "this draws a black wall with black lines", or "this draws an infinitesimally small scaled wall", etc.

Possibility 2:

Output text based art (not a graphical image) of the wall. It should be drawn using the box drawing characters. The wall must be drawn to scale, but apart from that, you have some freedom in what characters to use (so you can choose to use the double line ones if you wish), but they have to be part of the Box Drawing Unicode block. In addition, the wall must be visible, so you can't write a program that outputs nothing and say "this draws an infinitesimally small scaled wall", etc.

Question to reader: Which output format do you think would make a more interesting challenge?

| |
\$\endgroup\$
  • \$\begingroup\$ As is, this seems like a math problem rather than a coding challenge. There's probably a criterion one can derive without needing to test tilings in code. But I like the idea behind the challenge. May I suggest something like generating or testing for secure walls? \$\endgroup\$ – xnor Sep 25 '14 at 3:04
  • \$\begingroup\$ ​​​​​​​​​​​​​​​@xnor I found that there was indeed a closed form solution for any case of the problem. Generating wall positions sounds like a good idea. I'll rewrite. \$\endgroup\$ – absinthe Sep 25 '14 at 3:20
0
\$\begingroup\$

One digits or two digits

Here’s the rule:

They're 2 players. Each player has a pool of $99.

The player that takes the first turn will choose to invest an amount of $$$ taken (deducted)from your own pool. Then other player will do the same.

Who invests more wins the round. Who wins the most round is the match winner.

Unless it’s not that simple.

They’re a few twist:

Your opponent know how many points you use, well almost.

After you invest, your opponent know if you invest one digit number or two digit number. They’re told instantly after you invest your points. Just one or two digits. Not precisely.

WARNING: Player who moves first still get notified about your opponent who moves second.

Your opponent know how many points you still have left in your pool, well almost.

They’re only told if you have either $0 to $19, $20 to $39, $40 to $59 points, $60 to $79 points or $80 to $99. They’re told instantly after you invest your money.

WARNING: Since the notification is instant, that means if I move second, I got to know your score level before I move. If I notice a level change when you move first, I will know the level change before I make my move second. So I can act according to it.

It’s best of 9, and those $99 must survive those 9 rounds.

So you don't want to invest all $99 in round 1. Well, it doesn’t mean that you have to spread those $99 exactly in 9 rounds. You can use those $99 in any mean to get victory. If you have a sure-fire strategy that will give you a guaranteed win, but it needs you to use all your $99 in the first 5 round, by all mean, go. Just remember that invested point don’t return back to your point pool, win or lose.

In first round, the player who moves first decided randomly. In following round, the player who wins previous round moves first. If tie, the player who moves first last round, moves first again


SCORING METHOD

Each bot will be run double robin. The winner of the match results 1 point. Tie 1/2 point. Lose 0 point. After the match up, bot with most points declared as champion


COMMUNICATION PROTOCOL

During your turn, I will run your program and gives you lines of query from STDIO

Each line is a query of this following type:

START

Every input start with this.

YOU xx

This means that in that round, you played xx(exact number of dollar you invested)

ENEMY x y

This means enemy invest x digit int that round (x is 1 if enemy invested 1 digit, x is 2 if enemy invested 2 digit) and y is the money level after the player invests(y is 0 for $0 to $19, 2 for $20 to $39, 3 for $40 to $59, 4 for $60 to $79, 5 for $80 to $99)

FINISH

End of query. We expect you to give us output.

Your output must be to stdout and a single positive integer (0 is allowed)


EXAMPLE:

The match is between DEO vs WORLD. It was decided that DEO moves first.

ROUND 1

Deo will receive this query:

START
FINISH

Deo decides to invest $10. Now he only has $89.

WORLD receive this query:

START
ENEMY 2 5
FINISH

What WORLD deduces is that DEO played from $10 ~ $19. WORLD knew that DEO played at least $10 because the query said that ENEMY 2.. and WORLD knew that DEO played at most $19, because if DEO played $20, the query will be ENEMY 2 4

WORLD decides to invest $20.

In round one, DEO invests $19 while WORLD invests $20. Since WORLD invests more, WORLD receive 1 point.

Enter to round 2: WORLD starts first, since winner starts first by the rule

WORLD receive this query:

START
ENEMY 2 5
YOU 20
FINISH

WORLD decides to invest $0.

DEO receive this query:

START
YOU 19
ENEMY 2 4
ENEMY 1 4
FINISH

DEO realizes that in round 1, enemy played at least $20, due to level change. And he noticed that in round 2, enemy played 1 digit number. DEO taught that WORLD decides to save his money and invest $0. DEO decides to invest $1

WORLD invests $0 while DEO invests $1. Since DEO invests more money then WORLD, DEO win 1 point.

And so on

| |
\$\endgroup\$
  • \$\begingroup\$ what happens if both players invest the same number of points? Also, it seems you could guarantee a tie as player 1 by investing 0 in the first round (guaranteed loss/tie the round), then investing 99 the second round (guaranteed win/tie the round). \$\endgroup\$ – stokastic Oct 24 '14 at 20:38
  • \$\begingroup\$ @stokastic None wins the round. You do realize that you need that it's best of 9. So if I follow your strategy, I will get 1 point by round 2, however, my opponent easily wins the next 5 and end the game (since I already use all of my 99 ). \$\endgroup\$ – Realdeo Oct 25 '14 at 8:15
0
\$\begingroup\$

Traffic lights

Easy challenge

Write a program that that graphically shows traffic lights on a crossroads. It should output animation. There should be red, red+yellow, green, blinking green, yellow. Bonus - pedestrian traffic light.

Complex challenge

Write a program that manages traffic lights in a town. Input is a graph of roads, information about where people want to drive (i.e. in morning they mostly drive at work, in evening they return home) tied to the graph. The system models cars and reports you current positions and speeds of each car. Drivers' goals are to be inferred from statistics. Your goal is to provide the most optimal operation mode of each individual traffic light, avoiding accidents.

Questions

  • Which tags to use? Should it be a ?
  • Which is more viable - the easy or the complicated challenge? Should I try to work the complicated one to be more CodeGolf-worthy?
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I think both of these challenges are too vague for this site. In the first, you should provide precise requirements defining a 'traffic light.' For example, the cloud in this question is extremely well defined. Your second proposal could work as a code-challenge, again if you add much more precise requirements. \$\endgroup\$ – FryAmTheEggman Oct 28 '14 at 18:54
  • \$\begingroup\$ I see you're from Belarus. You have blinking green traffic lights there? I've not seen them in any of the 5 countries I've lived in. Don't assume people will know the exact sequence you want to use. Also in the USA you can turn right on a red light, but in western europe I've never heard of this. I would go for the easy challenge first, but you need to specify it more. How should it be displayed (I'm assuming plan view, light drawn on the right hand side of the road as seen by the driver with red nearest the intersection?) Is there a specified timed sequence or does it depend on demand? \$\endgroup\$ – Level River St Nov 9 '14 at 13:35
0
\$\begingroup\$

My telephone is a computer!

I finally took the plunge and purchased a push-button telephone. It seemed a waste to just bin the old telephone, so I got working with some surplus chips and boards and things, and a soldering iron, and made it into a computer!

Now I need a program. DialCode(c) can do Prime Numbers! I think.

So I need some help with an algorithm for Prime Numbers, with the following limitations:

10 variables, which can contain any number from zero upwards, limited only by 32,767; (Var0 - Var9)

10 labels; (Label0 - Label9)

10 Machine Instructions;

EndBlock: Ends a block - if the block was actioned, implicity Continue Main is executed, 
otherwise continues with next instruction (EndBlock) 

Test > 0: Starts a block, can test multiple variables (If > 0 Var0 ...)

Test = 0: Starts a block, can test multiple variables (If = 0 Var0 ...)
 
Set variable to another variable (Var0 = Var1)

Set variable to 1 (Var0 = 1)

Set variable to 0 (Var0 = 0)

Increment variable by 1 (Var0 +)

Decrement variable by 1 (Var0 -)

Unconditional branch to label (Br Label0)

Continue MAIN (Continue MAIN)

Output variable (Output Var0)

Instructions prior to the first Test are executed only once, at the start of the program.

Continue MAIN can be within a block or a "special case" unconditional use which is the target for the completion of a non-nested block.

The first Test defines MAIN.

MAIN is executed an "installation setting" number of times. These are 10 for Testing, and 1,200 for Production.

A Test can define an internal block if appearing before an EndBlock. The completion of an internal block does not cause automatic iteration (but an explicit Continue MAIN can be used for that).

All variables are initially zero.

Example program

Var1 = 1 
If > 0 Var1 Var3 
    Var2 +
EndBlock
If > 0 Var2
    Var1 +
    Var3 +
EndBlock
Var2 +
Continue MAIN
Output Var1
Output Var2
Output Var3

MAIN is defined here by the first IF > 0. The first test is not true. The second test is not true. Var2 gets one added, and MAIN starts up again (the unconditional Continue MAIN). The first test is still not true. The second test is now true, and Var1 and Var3 get one added. Since the block was executed, there is an implicit Continue MAIN. From this point on, the first IF > 0 will always be true, its block will be executed, with another implicit Continue MAIN so the program will finish quickly.

The above program demonstrates how to implement a "case-like" structure. Put another way:

Var1 = 1
BlockControl repeat 10 times
  case
    Var1 > 0 And Var3 > 0
      Var2 +
      break
  case
    Var2 > 0
      Var1 +
      Var3 +
      break
  case
    other
      Var2 +
EndBlockControl
Output Var1
Output Var2
Output Var3

The output from the program will be 2, 9, 1.

Algorithm can be demonstrated in any language, even pseudo-code (if guaranteed to work). Explanations will probably make your Answer more popular.

It is not required to write an emulator of the CPU, only to limit your choice of instructions in your language to those logically equivalent to what is supported by the CPU. DialCode(c) itself is a subset of your language (subject to differences in syntax)!

There is no input. Output can be whatever is convenient. Feel free to use any specialist libraries, as long as they follow the above limitations.

The Winner must work to the limitations. The most popular working algorithm will be chosen. Where submissions are effectively the same algorithm, the one posted first, which I was able to understand, is the tie-breaker.

Sandbox Questions

I can't find a question here about generating Primes only using addition and subtraction. I know one way to do it, so all the guff above is to funnel thought towards a known solution. The solution I've seen uses 10 variables, 10 or fewer types of instructions, and Labels are fun, but not necessarily necessary.

Not sure of a reasonable time-limit to impose before the Accept.

When I came across an algorithm for this, I thought it was really cool. Very easy to implement without knowing how the algorithm actually works, difficult to come up with the algorithm. Great fun finding out how the algorithm works.

I would like to see a wide range of answers in a lot of languages, so that even fairly inexperienced users can have a crack at implementing. That's not going to work with one question, because I don't think it is an easy type of algorithm to develop (without foreknowledge or practice).

So I was thinking one question to get an algorithm, a second question for implementation. I was thinking of "fastest code" but that puts Assembler/compiled languages/others as the natural rankings for that.

Prompted by a comment by @isaacg, I'm now thinking "total number of DialCode(C) instructions executed" may work for a follow-up implementation question.

So, Question One - get a nice algorithm. Question Two, implement in as few DialCode(C) instructions as possible.

Any implementation is going to be Ssssslllllooooooowwwwww, with a capital S. Fewest DialCode(C) instructions is fastest code, whatever language the DialCode(C) is written in. Reasonably level playing field.

I'll have a go at the suggested shortening of the question :-)

| |
\$\endgroup\$
  • \$\begingroup\$ I like the challenge, but three comments: 1. The post might be a bit long, try to shorten it up a bit. 2. Why is it a popularity contest? Why not have an objective victory condition, e.g. fewest instructions? 3. What does this have to do with a telephone? \$\endgroup\$ – isaacg Oct 24 '14 at 19:36
  • \$\begingroup\$ @isaacg Thanks. In reverser order; the telephone solely as a massively humorous way to limit everything to 10; perhaps not everyone can come up with an/the algorithm, but pretty much anyone can implement the algorithm, I didn't want APL 3 and everyone goes home, I want algorithm, and if successful a follow-up for implementation; if I take the humour out, it should be much shorter... \$\endgroup\$ – Bill Woodger Oct 24 '14 at 21:22
  • \$\begingroup\$ Okay, I think I get the humor, and that seems good. Perhaps you could have the tiebreaker between people with the same algorithm be fewer number of operations in your language used, not fewer characters. \$\endgroup\$ – isaacg Oct 24 '14 at 21:25
  • \$\begingroup\$ @isaacg Thanks again. I'll update the Sandbox Questions bit to try to expand on my thoughts on the follow-up. \$\endgroup\$ – Bill Woodger Oct 24 '14 at 21:39
  • \$\begingroup\$ Awesome, I'm looking forward to the question. \$\endgroup\$ – isaacg Oct 24 '14 at 21:43
  • \$\begingroup\$ @isaacg Finally got some time cleared to update this and cover the release. Any further suggestions, more shortening or otherwise, welcome. \$\endgroup\$ – Bill Woodger Oct 30 '14 at 16:42
0
\$\begingroup\$

This is an idea for an incremental answer-dependent question. I'm interested in comments. I will keep it here for a while and probably reword it at some point.


Print the name of the language of the previous answer

The first answer to this question must print the name Code-Golf without using any letters in Code-Golf.

Each answer that follows will have to print the name of the previous language, but without using any characters in the previous program (you can use letters in the language name, but not the code they posted). Each language can only be used once.

The winner is whoever posts the most valid answers. If there is a tie, then the length of each program is added together, and the answerer with the smallest total length is the winner.


The main problem I see with this is that multiple people would be racing towards the next answer. Allowing people to still post answers they worked on would cause clutter, and if people sign up to be the next answerer, we could be waiting forever for one to post. You could possibly have another question for answers that were too slow.

I would also need a rule against posting extraneous characters in your program that makes it impossible for the next one.

| |
\$\endgroup\$
  • \$\begingroup\$ Would repeating languages be allowed? Would there be an answer time limit for users? Is Unicode allowed? You could limit answers to 40 distinct chars instead of forbidding extraneous characters, which is very subjective. \$\endgroup\$ – Calvin's Hobbies Oct 30 '14 at 23:20
  • \$\begingroup\$ @Calvin'sHobbies I like the 40 distinct character limit idea! Repeating languages is not allowed, and I don't know what would be a good time limit for users. I think allowing Unicoding makes sense, unless that could be abused badly or gets boring. Thanks for the feedback! Did 8 hours feel too long or too short or just right on your Hello World question? \$\endgroup\$ – hmatt1 Oct 30 '14 at 23:26
  • \$\begingroup\$ I think it should be at least 2 hours. Though 8 or higher is better if you're scoring by number of answers, just so people only have to post a couple times a day to be a contender. One issue with this is that even with 40 unique chars it could continue on practically forever (as long as people find new languages), so I'd suggest more restrictions. Maybe something like the first language has to start with "A" the second with "B", the 26th with "Z" the 27th with "A" again.... \$\endgroup\$ – Calvin's Hobbies Oct 30 '14 at 23:38
0
\$\begingroup\$

Elevator Controller


Sandbox Note

  • I would love some feedback about whether you think this has enough room for algorithmic finesse to stick with or whether it should be .
  • Any kind of early questions or ideas are welcome, too.

Introduction

Every day on my way to work I have to take one of two neighboring elevators – and often, they are not currently on my floor, so I have to press a button and wait for it to stop by. Ever so often, I get the feeling the software behind these elevators was written by an army of monkeys who finally managed to type some program that would compile.

But it makes me think: isn't there a more clever way to manage elevators? Maybe you can help me make my way to work less annoying by implementing a new controller software!

The Challenge

You must write a complete program that takes input from stdin (or similar) and print to stdout (or similar). Your program will receive the following arguments:

  • The first line consists of two space-separated numbers:
    • The number N of neighboring elevators your software will have to manage.
    • One integer H specifying the number of the top floor level for the building (the ground floor level is marked 0, so H = 5 means there are six stories).
  • All subsequent lines of input are a space-separated list of two numbers in the range [0, H] with the following meaning:
    • The first integer specifies the level on which a passenger is requesting an elevator.
    • The second integer specifies the level this passenger would like to get to.

During each time tick, your program must print (to stdout or similar) one line with N characters wherein each character specifies what an elevator does (from left to right = first to last elevator). The following commands are available:

  • D for "Move elevator one level down."
  • U for "Move elevator one level up."
  • S for "Stop the elevator on this level." This command allows any number of passengers to enter or exit the elevator on this level. This will happen automatically and people will only exit the elevator on the level they want to get to.

Furthermore, all elevators are rather small and have a maximum capacity of 2 people. So no elevator can take more than two people. Since people are generally nice, they apply a first come, first serve pattern. Passengers who are "too many" will just wait the next turn.

If two (or more) elevators happen to stop on the same level with people waiting to enter, they will start filling up the elevators from left to right.

All N elevators will start on the ground level – 0 – upon start of the program.

As always, standard loopholes apply. No cheating, no networking etc. If possible, please submit your answer with a link to an online interpreter or instructions on how to run it.

Example

Input:

2 3
2 0
3 1

Possible Output:

UU
UU
SU
DS
DD
SD
SS

Here are more examples, but to keep the post short, newlines are represented as | and input/output is separated by #:

2 3|0 1|0 2|0 3 # SS|UU|SU|UU|SS|US|SS

1 2|0 1|1 2|1 0|1 0 # S|U|S|U|S|D|S|D|S

Scoring

This is a . There will be an unknown test case which I will only reveal after having accepted the winning answer (so you can make sure I didn't make scores up), but not before as to prevent answers optimizing for that test case only.

The score will be the number of steps your submission prints (= number of lines of your program's output). The lowest score wins with votes as a tiebreaker.

Verification

You may use the following snippet to verify your submission:

TODO (I will write this once I plan on publishing this question)

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

The Invincible Rock Paper Scissors

Make a bot that plays Rock Paper Scissors with the player. The bot should prompt the user for input (either rock, paper, or scissors) and then output the result. The result should include the user's hand, the bot's hand, and who won. An example of an acceptable result output would thus be:

I played rock! You played scissors! I won!

Another acceptable output:

The bot's rock beat the player's scissors.

This is the underhanded part: the bot should always win. However, the player has access to the source code of the program, so you should try and make the part of the code that causes the bot to always win as inconspicious as possible.

Here is an example in Python 2.x. If it were posted, it would not get many upvotes because it is extremely obvious that the bot will always win. A better answer would appear to be fair to the player, but in fact still causes the bot to win every time.

user_choice = raw_input("Pick a hand (rock, paper, or scissors)...")
if user_choice == "rock":
    print "I played paper! You played rock! I won!"
elif user_choice == "paper":
    print "I played scissors! You played paper! I won!"
elif user_choice == "scissors":
    print "I played rock! You played scissors! I won!"

Concerns

My main concern with this challenge is that it may be a close duplicate of random script that isn't actually random. I am not sure if the requirement for having a different output for the user's input (while maintaining the illusion of randomness) is enough to differentiate this challenge from the original underhanded random challenge. Feedback on this issue is appreciated.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ In my opinion, "underhanded" does not imply "always win." I think there are many more options for underhanded behaviors. For example, someone could write a RPS program with a weakness to be exploited by those with "insider info." That can help this challenge avoid being a duplicate. \$\endgroup\$ – PhiNotPi Nov 8 '14 at 17:47
0
\$\begingroup\$

Calculate the Delacorte Number of a square - posted

| |
\$\endgroup\$
  • \$\begingroup\$ Please help me improve this and add it to the directory (I can't). How to get syntax highlighting here? Please vote if you think it is a good idea and should be posted. \$\endgroup\$ – maf-soft Oct 24 '14 at 10:57
  • \$\begingroup\$ I think you should include all relevant definitions in sufficient detail so that the challenge is self-contained and people don't need to follow the links to understand the challenge. \$\endgroup\$ – Martin Ender Oct 24 '14 at 12:35
  • \$\begingroup\$ Thanks for the comment, I was also thinking about it. My current short explanation is a little golfed itself :) - but I have an explanation, I have an example and the expected result (just added, please refresh). What is your suggestion I should add from the linked page? I think it is not necessary to have the same detail. \$\endgroup\$ – maf-soft Oct 24 '14 at 13:23
  • \$\begingroup\$ It's more readable to put the short explanation first and then the link to a more detailed explanation. I don't think that a more detailed explanation is necessary, though, as long as you clear up the ambiguity about which metric you're using for "distance²". It would be good to have a test case which is a bit less structured. It would be very good to have a brief statement of motivation (which would seem to be that there's a contest to maximise and minimise Delacorte numbers for a given side length). \$\endgroup\$ – Peter Taylor Oct 24 '14 at 17:05
  • 1
    \$\begingroup\$ Finally, if the space dedicated to explaining your scoring system is 4 or 5 times as much as the space dedicated to explaining the problem, you've probably over-complicated it. What's wrong with asking for a function which takes the square as an array or string, optionally with a second argument giving the side length? \$\endgroup\$ – Peter Taylor Oct 24 '14 at 17:09
  • \$\begingroup\$ Ok, I improved it, what do you think now? Regarding the over-complicated rules: I am pretty new here, and from the code-golf-challenges I have seen, I got the feeling that this detail is necessary. I would prefer the same fixed rules (or a set I can choose from) for all challenges, so it would not be necessary to post them here. Asking for a function sounds wrong because some languages have a different concept. With my code examples I just wanted to give a feeling about the intentions, but I cannot do that for all languages... Side length should not be given as input, only the square. \$\endgroup\$ – maf-soft Oct 24 '14 at 19:29
  • \$\begingroup\$ Thanks for adding this to the directory. I will post this soon if I don't get any more comments. Is the Title ok? Any hints? It's my first one. \$\endgroup\$ – maf-soft Oct 31 '14 at 14:43
  • \$\begingroup\$ If you want a specific person to see a comment, you should use an @ tag: e.g. @maf-soft. The reason you were notified about Martin's and my comments was that they're in reply to your answer: I've only just seen that you replied to me because I came looking for the question to ask how you're getting on in the actual contest. I still think it would benefit from saying that you're measuring Euclidean distance (as opposed to e.g. Manhattan distance). \$\endgroup\$ – Peter Taylor Nov 3 '14 at 23:27
  • \$\begingroup\$ As for the scoring: code-golf implies a set of rules, and there are some currently active discussions in meta.codegolf about default assumptions on program vs function and forms of I/O. \$\endgroup\$ – Peter Taylor Nov 3 '14 at 23:28
  • \$\begingroup\$ @PeterTaylor, thanks. Is that you in the highscore list? :) I currently don't have the time to work on it, but i will. It's fun! Of course you are right, that it's not immediately clear what distance is meant. But I think, due to the examples, it is clear enough. I think it's ok and intended, when contestants have to think a bit :) \$\endgroup\$ – maf-soft Nov 4 '14 at 9:49
  • \$\begingroup\$ Yes, that's me. I'm quite pleased with how well I've managed to do already with fairly basic techniques. \$\endgroup\$ – Peter Taylor Nov 4 '14 at 10:09
  • \$\begingroup\$ @PeterTaylor, yes, reaching a score of 24.5 of the maximum 25 doesn't require very clever-clever effort :) but you will see, getting under the top ten is really hard and you need a lot of free time, I don't have. Two months left! \$\endgroup\$ – maf-soft Nov 5 '14 at 10:22
  • \$\begingroup\$ It's posted now (did I do it right?), can anyone remove it from the dictionary? \$\endgroup\$ – maf-soft Nov 10 '14 at 15:58
  • \$\begingroup\$ @maf-soft I removed it from the directory. The next step is deleting this sandbox answer to clear up space. \$\endgroup\$ – PhiNotPi Nov 10 '14 at 17:04
0
\$\begingroup\$

Lua Variables From Arguments?

In this question I challenge you to get variables from function arguments in Lua. The least amount of characters wins.

Basically I'm asking for you to create a function that takes an argument, and prints out the variable as a string.

Please note it has to work in a standalone Lua console.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ I don't know Lua, but I have no idea what this is asking. Do we need to extract the names of the arguments? Their values? You will probably benefit from including an example input/output for this program/function... \$\endgroup\$ – FryAmTheEggman Nov 14 '14 at 22:17
  • \$\begingroup\$ @Fry The variable, for example function hello(m) print(m) end m is an argument, the variable is m. \$\endgroup\$ – warspyking Nov 14 '14 at 22:26
  • 1
    \$\begingroup\$ @warspyking This definitely needs a proper spec. I do know a little Lua, but I'm still not sure what you're asking for. Please provide examples. Also, I should warn you that language-specific challenges are usually frowned upon, unless there are some reasons why the challenge only makes sense in that particular language (which I can't tell yet). \$\endgroup\$ – Martin Ender Nov 14 '14 at 23:28
  • \$\begingroup\$ OK, so that is still quite ambiguous: do you mean for us to get a reference to the variable? You need to tell us precisely where we get the information from (STDIN, file, etc) and precisely where and how to output it in the question. As it stands, this would be closed as unclear if posted. \$\endgroup\$ – FryAmTheEggman Nov 15 '14 at 0:03
  • \$\begingroup\$ @Martin Why is language specific questions frowned upon? \$\endgroup\$ – warspyking Nov 15 '14 at 0:11
  • \$\begingroup\$ @Fry I added a little more detail in. \$\endgroup\$ – warspyking Nov 15 '14 at 0:12
  • \$\begingroup\$ @warspyking Because most of the time, there's no good reason to exclude people from your challenge you don't happen to know the same programming language as you (and quite often, language-specific challenges are a good indicator that someone's trying to use PPCG to outsource their homework, although that's probably not the case here). So if this challenge makes sense in other languages, you should try to be inclusive. And you should really add an example to show us what exactly you're asking. \$\endgroup\$ – Martin Ender Nov 15 '14 at 0:33
  • \$\begingroup\$ @Martin I don't know any other language to be able to confirm the answer. \$\endgroup\$ – warspyking Nov 15 '14 at 0:45
  • \$\begingroup\$ @warspyking If you added an example, some people might be able to tell you. ;) \$\endgroup\$ – Martin Ender Nov 15 '14 at 0:46
  • \$\begingroup\$ If I understand the refined question correctly, the goal is to retrieve the parameter names for the parameters of a function from inside the function itself, using reflection-style capabilities. With some help, I think that could be turned into something language-agnostic (though it'd need some good way of disallowing hardcoded results). \$\endgroup\$ – FireFly Nov 15 '14 at 0:50
  • \$\begingroup\$ @FireFly Yep, you've understood it correctly. \$\endgroup\$ – warspyking Nov 15 '14 at 0:55
0
\$\begingroup\$

Number Datasheets

Write a program that accepts an integer n where 1 < n < 10000 and prints some facts about it. Each fact must be on a separate line, and in the order shown here.

  • even or odd
  • prime or composite
  • deficient, perfect, or abundant
  • square if it's a perfect square
  • cube if it's a perfect third power
  • fourth power if it's a perfect fourth power
  • fifth power, sixth power, etc. as appropriate (each on a separate line)
  • square-free if it has no factors that are perfect squares (except 1)
  • triangular if it's a triangular number
  • pentagonal if it's a pentagonal number
  • hexagonal, heptagonal, octagonal, nonagonal, decagonal as appropriat
  • 11-gonal, 12-gonal ... k-gonal. However, these should only be printed if k is less than n or if k is less than 10. In any event, each of these term is to be on a separate line.
  • x totatives where x is the count of the numbers between 0 and n that are coprime to n
  • lucky if it's a lucky number
  • Fibonacci if it's a Fibonacci number
  • Lucas if it's a Lucas number
  • Leonardo if it's a Leonardo number
  • repdigit in base b if it's a repdigit in base b, where 1 < b < n-1
    • If it's a repdigit in multiple such bases, instead print repdigit in base b, c, d
  • strictly non-palindromic if it's not a palindrome in any base b where 1 < b < n-1

Any feedback would be appreciated.

| |
\$\endgroup\$
  • 5
    \$\begingroup\$ Needs more links. I'd remove the polygonal numbers - that's a lot of hard-coded names to effectively duplicate your earlier question. \$\endgroup\$ – Peter Taylor Nov 18 '14 at 7:42
  • \$\begingroup\$ How many powers do we need to support? And are empty lines in the output allowed? \$\endgroup\$ – Martin Ender Nov 18 '14 at 10:12
  • 5
    \$\begingroup\$ I think you're asking for too many things. I wouldn't want to code all those different properties. Maybe cut down to about 5? \$\endgroup\$ – xnor Nov 19 '14 at 8:35
  • \$\begingroup\$ I agree with xnor that there's too many things here. Regarding @MartinBüttner's comment, the first thing I would change is limit the powers to no more than cube, and polygonal numbers to no more than triangular. You need to clearly define all the different types of number too. There's a difference between polygonal numbers and centred polygonal numbers that would need to be clarified. Off the top of my head I have no idea what lucas and leonardo numbers are \$\endgroup\$ – Level River St Nov 27 '14 at 20:38
0
\$\begingroup\$

Math golf

This challenge is about writing code that outputs the smallest formula possible for a sequence of position integers.

Input

I will choose 10 from the following test sequences of positive integers. However, please do not hardcode these into your answers. If I suspect this has happened, I reserve the right to change the test sequences without notice.

Your code should accept standard in with one list of comma separated sequences per line.

1, 2, 7

12, 9, 7, 5

40, 25, 16, 10, 7

2240, 1225, 679, 373, 213, 149, 141, 133

8064, 3969, 1969, 974, 494, 254, 164, 134, 119

118272, 53361, 24196, 10958, 5027, 2399, 1271, 863, 746, 695, 668, 665

1, 4, 36, 400, 4900

96, 1280, 17920, 258048, 3784704, 56229888, 843448320

72, 800, 9800, 127008, 1707552, 23557248, 331273800

40, 224, 1064, 3808, 21280, 59200, 322600

2240, 832, 240, 72, 20, 6, 3

53760, 17152, 4480, 1248, 384, 104, 44, 22, 11

329472, 86656, 20800, 5536, 1536, 440, 124, 44, 19, 8, 4

32800768, 6856704, 1536000, 394752, 103936, 27136, 7936, 2080, 656, 264, 132, 66, 33

206389248, 33216512, 7029760, 1743360, 448000, 112640, 30144, 8288, 2096, 688, 284, 102, 46, 18, 9

20956446720, 2527756288, 510181376, 122363904, 30720000, 7643136, 1972224, 508416, 136192, 35456, 10816, 3296, 1360, 632, 292, 146, 73

Output

A math formula per input line which maps an index n starting at 1 to the relevant value.

A formula can be made up as follows. It can consist of the sequence variable n, integer constants, *, /, -, +, !, (, ), ^ or (m,k). These are to be interpreted in their normal mathematical sense with (m,k) to be read as binomial(m,k). The formula has to be well formed with, for example, parentheses matching and the order of precedence of operators will be the usual mathematical ordering.

A special rule applies to the factorial function ! which requires parentheses if the ^ or ! operators are to be applied to the result of the factorial. I.e. it is (n!)^2 and not n!^2. Note that the !! is never allowed. Unary - also requires brackets if any further operator is applied to the result on the left hand side or if the result is to be raised to a power. For example it is n*(-1) and not n*-1.

Score

I will test your code on a number of sequences of integers that I make.

The score is the sum of the number of characters in all your outputs.

Example output

For the sequence that starts 96, 1280 above, the output 4^(n+1)*(2*(n+1))!/((n+1)!)^2 gives a score of 29.

| |
\$\endgroup\$
  • 3
    \$\begingroup\$ It's an interesting idea, but it sounds brutally hard in the absence of gimmicks. There is, generally speaking, no systematic or efficient procedure for turning a sequence of numbers into a formula. \$\endgroup\$ – COTO Nov 21 '14 at 1:22
  • \$\begingroup\$ There's always the polynomial of degree length-1... which is the only realistic option if you write something longer than 10 characters. One could try to golf the polynomial a bit but anyway it wouldn't be a great challenge. \$\endgroup\$ – feersum Nov 21 '14 at 2:19
  • \$\begingroup\$ @feersum and COTO , The challenge is interesting, I hope, if many of the test cases come from sequences which do have short formulae. You are right that if the sequences are genuinely chosen at random it is perhaps not so interesting. \$\endgroup\$ – user9206 Nov 21 '14 at 15:22
0
\$\begingroup\$

Generalized Array Indexing

Most programming languages provide an array datatype (which might be called a list or a vector) that supports indexing. Given an array and a nonnegative integer, we can fetch the element of the array at that position: [a,b,c][0] = a. Some languages, like Python, support a more general indexing system, where passing a negative index counts the position from the end: [a,b,c][-1] = c. But why stop there?

In this challenge, your task is to provide another generalization of this operation. In other words, you must provide a function that takes in an array and a number, and returns something, up to the following restrictions:

  1. If a nonnegative integer is passed to the function, it must return the element of the array at that position. In other words, it must be an extension of the array indexing operation.
  2. It must support more indices than just nonnegative integers, like negative integers, fractions, complex numbers, or even strings. In other words, it must be a proper extension.

If necessary, you may restrict the types of elements your arrays may contain, so you may choose to only handle arrays of, say, floating-point numbers, or other arrays. This is a popularity contest, so the answer with the most upvotes wins.

| |
\$\endgroup\$
  • 4
    \$\begingroup\$ I'm sure people would come up with some fun ideas, but I believe this is currently a bit too broad as it stands (the telltale sign being a "something" in italics in your spec). \$\endgroup\$ – Martin Ender Nov 25 '14 at 17:37
  • \$\begingroup\$ That was my fear too. I don't know whether this can be turned into a good challenge without changing the idea completely, but I'll leave it here for now. \$\endgroup\$ – Zgarb Nov 27 '14 at 16:43
0
\$\begingroup\$

Play Chopsticks

Disclaimer: Please fix the question and the scoring if they are not satisfactory. I am probably not qualified to run and score entries because I am not entirely familiar with the logistics of running two programs against one another, and, as such, I will not be posting this question to the main page myself. So, if anyone wants to take this off my hands, feel free. I just really like this idea and want to see it happen.

Chopsticks Wikipedia article

Your challenge is to write a program that, given the current position of the game as input (how many fingers on each hand), outputs the next move it chose to take.

Rules of the game

(Normal rules, no variations)

  1. When a hand's finger-count becomes >= 5, it's finger-count becomes 0.
  2. Splitting/transferring is allowed. You CAN bring a dead hand back by transferring some fingers from your other hand.
  3. However, splitting/transferring is not allowed if the move only results in you having swapped your hands. (eg. no prolonging the game by "doing nothing")
  4. A player loses if both their hands are dead.

Input

You will receive as input the number of fingers on each of your and your opponents hands.

Input will be given in the following format:

#_on_your_LH #_on_your_RH #_on_opponent_LH #_on_opponent_RH

Examples:

1 1 1 1

or

4 0 3 2

Output

Your program will output your move base on the input.

Key:

First number:
  0 (your LH)
  1 (your RH)
  2 (transfer from your LH to your RH)
  3 (transfer from your RH to your LH)

Second number:
  If first number was 0 or 1:
    0 (opponent's LH)
    1 (opponent's RH)
  If first number was 2 or 3:
    1-3 (# of fingers to transfer)

Examples:

0 0 (tap opponent's RH with your LH)
0 1 (tap opponent's LH with your LH)
1 0 (tap opponent's RH with your RH)
1 1 (tap opponent's LH with your RH)
2 1 (transfer 1 finger from your LH to your RH)
3 2 (transfer 2 fingers from your RH to your LH)

Scoring

Each entry will be made to play a game against every other entry.
If a game does not end after 100 rounds (?), it will be declared a tie.

Two points will be awarded for every win and one point will be awarded for every tie.
Entry with the most points is the king of the chopstick-hill.

| |
\$\endgroup\$
  • \$\begingroup\$ This sounds so familiar, I feel like it has been posted before, either on main or in the sandbox (or maybe it was just discussed in chat), but the game has so many names that it's hard to find right now. (Looks like it was the sandbox and died off right away: chat.stackexchange.com/transcript/message/17654246#17654246) \$\endgroup\$ – Martin Ender Nov 29 '14 at 23:01
  • \$\begingroup\$ @MartinBüttner I still think that this should be done. Perhaps it could be made more interesting by allowing the programs to see the whole game, not just on a turn-by-turn basis, and they then could adapt to their opponents. Though I believe that would require networking / competing on a server, of which I know little. Well, in any case, like I said, I just thought this was a good idea and wanted to see it happen, though I don't feel up to taking the responsibility to do it myself. If this dies off too... oh well. \$\endgroup\$ – kukac67 Nov 29 '14 at 23:23
  • \$\begingroup\$ I'm not sure if I remembered right, but I thought Chopsticks was a solved game for the second player? \$\endgroup\$ – Sp3000 Nov 30 '14 at 3:27
  • \$\begingroup\$ @Sp3000 Dang it. I think you're right. I wonder if any of the variations to the game change it enough for it to require more strategy and not be a solved game. \$\endgroup\$ – kukac67 Nov 30 '14 at 20:12
0
\$\begingroup\$

N-gon Naming

Challenge

Given the word name of a polygon n, you must output the number of sides polygon n.

Examples

Input:  triangle
Output: 3

Input:  dodecagon
Output: 12

Input:  megagon
Output: 1000000

Input:  hexahexagon
Output: 66

Winning

The shortest code wins.

The list of shape names can be found here with instructions on how shape names are constructed. Use the alkane naming system.

| |
\$\endgroup\$
  • \$\begingroup\$ In case you aren't aware, there's a pretty simple formula to find these numbers. \$\endgroup\$ – Geobits Nov 13 '14 at 19:58
  • \$\begingroup\$ @Geobits This is more parsing of the shape name \$\endgroup\$ – Beta Decay Nov 13 '14 at 19:59
  • \$\begingroup\$ For some reason I thought that part was a dupe, but it turns out I can't find anything except going the other way (3->tri). \$\endgroup\$ – Geobits Nov 13 '14 at 20:02
  • \$\begingroup\$ You'll probably need to define an upper limit, like this question did \$\endgroup\$ – FryAmTheEggman Nov 13 '14 at 20:46
  • 1
    \$\begingroup\$ If the challenge is really about parsing the shape name, then just have that be the question. \$\endgroup\$ – xnor Nov 14 '14 at 10:12
  • \$\begingroup\$ It might be a good idea to point out if we need to support Tetracontadigon, as well as 42-gon. \$\endgroup\$ – FryAmTheEggman Nov 19 '14 at 15:30
  • \$\begingroup\$ The rules on that new link are confusing. What is a hexahectogon? 6100? 600? \$\endgroup\$ – FryAmTheEggman Nov 20 '14 at 19:13
  • \$\begingroup\$ Can we really trust a site that says Is there actually a name for a 27 sided pentagon? Yes there is.? \$\endgroup\$ – feersum Nov 20 '14 at 21:56
  • \$\begingroup\$ @feersum Yeah... I was hoping to find a long list of every shape from 3 to n... That's the best I could do ATM \$\endgroup\$ – Beta Decay Nov 21 '14 at 7:03
  • \$\begingroup\$ en.wikipedia.org/wiki/Polygon has a better list with more rules than the site you linked. Anyway, both sites offer various alternative names and you should specify which are required, and the maximum number of sides to be supported. It is very, very unclear how a polygon with more than 1999 sides should be named. \$\endgroup\$ – Level River St Nov 30 '14 at 12:40
  • \$\begingroup\$ @steveverrill A polygon with more than 1999 sides -> circle ;) \$\endgroup\$ – FryAmTheEggman Dec 1 '14 at 17:34
0
\$\begingroup\$

Help Bob the Builder survive the communists, and fast!

The communists have taken over the world and you are the last remaining tower builder. In order to surive you must show that you are able to build towers and fast!

The challenge

Bob is given a set of building blocks b, and a number n of towers to build. Since we are in communist land the towers should have as equal of an height as possible. The catch is that you are only given 180 seconds to build the towers. The goal is to minimize the std of the tower height. In addition you have to build towers at three different sites. Which means three different sets of building blocks and three different set of towers.

Input & Output

blocks = [1,2,3,4,5,6,7,8,9]
towers = 3

The ouput should be on the form

7 6 2
8 5 4
1 9 5

std = 0

Here the towers are built vertically. The std is calculated as follows

std = sqrt[(mean - tower1)^2 + (mean - tower2)^2 + ...]

where tower1 represents the height of that tower and mean is the average of the heights.

mean = (tower1 + tower2 + ... + towern)/towers

Example 2

Input

blocks = [1,2,3,4,5,6,7,8,9]
towers = 2

Output

5 3 2 4 1
9 6 7 9 0

std = 0.7071

Since mean = (23+22)/2 = 22.5 and std = [(22.5-23)^2+(22-23)^2]^(1/2) = [1/4+1/4]^(1/2) = (1/2)^1/2.

These two are examples of optimal outputs. Since the problem is NP hard an optimal solution within a reasonable time is impossible.

Scoring

The blocks for the three building sizes are given below. The sum of these three tests judge your performance. Lowest score wins. Eg

 score = 100*std(1) + 50*std(2) + std(3)

Where std stands for the standard deviation obtained at building site n. Do not try to cheat and make a code that runs longer than 300 seconds. The KGB (Eg me) performs regurarly controls.


Question for meta

1) Is the problem clear enough? Eg use the three vectors and distribute them equally

2) Is the scoring now fair? Must have a run time beneath 3 minutes, lowest score wins.

Building site 1: 2 towers

Building site 2: 3 towers

Building site 3: 23 towers

| |
\$\endgroup\$
  • \$\begingroup\$ How is this different to your previous question? \$\endgroup\$ – Peter Taylor Dec 14 '14 at 17:48
  • \$\begingroup\$ In previous question the number of elements in each tower were fixed, here only the number of towers are fixed. There is now a logical time constraint as well as a fair score system. Plus slightly more creative vectors. Is that enough? \$\endgroup\$ – N3buchadnezzar Dec 14 '14 at 18:07
0
\$\begingroup\$

Quine is love, quine is life (well, almost)

Yes, another Life challenge. Inspired by this.

Challenge

Write a program (the generator) that, when given a representation of a Game of Life board on STDIN (or in a file if you like), outputs a program which contains a string representation of a Game of Life board in its source code.

The representation will be in the following format:

 h w x1 y1 x2 y2 x3 y3 . . . xw yh

where:

  • h = height of the grid
  • w = width of the grid
  • xi yi = coordinates of a live cell

When run, the new program should output its own source code - with a catch: the string in the output must represent the generation following the one previously encoded. (We shall call this program the replicator.)

Other stuff

  • All live cells will be provided as input, so all other cells may be assumed to be dead.

  • 0,0 is at the bottom left.

  • Both programs (the generator and the replicator) need not be in the same language.

  • There may be a width-one border around the string representation for a -10% bonus in score.

Scoring

Your score on a particular input will be defined as the length of the generator plus the average length of the first 100 generations of the replicator.

Your final score will be the average of your scores on all the test cases. The lowest score wins!


Question

Should we impose a format for the string representation, like maybe

* * * * * * * * * * * * * * * * * * *
*                                   *
*                                   *
*                 *                 *
*               *                   *
*               * * *               *
*                                   *
*                                   *
*                                   *
* * * * * * * * * * * * * * * * * * *

or should we let the GolfScripters and CJammers of PPCG use their unprintable black magic? :D

| |
\$\endgroup\$
  • \$\begingroup\$ Just to check, the scoring formula is generator_length + sum(replicator_lengths)/100? The bolding is a tad misleading: it seems to imply that the division is performed also on the generator length (which would be very odd). \$\endgroup\$ – FryAmTheEggman Dec 22 '14 at 3:33
  • \$\begingroup\$ That is indeed what I meant, but you're right; it is a bit odd. Fixing. \$\endgroup\$ – Soham Chowdhury Dec 22 '14 at 4:27
  • \$\begingroup\$ The scoring formula is generator_length + sum(lengths of first 100 replicators)/100. \$\endgroup\$ – Soham Chowdhury Dec 22 '14 at 4:30
  • 1
    \$\begingroup\$ This looks like a less interesting version of this Life quine question. If you do decide to allow flexibility in the representation, you'll need to be careful to avoiding being too close a duplicate. Other than that, I don't understand what h and w are (is there an unspoken assumption of boundary conditions?) nor what you mean about 0,0 being the bottom left (since the output doesn't care which directions the axes run) or about having a border around the string representation. \$\endgroup\$ – Peter Taylor Dec 24 '14 at 11:06
0
\$\begingroup\$

Query the icosahedral graph

You've been sent back in time to 1973 to change history by remaking a clone of Hunt the Wumpus. You need to code a network of rooms in the game that forms an icosahedral graph, whose vertices correspond to the 12 vertices of the icosahedron connected by edges, unlike the dodecahedral graph used in the original game. Each room connects to five others.

Your goal is to write a program or function that takes the ID numbers of two of the twelve rooms, and returns one value if the rooms are adjacent, and a different value if not. Due to space constraints, you code needs to use as few bytes as possible.

You can choose what ID's to label the 12 rooms, but due to hardware constraints, they must be numbers from 0 to 255. Specifying the ID's doesn't count for the code length.

Input

Two distinct ID numbers from 0 to 255 out of 20 of your choice. You can't restrict which order two numbers appear in.

Output

A consistent value for pairs of numbers that correspond to adjacent rooms in your ID scheme, and a different consistent value for non-adjacent pairs.

Your code may not use any built-ins that represent the dodecahdral graph or related structures.

| |
\$\endgroup\$
  • \$\begingroup\$ I haven't actually given much thought to how to do this and how hard or easy this easy. Looking for feedback on this half-baked idea. \$\endgroup\$ – xnor Jan 3 '15 at 18:24
  • \$\begingroup\$ Well, Hunt the Wumpus has been done. Not sure how much more room for variation this subchallenge gives other than ripping out the relevant parts from the answers of the previous challenge. \$\endgroup\$ – Martin Ender Jan 3 '15 at 18:37
  • \$\begingroup\$ @MartinBüttner Fair point, I'll switch to a different graph. \$\endgroup\$ – xnor Jan 3 '15 at 18:48
  • \$\begingroup\$ I'm not sure at the moment which graph the question is trying to talk about, but IIRC both dodecahedron and icosahedron have been done. In fact, you did a dodecahedron graph structure question already. \$\endgroup\$ – Peter Taylor Jan 3 '15 at 19:12
  • \$\begingroup\$ @PeterTaylor I guess I'm not conveying my idea well. The core idea is to make a two-input function whose truth table is isomorphic to some specific graph, with you getting to choose the input labels and the isomorphism. So, it's a question of how to represent the required graph as much as how to code it. For example, if I asked to make a 16-vertex hypercube graph, you could label vertices by the four-bits numbers 0 to 16 the natural way, and check for an edge by whether the xor of the two labels is a power of 2. \$\endgroup\$ – xnor Jan 3 '15 at 23:21
  • \$\begingroup\$ I understood that. How do you feel about switching to the Petersen graph? It's comparable in size and complexity, but it's definitely not treading on the toes of the previous questions. \$\endgroup\$ – Peter Taylor Jan 4 '15 at 9:16
  • \$\begingroup\$ @PeterTaylor The Petersen graph happens to have a compact and elegant solution that's surely optimal. Got any other graphs to suggest? \$\endgroup\$ – xnor Jan 5 '15 at 3:16
  • \$\begingroup\$ Fair point. How about the McGee graph? It's not vertex-transitive, so I think that probably forces a different approach to the group representational approach which was used on the earlier questions. Other interesting options might be the Pappus graph and the Coxeter graph, but they have more symmetry. \$\endgroup\$ – Peter Taylor Jan 5 '15 at 20:01
1
51 52
53
54 55
99

You must log in to answer this question.

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