490
\$\begingroup\$

What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, and click "Answer This Question". Click "OK" when it asks if you really want to add another answer. Write your challenge just as you would when actually posting it. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it. When you think your challenge is ready for the public, go ahead and post it, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

| |
\$\endgroup\$

2956 Answers 2956

1
73 74
75
76 77
99
0
\$\begingroup\$

Clean duplicate website from my history

Introduction

I am looking for help to monitor my history. I parsed everything, but I am not yet happy with the final result. Could you help me? I want to remove following same website.

My history looks like this:

| url                                               | id |
|---------------------------------------------------|----|
| https://codegolf.stackexchange.com/q/147318/15214 | 4  |
| https://codegolf.stackexchange.com/q/148927/15214 | 4  |
| https://en.wikipedia.org/wiki/Code_golf           | 3  |
| http://lichess.org                                | 2  |
| https://en.wikipedia.org/wiki/Code_poetry         | 1  |

But I want it to be:

| url                                               | id |
|---------------------------------------------------|----|
| https://codegolf.stackexchange.com/q/148927/15214 | 4  |
| https://en.wikipedia.org/wiki/Code_golf           | 3  |
| http://lichess.org                                | 2  |
| https://en.wikipedia.org/wiki/Code_poetry         | 1  |
  • If I browse a site, then another one, then the first one. I keep all of them.
  • If I browse a site, then another part of the same site. I keep only the first one.
  • The list is ordered from young to old. (we keep the older)

This challenge is inspired by my day work, but it is not related in any ways with anything in it.

Challenge

  • Input is a list of identifier.
  • Output is a list of two elements (identifier's index, identifier).
  • No Empty input
  • No standard loophole
  • This is code-golf, so shortest answer in bytes wins.

Examples Input and Output

2 links on website 1

Input:

[ 1, 1 ]

Output:

[
    [1,1]
]

1 link on website 2, then 3 links on website 1

Input:

[ 1, 1, 1, 2]

Output:

[
    [2,1],
    [3,2]
]

1 link on website 1, then 1 link on website 2, then 2 link on website 1

Input:

[ 1, 1, 2, 1]

Output

[
    [1,1],
    [2,2],
    [3,1]
]

Question

  • Should I allow outputs as list of object, list of tuple or dictionary/map?
  • Should I ask for url parsing where identifier is the hostname?
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Question title and tag? \$\endgroup\$ – user202729 Nov 24 '17 at 14:11
  • 1
    \$\begingroup\$ Also I think the I/O specification (Input is a list of two elements. / Output is a list of two elements.") seems to contradict the test cases. \$\endgroup\$ – user202729 Nov 24 '17 at 14:33
  • \$\begingroup\$ @user202729 Update title, tag and I/O specs. Thank you. \$\endgroup\$ – aloisdg moving to codidact.com Nov 24 '17 at 14:53
  • \$\begingroup\$ You definitely should allow using tuples, maps and dictionaries for input and output. In fact, that's an understatement. You should read the meta post on I/O methods. URL parsing will make the challenge more interesting, IMO. \$\endgroup\$ – NieDzejkob Nov 24 '17 at 19:12
0
\$\begingroup\$

File Selection

In this challenge, you will be given a number of files and a series of instructions corresponding to simulated key-mouse press combinations performed in a file explorer (rules below) and you are to return the files that are selected.

There are two "program states" you need to store: the target (which is the last file selected) and the files selected so far (this starts as [])

Static Combinations

These can be given as any constant values that are distinct from each other.

  • Ctrl-A: Select all files. Does not change the target.
  • Esc: Deselect all files. Sets the target to None.
  • Up-Arrow: Select only the file directly above the target. This should have no effect if the target was the first file. This should select the last file if there is no target. Sets the target to the selected file.
  • Down-Arrow: Select only the file directly below the target. This should have no effect if the target was the last file. This should select the first file if there is no target. Sets the target to the selected file.
  • Shift-Up-Arrow: If the most recent selection is a range going down, then remove the target from the selection and then set the target to the one above. If the most recent selection is a range going up or is a single file, then set the target to the one above and then add the (new) target to the selection. If there is no selection, this should select the last file. Alternatively, you can imagine this as undoing the last action, moving the target up, and then reapplying the last action with the new target; however, this idea is not 100% accurate when the last action was Esc.
  • Shift-Down-Arrow: Same as above, except with down and up swapped, all above and below swapped, and first and last swapped.
  • Home: Select only the first file and set the target to the first file.
  • End: Select only the last file and set the target to the last file.

Note that up arrow and down arrow should not wrap around.

Keyboard-Mouse Combinations

These can be given as any combination of a constant value that is distinct from the others on this list and a number representing which file was clicked.

  • Ctrl-#: Add # to the selection list and set the target to #.
  • Shift-#: Add all files between the target and # (inclusive) to the selection list and set the target to #. If there is no target before this operation, this will behave like Blank-#.
  • Blank-#: Set the target to # and select only #. Technically Blank isn't a key but to make matters simple, it's just a placeholder so I don't have to add a third class of combinations just for regular mouse presses.

Challenge Specifications

You will be given input as a positive integer representing the number of files, and a list of any of the combinations listed above, in a reasonable input format that you choose. The output should be a list of which files are selected, with any indexing.

Test Cases

All of these test cases have 10 files. [#] is a mouse press.

Input [1-indexed] -> Output [1-indexed]
Ctrl-A -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Shift-Down-Arrow, Shift-Down-Arrow, Shift-Down-Arrow -> [1, 2, 3]
Shift-Up-Arrow, Esc, Shift-[4], Ctrl-[7], Shift-[9] -> [4, 7, 8, 9]
Down-Arrow, Down-Arrow, Down-Arrow, Shift-Down-Arrow, Shift-Down-Arrow, Ctrl-[8], Shift-[10] -> [3, 4, 5, 8, 9, 10]

Rules and other technical things

  • Standard Loopholes Apply
  • Shortest code wins, but no answer will be accepted
  • You may not open a file explorer and run the commands :P (I think that would end up being longer anyway)
  • No builtin for this exact challenge (I will be very surprised if there is one, unless it's Mathematica)

Sandbox

  • I'm not confident that the explanation / specification is good enough for the Shift Arrow Key combinations; is that clear or do I need to specify it more rigorously?
  • Is anything else unclear?

Please leave an upvote if the challenge makes sense to you and please downvote if anything is unclear.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ "You may not open a file explorer and run the commands" and "No builtin for this exact challenge" - why? This just rules out what could have been an interesting/laughable solution. \$\endgroup\$ – NieDzejkob Nov 27 '17 at 15:37
  • 1
    \$\begingroup\$ @NieDzejkob Yeah but anyone who posts one will probably end up getting a ton of undeserved upvotes having done next to no work. It shouldn't be a huge problem because probably approximately 0 languages have a builtin to do this, but still. \$\endgroup\$ – HyperNeutrino Nov 27 '17 at 15:43
  • \$\begingroup\$ It's kind of implied that there is only one column, but if that's the case that should be explicit as things like Shift-UpArrow function very differently if there are multiple columns. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 14:55
0
\$\begingroup\$

DNA Quine

Problem Description

Design a quine that outputs its own source code, but encoded into amino acids.
Read your source code in as binary. Each pair of bits now maps to a nucleotide like so:

00 -> A
01 -> C
10 -> G
11 -> T

For example, the ASCII character N has a binary representation of 01001110, so it would produce the nucleotide sequence CATG. A set of three nucleotides produces an amino acid. You can find the charts online, and I can't access imgur, so... yeah.

Anyways, your program must output its own source code as the three letter amino acid names. For example, if your code were 013201323300 in base 4, its nucleotide representation would be ACTGACTGTTAA and its amino acid representation would be ThrAspCysSTP.

Output

Your program must output its representation in amino acids.

Further Rules

All quines must also be valid proteins themselves. This means that:

  • The quine has a number of nucleotides divisible by three
  • The last three nucleotides are either TAG, TAA, or TGA, corresponding to a STP codon
  • No STP codons appear anywhere but the end of the quine.

Apart from that, the standard rules apply.

Scoring

This is code golf, so the shortest code wins.

Notes/Questions for Sandboxing

Ok, so I get that it's rather short. Is my point clear? Is the scoring section clear? How about loopholes? Should I point out that printing a single STP is not allowed? Would that even be possible?

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ You might want to elaborate on "expand it into base 4". Does that mean get each byte's codepoint, concatenate into one big binary integer, and then convert to base 4? \$\endgroup\$ – FlipTack Nov 27 '17 at 20:00
  • \$\begingroup\$ What happens if the number of nucleotide is not a multiple of 3? | The base 4 conversion is indeed unclear. \$\endgroup\$ – user202729 Nov 28 '17 at 1:01
  • \$\begingroup\$ @user202729 if there's a spare nucleotide, it's not a valid program. \$\endgroup\$ – Jakob Lovern Nov 28 '17 at 1:27
  • \$\begingroup\$ So basically "program length must be a multiple of 3". / For example program 00 FF should be 00 00 00 00 11 11 11 11 = AAAATTTT or TTTTAAAA? \$\endgroup\$ – user202729 Nov 28 '17 at 1:52
  • \$\begingroup\$ Yeah, essentially. Except that some code golf languages have special character sets that aren't 8 bits, and some trickster out there might use that. \$\endgroup\$ – Jakob Lovern Nov 28 '17 at 2:10
  • \$\begingroup\$ @JakobLovern Unless there are some computers that can store fractional byte size, that won't be accepted. \$\endgroup\$ – user202729 Nov 28 '17 at 2:53
  • \$\begingroup\$ I have no idea how to convert CATG into amino acids. Challenges should be self-contained. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 14:46
  • \$\begingroup\$ I suspect most answers will be of the form "1. get string of source code by standard quine technique" and "2. convert string into dna form", so the first part doesn't add anything to the challenge. I'd suggest to change the task to write a program which translates a given string into your DNA format. \$\endgroup\$ – Laikoni Nov 29 '17 at 17:16
0
\$\begingroup\$

Create a Flip-Flop Program

Your challenge is simple: write a full program which alternates between two different outputs upon each run.

Your submission can choose which is printed the first time the program is run, but after that it should alternate between these exact outputs.

Rules/Details

  • You cannot assume the filename of your program.
  • The values must be distinct.
  • Creating files is allowed - you are allowed to assume a file such as a.txt does not already exist in the directory.
  • Reading and modifying the source is allowed.
  • This is , so the shortest solution (in bytes) wins! Standard golfing loopholes apply.

Sandbox

  • Should I allow assuming the program's filename at an additional bytecount (length of filename)?

| |
\$\endgroup\$
  • \$\begingroup\$ Is it neccessary that the first run always produces the same value? (That makes the problem considerably harder, because it requires detecting the first run.) I agree with the full program restriction here, btw; it avoids a lot of dubious rules-bending answers that change something in the execution state. \$\endgroup\$ – user62131 Jan 10 '17 at 16:58
  • \$\begingroup\$ If you want to be really crazy, you can do something like main(){int n = 1 Then change n in the compiled file return n;} \$\endgroup\$ – SIGSTACKFAULT Jan 12 '17 at 16:12
  • \$\begingroup\$ @FryAmTheEggman is this an explanation of the downvote or was that someone else? \$\endgroup\$ – FlipTack Nov 29 '17 at 8:02
  • \$\begingroup\$ @FryAmTheEggman see update. \$\endgroup\$ – FlipTack Nov 29 '17 at 8:14
  • \$\begingroup\$ Why the full program requirement? As far as I can tell, it will be very hard to do this with just functions. Why disallow something that could give interesting answers? Programs would likely just change their own source code, or read a value from a file and then change it (or append a new one). \$\endgroup\$ – Stewie Griffin Nov 29 '17 at 8:48
  • \$\begingroup\$ Closely related. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 14:39
  • \$\begingroup\$ @AdmBorkBork would you say that it's too similar? \$\endgroup\$ – FlipTack Nov 29 '17 at 16:36
  • \$\begingroup\$ Personally, I think they're distinct enough to not be a duplicate, they're just definitely related. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 16:41
  • \$\begingroup\$ I didn't downvote since to me this looked fairly good besides what felt like an arbitrary restriction that would just make gaming the challenge easier. Also, I remembered another related challenge, for reference. \$\endgroup\$ – FryAmTheEggman Nov 30 '17 at 0:25
  • \$\begingroup\$ @FryAmTheEggman that's why I recently helped add the stateful tag, all similar challenges involving storing data between runs and self-modifying code are gradually being added there \$\endgroup\$ – FlipTack Nov 30 '17 at 7:29
0
\$\begingroup\$

Thou shall permute!

Given a string of upper and/or lower case letters and/or numbers (or list of characters if you want), and a list of permutation cycles, compute every intermediate step of applying this permutation under the following rules:

  • The space to move letters around is one row above and one row below the input, with the same length available as the string length.
  • In the beginning, top and bottom row are empty, and the middle row contains the whole string
  • A character can only take the spot of another character, if that spot is empty
  • There can only be at most one character in the top row and one in the bottom row at any time
  • You can only move one character in one direction per state change. Directions are:
    1. Out of the middle top or down
    2. Left/Right (any number of steps at once)
    3. Into the middle

Cyclic Permutations

I'm assuming 0 based indexing. A list of cyclic permutations looks like this (I'm assuming list of tuples, but I don't mind if you want something else, as long as it conveys the same idea):

[(0,2,3),(1,4)]

This would mean that:

  • index 0 goes to index 2, index 2 goes to index 3, index 3 goes to index 0
  • index 1 goes to index 4, index 4 goes to index 1

Examples:

I'm using the -character to show available spots here, you may use a space or any character that can not be contained in the input string, such as #or $.

Given the string test and the cyclic permutations [(0,2)(1,3)], the steps would look as follows:

----
test  #Start state
----

----
-est  # Move index 0 out 
t---

--s-  
-e-t  # Move index 2 to the other side
t---

--s-
-e-t  # Move index 0 to where it needs to go
--t-

--s-
-ett  # Insert index 0 at index 2
----

s---
-ett  # Move index 2 to where it needs to go
----

----
sett  # Insert index 2 at index 0
----

----
s-tt  # Move index 1 out
-e--

---t
s-t-  # Move index 3 out
-e--

---t
s-t-  # Move index 1 to index 3
---e

---t
s-te  # Insert index 1 at index 3
----

-t--
s-te  # Move index 3 to index 1
----

----
stte # Insert index 3 at index 1. Done.
----

Here is the same example again, but this time using only one long permutation of all characters: [(0,2,1,3)] instead of 2 independent permutations:

----
test
----

----
-est
t---

--s-
-e-t
t---

--s-
-e-t
--t-

--s-
-ett
----

--s-
--tt
-e--

-s--
--tt
-e--

----
-stt
-e--

---t
-st-
-e--

---t
-st-
---e

---t
-ste
----

t---
-ste
----

----
tste
----

Rules

  • You will only receive valid cyclic permutations
  • Please indicate if you want 0 or 1 indexed permutations, either is fine
  • You will only receive valid strings up to length 10
  • Characters in the string are not guaranteed to be unique
  • it does not matter which order every permutation is processed as long as they're all processed (that means start and end states are the same, and the above rules are always fulfilled)
  • There will be at least one permutation in the list of permutations
  • All permutations in the list of permutations have at least length 2
  • The maximal length of one permutation is the length of the input string
  • There may be some indices that are not part of any permutation
  • No index is part of more than one permutation
  • You need to output the first step, the last step and all intermediate steps
  • You may have as many trailing newlines and spaces as you want
  • You may output a 2 dimensional array or anything equivalent instead of printing every step, or you can also return a list of all states in the end
  • You can also generate an animation if you like instead of printing sequentially
  • Lowest number of bytes wins
  • Standard loopholes are forbidden
  • You can write a full program or function

Test cases

I implemented a very un-golfed version in python3 here (redirects to repl.it). That code contains 2 functions. find_cycles takes a string and a permutation of that string and computes the cycles to go from one to the other. shuffle does the shuffling. It takes the start string and the cycles. You can use these functions to validate your program.

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

Find and execute a program from the internet

You have some task to do, but you are too lazy to do it yourself. Your also to lazy to make a program to do it. So you are going to make a program that finds a program to do the task you want.

Select a programming language Q (which must be Turing complete).

Your program will:

  1. Take an input task, as a string, and input, as a string.
  2. Search codegolf.stackexchange.com, using the input string as the query
  3. Select the first question in the search results with an answer which contains a valid Q program. (If there is no such question, the operation of your program may be undefined.) (You may assume that program is in a code block.)
  4. Select either the accepted answer if it contains a valid Q program, or the highest voted answer that contains a valid Q program.
  5. Execute the Q program that that answer contains, using the input from step 1.

Since you are lazy, you want your program to be the shortest program possible. So this is , shortest answer wins!

| |
\$\endgroup\$
  • 3
    \$\begingroup\$ What happens if the search result finds your answer? \$\endgroup\$ – Neil Dec 1 '17 at 9:55
  • \$\begingroup\$ @Neil Fixed it. \$\endgroup\$ – PyRulez Dec 1 '17 at 20:30
  • \$\begingroup\$ I don't know enough about the API to say, but can the order of results be changed by changing the search query to only allow questions? It seems like the searching may result in people trying to work around doing some API work, and it will be a pain to check. This isn't really a problem, just something I think you should know before posting. \$\endgroup\$ – FryAmTheEggman Dec 1 '17 at 20:37
  • \$\begingroup\$ @FryAmTheEggman I'm not sure. Think it would be better if I allow people to change the search query to only questions? \$\endgroup\$ – PyRulez Dec 1 '17 at 20:39
  • \$\begingroup\$ I think that would make it easier, but it kind of results in two separate golfing tasks: minimising the search query and minimising the code to parse/execute answers. I'm not sure of a good way to resolve that (or if it is that bad) but it does give me the feeling that it may be better split up in some way. \$\endgroup\$ – FryAmTheEggman Dec 1 '17 at 20:43
  • \$\begingroup\$ @FryAmTheEggman I could allow them to take a search query string template as input (or just say that it doesn't count towards their score). That way, there is no need to golf it. \$\endgroup\$ – PyRulez Dec 1 '17 at 20:45
  • 1
    \$\begingroup\$ What if the result takes no/more than one input? If Q is chosen well enough, you get away with a nop.. so this becomes a quest of finding languages unused on PPCG. What happens if these then get added? \$\endgroup\$ – ბიმო Dec 3 '17 at 3:15
  • \$\begingroup\$ @BruceForte It will be fed into the program via standard input. I said that Q must be Turing complete, which means it must take input. \$\endgroup\$ – PyRulez Dec 3 '17 at 4:51
0
\$\begingroup\$

Information Masking

Email Address Masking:

Only show the first and last characters of the username components of an email address, along with email domain name. Include 5 stars in the middle of the username to mask the length. The username part of the email address may use any of the ASCII characters listed below.

Rules

  1. Uppercase and lowercase English letters (a-z, A-Z)
  2. Digits 0 to 9
  3. Characters ! # $ % & ' * + - / = ? ^ _ { | } ~
  4. Character . (dit, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively.
  5. It is provided that email should end with @domainName.com, where the domain name has only alphabetic characters.
  6. It is provided that email address username part have at least 2 characters not starting and ending with a special character.

Example

JackAndJill@gmail.com --> j*****l@gmail.com

Phone number masking:

Rules

Mask all the digits in a phone number except the last 4 digits. Each number should be replaced by star(*). Input phone numbers can be with or without the country code. Input Phone numbers can only have +, (, ), - in them along with numbers and spaces. Make sure + is not masked in the output and make sure the number of stars is equal to the number of digits while masking.Phone numbers will always have 10 digits without country code and with the country code, they could be up to 13 digits.

Examples

Example1: +1 (333) 444-5678  --> +*-***-***-5678  
Example2: +91 (333) 444-5678 ->  +**-***-***-5678  
Example3: 333 444 5678 --> ***-***-5678  
Example4: (333) 444-5678 ---> ***-***-5678

Program input will start with E: for email and P: for phone numbers, ignore spaces if they are found in the input.

Complete Program Example

Input:

E: jackAndJill@gmail.com  
P: +13334445678

Output:

E: j*****l@gmail.com  
P: +*-***-***-5678
| |
\$\endgroup\$
  • \$\begingroup\$ How does hackAndJill start with a j? \$\endgroup\$ – NieDzejkob Nov 30 '17 at 21:06
  • \$\begingroup\$ Just a typo. Corrected now. \$\endgroup\$ – Siraj Alam Dec 1 '17 at 3:37
  • \$\begingroup\$ The examples show phone numbers of various different formattings what is it? Why are - in the output where in the input were only numbers how does that work? Is input always valid, can input be only a phone number etc. What about email addresses such as user@remote or u@remote.net? \$\endgroup\$ – ბიმო Dec 3 '17 at 3:25
  • \$\begingroup\$ The input number can be in any format as the given in the example. And it is should be output in the form that last phone numbers are shown and then a -, then every 3 numbers are masked as *** and a - after it until the numbers do not end. \$\endgroup\$ – Siraj Alam Dec 3 '17 at 6:41
  • \$\begingroup\$ Email address rules are updated. \$\endgroup\$ – Siraj Alam Dec 3 '17 at 6:45
  • \$\begingroup\$ What is the winning criterion? Code-golf? \$\endgroup\$ – Laikoni Dec 3 '17 at 20:24
  • \$\begingroup\$ Yes, code-golf. \$\endgroup\$ – Siraj Alam Dec 3 '17 at 20:25
0
\$\begingroup\$

Given an Integer array:

  1. Start from the first number (n)
  2. Go forward (n) positions depending on the current position
  3. Delete the current position, the rest of the array fill in to the current position.
  4. Goto step 2 until there are one number remaining
  5. Print that number

The array loops around (the next number after the last number in the array is the first number).

A zero removes itself.

Negative numbers are not allowed as input.

Test Cases

[1] => 1
[1,2] => 1
[1,2,3] => 3
[1,2,2] => 1
[1,2,3,4] => 1
[6,2,3,4] => 4
[1,2,3,4,5] => 5
[0,1] => 1
[0,0,2,0,0] => 0

This is , the shortest answer in bytes wins!


Step-by-step example

[1,4,2,3,5]
 ^          start from the first position
   ^        jump 1 position (value of the position)
[1,  2,3,5] remove number in that position
     ^      take next position of the removed number
         ^  jump 2 positions
[1,  2,3  ] remove number in that position
 ^          take next position (looping on the end of the array)
     ^      jump 1 position
[1,    3,5] remove number in that position
       ^    take next position (looping)
       ^    jump 3 positions (looping on the end of the array)
[1,      5] remove number in that position
         ^  take next position
 ^          jump 5 positions (looping)
[        5] remove number in that position
print 5

Example #2

[4,3,2,1,6,3]
 ^            start from the first position
         ^    jump 4 positions
[4,3,2,1,  3] remove number in that position    
           ^  take next position
     ^        jump 3 positions
[4,3,  1,  3] remove number in that position    
       ^      take next position
           ^  jump 1 positions
[4,3,  1    ] remove number in that position    
 ^            take next position
   ^          jump 4 positions
[4,    1    ] remove number in that position    
       ^      take next position
 ^            jump 1 position
[      1    ] remove number in that position
print 1

Note: This is my first challenge so any input is welcome.

| |
\$\endgroup\$
  • \$\begingroup\$ After the step 2 where is the "pointer"? \$\endgroup\$ – user202729 Dec 10 '17 at 14:40
  • \$\begingroup\$ The third step is worded a bit oddly, but I think I've understood it correctly from the examples. Do you mean that the elements after the deleted element are shifted to fill in the gap? It may be worth having one example written out step by step to make it easier for people to grasp what is happening. \$\endgroup\$ – FryAmTheEggman Dec 10 '17 at 15:13
  • \$\begingroup\$ @FryAmTheEggman I have edited the question to include 2 step-by-step examples. Can you help me word the third step more clearly? Perhaps: 2- jump forward n positions where n is the value of the current position. 3- delete the position you just arrived at. 4- the (new) current position is the next position. repeat step 2. \$\endgroup\$ – workoverflow Dec 10 '17 at 21:18
  • \$\begingroup\$ Problem title ? \$\endgroup\$ – user202729 Dec 11 '17 at 5:52
  • 1
    \$\begingroup\$ That is better, but maybe roll it into one? "Delete the current position, making what was the next position the current position" \$\endgroup\$ – FryAmTheEggman Dec 11 '17 at 5:57
  • \$\begingroup\$ @user202729 Haven't decided yet, Maybe "Football Jersey Josephus" or a variation of Duck, Duck, Goose. \$\endgroup\$ – workoverflow Dec 11 '17 at 7:38
0
\$\begingroup\$

Golf a number

Create a program or function, which when given an input integer, outputs a mathematical expression evaluating to the same value. Expressions which require fewer bytes to represent than the integer itself will achieve better scores!

Explanation

It is often useful when golfing to compress constant integer expressions by expressing them in the form of an equivalent mathematical expression. 387420489 for example is much more efficiently expressed as 9^9. Similarly 4194303 as 2^22-1

The challenge is, for each integer in the range 1 to 1E6, to golf the number into as short an expression as you can (although any expression which evaluates correctly is acceptable output, see Rules below). The shorter the expression, the better your score; but short programs will also score well so the two need to be balanced!

Rules:

Input integer as argument or from STDIN

Output as string or equivalent to STDOUT or as function output. Your string can only contain ascii characters [0,1,2,3,4,5,6,7,8,9], as well as those operators defined below, repetitions allowed.

You may use the following mathematical operators any number of times in your string:

() parentheses
^ exponentiation
* multiplication
/ division
\ integer(floor) division - see Test Evaluator
+ addition
- subtraction

NB: division, integer division and multiplication are all evaluated with equal priority, so 3/2\2 = 0 whereas 3\2/2 = 0.5

You may output the input value (if it can't be golfed for example), you do not have to output the perfectly golfed string:

 In: 10000

Out: 10000
     10^4
     2^13+1808

However the output must evaluate exactly to the input (assuming perfect precision of floats)

Scoring

Answers are scored on their compression ratio (how much they golf the input down on average), as well as program size

Program Size: byte count of program (as with normal code golf)

Compression Ratio: golfed Length (white-space ignored) / input Length

Individual Score = (Compression Ratio * 100 - 70)/6 + Log(Program Size, base 10)

Final Score = Mean score for first 10^6 integers

Lowest final score for each language wins!

Tags:


Sandbox:

related

related

The main sticking point is scoring how best can you combine 2 metrics into a single score?

The logic so far is that compression ratios will lie in the range 100 - 70 % where 100 is returning the input. Program lengths should be between 2 extremes; returning the input (1 byte) and looking up the input in a hardcoded list (~19,000,000 bytes). This gives the following distribution:

Score table

Actual program length I guestimate will be anywhere in the range 1 to 10000 bytes, hence the log to make the range more manageable. Quick reference; I could probably implement all power golfing (expressing n as a^b) in ~100-200 bytes in VBA. So 10% of that for golfing languages, and who knows what builtins Mathematica has ;).

But implementing more effective algorithms may require a more verbose language, so I think 1 - 10000 seems like a good range to handle in scoring

Open to alternative scoring though, and any required clarifications. Also suggestions what is a good range to test over?

I've suggested 1 to 1E6; The first 1000 integers I don't think are golfable, after that only a few are. So perhaps a greater range of test cases, or ones starting at a larger initial value? What's the biggest range I can feasibly test within say, 10 mins running time max? What's typical algorithm execution times can be expected per digit? I don't want golfers to have to spend too long generating their average score...

Test String Evaluation

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ requires fewer bytes to represent than the integer itself. -- but you had said The first 1000 integers I don't think are golfable, so it doesn't work. \$\endgroup\$ – user202729 Dec 11 '17 at 5:58
  • \$\begingroup\$ In your test, 2^13+1808 is longer than 10000. It contradicts your problem statement. Also you don't allow ^ to be used. / Evaluate left to right? \$\endgroup\$ – user202729 Dec 11 '17 at 5:59
  • 1
    \$\begingroup\$ returning the input is 0 byte in most languages, so the score would be log(0) = -Infinity. \$\endgroup\$ – user202729 Dec 11 '17 at 6:01
  • \$\begingroup\$ Related. \$\endgroup\$ – user202729 Dec 11 '17 at 6:17
  • \$\begingroup\$ @user202729 Your 1st point; I did include a sentence you do not have to output the perfectly golfed string in the rules section, but I'll fix the problem statement to match that. Good catch with ^, I'll add that - but a longer expression is supposed to be acceptable. log(0) - well let's hope that's an incentive not to post trivial answers! But seriously, do you think it's worth adding a log(program length +1)? I don't think it is because it adds an additional layer of complexity to the scoring system - and people shouldn't really be entering trivial solutions anyway (I hope) \$\endgroup\$ – Greedo Dec 11 '17 at 10:49
  • \$\begingroup\$ If they do post 0-byte solution and win, it's the fault of your scoring system. For reference, look at the score formula of this challenge. --- You may want to add "you must calculate your score" to the question, like in this challenge. \$\endgroup\$ – user202729 Dec 11 '17 at 12:36
  • \$\begingroup\$ This isn't code-golf - it's code-challenge. \$\endgroup\$ – Mego Dec 11 '17 at 16:30
0
\$\begingroup\$

All possible distributions of different items of a set to an arbitrary number of groups

See Descriptive Real World Example, Rules / Edge Cases or Sample Data for an idea about this or help me by adding a nice sentence explaining it while this is in sandbox.

Descriptive Real World Example:

Ordering a set of x items from a shop what are the possibilities to distribute them among 1 to x orders?

Rules / Edge Cases

  • Identical items are not being distinguished (AB, B == AB, B, compare examples #4, #5 and #6)
  • Order is not important
    • Order of items in order/group: AB == BA
    • Order of orders/groups in distributions: A, B == B, A
    • Order of possible distributions (i. e. lines among output)

Format

I don't really mind the exact format but as it probably makes sense (right?) to tie oneself down to one format I'll suggest the following:

  • Input: Set of items without delimiters. Supported chars: [A-Za-z0-9]
  • Output:
    • Hierarchy: Distributions (Orders (Items))
    • Delimiters:
      • Among distributions in overall output: EOL
      • Among orders/groups in distribution: Comma, Space
      • Among items in orders/groups: None

Sample Data

╔═════════╤═══════╤═════════╤════════════╗
║ Example │ Input │ Output  │   Output   ║
║   Nr    │       │ line nr │   lines    ║
╠═════════╪═══════╪═════════╪════════════╣
║   #1    │ A     │    1    │     A      ║
╠═════════╪═══════╪═════════╪════════════╣
║         │       │    1    │    A, A    ║
║   #2    │ AA    ├─────────┼────────────╢
║         │       │    2    │     AA     ║
╠═════════╪═══════╪═════════╪════════════╣
║         │       │    1    │    A, B    ║
║   #3    │ AB    ├─────────┼────────────╢
║         │       │    2    │     AB     ║
╠═════════╪═══════╪═════════╪════════════╣
║         │       │    1    │  A, A, A   ║
║         │       ├─────────┼────────────╢
║   #4    │ AAA   │    2    │   AA, A    ║
║         │       ├─────────┼────────────╢
║         │       │    3    │    AAA     ║
╠═════════╪═══════╪═════════╪════════════╣
║         │       │    1    │  A, A, B   ║
║         │       ├─────────┼────────────╢
║         │       │    2    │   AA, B    ║
║   #5    │ AAB   ├─────────┼────────────╢
║         │       │    3    │   AB, A    ║
║         │       ├─────────┼────────────╢
║         │       │    4    │    AAB     ║
╠═════════╪═══════╪═════════╪════════════╣
║         │       │    1    │  A, B, C   ║
║         │       ├─────────┼────────────╢
║         │       │    2    │   AB, C    ║
║         │       ├─────────┼────────────╢
║   #6    │ ABC   │    3    │   AC, B    ║
║         │       ├─────────┼────────────╢
║         │       │    4    │   BC, A    ║
║         │       ├─────────┼────────────╢
║         │       │    5    │    ABC     ║
╠═════════╪═══════╪═════════╪════════════╣
║         │       │    1    │ A, B, C, D ║
║         │       ├─────────┼────────────╢
║         │       │    2    │   AB, CD   ║
║         │       ├─────────┼────────────╢
║         │       │    3    │   AC, BD   ║
║         │       ├─────────┼────────────╢
║         │       │    4    │   BC, AD   ║
║         │       ├─────────┼────────────╢
║         │       │    5    │  A, BC, D  ║
║         │       ├─────────┼────────────╢
║         │       │    6    │  B, AC, D  ║
║         │       ├─────────┼────────────╢
║         │       │    7    │  C, AB, D  ║
║         │       ├─────────┼────────────╢
║   #7    │ ABCD  │    8    │  A, CD, B  ║
║         │       ├─────────┼────────────╢
║         │       │    9    │  A, BD, C  ║
║         │       ├─────────┼────────────╢
║         │       │   10    │  B, AD, C  ║
║         │       ├─────────┼────────────╢
║         │       │   11    │   ABC, D   ║
║         │       ├─────────┼────────────╢
║         │       │   12    │   BCD, A   ║
║         │       ├─────────┼────────────╢
║         │       │   13    │   CDA, B   ║
║         │       ├─────────┼────────────╢
║         │       │   14    │   DAB, C   ║
║         │       ├─────────┼────────────╢
║         │       │   15    │    ABCD    ║
╚═════════╧═══════╧═════════╧════════════╝
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ What is the winning criterion of this challenge? Code-golf? Also the current explanation seems more complicated as it needs to be. Only after seeing the examples it became clear that you are asking for set partitions \$\endgroup\$ – Laikoni Dec 20 '17 at 15:09
  • \$\begingroup\$ Possible duplicate of codegolf.stackexchange.com/q/8691/56433 \$\endgroup\$ – Laikoni Dec 20 '17 at 15:12
0
\$\begingroup\$

Show me your core

On many 8-bit machines, it is relatively easy to output the entire core syntax of the built-in language, as everything required is in ROM and most 8-bit machines allow you to PEEK at each location therein, or otherwise easily access the ROM contents.

Here's the complete syntax for a Sinclair ZX81 or Timex TS1000/1500 machine as an example:

 1 PRINT CHR$ 64;CHR$ 65;CHR$ 66;CHR$ 193;CHR$ 193;
 2 FOR I=196 TO 255
 3 PRINT CHR$ I;
 4 NEXT I

Is it as easy to output the core or standard syntax to a screen, console, or window in modern-days languages? How best would I word such a question? And would this make a good challenge?

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ What is the "core"? ...... \$\endgroup\$ – user202729 Dec 20 '17 at 15:03
  • \$\begingroup\$ Core syntax, i.e., non-extended PHP, such as stdClass is in the PHP core. Either the question is too ambiguous, or I don't know modern-days programming speak well enough to ask it. \$\endgroup\$ – Shaun Bebbers Dec 20 '17 at 15:08
  • \$\begingroup\$ More precisely, PDOException("blah", 0x00); would not be core in PHP even though it extends the standard Exception because the PDO extension needs to be switched on in your php.ini file; throw and new obviously would be as far as I'm able to work out \$\endgroup\$ – Shaun Bebbers Dec 20 '17 at 15:12
  • 1
    \$\begingroup\$ I don't know PHP so I don't understand that explanation. \$\endgroup\$ – user202729 Dec 20 '17 at 15:12
  • \$\begingroup\$ I only really understand PHP and some 8-bit hl languages and some assembly. Let's try this... if you don't <include xxx.h> in C (where xxx is the header or whatever), what are you left with? Is that even possible. \$\endgroup\$ – Shaun Bebbers Dec 20 '17 at 15:17
  • 1
    \$\begingroup\$ Actually GCC let the program pass with a lot of warnings. \$\endgroup\$ – user202729 Dec 22 '17 at 14:54
  • 1
    \$\begingroup\$ Some similar and related challenges showing that this type of challenge has a lot of difficulty in getting it exactly correct. \$\endgroup\$ – AdmBorkBork Dec 22 '17 at 15:10
  • \$\begingroup\$ Yes there is a lot of difficulty on modern-days tech stacks and such; on 8-bit machines, it's much easier as you only need to find the bit of ROM that holds the syntax and you're half-way there. \$\endgroup\$ – Shaun Bebbers Jan 2 '18 at 9:26
0
\$\begingroup\$

Sight Matrix


I haven't seen this done anywhere yet after a couple of searches, so I might as well post this anyways. If you see this done somewhere else, please tell me and I will delete this post.

The Story

You are a two meter tall sniper fighting in a war-torn area. Your teams have just beaten back the enemy, but the guerillas have an annoying habit of hiding out of sight and waiting patiently to take your unit by surprise, often inflicting heavy casualties. You have been tasked with dealing with these guerillas as a sentry.

The Task

Summary

Write a program that, when given a n x n 2D matrix of heights (in meters), outputs a n x n 2D binary matrix with ones being areas that you can see and zeroes being areas that you cannot see.

Input Format

The input will be a two-dimensional array of heights and two numbers signifying where you are standing.

Output Format

The output will be a two-dimensional array of ones and zeroes: ones where you can see and zeroes where you can't see.

Sample input/output

Input:

[[120,87,89,93,121], [120,91,83,91,114], [118,121,90,93,97], [124,129,115,120,101], [117,140,138,124,99]] 0 0

Output:

[[1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [0,0,1,1,1], [0,0,0,0,1]]

Hint:

Last time I checked, people's eyes were on their head. Put that into account when you are writing your code.


This is . Shortest answer in bytes wins. Standard loopholes apply.

Note: this is my first foray into code-golf stackexchange. Please tell me how to improve this or things that I need to add to this answer.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ There have been various questions on line of sight, but right now I think this question would be closed as "Unclear what you're asking" before there was consensus on which was the closest dupe. What are the rules for visibility? You've given my height, but I'm not sure whether it's relevant. You haven't said whether the guerrillas (note: double r) have a height, nor how the terrain is modelled, nor what point in the square I need to see for the square to count as visible. \$\endgroup\$ – Peter Taylor Dec 22 '17 at 13:47
  • \$\begingroup\$ May the input be 1-indexed? \$\endgroup\$ – user202729 Dec 22 '17 at 14:34
0
\$\begingroup\$

Output One More than Int Max

Your job is to create a program or function that will output a whole number (with no trailing decimal point) that is 1 greater than the max number an integer can hold for the language; more or less this:

MAX_INT + 1

You are not allowed to use Strings in your solution. Any other type may be used.

Shortest answer in bytes wins.

Note: I know this might be impossible in some languages. I have verified that it is possible in at least one (un-disclosed) language.


Notes on this puzzle

I posted this puzzle recently here and it promptly got closed and deleted (oops). Thankfully, @WheatWizard was kind enough to explain what some of the confusion was. Here where his comments:

I've voted to close this question as unclear. There are a couple of things I find especially unclear, 1) I'm not sure what "the max number an integer can hold for the language" means, it definitely needs a more concrete definition. It seems to presuppose some bounded "integer" type in the language. All the existing answers seem to suppose that long (or equivalent) is not this integer type but that is not at all clear from the question.

2) The requirement "You are not allowed to use strings in your solution" is neither clear nor enforceable. Without a rigorous definition of string there is no way to determine what is a string or not. For example Prolog has a type called "String" but all real string manipulation is actually done on lists of char codes. Are those strings? Prolog also has atoms which behave a lot like strings in many ways, (and act like integers in others) are they strings?

The main thing I would want to see before retracting my close vote/voting to reopen is clear definitions of the terms in question. To be clear that is a very tall order. These terms are not going to be easy to define, let alone define well. I would recommend temporarily moving this question to the sandbox so that you can workshop it a bit.

@Xcali said the following:

To follow on @WheatWizard's comment, what about languages where there's really no type to a variable. For example, in Perl, any single value may be treated as a string or a number at any time

And @Adám:

@CalebKleveter I think you can fix your challenge by removing the prohibition on strings and requiring documentation and/or additional supporting code showing that the produced number cannot be held as any type of integer. Do you want me to edit your post accordingly?

Are there any suggestions on how we could define the things pointed out in these comments? Are there any other issues that should be resolved?

| |
\$\endgroup\$
  • \$\begingroup\$ I'm not sure if it's possible to define such things such that it can applies to all languages. You may want to limit the challenge to specific languages, but that will disallow many languages to compete, and some person will get annoyed when their languages can't be used, they may downvote the question. / Original challenge link. \$\endgroup\$ – user202729 Dec 22 '17 at 14:07
0
\$\begingroup\$

Als pr Yrck, I knw hm Hrtio

Here is a link to a text file containing the script for Shakespeare's Hamlet.[to do: provide such a text file, or think of another freely available text input that leads to a wittier title.]

Your task is to write a program that will compress this text, and another that will decompress it to return exactly the original file. Your score is given by C + D + 0.5*F, where C is the size of your compression program, D is the size of your decompression program, and F is the size of the file that your compression program generates, all measured in bytes. The smallest score wins.

Further particulars

Your compression program should take hamlet.txt as input and produce a single file as output, which is to be given as input to your decompression program. You should make sure that the resulting output from your decompression program is identical to the original hamlet.txt file, e.g.

> myCompressor hamlet.txt > compressed
> myDecompressor compressed > output.txt
> diff hamlet.txt output.txt
[no output from diff command means they are identical]

Your programs' only purpose is to compress and decompress the hamlet.txt file - their behaviour on any other input is not part of the challenge. It's fine, for example, if the decompressor always outputs the text of Hamlet regardless of the original input, or if the compressor crashes on any input besides hamlet.txt.

Input and output can be by file I/O or STDIN/STDOUT or any other reasonable method, but the compressor and decompressor should be full programs. They need not be written in the same language.

Your compressor and decompressor must each be completely self-contained. Each must consist of a single file, and that file must be the source code for a programming language as defined here. With the exception of importing libraries, your compressor and decompressor must not open any other files besides their input.

The compressed file may be a text file or a binary file - the only thing that matters is its size in bytes. No information may be transmitted from the compressor to the decompressor by any means other than the content of this file.

You may not use any libraries or built-ins that implement data compression algorithms, such as gzip or bz2, or their corresponding decompression algorithms. This restriction only applies to "off the shelf" implementations - you can use any algorithm you like if you implement it yourself. For details on what counts as a data compression algorithm, see note 1.

If for some reason your language or libraries include a feature that outputs some or all of the text of Hamlet, you may not use that feature.

Although it's not part of the challenge, you are encouraged to explain/demonstrate what happens when your compressor is given some other input besides hamlet.txt, especially if it does something interesting such as produce a garbled Shakespearean version of the input text.

Note 1: For the purpose of this challenge, a data compression algorithm is anything listed in Wikipedia's Category:Lossless Compression Algorithms or Category:Lossy Compression Algorithms, or any of their subcategories. Note that these lists can change over time, and if Wikipedia's editors will allow a new item to be added then that will count as a compression algorithm, even if that happens after an answer using it is posted. This is to prevent the use of obscure algorithms that are not yet listed on Wikipedia. Editing Wikipedia to get around the restriction on off-the-shelf compression is not allowed.

This rule is intended to prevent the use of existing algorithms while allowing all other language features and built-ins. It may be the case that some items on the Wikipedia list are overly broad and end up banning common language features. If this is the case I will add exceptions on a case-by-case basis. This will only be used to permit things that would otherwise be banned, so it won't invalidate existing answers.


Sandbox note: the really tricky thing here is how to prevent trivial solutions that just wrap an existing compression algorithm, without also banning common language features. The above Wikipedia-based definition of a compression algorithm is a bit experimental and I'd welcome feedback on it. My intention is to prevent trivial solutions that just wrap an existing implementation of a compression algorithm, while allowing pretty much anything else.

Another possible approach is simply to allow anything and hope that answers specialised to the input can achieve better scores. That's effectively what I did in Paint Starry Night, but in the end I wish I hadn't, because it turned out that (so far at least) even really clever solutions based on neural nets and genetic algorithms can't come close to the off-the-shelf BPG algorithm. That's the sort of situation I want to avoid for this challenge.

| |
\$\endgroup\$
  • \$\begingroup\$ Would compressor, decompressor be acceptable? (only for illustration purposes) \$\endgroup\$ – user202729 Dec 30 '17 at 9:06
  • \$\begingroup\$ @user202729 I don't speak Jelly, but assuming it's not using any built-in compression, that would be fine. (It even says so already in the rules: "It's fine, for example, if the decompressor always outputs the text of Hamlet regardless of the original input".) The thing is that a solution of that form doesn't take any advantage of the discounted scoring for the compressed file, so it would very likely not be optimal. So while it's allowed, it would probably not win. \$\endgroup\$ – Nathaniel Dec 30 '17 at 9:46
  • \$\begingroup\$ Correct, if the text is sufficiently long. The “...» is Jelly string encoding codec using base decompression and some dictionary lookup. \$\endgroup\$ – user202729 Dec 30 '17 at 9:55
  • \$\begingroup\$ @user202729 then it would be fine. (I'm fairly certain the script for Hamlet is long enough - if it isn't, that would be an interesting surprise.) \$\endgroup\$ – Nathaniel Dec 30 '17 at 10:58
  • \$\begingroup\$ @user202729 Though actually, I guess by the letter of what I wrote, it wouldn't be fine, because Jelly's dictionary lookup is presumably explicitly intended as a way to compress text. That's not what I intended the rule to mean. This is pretty tricky - I want to disallow trivial things like just wrapping a bz2 compressor, while permitting pretty much anything else. It doesn't seem easy to do that in a way that avoids loopholes. (Comments on this are welcome from anyone.) \$\endgroup\$ – Nathaniel Dec 30 '17 at 12:46
  • 1
    \$\begingroup\$ You can't disallow "trivial" things, only discourage them. That's not really a problem - the real problem is they get more upvotes than they deserves, and solutions which the OP actually put effort in writing get less upvotes. \$\endgroup\$ – user202729 Dec 30 '17 at 13:02
  • \$\begingroup\$ @user202729 I can't disallow trivial things in general, but I can write the rules in such a way that specific types of trivial solution are not permitted. If I had disallowed built-in compression in paint Starry Night then it would have been a much better challenge (albeit possibly less epic in the long run, since the non-trivial answers made a good effort at keeping up with the trivial ones). Basically I don't want the winning answer to just be a shell script that runs bzip on its input. \$\endgroup\$ – Nathaniel Dec 30 '17 at 13:19
  • \$\begingroup\$ Anyway I've changed the wording of the rule - I'm not sure if the new version will work but we'll see if people have comments. \$\endgroup\$ – Nathaniel Dec 30 '17 at 13:20
  • \$\begingroup\$ Instead of stating something like "If for some reason your language or libraries include a feature that outputs some or all of the text of Hamlet, you may not use that feature." you could actually require the program to work for any input and only use Hamlet to get the scoring, this would elegantly close up that loophole but I'm sure people will find a way around this.. As you noted yourself this is a difficult task to solve. \$\endgroup\$ – ბიმო Dec 30 '17 at 14:00
  • \$\begingroup\$ @BruceForte I think I prefer the direct approach for that point. If I ask it to work for other inputs I open up the quagmire of trying to define what that should mean and how to test for it. However that's achieved I would likely still need the "if for some reason" rule, because there would probably still be ways to take advantage of a built-in database of Shakespeare plays if some language out there happens to include one. I think banning Shakespeare built-ins is unproblematic - my problem is more how to ban bz2 and the like without accidentally also banning common language features. \$\endgroup\$ – Nathaniel Dec 31 '17 at 2:26
  • \$\begingroup\$ "in the end I wish I hadn't" ... Why? What's the difference? \$\endgroup\$ – user202729 Jan 1 '18 at 9:06
  • \$\begingroup\$ @user202729 it would have been a better challenge. The best scoring answers would have been the cleverest ones that took the most effort, and there would be more motivation for people to continue doing cleverer things to beat the lowest score. If that doesn't seem desirable to you then fair enough, but it's what my taste is and it's the kind of challenge I want to design. \$\endgroup\$ – Nathaniel Jan 1 '18 at 9:15
  • \$\begingroup\$ How can you be so sure (without testing it)? bz2 developers definitely put a lot of efforts into writing their lossy image compression algorithms, so they may win. Not to mention that their code are not bytecount-limited. \$\endgroup\$ – user202729 Jan 1 '18 at 9:21
  • \$\begingroup\$ @user202729 I'm not sure what you mean. If you're referring to the Starry Night challenge I can be sure because I have tested it. Just look at the existing answers - some are really really nontrivial and use genetic algorithms, deep neural networks and other clever techniques, whereas others simply wrap an image in BPG or FLIF format and call an existing function to decompress it. There is some golfing and file type knowledge involved in this, but it's trivial compared to the other type of answer. Unfortunately the latter type did win, and that's exactly what I'm trying to avoid this time. \$\endgroup\$ – Nathaniel Jan 1 '18 at 9:29
  • \$\begingroup\$ (The clever answers on Starry Night exist in large part because I offered a series of bounties to answers that passed various milestones without using built-in compression. I could do that again this time, but I have only 2100 rep to give away, and in any case it's much more elegant if the challenge provides that motivation by itself.) \$\endgroup\$ – Nathaniel Jan 1 '18 at 9:36
0
\$\begingroup\$

Your Task:

To create a piece of code that takes in an input, and outputs ASCII art, which is encoded in the input string.

It seems unclear, but you are basically creating your own programming language that takes a piece of code in a syntax that you create, and then writing a code that takes that input, and turns it into ASCII art.


Example:

A simple example would be an input that runs through a line of input code with the syntax:

0 : An empty space
1 : A space that is occupied
2 : A newline character

I:

01010210101201010210101201010

O:

 The '|' character is just to show the matrix

| # # |
|# # #|
| # # |
|# # #|
| # # |

I:

11112000121111210002111122 // Shows a 2
11112100121001210012111122 // Shows a 0
0120120120120122 // Shows a 1
11112100121111210012111122 // Shows an 8

O:

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

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

 #
 #
 #
 #
 #

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

The code would read through the letters one by one and print out the characters, or create a newline character as expected.


Since this is , the code with the fewest bytes wins!

| |
\$\endgroup\$
  • \$\begingroup\$ Jelly, 0 bytes - is that what you meant? \$\endgroup\$ – user202729 Jan 6 '18 at 12:08
  • 1
    \$\begingroup\$ This is currently very unclear. As far as I see, you say we need to write code which decodes some input string to some output string. But what exactly is the decoding? Your 0,1,2 substitution seems to be an example only. \$\endgroup\$ – Laikoni Jan 6 '18 at 12:09
  • \$\begingroup\$ I think this would be pretty much trivial in most languages. Expect a lot of 2-3 byte answers. Might want to make it a bit more complex \$\endgroup\$ – Darren H Jan 6 '18 at 18:01
0
\$\begingroup\$

Stem and Leaf

A stem-and-leaf plot is a way to represent data and visualizing distribution. Usually the data is grouped in step of 10, with the last digit as "leafs" in ascending order, and the remaining digits as "stem". The steam and leafs are separated with a vertical line, with stem on the left and leafs on the right.

Challenge

Make a program or function which takes a list of non-negative integers as input, and outputs the corresponding stem-and-leaf plot.

Example Input and Outputs

Example 1:

Input: 10 2 15 4 2 24 18 17 24 24 25 15 18 22 17 23 24 33 19 28 28 28 26 32 25 27 37 28 41 38 38 30 35 30 41 45 40 40 37 33

Output:

0|224           
1|05577889      
2|23444455678888
3|0023357788    
4|00115

Example 2:

Input: 112 101 116 99 99 107 101 99 115 112 114 128 115 119 125 160 148 147 159 147 169 160 163 160 160 163 162 164 160 173 84 92

Output:

 8|4
 9|2999       
10|117       
11|2245569   
12|58        
13|
14|778       
15|9         
16|0000023349
17|3

Rules

  • The input may be a list, an array, a space or comma delimited string or other appropriate representation containing raw data values.
  • The vertical line of the output must be aligned.
  • A leading or trailing newline, or trailing spaces for each line are accepted.
  • Common loopholes applied.

This is a challenge, so the lowest-byte solution for each language wins!

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

Imagine you're a dishonorable scientist trying to prove that getting heads on a coin flip actually has about 70% probability when flipped 100 times. The trick is, you're going to flip the coin an arbitrarily large number of times (say, a million) and select the slice of 100 flips that contains the most number of heads. As input, take the number of total trials to do, and as output, return the number of heads contained within the most favorable contiguous slice of 100.

| |
\$\endgroup\$
  • 5
    \$\begingroup\$ Please "Write your challenge just as you would when actually posting it.". If you post the challenge like this you will get a lot of problems. \$\endgroup\$ – user202729 Jan 26 '18 at 5:55
  • 1
    \$\begingroup\$ (question title, winning criteria, tags, example input/output, everything you didn't have) \$\endgroup\$ – user202729 Jan 26 '18 at 5:58
  • \$\begingroup\$ I like the idea, but the correctness of the answer is a little hard to verify. Perhaps you should require the answer writers to explicitly indicate how the program does the required job, unless it's really obvious from the code. For example, someone may directly draw a value from the resulting distribution without actually generating the total number of trials. That should be acceptable, as long as the writer justifies that their approach is correct, that is, gives the exact required distribution for the output \$\endgroup\$ – Luis Mendo Jan 28 '18 at 16:54
0
\$\begingroup\$

Find a Path of Similar Proportions!

Given a point on a square lattice, find the shortest path (by jumps) from the origin to that point, following these rules:

  • You are allowed to make any number of jumps containing any number of steps along the grid lines to another lattice point. These jumps must be along the grid lines and have an integer length.
  • Each jump must contain one step more or be one step shorter than the step before it. (This is where the "similar proportions" comes into play. Name change pending?)
  • The first step can have any length.

As an example, here is how one possible way one might travel from A(0,0) to B(5,5) under these rules:

A
|
|
|
1----2
     B
     |
     |
     3

The numbers indicate which steps are taken. Note that this solution backtracks, moving to (5,8) before partially retracing its path to get to its destination. This solution takes four jumps and is therefore optimal.

Here is a diagram of the number of jumps required for the shortest (or is it?) path to any other point with both integer coordinates below or equal to 10. Note the symmetry around (x,x). I don't know if my solution for (7,10) is optimal.

  | 0  1  2  3  4  5  6  7  8  9  10
--------------------------------------
0 | 0  1  1  1  1  1  1  1  1  1  1
1 | 1  3  2  3  3  3  3  3  3  3  3
2 | 1  2  3  2  3  3  3  3  3  3  3
3 | 1  3  2  3  2  3  3  3  3  3  4
4 | 1  3  3  2  4  2  3  3  3  3  3
5 | 1  3  3  3  2  4  2  3  3  3  3
6 | 1  3  3  3  3  2  4  2  4  3  3
7 | 1  3  3  3  3  3  2  4  2  4  5?
8 | 1  3  3  3  3  3  4  2  4  2  4
9 | 1  3  3  3  3  3  3  4  2  4  2
10| 1  3  3  4  3  3  3  5? 4  2  4

The actual actual task

Your task is to continue the table for points with coordinates as large as (127,127).

Your submission should be a program which prints valid paths for all points whose two coordinates lie between 0 and an inputted positive integer inclusively, or a function, which, given any pair of positive integers, outputs a valid path to the point specified by these coordinates.

A valid output path is an array or list (or other comparable datatype) which uniquely represents a valid sequence of jumps that can be used to reach the specified point and which makes it as easy as possible to find the number of jumps required.

Example possible ways for the example path given above:

[["d", 4], ["r", 5], ["d", 4], ["u", 3]] // using chars to represent direction
[[0, 4], [5, 0], [0, 4], [0, -3]] // direction vectors
[0, 4, 5, 0, 0, 4, 0, -3] // As above, in just one list. len()/2

Scoring

Your submission will be scored by the sum of your solution's bytecount and the sum of all jump counts for all paths it outputs for reaching any point between (0,0) and (127,127), inclusively. Smallest score wins, standard rules and loopholes apply, etc...

Example response (Python 3):

def c(a,b):
    d,e,g=[[a,0]],a+1,0
    while not g==b:
        d.append([0,e])
        e,g=-e+1,g+e
    return d

This extremely simple and naive piece of Python code achieves a score of 92 (program length) + 1406272 (for the path part) = 1406364, as verified here - Try it online!

More?

  • missing tags?
  • clarifications?
  • Table is incorrect?

Please respond.

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

Collectables, Inc

You're an aspiring collector. You want to be the top collector for as many collections as possible.

Here's how you play (with P players):

  • The game consists of multiple Auctions, and 2P collections. Some collections are bigger than others. Smaller collections are more valuable and rare, bigger collections are cheaper.

  • Each Auction puts 2P random items up for sale

  • You place a bid on each item, grouped by collection. (e.g. If doll was a collection, you place a single bid for all of the dolls in the current Auction)

  • You win by having the most pieces for the most collections. (Each collection is worth 1 point. If you have the plurality of that collection, you gain that point).

Fine Details:

  • Players start with 30 gold.

  • Each collection contains a different number of items, from 2 to 2P+1.

  • There are 2P+3 auctions (until all items are sold)

  • Players can bid on multiple items, and their total bid can exceed their current gold.

  • Resolution of bids happens as follows:

    1. All invalid bids are removed. (Players without enough gold, or bids on items already sold).
    2. Find the top bid (by gold). Tiebreaker is the collection size (smallest first).
    3. If there is still a tie, then that item group is removed.
    4. Otherwise, the top bidder wins the item group. His money is added to the pot.
  • After an Auction is finished, the pot is evenly distributed among all players. Any remainder is put back into the pot.

I think that my rules are pretty complete.

  • Is it clear?
  • Is it interesting?
  • How many reads did it take you to understand the post?
| |
\$\endgroup\$
  • \$\begingroup\$ 1. It took me until the third read-through to understand that the collections are split into items and then recombined, possibly because I'm unconsciously applying real-world knowledge about how these things normally work. Explicitly saying that there are P*2+3 auctions would be a useful hint. 2. I was going to say that point 3 was missing a tie-breaker until I realised that the second sort criterion is collection size and not group size. 3. I think there's some interesting game theory here: things like weighting bids towards odd sized collections vs even sized collections. \$\endgroup\$ – Peter Taylor Sep 11 '17 at 7:37
  • \$\begingroup\$ @PeterTaylor thanks for the feedback! I added an overview, does that help? \$\endgroup\$ – Nathan Merrill Sep 11 '17 at 15:32
  • \$\begingroup\$ Best to ask someone who hadn't previously read the question. BTW I presume you're planning to add something later about the I/O? \$\endgroup\$ – Peter Taylor Sep 11 '17 at 16:01
  • \$\begingroup\$ Yep. There isn't any hidden information (unless you count simultaneous as hidden), so the API should be pretty straightforward. \$\endgroup\$ – Nathan Merrill Sep 11 '17 at 16:21
0
\$\begingroup\$

Unicode reversible programs

The goal is to make a program that includes unicode formatting characters that when executed as-is generates a OEIS sequence, and when copied as its rendered* and executed, returns a different sequence.

  • The renderer is one that properly reacts to unicode formatting. For example with RLO the text should be reverted. (Its stored as "\u202etest" but renders as "tset"

This is will be so the answer with less bytes wins.

| |
\$\endgroup\$
  • 3
    \$\begingroup\$ What do you mean by "copied as its rendered and executed"? \$\endgroup\$ – Peter Taylor Feb 1 '18 at 11:18
  • \$\begingroup\$ @PeterTaylor I mean that for example the text "\u202e hello" is rendered as "olleh " because U+202E is a unicode control character that reverses text (when rendered) \$\endgroup\$ – iovoid Feb 1 '18 at 19:28
  • \$\begingroup\$ Define it objectively. How browsers/text editors handle copy-paste are implementation-defined. (which browsers/text editors, which exact ways to copy-paste, put the pointer on which pixel of the screen, etc.) \$\endgroup\$ – user202729 Feb 2 '18 at 5:35
  • \$\begingroup\$ U+202E is not a Unicode control character: the Unicode control characters are the ranges U+0000 to U+001F and U+007F to U+009F. \$\endgroup\$ – Peter Taylor Feb 2 '18 at 12:19
  • \$\begingroup\$ Also: this question talks about characters and bytes but it doesn't address the relationship between them, which is a minefield. What about languages which don't use UTF-8 or UTF-16 for their source? What about languages which use either according to a command-line flag: can the transformed program change the state of that flag? \$\endgroup\$ – Peter Taylor Feb 2 '18 at 12:26
  • \$\begingroup\$ @PeterTaylor languages that dont use utf-8 it in their source can use a escaped form such as (0xe2 0x80 0xae). Also thanks for pointing that its actually a formatting character (not control) \$\endgroup\$ – iovoid Feb 2 '18 at 18:20
  • \$\begingroup\$ So basically split on the unicode char and reverse all that's after it? Possibly multiple times? Doesn't sound too interesting. \$\endgroup\$ – Magic Octopus Urn Feb 2 '18 at 21:29
  • \$\begingroup\$ "for example"? Questions (challenges) need to be self-included. List all of them please. \$\endgroup\$ – user202729 Feb 3 '18 at 5:29
0
\$\begingroup\$

Tags: Codegolf

Title: evil detection

When given any (you may choose the format and you should assume integer input) input, the output should be true if the input is a palindrome and false if not (or 1/0 or any equivalent).

To make it (a lot) harder, your code must work with a result that fulfills the challenge inverted if read backwards. So for a palindrome input, forward gives true, backwards false.

Example:

If your code is "abc12" and the input is 1221, your code should produce true-ish and "21cba" (your code read backwards) should produce false-ish.

Bonus if you think that's to easy: produce false if and only if the input is 666 forward and true backwards.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ Duplicate \$\endgroup\$ – Shaggy Feb 5 '18 at 16:58
  • \$\begingroup\$ First, I want to say thanks for using the sandbox! Also, I do think you could go somewhere with this idea that doesn't make it a duplicate. Your idea is marginally different, in that it only requires the code to behave the same forward and backwards, rather than actually be a palindrome. While I think for palindromes it will almost always be best to have a palindrome, perhaps you can think of a different pattern that makes it more interesting? I'll let you know if I think of anything. \$\endgroup\$ – FryAmTheEggman Feb 5 '18 at 22:23
  • \$\begingroup\$ @FryAmTheEggman, I don't think the fact that the code need not be palindromic is enough to make this not be a dupe; many of the solutions to the challenge above would also be the optimal solution here. Maybe if this one required that the code not be a palindrome and also required that it output a different pair of consistent and distinct values when run in reverse, it might be enough to differentiate it? \$\endgroup\$ – Shaggy Feb 6 '18 at 9:25
  • \$\begingroup\$ Thanks to both of you, I'll have a look at the other answers, but I agree that allowing the code to be semi-palindromic is not enough (unless the other answers are all extremely long, I haven't looked yet). I'm thinking about making the code required to not be symmetric, but haven't figured out what to do with the input to make it fit \$\endgroup\$ – DonQuiKong Feb 6 '18 at 9:28
  • \$\begingroup\$ @Shaggy That seems like a good start for changing it. For the record, I definitely think that as it was when I posted it was a duplicate, I just thought there was something good in this challenge and I didn't want it to just be discarded! The unfortunate thing about just requiring non symmetry is that comments/newlines could often just be added at the end without much cost, but I do think there is a good challenge here, somewhere. \$\endgroup\$ – FryAmTheEggman Feb 6 '18 at 18:39
  • \$\begingroup\$ @fryamtheeggman how about this? \$\endgroup\$ – DonQuiKong Feb 6 '18 at 18:59
  • \$\begingroup\$ I think the problem with this is that while some of the answers to the other question will no longer work, some are still usable here with only a slight modification, so I don't think this will cut it. \$\endgroup\$ – FryAmTheEggman Feb 6 '18 at 19:31
  • \$\begingroup\$ @Fryamtheeggman and if I make the bonus question mandatory? But I'll think some more \$\endgroup\$ – DonQuiKong Feb 6 '18 at 19:42
0
\$\begingroup\$

Build a Brainfuck transpiler

Your job is to build a program that transpiles valid brainfuck to a language (not brainfuck!) of your choice.

You are not required to handle cases where the program is invalid (mismatched [ ]s), or contains characters that are not +-<>[],. but all other cases must be handled.

Size limits on your input or output are fine as long as they are imposed by computer restrictions, like RAM.

The programming language you transpile to is covered under the "What defines a programming language" rules, and must have been created before this challange.

In extension to not transpiling to brainfuck (cheater!) you can't use a brainfuck derivative or trival brainfuck substitution as the transpiled to language either.

Scoring

Programs will be scored with the average ratio of bytes in the input brainfuck program to the output transpiled result, as based on the examples.

Meta questions

This is a rough draft!
What tags should be associated with this?
How can I improve the scoring system?
What examples should I use to keep the scoring fair, but prevent obvious tricks?
What loopholes are there in this rough draft that I need to patch?

This entire thing will be reorganized when I get enough info to make a better writeup.

| |
\$\endgroup\$
  • \$\begingroup\$ I'd tag it with code-challenge and brainfuck. Once you post the examples the scoring system seems to be fine, the major problem would be hardcoding but this is a standard loophole, so this should be fine. Also you should probably consider adding a non-terminating example. About preventing brainfuck derivatives: I'm not sure if this is well-defined enough, maybe others have some ideas? \$\endgroup\$ – ბიმო Feb 10 '18 at 14:22
  • \$\begingroup\$ @BMO About hardcoding: Just hide the official test cases. You don't need to prevent BF derivative, they would just be boring (and downvoted most likely). Also it's very hard to define them (What about 2D BF? What about Unary? What about Random BF / self-modifying BF?) \$\endgroup\$ – user202729 Feb 10 '18 at 15:39
  • \$\begingroup\$ Also, BF is too unclear as a language specification. (is memory wrapping or infinite to one end or infinity to both ends? Are values positive/negative/modulo 256? etc.) \$\endgroup\$ – user202729 Feb 10 '18 at 15:41
0
\$\begingroup\$

Chiasmus Indenter


Chiasmus is a literary form that is similar to palindromes. Some ideas are presented and then presented again in reverse order, often phrased differently.

Natural language processing is hard, so I'll be using a more computer-friendly definition. A chiasmic string is made up of a series of substrings that are repeated in reverse order in the second half of a string. Formally:

  • If a is some non-empty string, then aa is chiasmic.
  • If C is chiasmic and a is some string, then aCa is also chiasmic. Note that this applies recursively, thus abCba is chiasmic if C is also chiasmic and a and b are non-empty strings.

For example, batbat is chiasmic, as are glassbottlebottleglass and AliceBobCharlieCharlieBobAlice. All even-length palindromes are chiasmic, being made up of many length-1 strings.

Note that the empty string is not a chiasmus.

The Challenge

We're programmers, so we like nice indentation. Your goal is to take chiasmic strings and indent them so that each matching substring is at the same level of indentation. For example, cheesepizzawithanchoviesanchovieswithpizzacheese would be indented like so:

cheese
    pizza
        with
            anchovies
            anchovies
        with
    pizza
cheese

For base case chiasms (i.e. 2 repetitions of a string), no indentation is necessary, but the substrings should still be on separate lines. Thus, gumgum would be indented:

gum
gum

In order for there to be only one canonical output for each chiasmus, if it is possible to indent at more than one place, indent in a way such that the a substrings for the form aCa are as long as possible (applied recursively for each C until the aa base case is reached). For example, catdogcatdogdogcatdogcat should be indented like this:

catdogcat
    dog
    dog
catdogcat

Not like this:

cat
    dog
        cat
            dog
            dog
        cat
    dog
cat

Also not like this:

cat
    dogcatdog
    dogcatdog
cat

The behavior of indenting a non-chiasmus is undefined.

Rules

  • Indentation can use any amount of whitespace of any kind, so long as it is consistent (e.g. do not mix tabs and spaces). Lines may either be output as a list/array/whatever or a newline-separated string.
  • You may assume that the input is a chiasmus that contains only alphanumeric characters.
  • As this is , the shortest submission wins.
| |
\$\endgroup\$
  • \$\begingroup\$ May indentation be done with a \t character? \$\endgroup\$ – Kamil Drakari Feb 9 '18 at 22:25
  • \$\begingroup\$ I probably should do that since it saves 2 characters and is purely cosmetic. \$\endgroup\$ – Beefster Feb 9 '18 at 22:43
  • \$\begingroup\$ "Longest possible substrings" still leaves some room for ambiguity. What's the canonical output for ababbaba? \$\endgroup\$ – Nitrodon Feb 10 '18 at 4:40
  • \$\begingroup\$ aba b b aba. I see how it can be indented as a bab bab a, though. \$\endgroup\$ – Beefster Feb 10 '18 at 6:44
  • \$\begingroup\$ I kept waiting for a glassbottlebottleglass test case! \$\endgroup\$ – Shaggy Feb 11 '18 at 9:27
  • \$\begingroup\$ @Shaggy Wish granted. \$\endgroup\$ – Beefster Feb 11 '18 at 16:52
  • \$\begingroup\$ I don't understand the catdogcatdogdogcatdogcat example. It seems to me to directly contradict the rule it's supposed to be illustrating. \$\endgroup\$ – Peter Taylor Feb 12 '18 at 8:54
  • \$\begingroup\$ @PeterTaylor how so? \$\endgroup\$ – Beefster Feb 12 '18 at 20:15
  • \$\begingroup\$ On review, I agree that "directly contradict" is overstating it. But the minimalist indentation still doesn't fit the rest of the question. The stated grammar is pointless: the derivation aCa is only permitted for extremely limited values of C (strings of the form bb such that there aren't c and d satisfying ab = cd and |c| > |a|). The statement "indent in such a way that the lowest levels of indentation have the longest strings possible" (my emphasis) makes no sense, because there is at most one level of indentation (or two if you count "unindented" as the first). \$\endgroup\$ – Peter Taylor Feb 12 '18 at 21:49
  • \$\begingroup\$ And the statement "All even-length palindromes are chiasmic, being made up of many length-1 strings" is not true, because the canonicalisation forces it to be made up of one repeated length-1 string and an outer layer of a repeated length-(n-2)/2 string. \$\endgroup\$ – Peter Taylor Feb 12 '18 at 21:50
  • \$\begingroup\$ The aCa form is recursive. Maybe I should make that clearer with the examples. \$\endgroup\$ – Beefster Feb 13 '18 at 1:53
  • 1
    \$\begingroup\$ I would suggest dropping the requirement to produce an error on non-chiasmal(?) input, and instead just guarantee that the input will be a chiasmus. This changes it from two challenges (detect whether the input is a chiasmus, and then indent it if it is) to one (indent a chiasmus). Just my opinion though. \$\endgroup\$ – Nathaniel Feb 13 '18 at 7:56
  • 1
    \$\begingroup\$ Slightly related \$\endgroup\$ – Shaggy Feb 13 '18 at 10:16
  • \$\begingroup\$ @Shaggy Well yeah it's related. I created that challenge and it was a direct inspiration for this one. \$\endgroup\$ – Beefster Feb 13 '18 at 19:30
0
\$\begingroup\$

Self-removing executable (retracted: dupe)

| |
\$\endgroup\$
  • \$\begingroup\$ I don't like the restriction, it makes it easier for you to test (I guess that's the point of it?), but it prevents me (and many others) from competing. Saying it must handle "long and unusual characters" is underspecified. You can say that the program must be able to handle any valid filename, in the chosen operating system. The example code is already very short, so it doesn't leave much room for golfing, with all the restrictions in place. \$\endgroup\$ – Stewie Griffin Feb 14 '18 at 11:03
  • \$\begingroup\$ Which restriction? Shall it be centered around per-language leaderboard then? \$\endgroup\$ – Vi. Feb 14 '18 at 11:13
  • \$\begingroup\$ Always per-language. I guess t's not all restrictions, but all the Linux-specific stuff. Keep in mind that these are only my opinions though, others might disagree. \$\endgroup\$ – Stewie Griffin Feb 14 '18 at 11:22
  • \$\begingroup\$ It could be a good idea to have it Linux specific, but the example code is already so short that it leaves very little room for creativity. \$\endgroup\$ – Stewie Griffin Feb 14 '18 at 11:23
  • 1
    \$\begingroup\$ Dupe: codegolf.stackexchange.com/questions/19355/… ? \$\endgroup\$ – user202729 Feb 14 '18 at 12:52
0
\$\begingroup\$

Convert a number to (Name-To-Be-Specified)

(Name-To-Be-Specified) is a completely made up language. It uses a Senary (base 6) system of numbers with words for those numbers structured in a similar way to English.

0 to 6
Single digit numbers use a single word for each digit.

0 = "zeeroo"
1 = "nimbo"
2 = "feta"
3 = "tarumba"
4 = "ntamno"
5 = "waramaka"
(Any similarity to Kómnzo numbers are coincidental.)

6 to 11
The first set of two-digits numbers have special rules.

6 = "wi"
7 = "seeveen"
8 = "ayte"
9 = "tarumbawin"
10 = "ntamnowin"
11 = "waramakawin"

12 to 35
Multiples of 6 have the single digit word with a "wee" suffix.

12 = "fetawee"
18 = "tarambawee"
24 = "ntamnowee"
30 = "waramakawee"

Other numbers in this range are made by joining the word for the multiple of 6 with the word for single digit number, separated by a space. For example:
13 = "fetawee nimbo"
20 = "tarambawee feta"
27 = "ntamnowee taramba"
34 = "waramakawee ntamno"

36 to 1295
1296 to 46655
46656 to 1679615
1679616 to 60466175
(Since this is a sandbox, I'll leave these to-be-specified for now. Suffice to say I'll come up with words for each and consistent rules for joining them together and when you need the word "and".)

Challenge

Write a program that takes an integer as input and outputs that number in (Name-To-Be-Specified) words as described above. Shortest code wins.

| |
\$\endgroup\$
  • \$\begingroup\$ A language called Golfish already exists >_< \$\endgroup\$ – Mr. Xcoder Feb 23 '18 at 13:50
  • \$\begingroup\$ @Mr.Xcoder I believe you mean Gol><> \$\endgroup\$ – Mego Feb 23 '18 at 13:52
  • \$\begingroup\$ That's a programming language, not a spoken language. But fair point, if I graduate this to an actual question I'll pick a new name. \$\endgroup\$ – billpg Feb 23 '18 at 13:52
  • \$\begingroup\$ @Mego Well yeah but the repository name is Golfish... \$\endgroup\$ – Mr. Xcoder Feb 23 '18 at 13:53
  • \$\begingroup\$ Anyway, I'd advise referencing that you're not referring to Gol><> in any way. :) \$\endgroup\$ – Erik the Outgolfer Feb 23 '18 at 13:54
0
\$\begingroup\$

Paintball Tournament

Inspired by The Rock, Paper, Scissors, Lizard, Spock Tournament of Epicness as well as other King-of-the-hill challenges, I would like to propose a Paintball Tournament.

There is a game on my phone, called Game Pigeon that contains a paintball game. This paintball game is played by two players. The object of the game is to shoot your opponent x times before they shoot you x times.

Gameplay

The game is played in two sets of rounds. A moving round and a shooting round.

Both players, without their opponents knowledge, pick from three objects in front of them to hide behind.

                                (P1) X           X
                                     X           X (P2)
                                     X           X

Both players, without their opponents knowledge, choose which target across from them they would like to shoot at. After players decide which target to shoot at, players shoot at the targets chosen in unison, during which expose themselves from behind their target and are vulnerable to be hit.

Let's go through a small example. In the movement round, P1 has chosen to hide behind their left-most target. P2 has chosen to hide behind their middle target. In the shooting round, P1 chooses their leftmost target (Spot 1). P2 chooses their rightmost target (Spot 3). (See Below for diagram)

                                (P1) 3 <- Hit   1
                                     2          2 (P2)
                                     1  Miss -> 3      

For the above example, P1 would miss their shot and P2 would hit their shot, resulting in P1 losing one of their lives. During the shooting phase, players must choose a barrier to shoot behind, they cannot stay hidden.

After the shooting phase both players go back into the moving phase and, without their opponents knowledge, can move behind either of the other two objects or stay in place. They then continue to the shooting phase. They loop through these two phases until one of the players run out of lives, both players run out of lives, or a set number of rounds is completed.

Inputs

In the first game of the match, no arguments will be supplied to your bot. In each subsequent game of the match, you will be supplied 2 Args. -Arg1 will contain the location of the player([1, 2, or 3]) as well as the players move history. -Arg2 will contain the location of the players shot([1, 2, or 3]) as well as the players shot history. Both of these locations are referenced as if you are looking in the face of your opponent.

Example:

  • Round 1: PaintballBot.exe
  • Round 2: PaintballBot.exe 1 1
  • Round 3: PaintballBot.exe 12 11
  • Round 4: PaintballBot.exe 121 113

Output

Each round, your bot must output the location in which it is hiding, and the location it is going to shoot, to STDOUT, with two characters. All example outputs are shown below:

11 12 13 21 22 23 31 32 33

Match Format

Each submitted bot will play one match against each other bot in the tournament

Each match will last until one of the players loses their x amount of lives, or the match executes 50 rounds.

Matches will be played anonymously, you will not have an advanced knowledge of the specific bot you are playing against, however you may use any and all information you can garner from his decision making during the history of the current match to alter your strategy against your opponent. You may also track history of your previous games to build up patterns/heuristics etc... (See rules below)

Submission

Your submission should include:

  • Your Bot's name
  • Your Code
  • A command to
    • execute your bot from the shell e.g.
    • ruby myBot.rb
    • python3 myBot.py
    • OR
    • first compile your both and then execute it. e.g.
    • csc.exe MyBot.cs
    • MyBot.exe

Sidenotes

  • Need to describe that the location is relative to the shooter(from left to right) and the targets are relative to the shooter(from left to right)

  • I am still working on the control program for this event, and any help from other is greatly appreciated

If someone with more experience than me wants to take this over, please let me know. I would rather help with this challenge since it is my first and then have the knowledge and skills to run my own in the future.

Please let me know what still needs more clarification so we can have a fun tournament!

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

Sandbox Notes

  • Is this inflammatory, mean, and liable to draw unwanted and unnecessary attention to low-voted questions in the Network?
  • Better tags?
  • I should probably write a snippet to find all angry Metas.

Angry Meta

A site on the Stack Exchange network is considered to have an angry Meta if the lowest-voted Meta question (possibly closed, but not deleted) on the site is voted lower than the lowest-voted Main question.

For example, at the moment, the lowest-voted question on PPCG.SE is at -32, while the lowest-voted question on Meta.PPCG.SE is at -24. This means that codegolf does not have an angry Meta.

On the other hand, the lowest voted question on SoftwareEngineering.SE is at -13, while the lowest-voted question on Meta.SoftwareEngineering.SE is at -17. This means that softwareengineering does have an angry Meta.

Challenge

You will be given the name of a Stack Exchange site, which you can assume will not be Area 51, Stack Apps, Stack Overflow, a subdomain of Stack Overflow (such as the Spanish Stack Overflow), Ask Ubuntu, Super User, Meta.SE, or any other site that whose domain is not of the form *.stackexchange.com.

The name will be given as the name of the subdomain (e.g. codegolf for PPCG, puzzling for Puzzling, gaming for Arqade, etc.). You should return one of two distinct, consistent values depending on whether the site has an angry Meta or not.

Since this is liable to change over time, I will not provide a list of test cases here, but you can use this Stack Snippet which is the reference implementation:

TODO

| |
\$\endgroup\$
  • \$\begingroup\$ I suppose you mean to say lowest voted questions in your PPCG.SE example. \$\endgroup\$ – Weijun Zhou Mar 1 '18 at 13:12
  • \$\begingroup\$ @WeijunZhou Fixed. \$\endgroup\$ – Esolanging Fruit Mar 1 '18 at 16:38
0
\$\begingroup\$

Comment or not comment?

Write a function which given an all lowercase string, return the same string but with characters that are comments turned uppercase.

Input

Input is a null terminated ASCII string which may contain any of these characters abcdefghijklmnopqrstuvwxyz /*\ space newline
Last and only last character is null
You will not need to test for invalid input, such as "stringliterals" etc

Rules for what is comment

/* causes everything until */ (or end of string) to be comment
// causes everything until newline (or end of string) to be comment
'\' at end of line in a comment causes next line to be a comment aswell

Output

A copy of the input but with letters which are comments according to the rules above in uppercase, other characters shall remain unchanged

Examples

/comment -> /comment
//comment -> //COMMENT
/*comment -> /*COMMENT
no /*yes*/ no // yes -> no /*YES*/ no // YES

/*          ->              /*
comment                     COMMENT
*/                          */

//\          ->             //\
/*                          /*
not comment                 not comment
//\                         //\
*/                          */

ungolfed

| |
\$\endgroup\$
  • \$\begingroup\$ Which characters can be in the input? Printable ASCII? \$\endgroup\$ – user202729 Mar 4 '18 at 5:48
  • \$\begingroup\$ printable ascii yes and you can also assume input will not contain uppercase letters, function shall change a-z -> A-Z if they would be comment according to C-syntax \$\endgroup\$ – PrincePolka Mar 4 '18 at 16:52
  • \$\begingroup\$ I edited the proposal, clarified and simplified a little bit \$\endgroup\$ – PrincePolka Mar 4 '18 at 20:59
  • \$\begingroup\$ Potential dupe. This challenge is about removing comments instead of changing their capitalization, but the main part is the same. \$\endgroup\$ – Laikoni Mar 6 '18 at 21:00
  • \$\begingroup\$ @Laikoni, thanks I had not seen that one, looks almost the same \$\endgroup\$ – PrincePolka Mar 6 '18 at 21:21
0
\$\begingroup\$

There, I fixed it (with recycled parts)

Challenge

Given a string containing only letters a-z (either upper- or lowercase), fix it by adding characters to it so that the difference between two adjacent characters is no more than one, or if you can't, remove offending characters (in order) until the string satisfies the requirement.

For example, abcdfge must be fixed either by adding an e, resulting in abcdefge, or by removing f and g, resulting in abcde. Removing must be done only if adding can't be done.

You can add characters only from a recycle bin, which your program or function must store between calls. Characters removed from the string are placed in the recycle bin, and added characters are removed from the bin. The bin can store multiple instances of the same character. In the beginning, the bin is empty.

If you can't fix the whole string by adding characters, don't add any characters. That is, only ever either add or cut a string, not a bit of both.

Example

First call:
  Recycle bin: "" (empty)
  Input:       "abcdfge"
  Output:      "abcde"          // 'f' and 'g' are removed and placed in the recycle bin

Second call:
  Recycle bin: "fg"
  Input:       "defhiabcdeg"
  Output:      "defghiabcdefg"  // 'f' and 'g' are taken from the recycle bin and placed
                                // where they are needed.

Third call:
  Recycle bin: ""
  Input:       "codegolf"
  Output:      "cdef"           // The two 'o's and the 'g' and the 'l' are removed and
                                // placed in the recycle bin.

Fourth call:
  Recycle bin: "oogl"
  Input:       "mnpqrt"
  Output:      "mn"             // 'o' could be added, but it isn't, because an 's' is
                                // also missing and we don't have one. "pqrt" are added
                                // to the recycle bin.

Fifth call:
  Recycle bin: "ooglpqrt"
  Input:       "kmnrsu"
  Output:      "klmnopqrstu"    // Characters "lopqt" are added from the bin to fill all
                                // the gaps. Unused characters are left in the bin.

Sixth call:
  Recycle bin: "ogr"
  Input:       "qwerty"
  Output:      "qe"             // The gap between 'q' and 'w' can't be fixed so 'q' is
                                // removed. 'e'-'q' < 0 and therefore not more than 1,
                                // so 'e' stays. The rest of the characters are removed.
                                // The recycly bin will contain "ogrwrty".

This is , so the goal is to make your code as short as possible in whatever language you choose to participate with.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ "You can add characters only from a recycle bin, which your program or function must store between calls." Many languages don't have the capability to store information between program runs or function calls, or at least not easily. Perhaps having two inputs (recycle bin, 'input'), and two outputs (recycle bin, 'output') would be more inclusive? \$\endgroup\$ – Οurous Mar 9 '18 at 9:32
0
\$\begingroup\$

I wrote the following question then found this question. Is it similar enough to mine that mine would be considered a duplicate?

Recursive Prime Multiplicative Base

I've been thinking about this idea for months now, and, as far as I have been able to find, nobody else has thought of it. Please let me know if I wasn't the first!

Most number systems are additive positional. These take the form of ∑bi*di, where di is the sequence of digits and bi is the base sequence. For example, for the number 1234 in base ten, di={4,3,2,1,0,0,0...} and bi=10i.

I propose the idea of a multiplicative positional system.1 This instead takes a general form of ∏bidi. The most obvious useful multiplicative base is that of bi=Pi, where Pi is the i-th prime number. For example, one could write 3960 as 3,2,1,0,12, as 23*32*51*70*111=3960. This is mathematically interesting (e.g. multiplication gets reduced to addition, but addition is way harder) but we're still using an additive system underneath. This obviously cannot do. Thankfully, we can use recursion! This is probably best illustrated with an example:

3960=
  3    2   1  0 1
(0 1) (1)  () 0 ()
(0()) (()) () 0 ()
=(0())(())()0()

As you can see, each nonzero digit gets replaced with that digit's representation. 1 gets replaced with (), as a blank sequence is equivalent to an infinite series of zeros, and anything to the power of zero is one. If one were to include a symbol representing negation, one could write any rational number and even any expression obtainable from the integers using a finite number of multiplications and exponentiations in a finite sequence of four characters.

To give this number system a name, I term it the recursive prime multiplicative base or RPMB (unless you have any better ideas for it).

1Extending this, one can conceive of an infinite number of hyperoperational positional systems, but that's for another code challenge. ;)

The Challenge

You are to write a program that, when given an integer as input outputs the RPMB form of that integer. The output may be either as a string or a list. If the output is a string, you may substitute any characters for ()0. If the output is a list, the output should be a list of 0's and other lists matching this description. For example, for 3960, the program might output [[0,[]],[[]],[],0,[]].

Examples

(todo)

Scoring

This is , so the smallest program in bytes wins.

| |
\$\endgroup\$
  • \$\begingroup\$ Related. \$\endgroup\$ – user202729 Mar 11 '18 at 10:07
  • \$\begingroup\$ But 9 isn't a prime... \$\endgroup\$ – user202729 Mar 11 '18 at 10:08
  • \$\begingroup\$ @user202729 whoops, typo! Thanks for catching that \$\endgroup\$ – DanTheMan Mar 11 '18 at 17:30
1
73 74
75
76 77
99

You must log in to answer this question.

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