556
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3988 Answers 3988

1
93 94
95
96 97
133
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, 2017 at 6:56
  • \$\begingroup\$ 1. I'm still thinking about this. I think I'm going to randomly generate a triangular segment, and then mirror it across to the other 5 segments. 2. Oooh...I haven't thought about this. Thanks, I'll give it some thought. \$\endgroup\$ Jul 16, 2017 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, 2017 at 12:27
  • \$\begingroup\$ @officialaimm The characters can be of your choosing, there's no input currently \$\endgroup\$
    – dzaima
    Jul 3, 2017 at 12:27
  • \$\begingroup\$ So, all the positions marked by X should have same character or can have different characters? \$\endgroup\$ Jul 3, 2017 at 12:40
  • \$\begingroup\$ @officialaimm They can have any characters \$\endgroup\$
    – dzaima
    Jul 3, 2017 at 12:42
  • 1
    \$\begingroup\$ I think its better if you showcase sample output with different characters then. \$\endgroup\$ Jul 3, 2017 at 12:53
  • \$\begingroup\$ I can't tell what the task is from reading the description, or from looking at the example. It might help to walk through a few example columns to make it clear, then follow up with the full wave examples after that. \$\endgroup\$
    – trichoplax
    Jul 17, 2017 at 14:12
  • \$\begingroup\$ @trichoplax good idea \$\endgroup\$
    – dzaima
    Jul 17, 2017 at 14:12
  • \$\begingroup\$ Thanks. A second look at the examples was enough for me to grasp the pattern, but a step by step example would probably have got it across quicker. \$\endgroup\$
    – trichoplax
    Jul 17, 2017 at 14:14
0
\$\begingroup\$

Pristine Pristige

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

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

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

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

({}())

Is equivalent to the Pristige Program

(..|{|}(|))

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

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

Is an invalid program.

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

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

Task

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

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

Rules

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

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

  • You may use any default IO format.

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

Reference Implementation

Here will go an implementation I have not yet completed

Test Cases

Here will go test cases

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

Write a code poem

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

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

The challenge:

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

Coding rules:

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

Misc rules:

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

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

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

i_am > than_you # read symbols/operators as words

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

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

Winning:

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

For sandbox only:

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

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

Challenge

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

Key

Billion -> B

Million -> M

Thousand -> K

Rules

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

Examples:

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

Submissions

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

Bastion Breach

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

Introduction and rules

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

Input/Output format for bots:

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

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

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

Example scoring

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

Scoring for regular cards: 23456789JQK

Scoring for the ace:

wins: JQK
draw: A
lose: 23456789

Submission

You should write your entry as

Bot Name, Language

Insert
Code
Here

Explanation/Random stuff here

Running the tournament yourself

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

Other rules and information

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

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

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

Sandbox notes:

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

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

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

The output would look something like this:

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

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

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

Score = Stroke - Par

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

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

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

Fill to the line!

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

Example:

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

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

Test cases:

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

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

**********

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

Comparing Strings

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

Test Cases

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

input, input -> output

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

Rules

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

This is , so shortest answer in bytes wins.

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

Can you generate this random sequence for me?

Inspired by this question on Retrocomputing

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

Input

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

Task

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

Rules

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

Example implementation:

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

Make it night!

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

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

Challenge

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

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

Example

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

Original

Result

Voting

Please vote accordingly to how well the algorithms perform.

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

(If you have a suggestion, please comment.)

Test Cases

Test case 1

Test case 2

Test case 3

Winning

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

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

Intertwined Polyglot

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

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

Rules

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

Multiplicity of a Curve

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

Details

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

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

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

Example

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

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

So the decomposition is

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

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

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

TODO

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

Code the beach on the beach (heavily WIP)

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

Code the beach

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

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

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

To avoid this beach becoming overloaded, there should be:

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

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

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

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

TODO: Add example waves

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

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

On the beach

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

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

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

Here are the lookalikes:

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

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

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

Numbers to Algorithms

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

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

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

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

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

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

   505
   505
   505
111424333242
111424333242
111424333242
   050
   050
   050

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

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

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

Arbitrary base conversion

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

Rules:

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

Test cases

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

Sandbox

Is this a dupe?

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

Bomberman

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

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

Worked Example

An example board would be (without bombs):

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

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

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

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

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

Example 1:

Input:

XX
XX

Output:

XX
XX

Example 2:

Input:

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

Output:

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

Example 3:

Input:

X     X
 OOOO
  1114


X     X

Output:

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

Rules

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

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

Is Effort Inversely Correlated with Upvotes?

Inspired by this chat message and the subsequent conversation

Introduction

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

The Challenge

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

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

Defining Effort

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

Defining Votes

Votes is upVotes - downVotes.

Defining Correlation

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

What Points?

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

Test Cases

//TODO

Specifics

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

Meta

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

Word Problem Generator

Already exists here!

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

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

Rules

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

Examples

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

Submission

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

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

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

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

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

Minimum Requirements

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


All suggestions welcome!

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

Help Me Catch Up With xkcd!

I definitely enjoy xkcd, and you, as a code golfer, most likely enjoy it as well. However, I often find that I won't check the website for a while and there will be a lot to read! So, I want to make a solution for that. In proper code golf fashion.


The Challenge

Your task is to write a program which, when run, will check for a new xkcd and, if there is a new comic (in other words, it is different from the one when the program last ran), output the text "There's a new xkcd out!". Use this method to check:

  1. When the program is run, check if there is a file named .xkcd in the user's home directory. If not, create the file, which will contain the title of the current xkcd comic, then exit.
  2. If the file .xkcd does exist in the user's home directory, the program will check if the title of the xkcd comic on the front page of xkcd.com is the same as the one in .xkcd. If it is, the program will exit and do nothing else. However, if the titles aren't the same, the program will output the specified text, change the contents of .xkcd to the new title, then exit.

If you have any other methods, tell me about them.


This is , so may the shortest code win and the best programmer prosper...

\$\endgroup\$
4
  • 2
    \$\begingroup\$ This seems rather close to codegolf.stackexchange.com/q/91847/194 \$\endgroup\$ Aug 27, 2017 at 15:51
  • \$\begingroup\$ @PeterTaylor Dupe? \$\endgroup\$
    – ckjbgames
    Aug 27, 2017 at 22:06
  • \$\begingroup\$ @PeterTaylor Also, how could I distinguish it and add something unique so that it isn't marked as a dupe? \$\endgroup\$
    – ckjbgames
    Aug 27, 2017 at 22:10
  • \$\begingroup\$ My opinion in general is that when a question is a borderline dupe it's more productive to ditch it and try to think of a radically different question than to try to bisect to find the minimal sufficient difference. I don't see anything about this particular topic which would make it an exception to that general rule. \$\endgroup\$ Aug 28, 2017 at 14:09
0
\$\begingroup\$

? ?

JS, 44 bytes

Here's a list of languages & byte counts from PPCG:

Jelly, 27 bytes
Mathematica, 174 bytes
Scala, 91 bytes
05AB1E, 12 bytes
dc, 13 bytes
Python 2, 115 bytes
V, 25 bytes
Charcoal, 48 bytes
Jelly, 10 bytes
Haskell, 25 bytes
MATL, 14 bytes
x86-16, 43 bytes
Emoji, 50 bytes
Pyth, 9 bytes
C, 38 bytes
JavaScript, 69 bytes
R, 73 bytes
Node.js, 70 bytes
Ly, 7 bytes
Japt, 7 bytes
Java, 2777 bytes
Husk, 18 bytes
Beatnik, 148 bytes
APL, 10 bytes
Powershell, 127 bytes
Python 3, 111 bytes
Ruby, 38 bytes
Cubically, 1231 bytes
C++, 292 bytes
Common, 98 bytes
Swift 4, 63 bytes
Axiom, 91 bytes
Groovy, 7 bytes
Bitmap, 160 bytes
Batch, 86 bytes
Perl 5, 34 bytes
Pyke, 7 bytes
Java, 182 bytes
PHP, 1 bytes
C#, 163 bytes
Processing, 85 bytes
Tcl, 66 bytes
PowerShell, 11 bytes
LOGO, 33 bytes
axo, 22 bytes
Excel, 37 bytes
TXR Lisp, 76 bytes
Alice, 17 bytes
Moorhens, 716 bytes
PHP, 2943 bytes
Python, 79 bytes
QBIC, 25 bytes
D, 65 bytes
Emojicode, 50 bytes
REXX, 46 bytes
BBC, 70 bytes
Retina, 24 bytes
Bash, 74 bytes
Cubix, 28 bytes
cQuents, 7 bytes
J, 90 bytes
AHK, 110 bytes
Mathics, 46 bytes
RProgN 2, 8 bytes
SOGL, 36 bytes
Röda, 36 bytes
><>, 238 bytes
QuadR, 32 bytes
C#, 289 bytes
Bash, 385 bytes
JS, 2823 bytes
C, 14 bytes
HTML, 132 bytes
Ruby, 40 bytes
JS, 130 bytes
Gaia, 17 bytes
TI-BASIC, 17 bytes
Befunge, 10 bytes
Ruby 2.4, 53 bytes
Pari/GP, 21 bytes
Actually, 10 bytes
APL, 4 bytes
TXR, 74 bytes
Sage, 102 bytes
Grime, 28 bytes
Ruby, 101 bytes
C++17, 71 bytes
Perl, 41 bytes
CPython, 25984 bytes
SmileBASIC, 43 bytes
WendyScript, 50 bytes
Python, 2969 bytes
Clojure, 156 bytes
Lost, 57 bytes
C++, 19 bytes
Brachylog, 4 bytes
Octave, 25 bytes
C#, 123 bytes
Magneson, 102 bytes
Brain-Flak, 36 bytes

This list will change before this challenge is posted.

Your challenge

Look at the program before you. It will print something like JS, 23 bytes. That means that you must use JS as your language.

Then pick a line from the list. Let's say you pick LOGO, 33 bytes. That means that you must print LOGO, 33 bytes in JS.

Because LOGO, 33 bytes is the 44th line, your byte count modulo the number of languages in the list (there are 100) must equal 44.

The three restrictions:

  • You must use JS
  • You must print LOGO, 33 bytes
  • Your byte count modulo 100 must be 44

So a valid submission might be:

x=>"LOGO, 33 bytes"//just wasting some bytes

Then, after your submission, you add the list from the last answer to your answer. Then, you remove Logo, 33 bytes from the list: (in your answer, not the question)

That's the language you used, and the byte count you used. Add it to the bottom. Dupes are OK.

Your answer will look like this:

JS, 44 bytes

x=>"LOGO, 33 bytes"//just wasting some bytes

Here's the new list:

(Insert the list here, and remove `Logo, 33 bytes`)

The next submission must use Logo.

Note that the list will continually get smaller, making the challenge harder.


Meta

  • Winning criterion? Last answer? Second-to-last?
  • Unclear?
  • Dupe?
\$\endgroup\$
8
  • \$\begingroup\$ @BusinessCat Ok, I think I'll restrict to TIO-only langs when I update the list. Thanks for the feedback! \$\endgroup\$
    – user58826
    Aug 23, 2017 at 14:00
  • 3
    \$\begingroup\$ 1. In the interests of clarity, when picking arbitrary numbers make them different. 44 seems to occur in two different contexts in the example. 2. The bit about adding to the list is unclear. Are you saying that after submitting an answer, you must edit the question? That will (a) cause conflicts; (b) (I think) cause the question to become community wiki quite quickly; (c) break the example. And to accomplish what? 3. Expanding on that previous question: what is the motivation? Even answer-chaining questions benefit from a clear motivation for the core task. \$\endgroup\$ Aug 23, 2017 at 21:29
  • \$\begingroup\$ @PeterTaylor I hope the recent edit clarified 2., and I will use a different list when I post this (1.) \$\endgroup\$
    – user58826
    Aug 24, 2017 at 11:38
  • \$\begingroup\$ @programmer5000 Röda \$\endgroup\$ Aug 25, 2017 at 14:15
  • \$\begingroup\$ @programmer5000 Thanks, that clears up adding to the list. \$\endgroup\$ Aug 25, 2017 at 14:25
  • \$\begingroup\$ You probably want to remove from the list either what language was previously printed or what language you're currently printing, that way the list remains modulo 100. \$\endgroup\$ Aug 25, 2017 at 14:28
  • \$\begingroup\$ I think that every answer-chaining question so far has some mechanism to make it increasingly harder to extend the chain. With this one it seems to get easier to extend the chain rather than harder. Is this not a fundamental flaw? \$\endgroup\$ Aug 27, 2017 at 17:34
  • 1
    \$\begingroup\$ The way I read it, every answerer removes one item from the list and adds one item to the list, so it doesn't get shorter. \$\endgroup\$ Aug 28, 2017 at 13:56
0
\$\begingroup\$

Where in the world am I?

Original Challenge

This challenge has a single aim, given no input, print out the user's current location, with a minimum of the following info:

  • City
  • Country

So any of the following are allowed:

  • "London, England"
  • "Eifel Tower, Paris, France"
  • ["London", "England"]
  • {"country": "Scotland", "city": "Edinburgh"}

The following are not allowed:

  • [51.5074, 0.1278]
  • {"country": "Scotland", "city": "Edinburgh", ISP: "EE"}

Do not show the user's IP or ISP name, or any extra output.

Standard code golf rules apply

Good luck, and have fun!

Reason for limits

Thanks

programmer5000 - Suggesting to post here after original was deleted

caird coinheringaahing - Lon and Lat rules

\$\endgroup\$
7
  • \$\begingroup\$ Is returning a list of geo-cordinates allowed? You might want to clarify that in the question \$\endgroup\$ Aug 28, 2017 at 14:12
  • 3
    \$\begingroup\$ This has a number of issues with ill-defined cases. In particular, the following are not addressed: (A) my location is unambiguously in a given country, but there's no city within several hours' drive; (B) my location is unambiguously not inside any country; (C) the territorial ownership of my location is disputed; (D) it's not clear what the name of the country is (where your example of Edinburgh is a good one: if Scotland is correct, is UK incorrect? How about dependencies, colonies, etc?) \$\endgroup\$ Aug 28, 2017 at 21:26
  • 2
    \$\begingroup\$ In addition, it contradicts itself over whether {"country": "Scotland", "city": "Edinburgh"} is allowed or not; and it is not very testable. To make this a good challenge I would recommend taking latitude and longitude as inputs and providing a complete and unambiguous specification of exactly what the output string should be such that any incorrect answer can be shown to be incorrect with a test case which it fails. \$\endgroup\$ Aug 28, 2017 at 21:28
  • \$\begingroup\$ TBH, if someone was onboard the International Space Station and decided to take time out to complete my code golf challenge I would take it as a compliment. For international waters I would be OK with an answer that pointed towards that. For ones with multiple answers / disputed it would probably be reasonable to accept multiple answers, but there may be issues with this I have not foreseen. \$\endgroup\$
    – jrtapsell
    Aug 28, 2017 at 21:35
  • \$\begingroup\$ RE: The contradiction, this was an omission I hope I have fixed now \$\endgroup\$
    – jrtapsell
    Aug 28, 2017 at 21:37
  • \$\begingroup\$ Is there a way to fix this issue more generally? I know my answer is a bit vague and not built into the question \$\endgroup\$
    – jrtapsell
    Sep 1, 2017 at 10:31
  • \$\begingroup\$ Is this challenge good to go, needs changes, or not of use? \$\endgroup\$
    – jrtapsell
    Sep 2, 2017 at 23:20
0
\$\begingroup\$

Paint with Pride!

Task: Output a 6 banded version of the pride flag

Details:

The flag consists of 6 bands of colour, each band is rectangular, and all are the same size which is 9x1 units (WxH) . These bands are stacked one on top of each other in the order shown to form a flag that is 9x6 units in size.

The output scale can be chosen by the participant, but all components must be in those ratios, that is, an output must have an aspect ratio which is a multiple of 3:2.

The hexadecimal values and relative positions of the colours are as below:

Full size

Or from top to bottom RGB (255,0,0), (255,153,0), (255,255,0), (0,153,0), (0,0,255), (204,0,153)

A minimal version would look like this:

Min size

Acceptable output:

Output to screen or as a file in a commonly accepted image format is allowed, ascii art is however not.

Sandbox notes:

related, related

I chose this flag because I think the rainbow provides potential for an additional mathematical element

I'm not sure whether to include a minimum size limit, such as the one for drawing the french flag, as perhaps the small output size allows hardcoded answers to succeed (which I don't really want) - any advice?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This is a duplicate of this unfortunately \$\endgroup\$ Aug 29, 2017 at 19:05
  • \$\begingroup\$ @cairdcoinheringaahing Shoot, all that time searching for "Pride" and "Flags", forgot to search for rainbow! Perhaps this is significant-enough a variant (rectangle vs bow) that it will allow for different approaches though. I'm not sure what the etiquette is, but I guess I'll leave this up for a while longer and let votes tell me whether it is too much of a duplicate to post. \$\endgroup\$
    – Greedo
    Aug 29, 2017 at 19:25
  • \$\begingroup\$ personally, I would close as a duplicate, but if you want to keep it here and see otherwise, go ahead. \$\endgroup\$ Aug 29, 2017 at 19:26
0
\$\begingroup\$

The source of pi

Inspired by an International Obfuscated C Code Contest entry.

Task

As you all know, pi is a constant that represents the ratio of a circle's circumference to its diameter.

Using the dimensions of your own source code, approximate pi to at least two decimal places.

That is, your source code should read itself to obtain both circumference and diameter, then output the ratio.

For example, if your code is:

 AB
CDEF
 GH

Your circumference is 14 and your diameter is 4.

For the purposes of this challenge, let diameter equal the larger of the height or width of your code.

Rules

  • Take no input
  • Hardcoded values for pi are not allowed
  • Output pi to at least two decimal places (e.g., 3.14 and 3.1415 are both acceptable outputs)
  • Answers can be either whole programs or functions

Notes

Answers with higher precision values are acceptable.

Standard rules apply.


Meta

Looking for suggestions of a better title.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Well, I'm not sure what "Using the area of your own source code" means. I could do some pretty "standard" approximation algorithm to fullfill your rules. \$\endgroup\$ Aug 29, 2017 at 16:58
  • \$\begingroup\$ Wouldn't print(3.14) work? It isn't hardcoding pi, as pi isn't 3.14. \$\endgroup\$ Aug 29, 2017 at 19:22
  • \$\begingroup\$ @FelixPalmen - I've updated the specification. Hopefully it is more clear. \$\endgroup\$
    – CzarMatt
    Aug 29, 2017 at 20:14
  • \$\begingroup\$ @cairdcoinheringaahing - I've updated the specification. Hopefully it is more clear. \$\endgroup\$
    – CzarMatt
    Aug 29, 2017 at 20:16
0
\$\begingroup\$

"Square Root of Pi(e)"

A pie (r=3) is drawn as such:

  @@
 @@@@
@@@@@@
 @@@@
  @@

Pretending that it's a perfect circle, the square root of such a pie would be sqrt(PI*32) = 3sqrt(PI) ~ 5.317. Now take a square out of the pie, whose area is closest to the square root of the pie. In this case it would be a square of area 4. Therefore, you can output:

  @@
 @@@@
@@  @@
 @  @
  @@

Yep, I took a square out of the pie, how do you like that?


r=7

      @@
     @@@@
    @@@@@@
   @@@@@@@@
  @@@@@@@@@@ 
 @@@@@@@@@@@@
@@@@@@@@@@@@@@
 @@@@@@@@@@@@
  @@@@@@@@@@
   @@@@@@@@
    @@@@@@
     @@@@
      @@ 

7*sqrt(PI) ~ 12.407. Closer to 3x3 than 4x4 square.

      @@
     @@@@
    @@@@@@
   @@@@@@@@
  @@@@@@@@@@ 
 @@@@@@@@@@@@
@@@@@@@@@@@@@@
 @@@@@@   @@@
  @@@@@   @@
   @@@@   @
    @@@@@@
     @@@@
      @@ 

Specifications:

  1. Input will be only a "pie" with integer radius of at least two. As you can see, the longest row has 2r @s, and the smallest rows have 2 @s.
  2. You can use a symbol other than "@".
  3. You can take a square out of the inside or the edge.
  4. Approximate PI to at least 3.14.

Bonus: Valid answers that are in a language with food-related name get a free upvote!

\$\endgroup\$
1
  • \$\begingroup\$ You don't ever define How one forms the pie shape, and in general you seem to be lacking specification. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 3, 2017 at 3:37
0
\$\begingroup\$

The Best Question

This site gets a variety of questions: the good, the bad, the ugly. However, I've noticed some patterns that I think will help us find The Best Question (of a given week).

Procedure

You are given a date in a human-readable format of your choice as input. You need to find the best question from that week. The week starts on Sunday and ends on Saturday. Click on the link for a valid query to use if the input is Aug 31, 2017. Note that when using the API without a key you can use UNIX epoch time or YYYY-MM-DD to specify the dates (info here). Since this site gets only about 45 questions a week, you can assume that no more than 100 questions will be asked in a given week in order to avoid pagination.

Scoring

First of all, closed questions are disqualified. Next, here is the formula for Question Rating (QR)1, given Question Score (S) and Number of Answers (A):

The thinking is that there are two kinds of questions that undeservedly get a very high question score: 1) the ones that are easy and get a lot of answers, and 2) the ones that are so difficult that they get few or no answers. I've determined that the best questions have a QuestionScore:Answer ratio of about 3:2.

Output

All you have to do is output the full URL of the question that got the best question score. If multiple tie, you can output them all or just one.

Example

Here's a list of 8 imaginary questions, with their question score followed by the number of answers they received, and their resulting QR:

1. +6, 23A -> -0.333
2. +10, 0A -> 7.78
3. +8, 4A -> 7.56
4. -2, 6A -> -4.44
5. +5, 3A [closed] -> DQ
6. +20 2A -> 16.22
7. +24, 40A -> 16
8. +15, 14A -> 13.67

So the winner is question 6. Output its URL.

Note

You don't need to handle the rare edge case when there are no valid questions in a given week.

1Disclaimer: This scoring system is just a joke.


Suggestions on formula and other stuff welcome.

\$\endgroup\$
2
  • \$\begingroup\$ Is that abs((QuestionScore/2)-Answers)/2 or abs(QuestionScore/(2-Answers))/2? \$\endgroup\$
    – Shaggy
    Sep 1, 2017 at 12:05
  • \$\begingroup\$ Hopefully this looks a bit better. \$\endgroup\$
    – geokavel
    Sep 1, 2017 at 15:29
0
\$\begingroup\$

Extend the Pattern

Given a raster image with a lattice pattern, extend it to twice the size of the input image in both directions.

Details

The input image is a section of an infinite repeating pattern defined by two vectors u=(ux,uy),v=(vx,vy) with integer entries, that are linearly independent. This means that both vectors are nonzero and do not point in the same direction. The pattern is defined such that the pixel at a point p = (x,y) has the exact same colour as the pixel at

q := p + s*u + t*v 

for every integer s,t. This means if you know the colours of the pixels within the fundamental parallelogram Z = { s*u + t*v | s in [0,1),t in [0,1)} and corresponding vectors u,v you can extend the pattern to an arbitrary size. The goal of this challenge is finding the pattern and extend the image.

enter image description here

Specs

  • You can take the input image in any non-compressed image format that allows for at least 3 colours, this includes e.g. matrices, 2d arrays or strings.
  • The input method must match the output method. That means if you read a .png file as input, you must also write a .png file as output, or if you take the input via console, you must also print the output via console e.t.c.

Examples

(to be added...)

\$\endgroup\$
5
  • \$\begingroup\$ Is there freedom to choose which quadrant of the output image corresponds to the input image? \$\endgroup\$ Sep 3, 2017 at 18:05
  • \$\begingroup\$ You need to add some harder test-cases - at present you can just check for overlaps, tile "infinitely" then crop. \$\endgroup\$
    – wizzwizz4
    Sep 4, 2017 at 16:25
  • \$\begingroup\$ @PeterTaylor Good question, I think I will leave the direction arbitrary. \$\endgroup\$
    – flawr
    Sep 4, 2017 at 19:53
  • \$\begingroup\$ @wizzwizz4 I think this method works in any case, or do you have an example in mind where this does not work? \$\endgroup\$
    – flawr
    Sep 4, 2017 at 19:54
  • \$\begingroup\$ @flawr One where there's less than one copy of the parallelogram... wait, that wouldn't prevent the overlap technique from working. \$\endgroup\$
    – wizzwizz4
    Sep 4, 2017 at 19:58
0
\$\begingroup\$

Golf a Brainfuck compresser.

The eso-lang Brainfuck only has 8 instructions that do something: +-><[],. so in theory you could represent them in 3 bits. You could store 8 instructions in 24 bits or 3 bytes.

BrnFck

This is compressed brainfuck an instruction will be represented by its bits.

  1. + : 000
  2. - : 001
  3. > : 010
  4. < : 011
  5. [ : 100
  6. ] : 101
  7. , : 110
  8. . : 111

This is a language counted in bits, 8 bits is 1 byte depending on the challenge you may round up or keep a decimal.

The goal

Write the shortest program that can compile any inputted brainfuck code to BrnFck code:

  • You can choose how you output it, byte,bit/boolean arrays and output streams are all acceptable. Just printing ASCII-letters is too.
  • You can do anything (including crash) if the input isn't valid code or contains a non-bf character.

And can compile the BrnFck code back to Brainfuck (or any other language (except BrnFck)). You may ask which way you want to compile or write 2 separate programs/functions and sum their scores.

If you post the code online (for example as an answer) this should automatically allow BrnFck as a language in all future challenges!

Scoring

If you use brainfuck you can divide your bytes by 2.

If you use BrnFck you can divide your bytes by 4 (let's get some recursion going here).

1 bit will be counted as 0.125 bytes (please put both in the title) so decimal byte scores are allowed.

Tags

brainfuck,code-golf,...

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This encoding doesn't really work since no sensible architecture allows partial bits. Since each 3 bit word is already used, there is no way to distinguish say ,+. from ,+.. if you happen to fill the remaining bits in that way. That said, it isn't totally required for the question for this to work. Otherwise, the bonuses and scoring are needless and confusing, so I'd recommend removing them. \$\endgroup\$ Sep 3, 2017 at 16:57
  • 3
    \$\begingroup\$ Nearly every byte score on PPCG is decimal (base 10): I think you mean that fractional byte scores are possible. To deal with the padding problem, I suggest that you specify that where one or two padding bits are required, 0 should be used; and where three to seven are required, the padding should be 101 followed by as many 0s as necessary. Since [] must be balanced, this allows unambiguous detection of the padding on decompression. Then make sure to include a test case which ends in ] and requires no padding... \$\endgroup\$ Sep 4, 2017 at 8:02
0
\$\begingroup\$

Program that allows the user to edit it's own source code

Write a program that displays and allows the user to view, edit and save it's own source code.

  • If no edits are made, the output file should be the same as the program, and hence executing it should allow the user to edit the program's code again. (ie a quine)
  • If the code has been edited in a sensible way, running the program again should display the edited code. The definition of 'sensible' is left flexible to prevent this being impossible - as the source code can be edited, a user can obviously edit the program in such a way that it no longer displays it's source code.

The standard quine rule applies: no reading the source file directly.


Additional Notes and things to consider:

  • How robust is your program? What percentage of your program can be edited (sensibly) before it stops displaying it's own source or saving the edits you made.
  • Both overwriting and saving with a different filename are valid ways for the program to save it's new code
  • If it is a compiled language, the program does not have to invoke the compiler or do the compiling itself after saving.
  • This is a code challenge not code golf. Robustness, interface and 'coolness' of the solution are favoured over brevity.

  • Extra, uh, points(?!) if your program can identify errors in the quine before saving.


Is this a feasible challenge? Does it need clarification?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ If the only winning-criteria is "Percentage of the characters which can be changed without breaking it" then the answerer can arbitrarily pad their score with an irrelevant string if their language has very versatile quining capabilities. The other things "favored" only really count if it's a popularity-contest and challenges with that tag are discouraged. \$\endgroup\$ Sep 7, 2017 at 21:07
  • \$\begingroup\$ Do you have any suggestions on how to score it? I can't think of any cross-language methods. \$\endgroup\$
    – sdfgeoff
    Sep 7, 2017 at 21:21
  • \$\begingroup\$ Currently you are scoring it as (characters that can change / total), You could square or cube the total to incentivise golfing, that way padding can only hurt you. However you want to watch out for very short programs that make little effort to complete the task but by virtue of their shortness are highly scoring. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 17, 2017 at 0:35
0
\$\begingroup\$

Prime Number Locator

Given a prime number p > 1, determine at what index p appears in A000040.

  • You may 0 or 1 index, meaning 2 can return 0 or 1.
  • If you are given a non-prime number you must return -1.
    • If you are 1-indexing you may return 0 instead, or still return -1.
  • Your time complexity must be less than O(n): Please explain your calculations in the answer.

First 10 return values (0-indexed):

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
[0, 1, 2, 3,  4,  5,  6,  7,  8,  9]

This is : Reduce your byte-count to win.

\$\endgroup\$
4
  • \$\begingroup\$ Related \$\endgroup\$
    – H.PWiz
    Sep 8, 2017 at 17:41
  • \$\begingroup\$ @H.PWiz, I'd call that a dupe; the count is the index. \$\endgroup\$
    – Shaggy
    Sep 9, 2017 at 11:48
  • \$\begingroup\$ @Shaggy This one is restricted-complexity though \$\endgroup\$
    – H.PWiz
    Sep 9, 2017 at 12:00
  • \$\begingroup\$ o(n) is impossible: this isn't a problem which can be solved without reading all of the input. If that were relaxed to O(n) I think this would fit the "Too broad" close criterion because a properly explained answer would be a (very good) doctoral thesis. The current state-of-the-art algorithms are O(2^(2n/3) + epsilon), so a polynomial algorithm would already be impressive, and a linear one would be astounding. \$\endgroup\$ Sep 11, 2017 at 8:59
1
93 94
95
96 97
133

You must log in to answer this question.

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