538
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

If you think one of your posts needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3548 Answers 3548

1
82 83
84
85 86
119
0
\$\begingroup\$

Golf a program whose behavior is independent from Peano arithmetic

Your task is to write a program that doesn't take any input, and whose termination cannot be proved or disproved inside Peano arithmetic. This is , so the shortest byte count wins!

Rules

  • Standard loopholes apply
  • Shortest by count wins
  • You can assume that your program runs in a machine with an unlimited amount of memory.

Tags


Questions for meta

  • Is this a good challenge?
  • Is it a duplicate?
  • I think the same question with a behavior independent of ZF set theory might be interesting as well (see this link for instance), but will attract very different answers; should I post it as a separate challenge?
  • What can be improved? Are the tags ok?
\$\endgroup\$
9
  • \$\begingroup\$ Current sandbox post that's fairly close to this one. There might be two challenges in this space, but maybe just one; perhaps you could give feedback on the other post? \$\endgroup\$
    – user62131
    Jun 23 '17 at 2:45
  • \$\begingroup\$ It seems like the other sandbox post is pretty limited to Turing machines only, whereas this one allows any programming language, so I think the two will attract quite different answers. Secondly, I believe restricting to Peano arithmetic instead of ZF will make solutions that are simpler, so I believe the two challenges are still quite different (but I'd like input from others on this as well). \$\endgroup\$
    – nore
    Jun 23 '17 at 3:06
  • 2
    \$\begingroup\$ Is this the same as this challenge? \$\endgroup\$
    – xnor
    Jun 23 '17 at 7:10
  • \$\begingroup\$ @xnor it is the same indeed, so I guess I should instead go for independent of ZF. This makes it closer to the other sandbox proposal, but I still think allowing any programming language makes the challenge quite different from a Turing machine-only one. \$\endgroup\$
    – nore
    Jun 23 '17 at 13:25
  • \$\begingroup\$ See also: codegolf.stackexchange.com/search?q=aaronson \$\endgroup\$ Jun 23 '17 at 21:33
  • \$\begingroup\$ If a program’s behavior is independent of ZF or ZFC, it’s also independent of PA, so I’d be happy to see such programs posted on the existing challenge, unless it starts getting so many answers that they get drowned out (current trends suggest that’s unlikely ☹). \$\endgroup\$ Jun 24 '17 at 6:49
  • \$\begingroup\$ @AndersKaseorg true, it looks like people are not that interested in this kind of challenges :( The point for having two separate challenges was because ZF/ZFC-independent answers might be a lot more complicated than PA ones. \$\endgroup\$
    – nore
    Jun 24 '17 at 14:28
  • \$\begingroup\$ @nore Do you know of any simple answers to the PA challenge? I don’t think my PA answer is notably simpler than a ZFC version would be. \$\endgroup\$ Jun 24 '17 at 20:52
  • \$\begingroup\$ @AndersKaseorg I tried to find statements that are easy to check and that are independent of PA, but the simplest I have been able to find is still the ZF-independent one used in the busy beaver paper. \$\endgroup\$
    – nore
    Jun 25 '17 at 2:18
0
\$\begingroup\$

Iterate over all sets

(This question needs fixing so that the output size is not too large)

Consider all possible pairs of sets of integers (can have positive, negative and zero values) A and B such that |A| = |B| = 7. Define the set T_{A,B} = {a * b | a in A, B in B}.

The challenge is to iterate over all pairs of sets A and B so that |T_{A,B}| < 19 and the largest absolute value of an integer in A or B is at most 128. As an example of one such pair of sets, A = B = {2^i | for i in {1,...,7}}.

What should my code output?

Your code should output the pairs of sets A, B along with |T_{A,B}|.

For example:

A = {2,4,8,16,32,64,128}, B = {2,4,8,16,32,64,128}, |T_{A,B}| = 13.

Running time

I don't care how long your code takes to run except you must run your answer to completion before posting an answer.

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

Code golf the Fast growing hierarchy (fgh)

if your not familiar with the fgh you migth want to check out this explantion: Large Numbers, Part 3: Functions and Ordinals

and these value aproximations: Fast growing hierarchy Approximations

the goal this code golf is to golf the following functions:

  • the exact value of fω(x) this means you can't golf the ackermann function

  • the growth rate of fω2(x)

  • the growth rate of fω2(x)

In any language of your chose.

This is a code golf so the smallest program that defines each of these functions wins (Note:the functions are allowed to call each other).

It is also allowed to ask for an input x and output the 3 function values in any order.

Tags

,,,

Sandbox notes

I'm not sure on which functions should be the target but these functions seem challenging yet golf-able in less than 150 bytes.

Upon closer inspection I realized that fω2(x) is probably to easy since it can be golfed with something like:

f(x,a...) {
    for i in range(a.length) {
        if(a[i] != 0) { //first non zero
            Arrays.fill(a, 0, i, x); //replace 0's with x
            a[i]--; //decrement a[i]
            return f^x(x,a);
        }
    }
    //all zeros
    return x+1;
}

f(x,n) > fn(x)

f(x,0,n) > fωn(x)

f(x,0,0,n) > fω^n(x)

so f(x,0,...,0,x) (x zeros) ~= fε0(x)

Any other tags? Suggestions? Does this interest you?

\$\endgroup\$
4
  • \$\begingroup\$ Having three winners doesn't really work. But having three separate questions is probably not the right solution either: they're close enough to be borderline dupes of each other. Perhaps the best way would be to score for the total length of the three functions, allowing the faster ones to call the slower ones but at the cost of having to name them. That might make for some interesting tradeoffs between using the functions directly vs having one function for f_{w^2 a + wb} which the others call with different values of a and b. \$\endgroup\$ Jun 23 '17 at 21:23
  • \$\begingroup\$ @PeterTaylor good suggestion, I changed the win condition. But I realized those a probably not the right functions since w² can be golfed really easily. \$\endgroup\$
    – fejfo
    Jun 24 '17 at 7:47
  • \$\begingroup\$ Why not do exact values? \$\endgroup\$ Nov 24 '17 at 20:51
  • \$\begingroup\$ Your solution for f_{ω^2} is very sub-optimal. See my answer. \$\endgroup\$ Nov 24 '17 at 20:53
0
\$\begingroup\$

Monopoly KoTH

This is going to take me a while to finish and may never be fully done. Don't expect this to be posted anytime soon. However, this will be an ongoing project under development.


Who hasn't heard of Monopoly? If not, don't worry, as I will explain the rules! If you already know the rules, read on, for they may be different in this rendition.

The Rules of Monopoly

Monopoly is played on a board, with 36 different squares, that looks somewhat like this

monopoly board

For this version, we'll use the original British version, because I'm British and proud of it!

Squares are split into 3 categories:

  • Property. These are the ones with a coloured bar at the top, such as Old Kent Road or Whitehall. They also include the 4 stations in the middle of each side, and the utilities (Electric Company and Water Works)
  • Bonus Cards. These are the squares marked Community Chest or Chance. These allow for a player to either receive or lose money, depending on a random card choice.
  • Special Squares. These are the 6 other squares in the board, the 4 corner squares and the taxes (boo!)

Let's look at these categories in a bit more detail.

Property

Properties are grouped, depending on the colour of said property. Each property has a rent value that contains the amount that a player must pay to the owner of the property, when they land on that property. If one player owns all of the properties in one colour, the rent for each is doubled.

Players can also buy properties, which is how they own them. Each property also has a price, which is then deducted from the buyer's cash and given to the Bank, in exchange for the property. Stations cost £100 each and all other properties available to buy have their cost written below their square.

Stations' rent increases the more stations that someone owns. In the following progression

  • 1 Station: Rent = £25
  • 2 Stations: Rent = £50
  • 3 Stations: Rent = £100
  • 4 Stations: Rent = £200

Utilities' rent depends on the dice roll. If a player owns 1 utility, multiply the roll by 4 and that is the rent. If the player owns both, multiply the roll by 10 to get the rent due.

Properties can be built on. That means that a player builds houses and hotels on them, in order to increase that properties rent. A player can build houses and hotels on a property if

  • it has a coloured bar at the top
  • the player owns all of the properties in the group
  • they have enough money. Each house costs £50 and each hotel costs £100.

Each property can have a maximum of 4 houses. After that, the player must build a hotel. A property can only have 1 hotel on it. Houses and hotels drastically increase the rent of a property, for example £4 (no buildings) to £450 (one hotel).

Bonus Cards

The name of these are a bit of a misnomer. These are denoted on the board by ? symbols and chests on squares and can either give or take money from you. For this game, we will ignore Get Out of Jail Free cards and the Goto cards. The cards can result in a random integer between -1000 and 1000 added to your score. If this results in bankruptcy (we'll see this later), so be it.

Special Squares

  • Go. If you land on Go, you get given a £400 reward. If you simply go past it (Mayfair -> Old Kent Road), you get £200. It's also where the pieces begin.
  • Jail. If you roll and land on this square, don't worry, as you don't go to jail. You are "Just Visiting"
  • Free Parking. This is where the taxes go! If you have to pay taxes, either because of the Tax squares or because of a Bonus Card, that money goes to Free Parking. If a player lands on it, they get all the money there!1
  • Go to Jail. This does what it says on the tin. You go straight to Jail. But this time, you're in Jail, not just visiting. You stay in Jail until you roll a double.1 After which, game continues as normal. You cannot collect rent while in Jail.
  • Taxes. Super Tax and Income Tax are two squares which charge you £100 and £200, respectively. However, you can regain that money as it goes straight to Free Parking!

Bankruptcy

In Monopoly, if you run out of money, you are bankrupt. Here, you have two options. You can either mortgage your properties or, if you don't have any, you are out of the game! The last one with any money wins the game and the KoTH!

When you lose, all your properties go to the player who bankrupted you. If that's the Bank by virtue of Bonus Cards, then all your properties are available to be bought again.

Mortgage

You can mortgage properties in order to get more money if you're in a pinch. Unfortunately, this "deactivates" the property, meaning that you don't get any rent when people land on it. If you have enough money, you can unmortgage a property for 110% of its mortgage value. (£100 -> £110)

Auctions

If you land on an unbought property and don't buy it, either because you don't have enough or you just don't want to, the property goes on auction. This means that all players can bid on the property. Bidding starts at £1, which means that a player can, theoretically, get the property for a much lower or higher price than its original price.

Trading

I am hoping to be able to include trading but this does depend on my ability as a coder. In an ideal world, I will be able to get it working but, unfortunately, this may not happen :(

1: I am aware that this changes depending on who you're playing with, but this is how we'll do it in this version.

Rules of the KoTH

I have written (still finishing) a Player class in Python which contains all of the things that a Monopoly player can do. Your task is to rewrite 2 of the functions that can change your player's behaviour.

While thinking about how to make this KoTH, I listed out the complete process that gives you a chance to change what you do. Let's go over that process! This flowchart shows the process for each turn. Green items show the choices that you have to make.

This is the text version:

1. Roll dice and move
2. Is the property owned by the Bank?
    1. Yes. Nothing happens.
    2. No. Pay the due rent.
3. Choice of:
    1. Buy
    2. Auction
4. Choice of:
    1. Trade
    2. Build
    3. Mortgage
    4. Unmortgage
    5. Move On
5. Repeat until bankrupt

Auction

1. Choice of:
    1. Play the auction
    2. Don't play the auction
2. Are you playing the auction?
    1. Yes.
        1. Choice of:
            1. Bid new max
            2. Skip one round
            3. Skip all rounds
            4. 'All in'
        2. Repeat until 1 player left bidding
    2. No. Don't do anything.

Trade

1. Choose a player to trade with
2. Offer properties and/or money
3. Does the other player agree with the trade options?
    1. No. They counter offer. Do you like their options?
        1. No. Do you want to continue negotiating?
             1. Yes. Go to point 2 above
             2. No. The trade is over.
        2. Yes. You trade the agreed upon items.
    2. Yes. You trade the agreed upon items

But, for you coders out there, I'll explain using a bit of code.

Your submission should contain a single class that inherits from Player. You may add in as many extra attributes as you want, but in order to be used, your code must refer to them. I'm not editing the controller just for your bot to work.

However, each class must look like this

class NameOfPlayer(Player):
    def turn(self, square, roll):
        (code that determines your actions per turn)
    def auction_action(self, price, bidders):
        (code that determines your auction actions)
    def trade_actions(self, players, last_offer):
        (code that determines your trading actions)

    (any other functions you want)

Your turn function will return 3 numbers as a list e.g. [1,2,3] which are the results of the choices above. The first item should be either 1 or 2 (Buy or Auction), the second should be one of 1,2,3, 4 or 5 (of the 4. Choice of: options) and the third should be either 1 (play the auction) or 0 (don't play the auction) such as [1,5,0] would buy the property, move on to the next player and not play the auction on this turn (doesn't matter as there wasn't an auction).

Your auction_action function will return either a number (your bid) or one of a (all in), s (skip this round) or q (quit auction), which determines what you will do on that round of the bidding. This continues until either you quit the auction of you are the only one left.

Your trade_actions function will return a list every time it is called. The list consists of [agree with previous offer (as a bool), properties to trade (as a list), cash to trade (as an int)]. When a trade has just begun, the first item in the list will be ignored and the last_offer parameter will be ignored. The last_offer parameter contains the second 2 items returned by the person you are negotiating with, so that you can decide whether you want to continue trading or not.

If you lose all your money, your program with be taken out of the active players and placed into the results table. The last one standing wins!

\$\endgroup\$
8
  • \$\begingroup\$ I call dibs on the Go submission that always go to jail. \$\endgroup\$
    – Uriel
    Jun 25 '17 at 16:35
  • \$\begingroup\$ While you are allowed to use the monopoly rules, I'm not sure about using the picture of the board? \$\endgroup\$ Jun 26 '17 at 4:44
  • \$\begingroup\$ @DestructibleLemon what do you mean? \$\endgroup\$ Jun 26 '17 at 5:59
  • \$\begingroup\$ If I'm reading this correctly, this is a variant which doesn't allow trading properties, and that's the most interesting part of the game. The rules stated also fail to state what happens to the properties of a player who goes bankrupt. (Correct answer: they must mortgage all of them and then forfeit them to the player to whom they owe rent. I'm not sure offhand what happens if they're going bankrupt due to taxes, but presumably the properties revert to the bank and when someone lands on them they buy or auction). \$\endgroup\$ Jun 26 '17 at 9:23
  • \$\begingroup\$ @PeterTaylor I'm currently writing the controller and a base class, which will determine what I can and can't allow in the game. Once that's finished and all issues with the controller are sorted out, I will update the rules here to fit with it's capabilities. Also, the version I've played allows for a player to mortgage their properties to avoid bankruptcy (as in you mortgage and if you're still bankrupt, you lose) \$\endgroup\$ Jun 26 '17 at 13:54
  • 1
    \$\begingroup\$ My point is that unless it's a two-player game, you lose is not a sufficient description because the game needs to continue until there's only one winner. The comment about mortgaging is because if I owe you more money than I can get by mortgaging all my properties, I have to mortgage them and give you the money obtained and the mortgaged properties, and so you have to pay to unmortgage them before you can benefit from them. \$\endgroup\$ Jun 26 '17 at 14:05
  • \$\begingroup\$ What stops this from going into an infinite loop without a winner \$\endgroup\$ Jul 27 '17 at 16:12
  • \$\begingroup\$ Feedback copied from TNB: I think this would be way more interesting if the Goto cards were included, and the random amount given/taken was less significant (£1000 is a lot). The Goto cards add a bit of strategy in which properties to buy. Also, my version has the income tax be either £200 or 10% of the player's net worth. Is that different in yours, or is it just removed for simplicity? \$\endgroup\$ Feb 23 at 5:01
0
\$\begingroup\$

Just One More Time

Challenge

Write a program or function that will run without error once, but will crash when run for the second time.

If you are writing a function, you may assume the function will be run twice within the same interpreter session or program.

If you are writing a program, you may assume the machine will not be rebooted between runs.

Scoring

This is , so the shortest answer in each language wins.

\$\endgroup\$
4
  • \$\begingroup\$ I feel like the function version is much easier than the program version so I don't think you will see many programs in languages that could do both. Take C: i=1;f(){return 1/i--;}. I don't think you could reasonably ban "global" values to prevent this, but it's up to you if you even think this is a bad thing. \$\endgroup\$ Jun 27 '17 at 1:10
  • \$\begingroup\$ Will it run a third time? \$\endgroup\$
    – Okx
    Jun 27 '17 at 10:16
  • \$\begingroup\$ @FryAmTheEggman The answer you gave is exactly the type I would be looking for \$\endgroup\$ Jun 27 '17 at 15:01
  • \$\begingroup\$ @Okx It would not be run a third time. For functions, the assumption is that the crash would kill the interpreter session/program. For programs, I just won't run it a third time. \$\endgroup\$ Jun 27 '17 at 15:02
0
\$\begingroup\$

What Tiles did I have?

Everyone should be aware of the scoring system in a classic board game: Scrabble. I remember going back into my old scrabble box and finding some old post-it notes containing old scores. I always wonder what the heck was played for some of the more insane point scores. That gave me the idea for this challenge...


English-language editions of Scrabble contain 100 letter tiles, in the following distribution:

  • 0 points: * x 2 (These are the blank tiles)
  • 1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×4
  • 2 points: D ×4, G ×3
  • 3 points: B ×2, C ×2, M ×2, P ×2
  • 4 points: F ×2, H ×2, V ×2, W ×2, Y ×2
  • 5 points: K ×1
  • 8 points: J ×1, X ×1
  • 10 points: Q ×1, Z ×1

Your challenge is, given a single integer input between 0 and 185, output a corresponding sequence of scrabble tiles that sum to that score with a length between 2 and 100 characters in length.

The Specifics

  • The letters don't have to spell anything, they just have to sum to that score.
  • You can only use a tile the number of times it exists (E.G. E can be used 12 times).
  • The shortest word is 2 characters long, for an input of 0 you get **.
  • Outputs will not match between answers, as there are many solutions.

Inputs and Outputs

  • Input should be a single integer, anything else is wrong.
  • Output should be a single string, with no spaces, order of letters is arbitrary.

Example (Potential Solution)

0   | **
1   | *E
2   | EE
[... Pattern Omitted ...]
12  | EEEEEEEEEEE
13  | EEEEEEEEEEEA
[... Pattern Omitted ...]
68  | EEEEEEEEEEEEAAAAAAAAAIIIIIIIIIOOOOOOOONNNNNNRRRRRRRTTTTTTLLLLSSSSUUUU
[... Arbitrary Ordering Omitted ...]
185 | EEEEEEEEEEEEAAAAAAAAAIIIIIIIIIOOOOOOOONNNNNNRRRRRRRTTTTTTLLLLSSSSUUUUDDDDGGGBBCCMMPPFFHHVVWWYYKJXZQ

This is ,: Whomever contacts Cthulhu using the dark arts first wins.

\$\endgroup\$
9
  • \$\begingroup\$ Whomever contacts Cthulhu using the dark arts first wins. that's bait \$\endgroup\$
    – Stephen
    Jun 27 '17 at 20:25
  • \$\begingroup\$ @StephenS wellp, if you want more bait check out 20 of my other random ass winning criterion for my sandboxies. \$\endgroup\$ Jun 27 '17 at 20:27
  • \$\begingroup\$ Sorry Sandbox sucks :/ can output be a list of one-char strings? and integer includes negatives, dunno if that's on purpose or not \$\endgroup\$
    – Stephen
    Jun 27 '17 at 20:29
  • \$\begingroup\$ @StephenS nono! That wasn't a diss on you or sandbox! That was just me stating that last 20 submission I've made to the sandbox I've put random winning criterion like "Winner buys dennis a subway footlong, or his countries' equivalent". \$\endgroup\$ Jun 27 '17 at 20:35
  • \$\begingroup\$ Also, it says an integer between 0 and 185. Also I mentioned words must be at least 2-chars. I feel like either my challenge's wording blows or you misread it a little. Probably more likely the challenge is worded poorly, I've had 2 already. \$\endgroup\$ Jun 27 '17 at 20:35
  • \$\begingroup\$ I made it a diss on Sandbox, that no one noticed them xD and I was looking in the #Input section for all the input specifics - I should have looked at the whole challenge, my bad. I just read Input should be a single integer, anything else is wrong. so that's what I assumed the whole rule for Input was (reading is hard) \$\endgroup\$
    – Stephen
    Jun 27 '17 at 20:37
  • \$\begingroup\$ @StephenS to be honest, reading isn't hard, it's contextual. I always have noticed in my career that I 100% understand anything that I create. Then, when explaining it to others, it may make literally 0 sense but be 100% viable in my head. Then like 10/12 people come forth saying "What the heck did you even try to write man?" And I realize, "what the hell did I even try to write?" Hahaha. The way I explain things to others can be horrifically inadequate by my own experience. \$\endgroup\$ Jun 27 '17 at 20:48
  • \$\begingroup\$ Related. It's a borderline dupe, in that the only real difference is a suitable wrapping loop. \$\endgroup\$ Jun 27 '17 at 21:42
  • \$\begingroup\$ A standard Scrabble board is 15 x 15, and even a "Super Scrabble" board is only 21 x 21. Should the maximum word length be limited to 15 (instead of 100)? \$\endgroup\$
    – Jasper
    Jun 29 '17 at 5:50
0
\$\begingroup\$

Display the Undisplayable

I have sometimes seen answers to challenges, written in binary machine code. The users who post them usually display them in hexadecimal representation. This representation makes the code extremely long, and does not do them justice!

Thus, we should give them help, and I don't care if they don't need it. Your task will to write a program/function/eldritch incantation to turn their beautifully golfed binary code into the shortest possible string of printable characters.

Input

A sequence of random binary data of random length. Use any of the standard IO methods (note to self: find the link to the Meta post).

Output

A sequence of printable characters. Use any of the standard IO methods.

  • If encoding is relevant, you are free to choose any encoding, provided you clearly indicate which one you used in your answer. What is relevant is the number of characters anyway.

  • Whitespaces (regular space, new line, non-breaking space, form feed, etc.) are considered not printable. They can be added if you wish, but their presence or absence must not impact the decoding of the output.

Conditions

  • There must exist a program, that can take any possible output of your program, and turn it back into the input (providing it is not needed, but will be smiley'd at).

  • If your program is run twice, with 2 inputs of same size, the 2 resulting outputs must have the same size.

  • Standard loopholes apply.

Score

The score is calcaulated as the number of bytes in the input, divided by the number of characters in the output. The higher the better.

If the score varies depending on the length of the input, take its average over input sizes from 1 to 1024 bytes included (I don't think we'll have answer 1 kb long here).


Giving an answer in a binary language (machine code, LLVM bitcode, etc.) and adding the output when run with its own binary source will be smiley'd at (but no bonus, unless it can also summon Cthulhu).

Don't forget to explain how your code works!


Meta

  • Do you think it's a good idea? Is there already a challenge like this one?
  • Is there any blatant loophole/possible imporvements?
  • What tag(s) do you recommend for this challenge? (please edit the answer)
\$\endgroup\$
7
  • \$\begingroup\$ @Mr.Xcoder Sorry ^^ \$\endgroup\$ Jun 28 '17 at 12:43
  • \$\begingroup\$ it's spelled Cthulhu \$\endgroup\$
    – Mayube
    Jun 28 '17 at 13:10
  • \$\begingroup\$ @Mayube That was what Mr.Xcoder's deleted comment was about... At first I didn't want to make a trivial edit, but since spelling of culture reference is such an important matter... Fixed! Now maybe I'll get more reactions about the challenge itself ^^ \$\endgroup\$ Jun 28 '17 at 13:14
  • 2
    \$\begingroup\$ I think this needs a precise definition of printable character. Unicode doesn't define the term. But once that's provided this is just a base conversion with an awkward base and every answer should get the optimum score, so the scoring system doesn't work. \$\endgroup\$ Jun 28 '17 at 13:51
  • \$\begingroup\$ I just wanted to say thank you for using the sandbox! I hope things go well with your challenges :) That said, I have to agree with Peter Taylor, it seems like every answer will get the optimal score. I think requiring the optimal score and changing to code-golf will work better, but there are many other ways you could fix it. Good luck! \$\endgroup\$ Jun 28 '17 at 14:03
  • \$\begingroup\$ Worth noting that encoding is always gunna be relevant given non-printables don't count, as bytes 0x00-0x20 are non-printables by your definition, meaning if the given binary contains any of those bytes, ASCII can't be used. \$\endgroup\$
    – Mayube
    Jun 28 '17 at 14:06
  • \$\begingroup\$ @FryAmTheEggman I thought about something like that - maybe not the optimal score, but greater than a given value. And it seems I was right to use the sandbox, since there are already 2 potential loopholes detected! \$\endgroup\$ Jun 28 '17 at 14:08
0
\$\begingroup\$

Every Nth Line in Source Outputs N

Heavily inspired by Hello, World! (Every other character)

Related to my other Sandbox post Every Nth Char in Source Outputs N; is it a dupe?

Write a program that outputs 1. When the first, third, fifth, etc. lines are removed, it outputs 2. When all lines where their (1-based) index in the source, mod N, are not 0, are removed, it should output N.

This is . The winner is the program that works with the largest N, while working for all n < N (obviously, to run up to N, it has to be at least N lines long). If there is a tie, the winner is the shortest answer that reaches the largest N. Your program must at least work up to N=2, since I don't think any languages will struggle with simply printing 1.

Example

Examples are based off of this sample program:

test
hi
world
hello
12345
System.out.println(test);
timeout
let's dance

For the program to work for N=1, the original program should output 1.

For the program to work for N=2, the following should output 2:

hi
hello
System.out.println(test);
let's dance

For the program to work for N=3, the following should output 3:

world
System.out.println(test);

For the program to work for N=4, the following should output 4:

hello
let's dance

For the program to work for N=5, the following should output 5:

12345

etc.

The highest N this program could work for is its line length, 8.

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

Sandboxing this mostly so I don't forget about it (as I don't want to initiate this so soon after v3). Unlikely to need any serious revision, but comments are appreciated none the less.

Prisoner's Dilemma v4: The Amnesiac Gentlemen.

This is similar to v3 Petri Dilemma, except with one significant change: no one knows what round it is. The same setup, submission format, and scoring will be used. For sandbox brevity, I'm only noting the differences from v3.

Bots will receive input at the beginning of its turn in the format:

current points, enemies points, your previous moves, enemy's previous moves

The format of the move list (both yours and the enemy's) will be a string of characters, "c" for cooperation "d" for defection, in order from first round to last. However this list will contain only the first seven moves of the game as well as the most recent 7 moves (as everyone knows, you can only hold seven items in working memory). A String 14 characters or fewer would indicate a round at the beginning of the game where 14 total moves haven't yet been performed. Later rounds would be indeterminate.

Additionally, as the current round number is not being passed in, bots will be unaware of when the end of the game comes (games will still be 200 rounds). This should prevent "Ah ha, last round, I backstab!" "Ah ha, but I backstab you first, one round earlier!" strategies, which is what dominated a large swath of the v3 strategic playspace (I did tests where all backstab-early bots were coded to all backstab on the same round and there were only two that performed sub-optimally as a result, both of which were set to backstab "before all n-Tit-for-Tat strategies", moving them back 1 rounds re-elevated them above n-Tit-for-Tat again, as well as which one backstabbed the other first determining the winner between them). While several bots from v3 would be valid submissions in v4, all of the winning bots utilize more data than v4 will let them have, opening up the playing field for new techniques.

Here are four sample strategies that will be entered to start with:

Tit for Tat

def titfortatfunc(mypoints, enpoints, mylist, enlist):
    if not enlist or enlist[counter-1] == "c":
        return "c"
    else:
        return "d"

RandomPick

from random import choice
def randompickfunc(mypoints, enpoints, mylist, enlist):
    return choice(["d", "c"])

Cooperator

def cooperatorfunc(mypoints, enpoints, mylist, enlist):
    return "c"

Defector

def defectorfunc(mypoints, enpoints, mylist, enlist):
    return "d"
\$\endgroup\$
0
\$\begingroup\$

(Code Golf) How Many Notes Are There?

Background

Most music games (MUG) describes the "instructions" that the player must follow as "notes". When the charts (set of notes) are first available, MUG players usually record the chart as a video and upload them to video sites. However, unless playing a full combo (able to pick up all notes) that the combo count directly shows the number of notes, it is usually not practical to count the number of notes one by one directly (since there are usually hundreds of notes), so they calculate that from the scores that may show on those videos if the score formula is known.

One of those examples is jubeat, which is somehow like a MUG version of "Whack-a-Mole". Although officially "instructions" are called "chips", players have the consensus to call them "notes". (For those who don't know what jubeat is please check it out here: jubeat - RemyWiki)

Objective

What you have to do, is to:

  • Write a program or function,
  • Which accepts a list of integers as the only input,
  • That calculates the numbers of notes which is possible for all the given "basic scores".

Requirements

  • The input can be an array of integers or a string containing those integers (Please indicate the input format).
  • The integers in the input are guaranteed to be in the range of [0, 900000] inclusive.
  • A case (NOTES in the formula) is possible means that, for each integer in the input, there exists a variable ACH, when substituted into the formula below, the formula evaluates to that integer. (See The Formula and Test Cases for details)
  • All possible cases within the range [1, 1100] inclusive must be included in the output.
  • The output can be an array of integers or a string containing the results (Please indicate the output format).
  • If there is no case fulfilling the requirements, the program or function should either return an empty array, an empty string, null, or any objects indicating absence of results.
  • NO RUNTIME EXCEPTIONS shall be thrown in any circumstances.

The Formula

The max score is 1000000, but here we only consider BASIC_SCORE, whose maximum is 900000.

The BASIC_SCORE is calculated by BASIC_SCORE = floor(floor(ACH * 100000 / NOTES) * 0.9), where ACH is an integer in the range [0, NOTES*10] inclusive except NOTES*10-1 and NOTES*10-2.

As a concrete example, take ACH=6850, NOTES=900, we have BASIC_SCORE = floor(floor(6850 * 100000 / 900) * 0.9) = 684999.

As a result, NOTES=900 is a possible case for the basic score 684999.

Test cases

 Input                                    | Output
-----------------------------------------------------------------------------------------
 896757, 846353, 844486                   | 916
 891000, 893999                           | (all multiples of 30 within [1, 1100])
 899736                                   | 1024, 1025, 1026, 1027
                                          | (342, 683, 684 are false positives because  
                                          |  in these cases ACH = NOTES*10-1 or 
                                          |  ACH = NOTES*10-2)
 873540, 802468                           | (none: no case fits all inputs.
                                          |  some cases do fit some inputs but not all)
 0, 900000                                | (all values within [1..1100])
 800000                                   | (none)

Rules and Winning Criteria

This is a , so the source code with the shortest length (in terms of bytes) wins. Standard loopholes apply.

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

Poor Man's Ransomware

This challenge is loosely inspired by the cheapo-enigma machine question. However, I beleive that the differences are substantial enough that this would not be a dupe. Feedback welcome.


You have been captured by a morally questionable "employer" and forced to write a piece of "ransomware". All it has to do is take in a string "in whatever format" and output another string (which can be used to recover the files) Essentially, across the set of all possible inputs (infinite) you will define a one to one function.

Participants will then publish their code to stack-exchange, where other aspiring "hackers" will try to break your code. A "cop" submission will consist of a byte count a sample plaintext and a sample "encrypted" file as well as an encrypted copy of your code.

Robbers will work tirelessly in another thread to reproduce your code. Any submission which correctly produces the corresponding "encrypted" files when fed the sample plaintext and itself will be considered to be cracked.

If your code lasts 7 days or longer you may mark your submission as "safe" by publishing the source code for the encryptor and a decryptor. Until this time robbers may still work to break your code. If anyone finds that a specific decryptor fails on a certain plaintext it is invalid.

The winning cop has the shortest safe submission and the winning robber has the largest sum of the bytes of his cracked cops. Ties go to the earlier poster. Good Luck!

\$\endgroup\$
9
  • \$\begingroup\$ I'm not sure how much of the history of cops-and-robbers you are aware of. In the early days it was almost killed off as an interesting challenge type precisely by crypto, because it's so easy to make a problem which depends on e.g. factoring a large prime. In some senses this would be a duplicate of the very first cops-and-robbers. \$\endgroup\$ Jun 30 '17 at 20:07
  • \$\begingroup\$ Almost every cnr problem can be solved using cryptography. Would you then say that almost every cops and robbers problem is dupe of the other ones? \$\endgroup\$ Jun 30 '17 at 20:41
  • \$\begingroup\$ Many cnr's now try to ban the use of cryptography precisely to avoid this problem. \$\endgroup\$ Jun 30 '17 at 20:55
  • \$\begingroup\$ @PeterTaylor could I ban Crypto built ins? \$\endgroup\$ Jun 30 '17 at 21:32
  • \$\begingroup\$ What would be the point? It's crypto that's the problem, not crypto built-ins. \$\endgroup\$ Jun 30 '17 at 21:45
  • \$\begingroup\$ Maybe it might not be that bad of a thing? \$\endgroup\$ Jun 30 '17 at 21:57
  • \$\begingroup\$ I tmight be worth asking about this somewhere \$\endgroup\$ Jun 30 '17 at 21:57
  • \$\begingroup\$ It would be easy to implement some simple crypto and hardcode a key, making it impossible for robbers. \$\endgroup\$
    – Shelvacu
    Jul 1 '17 at 23:39
  • \$\begingroup\$ Isn't that what most cnr challenges center on? \$\endgroup\$ Jul 2 '17 at 0:30
0
\$\begingroup\$

Count bytes like a Java golfer

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

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

The rule in question is the following:

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

Challenge

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

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

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

You may assume the following:

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

You may not assume the following:

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

Bonus

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

How to count the number of UTF-8 bytes?

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

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

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

Test cases

Work in progress!


Notes for review:

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

What feedback do you have for me?

Challenge

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

Examples

Input:

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

Ouput:

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

Rules

\$\endgroup\$
9
  • \$\begingroup\$ I think this question has been covered pretty thoroughly by this challenge and this one, and would probably be closed as a dupe. \$\endgroup\$ Jul 1 '17 at 1:20
  • \$\begingroup\$ did not realize it had already been done :( \$\endgroup\$
    – zoecarver
    Jul 1 '17 at 1:22
  • \$\begingroup\$ It's not exactly the same question, but I think that area has been pretty much covered. Now, what you could do is use this question as a model, but go from 24-hour time to 12-hour time :) \$\endgroup\$ Jul 1 '17 at 1:28
  • 1
    \$\begingroup\$ I like that Idea! in fact I could take it a step further and convert a string in the following format: 2017-07-01T02:58:38.799Z to 12 hour time \$\endgroup\$
    – zoecarver
    Jul 1 '17 at 2:58
  • \$\begingroup\$ @musicman523 I made an edit to the question, what do you think? \$\endgroup\$
    – zoecarver
    Jul 1 '17 at 4:16
  • \$\begingroup\$ I definitely like this better. You should add more test cases with different days (for example, does 1 come out as 1 or 01?), months, days of the week, etc. so there is no confusion about the input format \$\endgroup\$ Jul 1 '17 at 4:27
  • \$\begingroup\$ ok, sounds good. Is that enough test cases? feel free to edit and add more details. \$\endgroup\$
    – zoecarver
    Jul 1 '17 at 4:28
  • \$\begingroup\$ I feel like the testcases should be formatted like input -> output\ninput -> output. What about the midday and midnight? \$\endgroup\$
    – NieDzejkob
    Jul 2 '17 at 17:53
  • \$\begingroup\$ Ok, Sounds good. I am posting it. \$\endgroup\$
    – zoecarver
    Jul 2 '17 at 23:12
0
\$\begingroup\$

Help! My code has exploded!

Insert backstory here

Task:

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

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

For example, if your program was the following:

aabbccdd

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

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

Scoring requirements:

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

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

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

Rules:

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

Introduction

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

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

Challenge

Output the number 13256278887989457651018865901401704640.

Example input and output

Input:

Not applicable.

Output:

13256278887989457651018865901401704640

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

Decode Reddit's Voting System

Background

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

Challenge

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

Constraints

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

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

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

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

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

Test Cases

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

Meta

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

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

Create The Correct Path

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

( OR )

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

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

Input

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

Output

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

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

Draw a Probability Road

Background

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

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

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

The Challenge

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

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

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

But what is a probability road?

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

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

| |
| |
| |

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

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

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

| | |
| | |X
| | | |

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

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

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

Note that the Week X labels are not necessary

Another example, this time for the input 80:

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

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

Rules

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

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

Meta

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

Also is there anything else that needs specifying or clarifying?

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

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

Story

(I guess)


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

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

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

Example:

Input:

test

Output:

8

Explanation: All keys have to be pressed down and released


Input2:

TEst

Output2:

10

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


Rules

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

Happy golfing!

Edit:

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

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

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

Thanks for the feedback so far.

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

Abbreviate a rename

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

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

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

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

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

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

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

This is , so the shortest program wins!

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

Lazy programmers need help versioning!

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

Your challenge

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

Input

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

Output

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

Rules

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

Test cases

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

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

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

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

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

Sandbox Questions

Not sure if this is dupe of Please release me!

Any feedback welcome.

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

Let's simplify polynomials

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

Motivation

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

Here is an example. Suppose we need to expand

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

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

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

, and so the expanded polynomial is .

The task

Write a program or function which satisfies the following:

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

Examples

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


Input
1003005007

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

Rules

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

Fighting a Land War

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

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

Each tile is either:

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

Board

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

Each turn, the following happens:

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

Notes:

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

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

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

What's Underneath the Sine Wave?

Task

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

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

Or a visual explanation:

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

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

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

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

so for this the output would be

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

Clarifications

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

Sample outputs

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

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

sandbox

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

Pristine Pristige

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

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

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

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

({}())

Is equivalent to the Pristige Program

(..|{|}(|))

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

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

Is an invalid program.

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

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

Task

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

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

Rules

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

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

  • You may use any default IO format.

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

Reference Implementation

Here will go an implementation I have not yet completed

Test Cases

Here will go test cases

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

Write a code poem

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

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

The challenge:

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

Coding rules:

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

Misc rules:

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

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

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

i_am > than_you # read symbols/operators as words

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

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

Winning:

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

For sandbox only:

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

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

Challenge

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

Key

Billion -> B

Million -> M

Thousand -> K

Rules

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

Examples:

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

Submissions

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

Bastion Breach

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

Introduction and rules

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

Input/Output format for bots:

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

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

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

Example scoring

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

Scoring for regular cards: 23456789JQK

Scoring for the ace:

wins: JQK
draw: A
lose: 23456789

Submission

You should write your entry as

Bot Name, Language

Insert
Code
Here

Explanation/Random stuff here

Running the tournament yourself

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

Other rules and information

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

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

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

Sandbox notes:

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

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

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

The output would look something like this:

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

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

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

Score = Stroke - Par

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

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

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

Fill to the line!

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

Example:

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

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

Test cases:

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

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

**********

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

You must log in to answer this question.

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