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

2970 Answers 2970

1
89 90
91
92 93
99
-1
\$\begingroup\$

The challenge

  • Write a Discord bot with a single command, !oldest, that gives the oldest user in the server that the command that was run in.

  • Gracefully failing in DM channels is not required.

  • Assume the bot's token is this invalid token: MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4.
    If the token is compressed in the program, provide instructions on how to change it so I can test it.

Sample discord.py implementation

import discord
client = discord.Client()
@client.event
async def on_message(M):
 if(M.content=="!oldest"):
  N=sorted([x.id for x in M.server.members])[1]
  await client.send_message(M.channel, str(M.server.get_member(N)))
client.run("MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4")
  1. Get a list of every user in the server
  2. Sort their snowflake IDs
  3. Print the username and discriminator of the member with the smallest ID.

No API for your language? Have fun.

Standard loopholes forbidden, etc, etc.

Shortest code in bytes wins.


Sandbox

I originally posted this question on the main site, but I deleted it, as it turns out I'm bad at writing these. Please forgive me.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I'm sure I've seen this already, but with comments saying that it needed a lot more information to be self-contained. It still needs a lot more information to be self-contained. \$\endgroup\$ – Peter Taylor May 5 '18 at 11:11
  • \$\begingroup\$ Yep. I've edited the question to clarify. \$\endgroup\$ – SIGSTACKFAULT May 5 '18 at 12:35
  • 2
    \$\begingroup\$ Are you talking about discord servers? Other than form the example this is not clear at all. What is a DM channel? What is a token in this context? \$\endgroup\$ – flawr May 5 '18 at 13:02
  • \$\begingroup\$ A: Clarify that you're talking about Discord B: When you make a challenge that requires a library does that mean I can use a library that conveniently has the command you're asking of? \$\endgroup\$ – IQuick 143 May 6 '18 at 2:12
-1
\$\begingroup\$

Divide two strings


One day, I saw the challenge to multiply two strings and I thought I might be able to do one better.

That challenge was fake. It was elementwise maximum. It was not real multiplication. So I set out to make something real. Real division between two strings.

I quickly realized that this would make an amazing challenge, as the algorithm was surprisingly complex and interesting to implement.

I then realized that it was actually easily reduced into a mere few operations. I'm still doing the challenge, though.

Enough with the backstory. Let's go.

Method

To divide two strings, do the following, where x is the first string and y the second:

  • If x does not contain y, return a space and a period concatenated to x.
    • For example, testx and blah would become .textx, with a space at the beginning.
  • Otherwise, return every occurrence of y in x, a period, then y divided by x with every occurrence of y removed, with all the periods removed.
    • For example, eestestst and est would become estest.est.

Challenge

Write a program or function that, given two strings via standard input, returns the first string divided by the second.

You may assume that neither input string contains a space, newline or period, and that the operation does not require more than 10 layers of recursion.

Test cases

test, es => es. es
test, blah =>  .test
okayye, y => yy. y
testes, es => eses. es
battat, at => atat. at
see, es =>  .see
see, e => ee. e
same, same => same. 
aabb, ab => ab.ab 
eestestst, est => estest.est
aheahahe, aheah => aheah.aheah ah

Scoring

As this is , the submission with the least amount of bytes wins.

Sandbox questions

  • Is this a duplicate?
  • Have I missed anything?
  • Does anything need further explaining?
  • Is there an issue with the concept of the challenge?
| |
\$\endgroup\$
  • \$\begingroup\$ What for aabb / ab? \$\endgroup\$ – l4m2 Jun 1 '18 at 12:42
  • \$\begingroup\$ okayye, y => yy. okay typo? \$\endgroup\$ – l4m2 Jun 1 '18 at 12:42
  • \$\begingroup\$ The test case battat, at => atat. by seems like it should be battat, at => atat. bt instead. \$\endgroup\$ – Kamil Drakari Jun 1 '18 at 13:47
  • 1
    \$\begingroup\$ It seems odd to me that when no characters are matched the output format is {matched characters (empty)}<space>.{unmatched characters} while the format when there are matches becomes {matched characters}.<space>{unmatched characters}. I would much rather see consistent ordering of the . and <space> \$\endgroup\$ – Kamil Drakari Jun 1 '18 at 13:50
  • \$\begingroup\$ @KamilDrakari 2 / 4 is 0.5, not .05, when 4 is not contained within 2 at all. Thus it makes no sense for test / blah to be . test when blah is not contained within test. We treat a space essentially like a zero would be with normal numbers. \$\endgroup\$ – LyricLy Jun 1 '18 at 22:15
  • 1
    \$\begingroup\$ @LyricLy 6/4 is 1.5 not 1.05. If you're treating space as 0 then there shouldn't be any space after the dot in any of the test cases. \$\endgroup\$ – Kamil Drakari Jun 1 '18 at 22:58
  • \$\begingroup\$ @KamilDrakari Actually, you're right. I was entirely mistaken because you get a fraction from 1 / remainder, not original number / remainder. Meaning this entire thing is wrong and I need to figure out a good replacement for 1 in string form. \$\endgroup\$ – LyricLy Jun 2 '18 at 3:32
  • \$\begingroup\$ Fixed the issues. \$\endgroup\$ – LyricLy Jun 2 '18 at 3:50
  • \$\begingroup\$ I accept downvotes, but I'd appreciate suggestions on how to improve the idea, or at least an explanation of what's wrong with it, so I know why I shouldn't post it. \$\endgroup\$ – LyricLy Jun 2 '18 at 8:18
-1
\$\begingroup\$

Introduction

I recently came across an oral exam where the candidates were asked to find a logical circuit than can negate 3 inputs A,B,C using only two NOT gates.

The question also specified that such a circuit is unique up to removal of useless gates and reordering inputs/outputs. The candidates were asked to prove this assertion by writing a piece of code that generates all such circuits.

Challenge

No inputs whatsoever are given.

The program must output all logical circuits using unlimited AND and OR gates but only two NOT gates which take in three inputs which map to three outputs. The outputs should be the negation of each input.

The outputted circuits should not have any redundant/trivial gates (gates that always output the same thing) or unused gates (whose output doesn't influence the outcome).

The program should use as little precalculated data as possible.

Output format is left up to the coders.

The winner will be determined by overall simplicity -- low run time and code elegance. It is not an objective criterion.

Example Input and Output

Input:

N/A

Output:

R    = (A & B) | (A & C) | (B & C)
notR = !R
S    = (notR & (A | B | C)) | (A & B & C)
notS = !S

notA = (notR & notS) | (notR & S & (B | C)) | (R & notS & (B & C))
notB = (notR & notS) | (notR & S & (A | C)) | (R & notS & (A & C))
notC = (notR & notS) | (notR & S & (A | B)) | (R & notS & (A & B))
| |
\$\endgroup\$
  • \$\begingroup\$ Example output and proof of existence are provided here \$\endgroup\$ – John Do Jun 17 '18 at 9:22
  • 1
    \$\begingroup\$ "It is not an objective criterion." Then it is not an on-topic question. \$\endgroup\$ – Peter Taylor Jun 19 '18 at 8:49
-1
\$\begingroup\$

Two functions with same input/output, with largest difference in bytes.

This challenge is a terrible idea. Don't try submitting it or anything similar!

Provide two functions with the largest difference in bytes. (These two functions will be referred to in bold italics to distinguish them from built-in functions available in your language in the rules below.)

Rules:

  1. Both functions must take an input and must produce an output. The input to and output from both functions must be identical.

  2. Both functions must be explicitly named. The function names must have the same byte count.

  3. You may not define any other functions.

  4. If you use a built-in function your language provides, it must be used with the same number of parameters in each of the functions.

  5. You may use string/numeric literals or any built-in constants, but you must use exactly the same ones in both functions.

  6. You can define variables, must you must use the same variable names in both functions.

  7. You can use comments, no-ops, and the equivalent, but they must be the same in both functions.

  8. Both functions must contain the same amount of whitespace (or equivalently, don't count whitespace at all.)

  9. You can import libraries/packages and the equivalent, as long as you import the same ones for both functions.

  10. You can use pre-processor directives as long as they are the same for both functions.

If any of these rules mean your language cannot compete, so be it.

Not really sure how to tag this. A little bit of and .

| |
\$\endgroup\$
  • \$\begingroup\$ I don't think this is a good idea. {Main downvote} \$\endgroup\$ – user202729 Jul 12 '18 at 16:26
  • 1
    \$\begingroup\$ Give up. E.g. in APL, and ⊢⊢⊢⊢⊢⊢⊢⊢ do the same. \$\endgroup\$ – Adám Jul 12 '18 at 16:26
  • \$\begingroup\$ @Adám, with those rules, it'd be something like f←⊢ and g←⊢(⊢(⊢(⊢(...)))) due to rules #2 and #3. The same thing still applies to OP: give up! \$\endgroup\$ – Zacharý Jul 12 '18 at 16:36
  • \$\begingroup\$ Thank you. I am happy to give up! \$\endgroup\$ – ngm Jul 12 '18 at 16:56
  • \$\begingroup\$ @Zacharý I intended them to be dyadic, but whatever… \$\endgroup\$ – Adám Jul 12 '18 at 17:18
  • \$\begingroup\$ "Both functions must take an input", which I assume would restrict the functions to monadic. \$\endgroup\$ – Zacharý Jul 12 '18 at 17:39
-1
\$\begingroup\$

Quiet QR

Your mission, should you choose to accept it is to infiltrate the top secret HQ of the Big Bad Evil Guy (TM) and extract information on their latest evil scheme saved in the file Plan.txt.

The target PC is isolated from any and all network connections, and you can't physically connect anything to it. The server room is equipped with sound sensors that will detect key presses.

Your tools are restricted to a mobile phone equipped with a QR code reader. Your recommended course of action is to write a code on the target machine that will display the file content as QR code.

You are to complete the mission with the least number of keystrokes as to minimise the sound generated by the mechanical keyboard.
It is advisable not to use languages that require unicode characters as entering one character will require multiple key presses (Eg:þ = Alt+0254) is considered 5 keystrokes.

You are to assume that the machine will have its terminal open and ready for input at the root directory of the system (C:\> or /).

All programming languages can be accessed directly from root folder. The target file is on the root folder.

Javascript is available as command line executable named js usable as (js filename) and prints output.

Image viewer is called view and usable as (view imagefile) [Extension is not needed]

Possible ways of output:

  1. An image containing the QR code

  2. ASCII art depicting the QR code using characters like █ ▄▀

  3. Or any form readable by any standard-issue QR code reader

  4. Other formats of 2D barcodes are accepted on the condition of being readable by a standard reader.

Example Solution for batch file:

copy con a.bat
open file Plan.txt
echo █ ▄▀
^Z
a

=59 keystrokes.

The symbols are 4 keystrokes each:

  • ▀ Alt+991

  • █ Alt+987

  • ▄ Alt+988

^Z as Ctrl+z and is considered 2 ketstrokes (F6 is considered one).
New lines and spaces are one keystroke each.
Capital letters are 2 strokes (Shift+c).
CAPITAL words are one keystroke added to the length of the word (Shift+capital).
No need to clean the screen at the end because the evidence will be erased by a Micro-EMP device that will disable the machine.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Why not just have a question to turn text into a QR code? The keystroke golfing just seems to complicate things \$\endgroup\$ – Jo King Jul 18 '18 at 11:54
  • \$\begingroup\$ @JoKing The premise of the challenge is to extract information from a pc with the least keystrokes. \$\endgroup\$ – workoverflow Jul 22 '18 at 9:06
  • \$\begingroup\$ In that case, what operating system is the PC? What type of QR code do you want (alphanumeric or byte?)? Can you add a link or explain an algorithm to generate you type of QR code (questions should be self-contained)? How big can the input be (100 bytes? 1kb?), and what characters can it contain? \$\endgroup\$ – Jo King Jul 22 '18 at 9:15
  • \$\begingroup\$ You may assume that the PC have an open terminal window ready for input in whatever OS you'd want (Bash, PowerShell, Command prompt,.....) The QR code must be able to encode alphanumeric+punctuation text in the file Plan.txt \$\endgroup\$ – workoverflow Jul 24 '18 at 10:29
-1
\$\begingroup\$

Projective related points

Points A, B, C, D and A′, B′, C′, D′ are related by a projective transformation if their cross ratios are equal.

Projective related points

Given A, B, C, D four ordered points on a line, their cross ratio is defined as:

\$\displaystyle\frac{distance(A,C)\times distance(B,D)}{distance(A,D)\times distance(B,C)}\$,

where \$distance(A,C)\$ is the Euclidean distance between points A and C.

Challenge

Given a set of eight points, say if yes or no the set can be splited into two subgroups (each subgroup with four points) where the two subgroups are related by a projective transformation.

Input

A set of 8 points, each point defined by its Cartesian coordinates (integer coordinates).

Output

Either a specific true output (true, 1, yes, ...) or a specific false output (false, 0, no, ...).

Example

{(10,100),(25,100),(2,63),(2,33),(31,100),(2,13),(2,3),(17,100)} --> true
with subgroups:
{(10,100),(25,100),(31,100),(17,100)} 
and 
{(2,63),(2,33),(2,13),(2,3)}

{(45,54),(8,23),(8,8),(8,29),(27,30),(15,14),(9,6),(8,15)} --> true
with subgroups:
{(8,23),(8,8),(8,29),(8,15)}
and 
{(45,54),(27,30),(15,14),(9,6)}

Hint (no need to use division or square root)

In order to avoid floating points, you can use the fact that points A, B, C, D and A′, B′, C′, D′ are related by a projective transformation implies:

\$distance^2(A,C)\times distance^2(B,D)\times distance^2(A',D')\times distance^2(B',C')\$

equals

\$distance^2(A',C')\times distance^2(B',D')\times distance^2(A,D)\times distance^2(B,C)\$

Rules

  • The input and output can be given in any convenient format.
  • No need to output the two subgroups.
  • No need to handle the case when at least two points in the set are the same.
  • No need to check the fact that the four points in each subgroup are aligned.
  • In your submission, please state the true and the false values.
  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • If possible, please include a link to an on-line testing environment so other people can try out your code!
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
| |
\$\endgroup\$
  • \$\begingroup\$ As with most problems involving floating point comparisons, I think you should include a large-ish number of test cases and require that submissions pass all of those cases. That way people can be sure their submissions are sufficiently accurate. \$\endgroup\$ – FryAmTheEggman Jul 13 '18 at 20:40
  • \$\begingroup\$ @FryAmTheEggman In fact there is a way to work only with integers, I'll add a hint. \$\endgroup\$ – mdahmoune Jul 16 '18 at 10:53
  • \$\begingroup\$ I had totally missed that the input would always be integers. Cary on, but I still recommend including at least several test cases to make users more able to be sure their submission works without having to find edge cases on their own. \$\endgroup\$ – FryAmTheEggman Jul 16 '18 at 14:35
  • \$\begingroup\$ @FryAmTheEggman Ok I'll add more examples. \$\endgroup\$ – mdahmoune Jul 16 '18 at 15:55
  • \$\begingroup\$ Is the cross ratio \$\overline{AC}\times\frac{\overline{BD}}{\overline{AD}}\times\overline{BC}\$ or \$\frac{\overline{AC}\times\overline{BD}}{\overline{AD}\times\overline{BC}}\$? \$\endgroup\$ – wastl Jul 18 '18 at 11:31
  • \$\begingroup\$ @wastl it's the second one, thanks for the remark, I just updated the formula. \$\endgroup\$ – mdahmoune Jul 18 '18 at 11:39
-1
\$\begingroup\$

A function to traverse an array and re-generate the same array

We take an array, then write a function that will traverse the array and generate the array in a format given in the example below.

For example, given the array:

Array

(

  [0] => Array
  ( [name] => Tom
      [age] => 32
      [key] => Array
      ( [0] => abc
          [1] => def
          [2] => efg
          )
      )
  [1] => Array
  ( [name] => Jim
      [age] => 30
      [key] => Array
      ( [0] => abc
          [1] => def
          [2] => efg
          )
      [address] => Array
      ( [0] => Array
          ( [state] => CA
              [country] => US
              )
          [1] => Array
          ( [state] => NY
              [country] => US
              )
          )
     )
)

Output should be:

User: 0
 name: Tom
 age: 32
 key:
  0: abc
  1: def
  2: efg
User: 1
 name: Jim
 age: 30
 key:
  0: abc
  1: def
  2: efg
address:
0:
 state: CA
 country: US
1:
 state: NY
 country: US

Challenge rules:

  • You can assume array can be multidimensional
  • The array can also be array of cars, schools, districts etc.
  • The preferred output is in json format
  • Indentation for the output is a simple json format

code-golf

The function will be tested with any sort of multidimensional arrays for speed of execution

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Can you give a quick explanation of how you generated the array? For example, where does Name come from, and what are the rules behind indentation? \$\endgroup\$ – Jo King Aug 9 '18 at 6:17
  • \$\begingroup\$ The array just contains User details which will include the Name, Age, Address etc. \$\endgroup\$ – Mochesane Aug 9 '18 at 6:45
  • 1
    \$\begingroup\$ Hi! Welcome to PPCG. We usually require challenges to be a bit more precisely defined, to avoid ambiguity. For eg., you mention " generate the array in a format given in the example below", and the rules say "the preferred output is in json format" - but the format in the example is not JSON (and has some possible issues, for eg. address not being indented). Also, the post says "array" throughout, but what you're actually working with looks like a nested hashmap/dictionary structure. \$\endgroup\$ – sundar - Reinstate Monica Aug 12 '18 at 11:46
  • 1
    \$\begingroup\$ Finally, you've mentioned code-golf, but also that the answers will be tested for speed of execution - do you intend code-golf (number of bytes) to be the primary winning criterion and the speed of execution the tie-breaker? Or do you mean all answers have to transform a particular large input within a certain time (say 1 minute) to be valid? In the latter case, it would be useful to specify what the large, multidimensional input will be, and what the maximum time of execution allowed is. \$\endgroup\$ – sundar - Reinstate Monica Aug 12 '18 at 11:46
-1
\$\begingroup\$

Pyramid of Bots

In this game, your bot is trying to get as high off the ground as possible. However, it can only stand on top of other bots, which are trying to get higher, too!

Overview

Your bot should be a Javascript function. It's return value should tell the program if the bot should move left, move right, or jump. Every bot starts out on a 2 dimensional grid, with a width and height set by (botCount * 2) + 1. Bots are placed on either side of the center space, and every other bot is spaced 1 apart from any other bot. They all start at y=0, and far left is x=0.

Gravity

If there is no bot on top of your bot, it can return the value jump. When a bot jumps, it moves 1 square up. If at any point in time there is nothing under the bot, it moves down 1. A bot cannot return jump if nothing is under it. If your bot is on top of another bot which moves left, your bot will fall.

Function params

Your function has 3 parameters: dirs, height, and map. The array dirs contains four boolean values, representing if there is a bot or arena border: below, to left, to right, above. The parameter height is an array with 2 elements: your height, current winner's height. The map array contains the height/width of the array, and then the amount of turns left in the game.

Running the game

In one game, the bot function will be run 800 times. Each of these is a turn. Your bot should return jump, or a direction. The bot can only move in a direction if there is no bot currently there. The two directions are left and right. Standard loopholes are not allowed (when are they ever allowed??), and the bot who wins the most out of 1000 games is the winner.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ I don't see the strategy in this. There's no way for a bot to reliably move up. No bot will stand still, so you literally have to guess whether or not an adjacent bot will move under you, and then hope that they move up while other adjacent bots move under. \$\endgroup\$ – Nathan Merrill Aug 27 '18 at 16:21
-1
\$\begingroup\$

My Ribosomes Got a Firmware Upgrade


So all of the Apple iBosomes in my body have been updated to RibOS 4.0 now… while I appreciate the additional optimizations that were added, unfortunately for me they've dropped support for the legacy mRNA API.

So since my RNA Polymerase library still needs to return strings in the format AUUCGGUCAAAGU for the code still using it, I'll need to add some code to the getBasePairs() method to translate it from the new API.

Challenge

  • Your input will be a string in base64 (because codons are exactly 6 bits) representing the genome.
  • You should output a string with the equivalent RNA base pair sequence:
    • 00 becomes A.
    • 01 becomes G.
    • 10 becomes C.
    • 11 becomes U.
  • All languages are allowed.
  • Your I/O must be in these exact string formats, even if they're small enough to encode as integers.
  • The shortest answer in bytes wins.
| |
\$\endgroup\$
  • \$\begingroup\$ Are you asking for a method that does a base64 to base4 conversion and pretty-prints the result? \$\endgroup\$ – Jonathan Frech Sep 18 '18 at 21:15
  • \$\begingroup\$ @JonathanFrech Kinda, I guess. \$\endgroup\$ – Nissa Sep 18 '18 at 21:17
  • \$\begingroup\$ So using lax I/O I can take the input as an integer and output four unique values like this? \$\endgroup\$ – Jonathan Frech Sep 18 '18 at 21:21
  • \$\begingroup\$ @JonathanFrech wasn't what I had in mind; I'll edit the proposal once I finish the essay I'm working on right now. \$\endgroup\$ – Nissa Sep 18 '18 at 21:26
-1
\$\begingroup\$

Trilateration

Intro:

Similar to Trilaterate your position with a small twist.

In a n x m array,

Original Problem:

You will be given a list of (x,y,d) as input, where d is the distance of your position from the point (x,y). Using this we can find our position.

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

In the above problem, d is the exact distance from the respective point.

In this problem, due to some error, we know that the distance is actually the maximum distance from the respective point. Because of that, instead of a single point, we will get a small area of our position. Objective is to get that area.

It should be in the format(a function):

f(list,n,m):
  #your code here
  return #list of all indices where you may be.

What's returning should be a list of points (x,y) with 0<=x<=n,0<=y<=m.

In case there is no solution return an empty list. The winner will be the fastest code. In case of a tie shorter code wins. The time taken will most likely depend on n,m and list of points.

| |
\$\endgroup\$
  • \$\begingroup\$ On which test(s) will the code be measured? \$\endgroup\$ – user202729 Sep 26 '18 at 15:14
  • \$\begingroup\$ Edited it.. Also, what are the tags I should add other then fastest-algorithm \$\endgroup\$ – Vedant Kandoi Sep 27 '18 at 10:54
-1
\$\begingroup\$

The goal of this challenge is to make an interpreted language that can print anything! The format of the language needs to be

[command eg: print] [args];

You have to use regex, even though it is not the typical way to write a language, to avoid people finding loopholes. Your interpreter also needs to ask for a file to open to interpret; example input file prompt:"File to interpret: "

Some tests to try:

print Hello World;


print This is a very very very very very long test;

ktrgjkfgjk;

print hi

If your interpreter runs these tests correctly, you can submit your interpreter.

Notes:

Do not just cut off the print!

If the command given does not exist, or if semicolon not present, print "Error"

This is so the lowest byte count + working code wins!

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I recommend some more explanation of the "File: " part \$\endgroup\$ – trichoplax Oct 7 '18 at 19:06
  • \$\begingroup\$ @trichoplax Thats the input file prompt \$\endgroup\$ – Menotdan Oct 7 '18 at 19:09
  • \$\begingroup\$ @trichoplax, well then i wont accept those answers, hold on let me edit \$\endgroup\$ – Menotdan Oct 7 '18 at 19:11
  • \$\begingroup\$ Read it again: it says: The format of the language needs to be [command eg: print] [args]; <--- note semicolon It was just a typo (I didnt type the ;) \$\endgroup\$ – Menotdan Oct 7 '18 at 19:14
  • \$\begingroup\$ The problem with saying "do not just cut off the print" is that there may be other ways of achieving the same thing, then the challenge just becomes a long list of things which are banned. You can avoid this by trying to set the requirements and inputs in a way that doesn't have these loopholes. \$\endgroup\$ – trichoplax Oct 7 '18 at 19:16
  • \$\begingroup\$ @trichoplax Ok i only want the print though \$\endgroup\$ – Menotdan Oct 7 '18 at 19:20
  • 2
    \$\begingroup\$ Writing challenges can be tricky, and people have posted advice on meta that can help: things to avoid when writing challenges and things to consider when creating a challenge \$\endgroup\$ – trichoplax Oct 7 '18 at 19:21
  • 1
    \$\begingroup\$ If you only want print, then is there a difference between this challenge and "remove the first 6 characters and the last character from this string"? If you don't want people to solve it that way, you could consider what they need to do when the input is not a valid print command, and specify that in that case it should do something different (like not output anything). \$\endgroup\$ – trichoplax Oct 7 '18 at 19:24
  • \$\begingroup\$ @trichoplax Yes, i didnt think of that \$\endgroup\$ – Menotdan Oct 7 '18 at 19:25
  • \$\begingroup\$ "do not just cut off the print" is an example of a non-observable requirement. Here's a good explanation of why that can be a problem \$\endgroup\$ – trichoplax Oct 7 '18 at 19:26
  • \$\begingroup\$ Here, new update \$\endgroup\$ – Menotdan Oct 7 '18 at 19:31
  • \$\begingroup\$ I hope all the comments don't put you off - writing challenges is difficult, but we get much more answers than challenges so more challenges are needed. I had lots of useful feedback from this community when I started out. \$\endgroup\$ – trichoplax Oct 7 '18 at 19:32
  • \$\begingroup\$ Is this better @trichoplax and where else can i improve \$\endgroup\$ – Menotdan Oct 7 '18 at 19:36
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – Menotdan Oct 7 '18 at 19:37
  • 1
    \$\begingroup\$ you have to use regex ... , to avoid people finding loopholes This seems very arbitrairly restricting. What about languages without regexes? You haven't actually said what the outputs of the test are. And what exactly is the program meant to have as input? I recommend a string input instead of messing around with files \$\endgroup\$ – Jo King Oct 8 '18 at 12:35
-1
\$\begingroup\$

Name: Create a Programming Language

Tags: code-bowling, and cops-and-robbers

Cops:

The cops must design a programming language that takes in the contents of the program from a default I/O method, and do something.

Rules:

  • The program must not print anything to STDERR
  • The program must be able to output to STDOUT with certain program contents of your choice
  • The program must be able to calculate any function up to \$f_{\omega}(n)\$ where f is the fast-growing hierarchy. In other words, it needs to be able to evaluate any primitive-recursive statement.
  • There cannot be a way to execute commands in other languages (for example, if there is a command in your programming language that can execute Python code based on the argument, that would be cheating)

Since there are tons of loopholes, whether or not the answer is valid is up to me (and also, standard loopholes are also not allowed).

Robbers:

Your job is to make the same compiler (which does the same thing with the same commands given as the equivalent cop answer), with more characters. The programming language may be different.

Standard loopholes aren't allowed, and whether an answer is valid or not will be judged by me.

As always, since this is code-bowling, aim for the most bytes!

| |
\$\endgroup\$
  • 3
    \$\begingroup\$ "whether or not the answer is valid is up to me" unfortunately, this is going to make the challenge unclear. \$\endgroup\$ – Erik the Outgolfer Nov 6 '18 at 20:35
  • 4
    \$\begingroup\$ I'm afraid I don't really understand the core of this challenge. The robbers have to make the compiler larger without affecting its functionality? That seems trivial to do; just add a comment or some whitespace. \$\endgroup\$ – Dennis Nov 6 '18 at 21:26
  • \$\begingroup\$ Your job is to make the same compiler ... with more characters Should this be less characters? also, shouldn't it be bytes? \$\endgroup\$ – Jo King Jan 29 '19 at 5:06
  • \$\begingroup\$ @JoKing Yeah, I realized that. \$\endgroup\$ – MilkyWay90 Jan 29 '19 at 12:24
-1
\$\begingroup\$

Win 2048

Win 2048. You can decide where to summon block of 2(no 4), and how you move. The output would be [place, place, move, place, move, ..., place, move](finally you reach 2048).

Shortest code win.

SN: Similar to Play a perfect game of 2048 ?

| |
\$\endgroup\$
  • 3
    \$\begingroup\$ (in case somebody don't understand the challenge: the program should take no input, and output any sequence of moves in 2048 game such that the tile 2048 is generated. As said in the challenge, the new block must be [2] (not [4]) and the program can determine where the block appears) \$\endgroup\$ – user202729 Nov 15 '18 at 14:31
-1
\$\begingroup\$

Coprimes upto N (Performance Edition)

There is this question: Coprimes up to N

Most of the answers there take way to long for larger numbers.

So, your task is to find all the coprimes of a number n (gcd(n,coprime)==1) up to nas fast as possible.

Scoring

Score=Largest n for which your code will output in less than 10 seconds on my laptop. Provide instructions to run it on my machine.

Highest score wins.

I will put the specs of my pc, anything else needed?

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ I think this is not interesting. The output (φ(n) numbers) is too large in comparison with the time complexity of a reasonably-competitive algorithm (I'd expect algorithms to take n log n time at worst), so printing output is going to be the bottleneck. \$\endgroup\$ – user202729 Nov 23 '18 at 11:54
  • \$\begingroup\$ What if I make it to print the number of coprimes instead? @user202729 \$\endgroup\$ – Vedant Kandoi Nov 23 '18 at 12:08
  • \$\begingroup\$ That is number of primes @user202729. This is co-primes of n. \$\endgroup\$ – Vedant Kandoi Nov 23 '18 at 12:24
  • \$\begingroup\$ Still, very similar to codegolf.stackexchange.com/questions/26739/… . \$\endgroup\$ – user202729 Nov 23 '18 at 13:03
-1
\$\begingroup\$

A Quine that Grows!

Challenge

Create a quine that, when run, outputs itself but copied larger in the next one. The output should be able to be run, and get larger each time the output is run. The output must consist only of characters from the original quine!

EX:

abc //original
abcabc //output

or

abc //original
aabcc //output

What not to do

abc //original
abcgef //output

abc //original
abcoooooooooooo //output

An example I created

Try it Online! It replicates pretty fast if I do say so myself!

Points

This challenge is meant to be a codegolf, but also emphasize on how fast it replicates. So perhaps something like the speed at which it gets bigger divided by the number of bytes.

I really don't want loopholes like just repetitively adding characters to a section of the code, making infinite loops, and things of the like.

Any input on how to make this a good challenge? I'm open to suggestions!!!

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Related, related (probably a dupe) \$\endgroup\$ – Jo King Feb 10 '19 at 10:25
  • \$\begingroup\$ @JoKing What about a polyglot that gets bigger? It runs, making another program that runs and outputs a bigger version of the original, and vice versa. \$\endgroup\$ – KrystosTheOverlord Feb 10 '19 at 16:02
  • \$\begingroup\$ where's the polyglot part come from? otherwise that sounds like the second one \$\endgroup\$ – Jo King Feb 10 '19 at 22:04
  • \$\begingroup\$ @JoKing The output has to be in a different programming language, and then create a larger version of the original, then this larger original makes a larger of second program etc... Also to prevent easy loopholes, no using program languages that are derivatives of eachother \$\endgroup\$ – KrystosTheOverlord Feb 10 '19 at 22:32
-1
\$\begingroup\$

Just idea. Not sure what to do exactly.

Evolutionary Golf

Make simple (not golfed at all at first) code for (some program) with language (something).

Now, change a little bit (maximum 3 byte) of code to make it shorter.

Altered code must work properly (this is how evolution work).

(Maybe here will be starting code).

Sandbox

First. What program would be best? For example, 'Hello World' program is not proper, because it is too short, and can't golf that much.

Second. What language would be best? Esolang like BF? Or something like C?

| |
\$\endgroup\$
  • \$\begingroup\$ If I understand the challenge idea correctly you will post an ungolfed answer that does something in some (probably verbose) language (i.e. FizzBuzz in C#). And then answers after that should have a Levensteihn distance change \$c\$ where \$1\leq c\leq3\$ (at least 1 delete) that does the same thing (in any language). And the shortest answer that's at the end of the answer chain wins if no other answers are posted within 2-3 weeks (which is usually the case with answer-chaining challenges)? Or do you mean that anyone can post an ungolfed program, and others using the same language chain it? \$\endgroup\$ – Kevin Cruijssen Jun 26 '19 at 9:04
  • \$\begingroup\$ @KevinCruijssen I'm thinking of both. This is just brief outline, so everything can be changed. \$\endgroup\$ – LegenDUST Jun 26 '19 at 12:10
  • \$\begingroup\$ this is just game of nim with extra steps \$\endgroup\$ – Kenzie Aug 2 '19 at 17:51
-1
\$\begingroup\$

Print all the commands

META Just a rought idea, needs to be worked out.

Write a program that prints all the keywords and commands that are available in your langauge when you do not import/add anything

Details

  • require full program or standard code-golf?
| |
\$\endgroup\$
  • 2
    \$\begingroup\$ Understanding that this is a rough idea, what happens in languages without commands corresponding to single tokens e.g. ///? \$\endgroup\$ – lirtosiast Jul 18 '19 at 15:49
  • 7
    \$\begingroup\$ It is my opinion that this sort of challenge will likely never be clear. \$\endgroup\$ – Wheat Wizard Jul 18 '19 at 16:08
  • \$\begingroup\$ I'd imagine for /// you'd output all valid non-text characters, so \ /. \$\endgroup\$ – bigyihsuan Jul 18 '19 at 17:08
  • 1
    \$\begingroup\$ Another thing is that language version would be specified. For example, Python 2 has print as a keyword, while Python 3 has print() instead. \$\endgroup\$ – bigyihsuan Jul 18 '19 at 17:10
  • \$\begingroup\$ Pretty sure this (or something similar enough to be a dupe) has been done before. Lemme see if I can find it .... \$\endgroup\$ – Shaggy Jul 21 '19 at 21:11
  • \$\begingroup\$ Found it! codegolf.stackexchange.com/q/162384/58974 \$\endgroup\$ – Shaggy Jul 21 '19 at 21:13
  • \$\begingroup\$ One way to do this might be to make it language specific? While that isn't usually popular, outputting all of, say, Python's commands in most languages besides python is a dupe of the Rickroll challenge. However, in python itself that isn't the best approach. I can't say how well reveived it'd be, but you could try "output these MATLAB commands in MATLAB" and see what people think. \$\endgroup\$ – FryAmTheEggman Jul 23 '19 at 19:45
-1
\$\begingroup\$

Here's a challenge I'd like post because I'm curious to see what people will come up with. It's a bit of an anti-code-golf question because the code should look normal.

Is it clear what the constraints? Did I miss anything?


Introduction

Write a piece of unsuspicious code that does the following:

Let's say you've written a parser that parses it's input line by line and somewhere in your code is

find_string(line, "[start]", "[end]") // returns string between [start] and [end]

This program, when given it's own source code plain text as input, will match that line (twice actually); but we don't want that. It should still parse what it was designed for but not match any line of it's own source code.

Rules

  • It's preferred that your code makes it obvious that one of it's intended uses is to parse (and not match) itself. This is so anyone 'refactoring' the code will not accidentally undo the trick that made it work.
  • Your source code as input will be reduced to a single line.
  • Your program should be able to handle large input (~10mb) and perform reasonably (for your chosen language).
  • Your program does not need to parse the input line by line but that just seems like something reasonable code would do.
  • Points are awarded for code that looks like a normal parser and contains as little assumptions about the input as possible. Bonus points for solutions that contain the start and end delimiters in that order.

Easy solutions are to swap the start and end token arguments or to pre-treat the tokens in some way but that would look suspicious. Someone will come along and refactor your code and break the 'trick'.

I'm interested in reasonable solutions because this is a reduction of a real life problem.

Example Input and Output

  • Input lines may or may not contain [start] or [end], only return it in the output when it occurs in a pair.
  • Input lines will never contain more than one pair of [start] and [end] tokens.
  • Input lines may contain additional content before [start] or after [end]
  • Your source code plain text will be inserted at a random line in the input.

Input #1:

[start]hello[end]
<<your source code plain text>>
dont output this[start]world[end]

Output #1:

hello world

Input #2:

lorem[start]i solemnly[end]
[start]false start
[start]swear[end]
ope, sorry just passing through
this is not the[end]
[start]that i'm up to[end]ipsum
[start]no[end]dolor
<<your source code plain text>>
[start]good[end]

Output #2:

i solemnly swear that i'm up to no good
| |
\$\endgroup\$
  • \$\begingroup\$ What is the objective winning criterion? \$\endgroup\$ – Unrelated String Aug 9 '19 at 5:16
  • 1
    \$\begingroup\$ This could be a good challenge if it was just 'Write a program that takes a line of input and returns the concatenation of anything between [start] and [end] on each line, otherwise an empty string', with the restriction that if it was fed itself, it wouldn't return anything \$\endgroup\$ – Jo King Aug 9 '19 at 6:05
  • \$\begingroup\$ I'm a little confused about what Bonus points for solutions that contain the start and end delimiters in that order. means, since I thought the point was that we're not allowed to have that? \$\endgroup\$ – Jo King Aug 9 '19 at 6:07
  • 2
    \$\begingroup\$ "unsuspicious code" will raise red flags in the minds of a number of old-timers, for historical reasons which I won't explain in detail. What I will say is that unsuspicious is subjective, and we insist on objective criteria. In terms of actual reasonable solutions to the real world problem: don't use magic strings. If "[start]" and "[end]" are both constants and defined on separate lines, the problem is averted, and anyone who refactors to inline them deserves all the bugs that causes. \$\endgroup\$ – Peter Taylor Aug 9 '19 at 10:45
-1
\$\begingroup\$

Title: Transposition

** The challenge **

Given a set of notes (as a string, or a list, or any other reasonable input - but as letters and accidentals, not a numerical equivalent), the key those notes are in, and a target key; output the notes transposed into the new key. Some of the notes may not exist in the scale for the given key (e.g Eb in the key of C).

** Inputs **

The complete set of input notes for this challenge will use the English naming convention, and so are as follows:

Ab,G##,A,A#,Bb,B,C,C#,Db,C##,D,D#,Eb,E,F,F#,Gb,F##,G,G#

where "b" represents a flattened note (down one semitone per b), and # represents a sharpened note (up one semitone per #). Theoretically all notes can be extended further with more #s and bs; but for the purposes of this program that won't happen beyond what is already given.

** What is transposing? **

Transposing a song involves "moving" the song into a different key, by finding the equivalent note of the scale in that key.

We will assume Major scales for the purposes of this challenge.

** Scales **

The scales for this challenge are officially as follows:

  • C: C, D, E, F, G, A, B, C
  • C#: C#, D#, E#, F#, G#, A#, B#, C#
  • Db: Db, Eb, F, Gb, Ab, Bb, C, Db
  • D: D, E, F#, G, A, B, C#, D
  • D#: D#, E#, F##, G#, A#, B#, C##, D#
  • Eb:Eb, F, G, Ab, Bb, C, D, Eb
  • E: E, F#, G#, A, B, C#, D#, E
  • F: F, G, A, Bb, C, D, E, F
  • F#: F#, G#, A#, B, C#, D#, E#, F#
  • Gb: Gb, Ab, Bb, Cb, Db, Eb, F, Gb
  • G: G, A, B, C, D, E, F#, G
  • G#: G#, A#, B#, C#, D#, E#, F##, G#
  • Ab: Ab, Bb, C, Db, Eb, F, G, Ab
  • A: A, B, C#, D, E, F#, G#, A
  • A#: A#, B#, C##, D#, E#, F##, G##, A#
  • Bb: Bb, C, D, Eb, F, G, A, Bb
  • B: B, C#, D#, E, F#, G#, A#, B

For simplicity, we can assume that both notes in the pairs A#/Bb, C#/Db, D#/Eb, F#/Gb, G#/Ab, C##/D, F##/G, G##/A are enharmonically equivalent (i.e. interchangeable - although they're not, always).

For scales with double-sharps, I will accept the enharmonic equivalents as an alternative implementation:

  • D#: D#, E#, G, G#, A#, B#, D, D#
  • G#: G#, A#, B#, C#, D#, E#, G, G#
  • A#: A#, B#, D, D#, E#, G, A, A#

but for all other notes in the scale, they must match. If the note isn't in the scale, either can be used.

e.g.

  • F in the key of C should transpose to F# in the key of C#, and not to Gb, because that option in the pair is explicitly in the scale
  • but D in the key of C# could transpose to either C# or Db in the key of C, because it's an incidental anyway and so there's no easy rule to determine which it should be.

BONUS feel-good points *: normally it's # if you're going up, and a b if you're going down - feel free to implement this if you want!

For double-sharps (e.g F##) in all cases, It's OK if the program "resolves" these (e.g.to G in that case) even if they are in the scale; but again, some BONUS feel-good points * if you keep the double-sharps in.

Examples

  • CDEFGABC in C to A -> ABC#DEF#G#A
  • C# in C to A -> A# OR Bb
  • ABCDEFGBAF#Bb in Bb to Gb -> FGAbBbCDbEbGFDGb
  • CCGGAAAAGFFEEDDCGGGFFEEEDCGGGFFFFEEED in C to G# -> G#G#D#D#E#E#E#E#D#C#C#B#B#A#A#G#D#D#D#C#C#B#B#B#A#G#D#D#D#C#C#C#C#B#B#B#A#

Websites like http://www.logue.net/xp/ can be used to test your answers to other inputs

* Bonus feel-good points don't get you anything extra, unless someone can come up with a quantifiable difference that it should make to the score?

| |
\$\endgroup\$
  • \$\begingroup\$ This is kind of similar but doesn't use scales and has a different set of chords, so I think this is effectively different? \$\endgroup\$ – FryAmTheEggman Sep 24 '19 at 18:47
  • \$\begingroup\$ Yes, I agree it's similar but doing a different thing to me (they're using chords, and so have the extra text to worry about; but I'm doing notes, like sheet music; and so you have accidentals to worry about) \$\endgroup\$ – simonalexander2005 Sep 25 '19 at 8:48
-1
\$\begingroup\$

Interpret Unneccesary (Not quite)

Unneccesary is a joke language created by Keymaker. The source is unneccesary, and if given, it will error out.

Your task here is similar. If there is input, your program should error out. If the input is empty, your program should do nothing and terminate.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ What does it mean to error out? \$\endgroup\$ – Beefster Oct 24 '19 at 19:14
  • \$\begingroup\$ @Beefster throw a runtime error... Or? \$\endgroup\$ – null Dec 1 '19 at 10:15
  • \$\begingroup\$ What if I'm using a language that does not have terminal errors such as Bash? \$\endgroup\$ – Beefster Dec 2 '19 at 19:34
  • \$\begingroup\$ @Beefster Are there any specifications for, something like error quine? \$\endgroup\$ – null Dec 21 '19 at 10:54
-1
\$\begingroup\$

Mirror, Mirror, on the wall. Who's the fairest of them all?

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?

Challenge:

Given an arbitrary number (>= 2) of possibly duplicated hexadecimal color values (ranging from #000000 to #FFFFFF) and paired strings, calculate the following:

  • If #FF0800 (Candy apple red) appears in the input, return "Return to Sleeping Death"
  • If #000000 appears in the input, return "Saved by Grumpy"
  • If #A98AC7 or #111111 appears in the input, return "Saved by Happy"
  • If #21E88E or #222222 appears in the input, return "Saved by Sleepy"
  • If #32DCD5 or #333333 appears in the input, return "Saved by Bashful"
  • If #43D11C or #444444 appears in the input, return "Saved by Sneezy"
  • If #54C563 or #555555 appears in the input, return "Saved by Dopey"
  • If #65B9AA or #666666 appears in the input, return "Saved by Doc"
  • If #76ADF1 or #777777 appears in the input, return "Saved by the Seven Dwarfs"
  • If #FFFAFA (Snow) appears in the input, return "Saved by Love's first kiss"
  • If an F variant appears in the input, return "Press F to pay respects to Snow White"
    • An F variant is any number that contains at least one F in its hexadecimal form, and is otherwise all 0s (e.g. #0FF0F0, #FFFFFF, #00000F, #F00F00)
  • If multiple of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • For all N occurrences of special color values, choose the (N-1)/2-th (truncating division) occurrence. The associated special output is the "fairest" answer.

"Appears in the input" here refers to only the hexadecimal color values, and not to the paired strings.

  • If none of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • Take the hexadecimal color value at the end of input values, write it down, and exclude that single color-string pair from consideration as the "fairest" answer
    • Show its binary form to the mirror, computing a reflection of only the last 24 (#FFFFFF is the mask) bits.
    • Choose the hexadecimal color with least Hamming distance from the reflection. If there are multiple (N) such colors, choose the middle ((N-1)/2-th, truncating division) instance of the color. The "fairest" answer is the associated string for the color.

Inputs:

A sequence of hexadecimal color values and String values separated by a space. The input may also be read as two separate sequences of hexadecimal color values and String values, or a single sequence of 2-tuples (either (hexValue, stringValue) or (stringValue, hexValue) is permissible, as long as the ordering is consistent across all 2-tuples). Input order matters - for each index, the corresponding element in the supply of color values is "associated" with the corresponding element in the supply of String values, and duplicates can affect the "fairest" answer. The effect is something like Function(List(HexColorValue),List(AssociatedStrings)) -> "fairest" answer. Hexadecimal color values may be represented as either (your choice of) a String "#"+6 digits, or 6 digits alone, as long as the representation is consistent across all color values.

Here's an example input:

76ADF1 Return to Sleeping Death
2FE84E Return whence ye came!

Here's another example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
2FE84E Return of the Jedi

Here's the third example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
7217F8 Return of the King

Here's the final sample input:

F4A52F Eating hearts and livers
F4A52F Eating apples
F4A52F Eating porridge
F4A52F Eating candy houses
F4A52F A Modest Proposal

Outputs:

The "fairest" answer as computed by the specified logic. For example, on the first sample input, the "fairest" answer would be Saved by the Seven Dwarfs, due to the special hex color 76ADF1 appearing within the input.

In the second sample, there are no special inputs. First, we take "2FE84E Return of the Jedi", which has value #2FE84E. In binary, this is:

001011111110100001001110

We take the reflection from the mirror, getting:

011100100001011111110100

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 18 and 12 from the reflection, respectively. Since #4FFAFC has the uniquely lowest Hamming distance from the reflection, the "fairest" answer is Return of the Obra Dinn.

In the third sample input, there are no special inputs. First, we take "7217F8 Return of the King", which has value #7217F8. In binary, this is:

011100100001011111111000

We take the reflection from the mirror, getting:

000111111110100001001110

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 2 and 8 from the reflection, respectively. All 3 instances of hexadecimal color value #2FE84E have minimum Hamming distance from the reflection, so we take the (3-1)/2=1th instance (0-indexed) of #2FE84E. Therefore, the "fairest" answer is Return to the house immediately, young lady!.

In the last sample input, there are no special inputs. First, we take "F4A52F A Modest Proposal", which has value #F4A52F. In binary, this is:

1111010011001100101111

We take the reflection from the mirror, getting:

1111010011001100101111

We compare it against F4A52F (1111010011001100101111), which has Hamming distance 0 from the reflection. All instances of hexadecimal color value #F4A52F have minimum Hamming distance from the reflection. There are FOUR instances of #F4A52F, because we always exclude the last hexadecimal color instance from evaluation. Therefore, we take the (4-1)/2=1th instance (0-indexed) of #F4A52F, and the "fairest" answer is Eating apples. If you don't exclude the last value from consideration, you actually get the (5-1)/2=2th instance of #F4A52F (Eating porridge), which is wrong.

Rules:

  • No standard loopholes
  • Input/output taken via standard input/output methods.
  • The output must be exactly equal to the "fairest" answer

Scoring:

This is code golf, so shortest program wins.

Posted~ you can see it here

| |
\$\endgroup\$
  • \$\begingroup\$ Going to need tag suggestions :) \$\endgroup\$ – Avi Sep 30 '19 at 20:57
  • \$\begingroup\$ Can each entry be taken as a tuple, i.e. ("#FFFFFF","Return the Slab")? Can the label part also have a hex number in it or are we guaranteed it wont? Rules has the # but the examples do not, is either form fine? Can we get a worked example of a list containing multiple matching entries? \$\endgroup\$ – Veskah Oct 1 '19 at 12:33
  • \$\begingroup\$ @Veskah You can take tuples as input. You can choose whether to keep # in your input hex colors or not, as long as you keep it the same for every single input (no sneaky stuff like putting a # before the correct answer every time). I've added more sample inputs/outputs with explanation. \$\endgroup\$ – Avi Oct 1 '19 at 14:28
  • \$\begingroup\$ -1: This has way too many hardcoded input/output mappings. This challenge is more about encoding those than solving a problem. \$\endgroup\$ – Beefster Oct 24 '19 at 19:10
-1
\$\begingroup\$

CMC: Cross-Multiplication Calculator

In this task you should create a Cross-Multiplication Calculator.


Cross-multiplication is a way of factoring an algebraic expression. This is the expression form that this way can solve:

$$x^2 + ax + b$$

\$a\$ and \$b\$ are constants here, and \$x\$ is a variable.

Anyway, as far as I can tell, this expression form is only solvable in this method.

Anyway, how do I do Cross-Multiplication? (TODO)

You first take the number \$b\$ and factor this number into integral factors.

Okay. We are using the expression \$x^2 + 8x + 16\$ as an example.

(Although 16 is not a prime) let us assume that 16 only has 2 possible factors:

  • \$-1 \times -16\$ (because \$-x \times -x = x^2\$)
  • \$1 \times 16\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

Now you sum these possible two factors and check this against the number \$a\$.

  • Check 1. So \$-1 + (-16) = -17\$. And unfortunately -17 is not 8, we proceed to the next check.
  • Check 2. So \$1 + 16 = 17\$. And unfortunately 17 is not 8, we proceed to the next check. There are no checks left.

Did I make a mistake? Of course, I need to change the factors.

  • \$-2 \times -8\$ (because \$-x \times -x = x^2\$)
  • \$2 \times 8\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

We sum those values, and they are -10 and 10 respectively. So I should change the factors to another value:

  • \$-4 \times -4\$ (because \$-x \times -x = x\$)
  • \$4 \times 4\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

Finally! \$4+4 = 8\$, and here is the factorization:

$$(x+4)(x+4)$$

Now you will probably realize why I desperately need a program to automate this.

Test cases

You can assume that the input is always valid. You do not have to specify the variables, only the numbers. Therefore the expression

$$x^2 + ax + b$$

is converted into:

$$+a \, +b$$

The expected output is not:

$$(x+\alpha)(x+\beta)$$

but:

$$+\alpha \, +\beta$$

a, b => α, β
8, 16 => 4, 4
-5, -24 => 3, -8

Scoring

This is , so shortest answer in bytes wins.

Meta

  • Is this clear enough?
  • I haven't found a duplicate, but anything? (Although unlikely, I found nothing by searching "Cross Multiplication".)
  • Tags are code-golf, string and interpreter. Anything else?
  • Any further feedback?
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I've edited your post to use MathJax for the mathematical formula/workings. In addition, I've edited out the rather strict input/output format (leading + etc.) as it's generally recommended to allow the most natural output format. Feel free to revert these changes if you dislike them. Also, your tags bullet point in the Meta section appears to be different to the tags in the title? \$\endgroup\$ – caird coinheringaahing Oct 21 '19 at 17:48
  • \$\begingroup\$ Finally, I'd vote to close this as a duplicate of this or this challenge (as it is a subset of both) \$\endgroup\$ – caird coinheringaahing Oct 21 '19 at 17:51
-1
\$\begingroup\$

Return the maximum value in the final List

In this challenge, start with an array initialized to zeros with indices starting at 1 and a series of operations to perform on segments of the list. Each operation will consist of a starting and ending index within the array, and a number to add to each element within that range.

Determine the maximum value in the final array.

For example, start with an array of 5 elements: list = [0, 0, 0, 0, 0]. The variables a and b represent the starting and ending indices, inclusive. Another variable, k, is the addend. The first element is at index 1.

a    b    k             list

               [  0,  0,  0,  0,  0]

1    2   10    [ 10, 10,  0,  0,  0]

2    4    5    [ 10, 15,  5,  5,  0]

3    5   12    [ 10, 15, 17, 17, 12]

The maximum value in the resultant array is 17. That is the value to be determined.

Function description

The function must return a long integer that denotes the largest value in the array after all operations have been performed.

listMax has the following parameters:

n: an integer, the size of the initial array.
operations: a 2D integer array where each element contains an operation.

Constraints

\$3 ≤ n ≤ 10^7\$

\$1 ≤ o ≤ 2 × 10^{5}\$

\$1 ≤ a ≤ b ≤ n\$

\$0 ≤ k ≤ 10^{9}\$

Input Format

Allowed inputs are STDIN, function argument, System argument, file input, etc.

inputs are optional and both 0- and 1-based indexing is allowed.

Sample Case 0

Sample Input 0

5

3

3

1 2 100

2 5 100

3 4 100

Sample Output 0

200

Explanation 0

Perform the following sequence of o = 3 operations on list = [0, 0, 0, 0, 0]:

  1. Add k = 100 to every element in the inclusive range [1, 2], resulting in list = [100, 100, 0, 0, 0].

  2. Add k = 100 to every element in the inclusive range [2, 5], resulting in list = [100, 200, 100, 100, 100].

  3. Add k = 100 to every element in the inclusive range [3, 4], resulting in list = [100, 200, 200, 200, 100].

Return the maximum value in the final list, 200, as the answer.

Sample Case 1

Sample Input 1

4

3

3

2 3 603

1 1 286

4 4 882

Sample Output 1

882

Explanation 1

Perform the following sequence of o = 3 operations on list = [0, 0, 0, 0]:

  1. Add k = 603 to every element in the inclusive range [2, 3], resulting in list = [0, 603, 603, 0].

  2. Add k = 286 to every element in the inclusive range [1, 1], resulting in list = [286, 603, 603, 0].

  3. Add k = 882 to every element in the inclusive range [4, 4], resulting in list = [286, 603, 603, 882].

Return the maximum value in the final list, 882, as the answer.

References:

| |
\$\endgroup\$
  • \$\begingroup\$ Thanks for using the sandbox! This challenge looks a bit like one taken from another site, so I'd urge you to either put a reference or change some of the wording. Notably, the strict input format isn't a good idea, particularly input that conveys no information (i.e. the 3 after o). I strongly recommend changing the input to match what is usually done for challenges on this site: allowing the information in any convenient format. \$\endgroup\$ – FryAmTheEggman Nov 6 '19 at 16:48
  • \$\begingroup\$ @FryAmTheEggman Please take a look and let me know if there are any changes need to be considered. \$\endgroup\$ – Pluviophile Nov 7 '19 at 6:28
  • 1
    \$\begingroup\$ Thank you for adding a reference! I would recommend also including a link, if you can. I would also like to reiterate my suggestion to change the input format to be more lenient. \$\endgroup\$ – FryAmTheEggman Nov 7 '19 at 18:25
  • \$\begingroup\$ Hi Krishna, welcome and thanks for using the sandbox! I would agree with FryAmTheEggman regarding allowing "any convenient format" for the input, as is usual on this site. So for your example, f(5,[[1,2,100],[2,5,100],[3,4,100]]) would be a valid option. \$\endgroup\$ – Chas Brown Nov 7 '19 at 22:50
  • \$\begingroup\$ @FryAmTheEggman Added reference Links, and inputs are optional. \$\endgroup\$ – Pluviophile Nov 8 '19 at 10:36
  • \$\begingroup\$ @ChasBrown Hi, Thank you for your time & the Suggestion. Could you please elaborate on the Convenient input format. And do I need to change the sample test cases as well? or Only "Input Format" \$\endgroup\$ – Pluviophile Nov 8 '19 at 10:42
  • 1
    \$\begingroup\$ Thanks for adding the link! I've looked through the Terms of Service for hackerrank, and I couldn't figure out whether basically reusing challenges was allowed. I think it would be good if you explained why you were sure it is ok to post (this is the first time I've seen a hackerrank question posted here). The changes you made to input are good, and you can leave the test cases. However, I recommend re-wording the input part so that you don't have "first line," etc., in them anymore. \$\endgroup\$ – FryAmTheEggman Nov 8 '19 at 17:23
-1
\$\begingroup\$

Parse a regex

Grep is a wonderful tool. It can find stuff in files, it can help you spell stuff correctly (grep 'whatever' /usr/share/dict/words or wherever that file is), and it can even test if something is a prime number!

However, the first version was implemented back in the golden age, when FORTRAN was respected, Pascal was the language for beginners, and object orientation was just starting out in on its great adventure.

One could argue that modern developers have nowhere near that much talent or skill, what with their flashy "IDEs" and "frameworks". If they would be asked to implement something similar, they would just jump at the nearest library or cloud thingimabob and say "Done!".

At least, that is what some would say.

Prove them wrong! Golf grep!

Parse a regular expression without calling any built-in functions or operators explicitly meant for this.

input:

Basically the same as a simple grep: a regular expression as a command line parameter, followed by an optional filename or a dash. If the filename is not present, or it is a dash, read for stdin.

This is the recommended way to do it, but if you can write an adapter (eg: post stuff to a php form for your program via a shell script), then that is OK as well. The adapter does not contribute to your score.

output

Lines that match the regular expression.

Notes:

The regex dialect is PCRE (perl compatible). Files use unix line terminators if it is relevant.

| |
\$\endgroup\$
  • \$\begingroup\$ Closely related, but not quite a duplicate. \$\endgroup\$ – AdmBorkBork Nov 18 '19 at 20:42
  • \$\begingroup\$ Why the downvote? \$\endgroup\$ – Mark Gardner Nov 20 '19 at 8:16
  • \$\begingroup\$ You've likely been downvoted because you "ban built-in functions or operations explicitly meant for this." Consider this post for a lengthy discussion of why this has fallen out of favour. Beyond this being trivial besides parsing regular expressions, it also doesn't actually describe what a regex is or what it means to be PCRE. Challenges need to be self contained! I think your bet is to make a different matching language yourself and ask us to implement grep but with that language instead of regex. \$\endgroup\$ – FryAmTheEggman Nov 20 '19 at 19:09
-1
\$\begingroup\$

Predict the state of a Minecraft inventory after click events

Minecraft does inventory management over the network by sending packets describing the clicks that a player does. If you're caching these events, it can be non-trivial to predict what state the inventory is in after the clicks

Challenge

Take an inventory of 9 slots, each with an item and a type. Assume all items can stack up to 64 and that if a slot would be "overfilled" that the cursor will continue holding onto the items. Then, take a list of the slot index, button, and mode variables for the clicks to be done (mode and button are defined at https://wiki.vg/Protocol#Click_Window). Output the inventory afterwards.

Restrictions/Rules

You may input and output the inventory in any reasonable format. You may take click input in any reasonable format. You may ignore Mode==2, as the player inventory is not implemented correctly enough for this. You may ignore Mode==3 because this is a survival player You may ignore Mode==5 where Button==8, 9, or 10 for the same reason as Mode 3. Dropping the item is a delete. Your player won't pick it back up or anything silly like that. You may assume that input will have valid counts Don't use standard loopholes

Examples

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

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

Output

[[],["diamond",64],[],[],[],[],[],[],[]]

Input:

[["diamond",64],["dirt", 64],[],[],[],[],[],[],[]]

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

Output

[[],["diamond",64],["dirt",64],[],[],[],[],[],[]]

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
 [0, 0, 0],
 [-999, 4, 4],
 [0, 4, 5],
 [1, 4, 5],
 [2, 4, 5],
 [3, 4, 5],
 [4, 4, 5],
 [5, 4, 5],
 [6, 4, 5],
 [7, 4, 5],
 [8, 4, 5],
 [-999, 4, 6],
 [8, 0, 0]
]

Output

[["diamond",56],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1]]

Meta

I have no clue what I'm doing writing a question.

Tagged code golf

Critique goals:

  • Improve testcases
  • Improve description of problem
  • Determine if the problem is too complex
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Challenges are meant to be self-contained. While information where the idea/process comes from can be nice, everything needed to solve the challenge should be in the description. This means you should write down what click does what, for all the people who don't remember what Minecraft clicks do by heart. \$\endgroup\$ – AlienAtSystem Nov 22 '19 at 6:43
-1
\$\begingroup\$

A very-very old (maybe early 2000s) problem:

Print out a decimal number \$n\$ such as \$n^2\$ ends with \$n\$ with maximal length your program can compute in 60 seconds

In other words it's needed to find some long enough \$n\$ such as \$10^{\lfloor\log_{10}n\rfloor+1}|(n^2-n)\$.
A hint may be that an \$n\$ ending with \$5\$ is more easy to compute than an \$n\$ ending with \$6\$.

code-challenge

| |
\$\endgroup\$
  • \$\begingroup\$ How can this be king-of-the-hill? Do you mean code-challenge? And what stops us from hardcoding some extremely large number? \$\endgroup\$ – Jo King Nov 21 '19 at 23:36
  • \$\begingroup\$ king-of-the-hill needs interaction between submissions. I don't see any here \$\endgroup\$ – Jo King Nov 22 '19 at 1:43
  • \$\begingroup\$ @JoKing the problem becomes very simple with modular arithmetic: got 205k digits for free with ~len(n) time for each step imgur.com/ExPdwMb , so there's no need for hardcoding and it's not much interesting. ) \$\endgroup\$ – Alexey Burdin Nov 22 '19 at 14:11
-1
\$\begingroup\$

JavaScript: Free for All

This is a very experimental idea of mine: given a function which is provided a single function as an argument, try to run that function the most times possible in a browser environment while competing against other bots.

Bot submissions

Each bot consists of a function. This function takes a scoring function as input. Each bot has a state consisting of three values:

  • score: Number indicating score, winning criterion
  • locked: Boolean which, when true, prevents further score increases
  • calls: Number of times scoring function called in last 100ms (?), will set locked to true for the remainder of the round if it exceeds a certain value

The scoring function increments score and calls, as long as locked is not true.

Restrictions

If any of these restrictions are violated, a bot will have locked set to true.

No bot or bot-defined function may:

  • Run longer than 5ms
  • Attempt to modify the window location (location.href, location.assign, etc.)
  • Attempt to connect to the internet (AJAX, WebSockets, etc.)
  • Create web workers
  • Affect hardware (sound, microphone, camera, USB, gamepads, etc.)
  • Download files
  • Leave an impact which cannot be fixed by reloading the page

Notes

This is almost certainly a very bad idea on an assortment of levels. If you have any suggestions of restrictions or ways to make the challenge more interesting, be sure to comment.

I'm considering some sort of system to determine which bot runs first that adds to the strategy, and interesting attack angles for other bots.

To prevent this from becoming a "read the last answer and exactly cancel out its strategy" type thing, I'm open to any suggestions.

| |
\$\endgroup\$
-1
\$\begingroup\$

Given a digit as an English word, output its numerical value.

For example, given the input one, you should output 1 (optionally with a trailing newline).

Your program should cover all the following cases:

zero  => 0
one   => 1
two   => 2
three => 3
four  => 4
five  => 5
six   => 6
seven => 7
eight => 8
nine  => 9

| |
\$\endgroup\$
-1
\$\begingroup\$

Introduction

This challenge was inspired by the 24 Game.

In the 24 Game, you are given 4 numbers and are asked to make 24 using addition, subtraction, multiplication, division, and parentheses. So...

What is the biggest number you can make given 4 numbers using the above operations?

Challenge

For four given inputs a, b, c, d, output the biggest number you can get using addition, subtraction, multiplication, division, and parentheses.

This is code-golf, so the shortest answer wins.

Example Input and Output

  Input  -->  Output  -->   Explanation
 1,3,2,4 -->    36    --> (1 + 2) × 3 × 4
 5,5,5,5 -->   625    -->  5 × 5 × 5 × 5
 9,2,3,1 -->    81    --> (1 + 2) × 3 × 9
 

Please give feedback on this challenge and correct me if my outputs are wrong. Should I change it to the smallest number?

| |
\$\endgroup\$
  • \$\begingroup\$ Related. \$\endgroup\$ – FlipTack Dec 30 '19 at 23:19
  • 1
    \$\begingroup\$ Also the subtraction and division are surely obsolete for the challenge? \$\endgroup\$ – FlipTack Dec 30 '19 at 23:21
  • \$\begingroup\$ Will positive number divide zero yield Infinity as what IEEE 754 does? \$\endgroup\$ – tsh Dec 31 '19 at 3:37
  • 1
    \$\begingroup\$ Shouldn't (1+2)x3x4 greater than 1+2x3x4? \$\endgroup\$ – tsh Dec 31 '19 at 3:37
  • \$\begingroup\$ @FlipTack Probably but maybe not in some circumstances. \$\endgroup\$ – Yousername Dec 31 '19 at 22:18
  • \$\begingroup\$ @tsh No, infinity will not count as the solution. Thank you, that is true that (1+2)x3x4 is greater. \$\endgroup\$ – Yousername Dec 31 '19 at 22:19
  • \$\begingroup\$ Does order matter? From the input it seems the order matters, i.e. we are not supposed to change the order of the input. So, for 1,3,2,4, the answer is 32, rather than 36. \$\endgroup\$ – Element118 Jan 1 at 5:25
  • \$\begingroup\$ @Element118 No, order does not matter, those were just the random numbers that came from my head. \$\endgroup\$ – Yousername Jan 4 at 21:11
-1
\$\begingroup\$

How many ACus do I have?

Posted to main

| |
\$\endgroup\$
  • \$\begingroup\$ I'm not sure this counts as a dupe, but what it seems to be is n=floor(days_between(input, date(1,1,2020)) / 7); return n*(n-1)/2, which doesn't seem terribly interesting to golf. (Also just fyi, the 01 you used in your dates in your script is actually an octal literal i.e. 010 is 8) \$\endgroup\$ – FryAmTheEggman Jan 7 at 21:33
  • \$\begingroup\$ Thanks for the feedback. I have corrected the script. Not sure how the extra 0's managed to slip in! I'll leave the challenge here for a couple more days to see if there are any more comments. \$\endgroup\$ – ElPedro Jan 8 at 7:43
  • \$\begingroup\$ @ElPedro You need to wait longer. At least a month or two, but a few months is really good. \$\endgroup\$ – S.S. Anne Jan 11 at 21:25
  • \$\begingroup\$ I'm sorry and no personal offence intended but I find it a bit strange that a member of 3 months is telling a member of over 4 years with lot's of experience and over 5000 rep how to use the sandbox and the main site. Maybe I am simply getting too old for this community. \$\endgroup\$ – ElPedro Jan 11 at 21:36
  • \$\begingroup\$ And besides which, none of that alters my opinion that downvotes without the downvoter giving a reason are not any help to anyone. If you think differently then please feel free to give me a good reason. I am happy to listen and learn. \$\endgroup\$ – ElPedro Jan 11 at 21:40
1
89 90
91
92 93
99

You must log in to answer this question.

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