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

2973 Answers 2973

1
65 66
67
68 69
100
0
\$\begingroup\$

Where am I?

(Some other tags pls help)

Your task in this challenge is to output the location of the user. This may be done by means of GeoIP, a builtin GPS device, or any other means. Output should either be in the format (latitude, longitude) accurate to at least one degree, or (City, [optional state/province/etc], Country). Errors due to the GPS device being inaccurate or similar which are not the fault of your code are allowed. Fewest bytes wins.

| |
\$\endgroup\$
  • \$\begingroup\$ Accurate to one degree? Holy hell, do you know how much one degree is? google.com/maps/dir/11.00000,+2.000000/10,1/… \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:09
  • \$\begingroup\$ Also, this is more or less "output the location of the users ISP"... \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:10
  • \$\begingroup\$ @carusocomputing one degree of Latitude/Longitude. That's just 11, 2. \$\endgroup\$ – Pavel Jan 18 '17 at 20:16
  • \$\begingroup\$ I was just pointing out that if you look at 10,1 compared to 11,2 it's in a different country. If you say closest to the nearest degree the answers will not be constant. \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:31
  • \$\begingroup\$ @carusocomputing Oh, I misunderstood. I know 1 degree is a lot, but I think it's good enough. It requires actually finding the location rather than relying on other information, which is all that's really needed. This way could cut out some code necessary for formatting which isn't part of the challenge. \$\endgroup\$ – Pavel Jan 18 '17 at 20:36
  • \$\begingroup\$ Ping the router. Ask the router where it is. Done. (No idea if this would work) \$\endgroup\$ – SIGSTACKFAULT Jan 22 '17 at 15:49
0
\$\begingroup\$

Do you accept me?


Introduction

Being accepted is very important to people. But words are also people (right!?). So they also want to be accepted. However most people work non-deterministically and as such it's only fair to transfer that into our decision whether we accept a word. Of course, because a stupid human can't remember much the instructions to decide whether to accept a word must be short...

Input

Your input will be

  • a list of non-negative integers - the "word" (this is easier than using strings and actual alphabets)
  • a list of triples of non-negative integers - the transitions, you may also use unordered data structures here
  • an integer - the starting state
  • a list of non-negative integers - the accepting states, you may also use unordered data structures here

You may use any other object or whatever than integers if it pleases you.

Output

A truthy or a falsey value.

What to do?

Basically implement an NFA.
That is, read every single character (ie every number) from left to right and for each one of them look whether there exist a transition from your current state using this character. If so follow it and repeat the process for the next letter. If you face an empty list, your current state must be in the list of accepted states if it is output true and stop examining other paths if it isn't continue examining the other options. If you get stuck (ie the word isn't empty but there's no way to continue), output false.

Who wins?

This is so the shortest answer in bytes wins.

Examples

For the following examples I'm going to use this automaton: Example NFA

which has starting state 10, accepting states [13] and transitions

[(10,4,11),
(11,4,11),
(11,1,12),
(12,1,12),
(12,3,13),
(13,3,13),
(11,3,13)]

These three parameters are assumed to be also passed in the examples. Word examples for this automaton are:

[1,2,3,4] -> false
[4,1,3,4] -> false
[4,1,3] -> true
[4,1,3,3,3] -> true
[2,1,3,4,3,2] -> false
[4,1,4] -> false
[4,3,1] -> false
[4,3,3] -> true
| |
\$\endgroup\$
  • \$\begingroup\$ I'm aware of this other challenge but truly believe that mine is different enough because a) it uses relations instead of a function b) it only asks for NFAs and not for three different automatons c) it asks for truthy / false instead of hard-coded strings d) it's not limited to strings e) it doesn't assume an implicit starting state. \$\endgroup\$ – SEJPM Jan 19 '17 at 11:24
0
\$\begingroup\$

Simulate a vibrating string

Vibrations are an integral part of physics. In this challenge, you will be implementing a simulation of a vibrating string.

This is actually rather easy to do as a result of the Huygens–Fresnel principle, which allows us to use a simulation process similar to cellular automata.

(don't have time to write a full spec right now. Also, I have a 2D version working but figured 1D was enough for a challenge)

Below is an example of a string vibrating at its second harmonic, with each row being 1 tick of the simulation.

  1.00  2.00  1.00 -1.00 -2.00 -1.00
  0.95  1.90  0.95 -0.95 -1.90 -0.95
  0.85  1.70  0.85 -0.85 -1.70 -0.85
  0.71  1.42  0.71 -0.71 -1.42 -0.71
  0.54  1.07  0.54 -0.54 -1.07 -0.54
  0.33  0.67  0.33 -0.33 -0.67 -0.33
  0.11  0.23  0.11 -0.11 -0.23 -0.11
 -0.11 -0.22 -0.11  0.11  0.22  0.11
 -0.33 -0.66 -0.33  0.33  0.66  0.33
 -0.53 -1.07 -0.53  0.53  1.07  0.53
 -0.71 -1.42 -0.71  0.71  1.42  0.71
 -0.85 -1.70 -0.85  0.85  1.70  0.85
 -0.95 -1.90 -0.95  0.95  1.90  0.95
 -1.00 -2.00 -1.00  1.00  2.00  1.00

This challenge is based off the math found on this website.

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

Task Scheduling

Given as input:

  • A unix time at which to first run the program
  • Delay between runs (can be 0)
  • Number of times to run the program (-1 if infinite)
  • A program to be run through the console when triggered

Run the program under specified conditions.

  • You can assume your program will always be running
  • Run the equivalent of nohup <command> &.
| |
\$\endgroup\$
  • \$\begingroup\$ What happens if the unix time is before now? What is the delay measured in? What should I do if the delay is 0? What do you mean by "You can assume your program is always running?" Isn't the ability to keep my program running up to my program?. nohup is not a command I'm familiar with, so I'd definitely explain that. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:05
  • \$\begingroup\$ @NathanMerrill 1. undefined behavor, ie do whatever you want 2. seconds 3. undefined behavior 4. if you want to 5. it isn't? \$\endgroup\$ – noɥʇʎԀʎzɐɹƆ Jan 20 '17 at 18:17
  • \$\begingroup\$ All of that needs to be in the in the post. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 18:19
0
\$\begingroup\$

The many names of Túrin

Tolkien's character Túrin had a multiple personality disorder and consequently needed to change name on a regular basis to be called by something fitting its current mood. He has been known as Turambar, Mormegil, Gorthol, Adanedhel, Dagnir Glaurunga, the Wildman of the Woods, Neithan and some other unofficial nicknames alluding to his tenderness for his sister.

This must have been a real headache for the author: not only had he to find the new names but he also had to remember the translation in English1, since every new name is introduced along the lines of "From this day he was known as [Compound_Elvish_word], that is [Word of word]"

Your task is to automatize the production of epithets to help Tolkien finish his Unfinished Tales.

Given a list of Sindarin2 substantives and their English translations (see list below) as an external file, a list or any reasonable format, randomly take two Sindarin substantives (repetition is possible) and print "From this day he was known as Sindarin1sindarin2, that is English2 of English1"

(Note the inversion of words in the translation, and the capitalisation)

Input: none

Output: A string

The list: (names can be capitalized in your own list, but the formatting must be consistent. The order of the couples can also be changed)

Sindarin    English
--------------------
amarth      fate
ang         iron
aur         morning
brethil     birch
carch       fang
celeb       silver
draug       wolf
galad       glittering
glor        light
gwathel     sister
manadh      doom
megil       sword
melethron   lover
mor         darkness
naur        flame
taur        forest

Examples:

  • From this day he was known as Galadaur, that is Morning of Glittering
  • From this day he was known as Mormelethron, that is Lover of Darkness
  • From this day he was known as Draugdraug, that is Wolf of Wolf

Hobbits played golf and Codë was the Vala of challenges in the Silmarillion, so this is .

1 Sorry, Tolkien specialists, I'm probably massacring Quenya, Sindarin and many other concepts

2 I think

| |
\$\endgroup\$
  • \$\begingroup\$ Children do visit this website, so if you consider something unsuitable for them, do not mention it at all, even to hint at avoiding mentioning it. \$\endgroup\$ – trichoplax Jan 20 '17 at 15:32
  • \$\begingroup\$ Changed as asked, the example as well. \$\endgroup\$ – drolex Jan 20 '17 at 15:48
  • \$\begingroup\$ 1. Substantives are far more commonly called nouns in English. 2. This would be a more interesting challenge if the word list had a lot of common substrings to exploit for compression. Maybe it would work better with a fictional language rather than Sindarin? \$\endgroup\$ – Peter Taylor Jan 20 '17 at 22:32
0
\$\begingroup\$

Minimum exchange of bills

You're at the supermarket, buying groceries for the week. At the end, the cashier rings up your cart and declares that your total cost is exactly $76. You reach into your wallet, and find a $50, four $20s, and a $1, for a total of six bills.

We consider a transaction to be you paying money to the cashier, and the cashier giving you your change (if applicable). Your total for a transaction is the net amount of money you owe the cashier, which is calculated by the amount you pay less the amount of change you get. We can think of a transaction as adding the bills you pay to the cashier, and subtracting the bills you get in return. Thus, the following is a non-exhaustive list of possible transactions in this scenario:

$50 + $20 + $20 - $10 - $1 - $1 - $1 - $1 (8 bills)
$20 + $20 + $20 + $20 - $1 - $1 - $1 - $1 (8 bills)
$20 + $20 + $20 + $20 + $1 - $5           (6 bills)
$50 + $20 + $20 + $1 - $10 - $5           (6 bills)

Given a total of $76, and having 1 $50, 4 $20s, and 1 $1, the minimum exchange of bills comes out to 6 bills.

Challenge

Given an integer Bill and a list of bills in your wallet [Ones Fives Tens Twenties Fifties Hundreds], calculate the number of bills in a minimum exchange of bills between you and the cashier.

Rules

  1. Your program can accept your input in any reasonable way. You can accept an integer followed by a list of six integers separated by reasonable means. You can accept seven integers separated by any reasonable means. If your language cannot accept input in any reasonable form, you may, at no penalty, hardcode the input into your program. You may only hardcode input if your language cannot reasonably accept meaningful input.
  2. Your program must output the number of bills in the minimum exchange transaction. Your program may not print any of the possible transactions themselves.
  3. You may assume that you will always have enough money to cover your bill, possibly requiring some change from the cashier.
  4. You may assume that the cashier has an unlimited number of all bills at their disposal.
  5. You may assume that all inputs are non-negative integers. It is possible that your bill comes out to $0. No integer input will ever be greater than 1000. That's too many bills and quite frankly, too many groceries.
  6. This is , so fewest bytes wins.

Test cases

Input                        Output
[76,1,0,0,4,1,0]              6

I'll come up with and post some more test cases if people think this is a good challenge.

Possible bonus challenge:

In the United States, a $2 is a rare, but legal, bill issued by the treasury. If you wish, you can have your program accept another integer, between the number of Ones and Fives, representing the number of $2-bills you have in your wallet, which you can use to pay for your groceries. However, since such bills are so uncommon, the cashier will not have any on-hand to give to you as change.

| |
\$\endgroup\$
  • \$\begingroup\$ Never allow arbitrary separators in the input, at least without some length limit; some languages may be able to slip the entire program in there. The easiest method is normally to say that the program takes a list of integers as input via any reasonable means; we have various rulings on Meta about which means are reasonable, and that saves you having to duplicate it in your challenge. I'd recommend against the bonus challenge, by the way; it just makes entries harder to compare. \$\endgroup\$ – user62131 Jan 20 '17 at 17:24
  • \$\begingroup\$ Essentially the making change problem ( codegolf.stackexchange.com/q/70847/194 and probably others) but adding negative value coins (bills). There's a risk it will be closed as dupe; it's borderline enough that I wouldn't cast a supervote. One thing I will suggest, as I have in the past on this type of question, is making the coin (bill) system be input rather than hard-coded. That way you can forget about the bonus challenge and the question feels a bit less culture-specific. \$\endgroup\$ – Peter Taylor Jan 20 '17 at 22:26
  • \$\begingroup\$ I vote no on $2 bills, that sounds like it doesn't add much. \$\endgroup\$ – Magic Octopus Urn Jan 23 '17 at 19:39
0
\$\begingroup\$

loripsum.net

The purpose of this challenge is to emulate the functionality of the loripsum.net website. This website takes in a "number of paragraphs" and a list of randomized HTML5 stylizations and outputs a pre-formatted HTML5 lorem ipsum text that is REALLY good for placeholders on a prototype website. Your code, however, will focus more on the stylization aspect of this website.


Given a block of lorem ipsum text in the following format:

<segment> := <paragraph> | <paragraph><new-line><segment>

<paragraph> := <sentence> | <sentence><paragraph>

<sentence> := <character_run><sentence_end>

<character_run> := <printable_ascii_without_newline_or_period>|<pawnop><character_run>

<sentence_end> := \n | . | ? | !


Here's an example of a possible input:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quonam, inquit, modo? Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Quod non faceret, si in voluptate summum bonum poneret. Duo Reges: constructio interrete.

Tubulo putas dicere? Cum salvum esse flentes sui respondissent, rogavit essentne fusi hostes. Dat enim intervalla et relaxat. Satisne ergo pudori consulat, si quis sine teste libidini pareat? Negare non possum. An hoc usque quaque, aliter in vita? Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Quid ei reliquisti, nisi te, quoquo modo loqueretur, intellegere, quid diceret?

Itaque ad tempus ad Pisonem omnes. Universa enim illorum ratione cum tota vestra confligendum puto. Haec dicuntur inconstantissime. Dicimus aliquem hilare vivere; Qui non moveatur et offensione turpitudinis et comprobatione honestatis? Sed quot homines, tot sententiae; Quippe: habes enim a rhetoribus; Omnes enim iucundum motum, quo sensus hilaretur. Tria genera bonorum; Profectus in exilium Tubulus statim nec respondere ausus;

Certe non potest. Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Graece donan, Latine voluptatem vocant. Itaque a sapientia praecipitur se ipsam, si usus sit, sapiens ut relinquat. Quid est igitur, inquit, quod requiras? Atque haec coniunctio confusioque virtutum tamen a philosophis ratione quadam distinguitur. Ego vero volo in virtute vim esse quam maximam;

Verum hoc idem saepe faciamus. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere. Si enim ita est, vide ne facinus facias, cum mori suadeas. Indicant pueri, in quibus ut in speculis natura cernitur. Apparet statim, quae sint officia, quae actiones. An est aliquid per se ipsum flagitiosum, etiamsi nulla comitetur infamia? Non autem hoc: igitur ne illud quidem. Res enim se praeclare habebat, et quidem in utraque parte.


Your task, given the input t from above, is to apply one formatting operations at random once per paragraph, defined by the following list of operations:

  • Character Run Operations (Should be performed on 1-5 word runs chosen at random. This should NEVER cross sentence boundaries (\n|.|?|!))
    • Bold <b></b>
    • Italic <i></i>
    • Underline <u></u>
  • Sentence Operations (Should be performed on 1-2 sentences in the paragraph)
    • Block Quote <blockquote></blockquote>
    • Preface <pre></pre>
    • Heading <h1></h1> ... <h6></h6> (Chosen at random)
  • Paragraph Operations (Should turn entire paragraph into this format, separated by sentences if the operation is segmented (like a list)).
    • Unordered List <ul><li>Sentence 1</li>...<li>Sentence n</li></ul>
    • Ordered List <ol><li>Sentence 1</li>...<li>Sentence n</li></ol>

So, here is one possible random output:

[1:HEADING(h1 chosen),2:BOLD(4 times),3:PREFACE(1 sentence),4:UNORDERED-LIST,5:BLOCKQUOTE(2 sentences)]

Applied to the input from above (t):

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Quonam, inquit, modo? Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Quod non faceret, si in voluptate summum bonum poneret. Duo Reges: constructio interrete.

Tubulo putas dicere? Cum salvum esse flentes sui respondissent, rogavit essentne fusi hostes. Dat enim intervalla et relaxat. Satisne ergo pudori consulat, si quis sine teste libidini pareat? Negare non possum. An hoc usque quaque, aliter in vita? Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Quid ei reliquisti, nisi te, quoquo modo loqueretur, intellegere, quid diceret?

Itaque ad tempus ad Pisonem omnes. Universa enim illorum ratione cum tota vestra confligendum puto. Haec dicuntur inconstantissime. Dicimus aliquem hilare vivere; Qui non moveatur et offensione turpitudinis et comprobatione honestatis?

Sed quot homines, tot sententiae;
Quippe: habes enim a rhetoribus; Omnes enim iucundum motum, quo sensus
hilaretur.
Tria genera bonorum; Profectus in exilium Tubulus statim nec respondere ausus;

  • Certe non potest.
  • Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Graece donan, Latine voluptatem vocant.
  • Itaque a sapientia praecipitur se ipsam, si usus sit, sapiens ut relinquat.
  • Quid est igitur, inquit, quod requiras? Atque haec coniunctio confusioque virtutum tamen a philosophis ratione quadam distinguitur.
  • Ego vero volo in virtute vim esse quam maximam;

Verum hoc idem saepe faciamus. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere.
Si enim ita est, vide ne facinus facias, cum mori suadeas. Indicant pueri, in quibus ut in speculis natura cernitur. Apparet statim, quae sint officia, quae actiones. An est aliquid per se ipsum flagitiosum, etiamsi nulla comitetur infamia? Non autem hoc: igitur ne illud quidem. Res enim se praeclare habebat, et quidem in utraque parte.

Wow! Isn't that much prettier? Here's the code view:

<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1> Quonam, inquit, modo? Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Quod non faceret, si in voluptate summum bonum poneret. Duo Reges: constructio interrete.

Tubulo <b>putas dicere</b>? Cum salvum esse flentes sui respondissent, rogavit <b>essentne fusi</b> hostes. Dat enim intervalla et relaxat. <b>Satisne ergo pudori consulat, si quis sine</b> teste libidini pareat? Negare non possum. An hoc usque quaque, aliter in <b>vita</b>? Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Quid ei reliquisti, nisi te, quoquo modo loqueretur, intellegere, quid diceret?

Itaque ad tempus ad Pisonem omnes. Universa enim illorum ratione cum tota vestra confligendum puto. Haec dicuntur inconstantissime. Dicimus aliquem hilare vivere; Qui non moveatur et offensione turpitudinis et comprobatione honestatis? <pre>Sed quot homines, tot sententiae; Quippe: habes enim a rhetoribus; Omnes enim iucundum motum, quo sensus hilaretur.</pre> Tria genera bonorum; Profectus in exilium Tubulus statim nec respondere ausus;

<ul><li>Certe non potest.</li><li>Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Graece donan, Latine voluptatem vocant.</li><li>Itaque a sapientia praecipitur se ipsam, si usus sit, sapiens ut relinquat.</li><li>Quid est igitur, inquit, quod requiras? Atque haec coniunctio confusioque virtutum tamen a philosophis ratione quadam distinguitur.</li><li>Ego vero volo in virtute vim esse quam maximam;</li></ul>

<blockquote>Verum hoc idem saepe faciamus. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere.</blockquote>Si enim ita est, vide ne facinus facias, cum mori suadeas. Indicant pueri, in quibus ut in speculis natura cernitur. Apparet statim, quae sint officia, quae actiones. An est aliquid per se ipsum flagitiosum, etiamsi nulla comitetur infamia? Non autem hoc: igitur ne illud quidem. Res enim se praeclare habebat, et quidem in utraque parte.

Take note specifically of how I split the sentences on the paragraph operators, you delimit by ONLY periods and NEWLINES, nothing else ends a sentence. Also, make not of how the character run operators can span multiple words, BUT NOT MULTIPLE SENTENCES, you must stop before the next sentence begins (EXCLUDING THE ENDING NEWLINE OR PERIOD). As in, it's only applicable to the <character_run> language definition.

This is lowest byte-count will be declared the winner.

| |
\$\endgroup\$
  • \$\begingroup\$ I think you're missing ; from <sentence_end>. I also don't see any sentences ending in \n, but perhaps you were referring to the end of a paragraph? Also, I think the <paragraph> rule should be <sentence> | <sentence><paragraph>. \$\endgroup\$ – ETHproductions Jan 20 '17 at 2:27
  • \$\begingroup\$ @ETHproductions that sentence doesn't end due to the ;, rather it ends due to the newline. \$\endgroup\$ – Magic Octopus Urn Jan 20 '17 at 18:20
  • \$\begingroup\$ Coulda sworn at least one person would like this haha. \$\endgroup\$ – Magic Octopus Urn Jan 26 '17 at 14:55
  • \$\begingroup\$ Are you sure about character runs including any ASCII char except newline or period? I would restrict it to [A-Za-z ], at least for the most part. \$\endgroup\$ – ETHproductions Jan 26 '17 at 16:41
0
\$\begingroup\$

Find square sum products

It's possible to find sets of three numbers whose product including their sum is a square number. Examples:

  • (3 + 2 + 1) * 3 * 2 * 1 = 6²
  • (3 + 3 + 2) * 3 * 3 * 2 = 12²
  • (4 + 4 + 1) * 4 * 4 * 1 = 12²
  • (9 + 8 + 1) * 9 * 8 * 1 = 36²
  • (8 + 5 + 5) * 8 * 5 * 5 = 60²
  • (8 + 7 + 6) * 8 * 7 * 6 = 84²
  • (9 + 8 + 8) * 9 * 8 * 8 = 120²

Please write a program or function to find square sum products for me.

Since there are an infinite number of square sum products, even excluding trivial multiples, you should limit your output to depend on a characteristic number N. Your program should always output the same square sum product(s) for a given N, and there should be at least one value of N for each possible square sum product that will cause your program to output that product. However, I will be flexible in what N actually represents, as long as you describe it in your answer. Here are some examples:

  • N is one sixth[citation needed] of the square root of the square sum products. For example, an N of 2 would find the second and third of my examples.
  • N is the upper bound of the largest summand. For example, an N of 9 would find all of my examples and then some.
  • N is the number of square sum products to be found. For example, an N of 12 would find all of my examples and then some.

For the output, I don't actually want the summands or the square root. Instead, please output the pairwise sum of the summands. Please also exclude duplicates (i.e. reorderings) from your answer.

This is , so the shortest program wins!

| |
\$\endgroup\$
  • \$\begingroup\$ You can drop the first [citation needed]: if (a, b, c) is a valid triple, then so is (a*k, b*k, c*k) for k integral. \$\endgroup\$ – Sp3000 Jan 21 '17 at 11:43
  • \$\begingroup\$ @Sp3000 Sure, but that's a trivial case. I'm pretty sure there are infinite nontrivial cases too. \$\endgroup\$ – Neil Jan 21 '17 at 11:48
  • \$\begingroup\$ My point was just that an infinite number do exist, so you can drop the superscript. I'm sure you could come up with something less trivial if you really wanted, like (2*k*k+4*k+2, 2*k*k+4*k+3, 1) \$\endgroup\$ – Sp3000 Jan 21 '17 at 12:03
  • \$\begingroup\$ @Sp3000 Indeed, you can generate a subset by multiplying a triangular number by 4, and taking that number twice with a final 1. \$\endgroup\$ – Neil Jan 21 '17 at 13:28
  • \$\begingroup\$ I find the proposed relationship between input and output too vague, and also open to abuse. For example, I could say that every single N outputs 6^2 unless N is of the form 2^a 3^b 5^c where a,b,c generate a square sum product. Why not just pick a spec, for example, that N is the upper bound of the largest summand? \$\endgroup\$ – Greg Martin Jan 26 '17 at 8:36
  • \$\begingroup\$ @GregMartin I didn't want to be overly restrictive because on other sandbox posts I atttracted comments complaining about what I chose to spec, but I guess some sort of restriction is necessary, sigh... \$\endgroup\$ – Neil Jan 27 '17 at 0:33
  • \$\begingroup\$ I agree that it's not always clear what will make the best challenge...! \$\endgroup\$ – Greg Martin Jan 27 '17 at 0:38
0
\$\begingroup\$

Dual Kimian (Error) and Regular Quine Polyglot

Create a program that is

  • a non-erroring proper quine in one language...
  • ...and a proper quine that produces its own source code through an error in another language

What is an error quine?

The compiler/interpreter/runtime to produce error output when compiling/running your program which is identical to your program's source code.

  • Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
  • Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result.
  • The program does not need to be syntactically or semantically valid.
  • The program must not produce any output of its own (e.g. by calling print or an output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.
  • The complete output of the compiler/interpreter/runtime must be exactly identical to your program source code.
  • The compiler/interpreter/runtime must generate at least one error message when invoked with your program.

(adapted from nneonneo's "Make an error quine!" challenge)

  • Polyglots from different versions of the same language or similar languages are allowed
| |
\$\endgroup\$
  • \$\begingroup\$ Related. \$\endgroup\$ – user62131 Jan 22 '17 at 2:40
  • \$\begingroup\$ I fear the spec here isn't clear enough to prevent people using absurd definitions of what counts as an error, like happened in my attempt. (For example, what happens if you throw a string, and the runtime's unhandled-exception handler prints it? Some people consider that to be an error, and it's printed by the runtime, but the text is entirely under user control.) \$\endgroup\$ – user62131 Jan 22 '17 at 2:45
0
\$\begingroup\$

Sandbox Questions

  • Is it a good idea to post this as a separate challenge? This one is significantly easier and I fear that posting it would take too much attention away from the original challenge.

Detect if your program has been bit-flipped

Write a program that outputs

NOT CORRUPTED

If any single bit is substituted by the alternate bit the program should output

CORRUPTED
  • Do not read your source code from a file
| |
\$\endgroup\$
  • \$\begingroup\$ Isn't this already a question? If so why not just replace it with a link to the question? \$\endgroup\$ – user63571 Jan 22 '17 at 17:52
0
\$\begingroup\$

Binary beads clock

The challenge is dedicated to pseudo-graphical representation of objects, e.g. like by ascii-art. Puzzle is geometrical: to represent bistrings as beads using tiles. The result must be beads-like strings where one is more like a bead and zero is more like a stem (or smaller bead). The solution can result in wide variety of visual concept but there are specific guides, see below.

A simple example of binary beads using single tiles, here standard characters:
Input: 1001, 0101, 0011.
Output:

s--s
-s-s
--ss

or e.g. PETSCII console:

enter image description here

So these are only example form, but now you must "upscale" it, but since you are not in graphical mode, the resulting image must be structure of source units, i.e. it must be a rectangular tiling. In other words. it is not allowed just to draw sprites for each next upscale step. So the whole must be a real console app or code which emulates the console behaviour itself within the guidelines. So you can draw any tiles and use them also. Solution should show some reference to console output, e.g. if using graphical lib, a "print" function should be made which takes the data.

Task

The task is to write an application or function wich draws scalable yet visually consistent beads with efective usage of tiles. Tilesets with least amount of tiles and yet with outstanding rich beads look must win. In other words, one should find good relation between tiles amount and good possibility to present different sizes.

One can present different length strings, but the whole layout must be of adequate size. Multiple words on line is allowed and even welcome especially if shows interesting use case.
Usage of graphical libs is welcome, e.g. to emulate a simple console-like output.
All tiles can be custom, i.e. this should not be necessarily standard characters of console. In real console any characters possible can be used or patched with custom tiles if possible. Any OS can be used.

Restrictions:

Final image:

  • must include at least 2 different types of beads (different sizes), i.e. interesting scalability example
  • each bead type must share some tiles with other beads
  • structures should be good visible from various distance and contiguos as possible
  • "zero=stem, ones=bead" rule is not strict, creativity is very welcome but it should be not too far from rule to compare results
  • artiscism in forms is always bonus points!

Tiles:

  • maximal amount of tiles in the tileset : 16
  • are rectangular, e.g 16x8, 8x8 pixels ...
  • minimal size: 6x6, maximal size: 24x24 pixels
  • only two-color but the whole image can have more colors.

Code:

  • Non-cryptic plain code: C, Python, Basic, Fortran and those not too far from it
  • hacks (e.g. for old platforms) should be documented somehow and reproducable in theory

Points given for:

  • less unique tiles yet with rich possibilities
  • visual consistence by each beads type presented, but two types must not necesserily have same style
  • Hint: even within one type, the look of one bead can vary but the whole string easily decodable
  • interesting scaling possibilities, e.g. parametric scaling
  • fullfill the restrictions
  • less operations and minimalistic code
  • working application, e.g. interactive counter or a micro-game is welcome

Solution publishing:

  • title: amount of tiles used and pixel sizes info
  • visual examples easy to follow
  • notes about interesting sides of solution
  • code and some explanation

Sandbox note: If there are unclear point, free to point to corrections. Please suppose better tags if needed.

Tags:

| |
\$\endgroup\$
  • \$\begingroup\$ I really like this challenge, though I'd remove the "only monochrome mode is allowed" rule to give the designers more freedom. I'd also include only the first primitive output example, and add a line stating that users are free to format this, since all these examples might push all answers roughly in the same direction. Maybe you can make an answer as well, since the PETSCII example looks great! \$\endgroup\$ – Luke Jan 20 '17 at 10:59
  • \$\begingroup\$ I fear that this question is too broad for a popularity-contest. There are two primary problems: 1. The judgement criterion (which clock is most useful to low-sighted people) does not naturally gather votes. You are far more likely to get upvoted answers that are funny and interesting. 2. The challenge isn't really about programming, but about design. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:00
  • \$\begingroup\$ If you are wanting design help, ux.stackexchange is great for that. If you want people to implement a specific clock, then make objective requirements, and change the challenge type :) \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:01
  • \$\begingroup\$ Hi @NathanMerrill, thanks for input. The aim is not for people with low vision, it is just background, I will make that point more clear. And do you mean design challenge is not welcome here? My idea was exactly to challenge different designs with few restrictions. \$\endgroup\$ – Mikhail V Jan 20 '17 at 17:50
  • \$\begingroup\$ Right. Design questions aren't a good fit for this site. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:55
0
\$\begingroup\$

Rainbow Cat Program

Recently, I remembered a program I'd written in C# a while back for fun. It takes a string as input, then outputs that same string, cycling through a rainbow of colours. I now realize that this is basically a cat program, but with the added complexity of the output changing colour every 100ms. So I figured it would make an interesting challenge.

The aim is to make your own "rainbow cat program", taking a string as input, and outputting that same string cycling through the following colours in sequence: red, yellow, green, blue, purple, and pink. Not quite a proper rainbow, but close enough. The colours must change every 100ms (or as close to 100ms as your chosen language will allow).

For reference, here's an extremely badly-golfed version of my original C# program (370 bytes):

using System;using System.Threading;class P{static void Main(){var a=Console.ReadLine();for(;;){L(a,ConsoleColor.Red);L(a,ConsoleColor.Yellow);L(a,ConsoleColor.Green);L(a,ConsoleColor.Blue);L(a,ConsoleColor.DarkMagenta);L(a,ConsoleColor.Magenta);}}static void L(string a,ConsoleColor b){Console.Clear();Console.ForegroundColor=b;Console.WriteLine(a);Thread.Sleep(100);}}

And a gif of it in action!

Other Rules

  • Trailing whitespace/newlines are allowed; printing so many newlines that you push the text off the screen, then writing it again in the next colour, is not allowed. You must physically clear the screen and rewrite the text rather than writing it out over and over.
  • Once the cycle starts, it should continue indefinitely without any user input.
  • Standard golfing loopholes apply.
  • This is , so shortest program wins. Feel free to compete for the shortest program in any given language, though: don't feel put off by the golfing languages!
| |
\$\endgroup\$
0
\$\begingroup\$

Avoiding Averages

Given a non-empty list of positive integers, reorder the list such that for every pair of indices, the average of the values at those indices is not contained in any index between them.

Rules

  • This is so the shortest code wins.

Work in-progress

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ Maybe add some sample input->output? \$\endgroup\$ – Leo Jan 23 '17 at 15:41
  • 1
    \$\begingroup\$ I like this, but there's also not much here. Maybe add a picture of a kitten or some I/O like Leo said. \$\endgroup\$ – Magic Octopus Urn Jan 23 '17 at 19:33
  • \$\begingroup\$ Can we expect the input to be valid, or if not, what should be done if such an ordering does not exist? (e.g. [1,1,1]). \$\endgroup\$ – flawr Jan 23 '17 at 20:22
  • \$\begingroup\$ @flawr I'm wondering the same thing, should the input always have a possible solution. If multiple solutions exist, return only one or all of them? I'm still ironing out the details. \$\endgroup\$ – miles Jan 23 '17 at 20:40
  • \$\begingroup\$ I'm struggling to think of a set of numbers that doesn't have a possible ordering (where each number occurs once). I think returning only 1 is sufficient. \$\endgroup\$ – Nathan Merrill Jan 23 '17 at 21:00
0
\$\begingroup\$

Compute the CYK-Table!


Context-Free Grammars

A context-free grammar is a grammar consisting of rules from one variable to a list of variables and symbols. Every string purely consisting of symbols that can be produced using these rules is said to be accepted by the language. For the purpose of this challenge we're only going to consider grammars in CNF which means that on the right side there's either two variables or one symbol (we're gonna ignore the empty language for this challenge).

The CYK-Algorithm

The CYK-Algorithm is a method to check whether a given word is recognized by a context-free language in CNF. For doing this it iterates over the word and applies all possible rules on all substrings and writes them down in a nice table. This table can then be used to successively find variables generating larger substrings until you (don't) hit the word.

The Input

Your input will be

  • A list of strings representing the word
  • A list of triples of strings, representing the rules from one variables (the first in the triple) to two variables
  • A list of pairs of strings, representing the rules from one variable to a symbol
  • A string, representing the starting variable

You may replace the above input format with your favorite input format, as long as you can encode the same amount of information.

The output

The output will be three-dimensional: A list of rows consisting of a list of "candidates" which is a list of strings representing a list of variables. An illustration of this is on Wikipedia.

You may replace the above output format with your favorite output format, as long as you can encode the same amount of information.

Who wins?

This is so the shortest code in bytes to solve the challenge wins!

Example

Start Symbol: "X"
Word: ["b","a","c","b"]
Rules #1: [("X","X","Y"),("X","Z","Z"),("Y","W","Z"),("Z","X","Y"),("W","Y","W")]
Rules #2: [("X","a"),("Y","a"),("Z","b"),("W","c")]

We're gonna do this step-by-step:

The substrings of length 1 first (this is your first row):

b    , a       , c   , b
["Z"],["X","Y"],["W"],["Z"]

Now for the substrings of length 2 (this is your second row):

[],["W"],["Y"] 

(because there's no way to get ZX or ZY, but W -> YW and Y -> WZ)

Now for the substrings of length 3 (this is your third row):

[],["X","Y","Z"] 

(because there's no rule to get ZW, but X->XY (1+2), Y->WZ (2+1), Z->XY (1+2) where the sum denotes the lengths of of the used substrings)

Finally for the substrings of length 4 (this is your fourth row):

["X"]

(because X->ZZ(1+3))

So in total your final table for this example is gonna look like this:

[
[["Z"],["X","Y"],["W"],["Z"]],
[[],["W"],["Y"]],
[[],["X","Y","Z"]],
[["X"]]
]

where the first index increases as we go downwards, the second increases as we go to the right an dthe third denotes the variable within the "cell".

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

Physical String Length

Given the following information:

  • (String) s - A string to be printed.
  • (String) f - The font in which it is to be printed.
  • (int) pt - The size of the font in which it is to be printed in pts (no decimals).
    • Note that the input units are in pt (1/72 inch).
    • The output unit should be pixels, rounded to the nearest integer.
    • Use 96 PPI in your conversion.

Output:

  • The physical length of the string (how many pixels wide the final string is).

Below are a few examples and a piece of code that will let you test arbitrary combinations.


import java.awt.Canvas;
import java.awt.Font;
public class F {
    public static void main(String[]args){
        System.out.println(physicalStringLength("What?", "Calibri", 12));
        System.out.println(physicalStringLength("What?", "Calibri", 24));
        System.out.println(physicalStringLength("What?", "Calibri", 36));
        System.out.println(physicalStringLength("What?", "Calibri", 72));
        System.out.println(physicalStringLength("What?", "Helvetica", 12));
        System.out.println(physicalStringLength("What?", "Times New Roman", 12));
        System.out.println(physicalStringLength("What?", "Courier New", 12));
    }
    
    public static int physicalStringLength(String s, String f, int pt) {
        System.out.print(s + "@[" + f + "," + pt + "]=");
        return new Canvas().getFontMetrics(new Font(f,0,pt)).stringWidth(s);
    }
}

Here's some base-line examples, the output has be created using the above piece of Java code:

What?@[Calibri,12]=35
What?@[Calibri,24]=65
What?@[Calibri,36]=97
What?@[Calibri,72]=193
What?@[Helvetica,12]=35
What?@[Times New Roman,12]=31
What?@[Courier New,12]=35

If you want to see the length of any other strings, use the code provided as a base-line. Using a Java has been banned due to the usage of the example unless you'll be providing a different methodology (kinda sucks, cause Java may be one of the few with a built-in).


This is , lowest byte-count wins.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ The font is an integer? \$\endgroup\$ – Poke Jan 24 '17 at 21:25
  • \$\begingroup\$ Yep, no float font sizes. \$\endgroup\$ – Magic Octopus Urn Jan 24 '17 at 21:26
  • 2
    \$\begingroup\$ Sorry, I mean the second parameter "f" \$\endgroup\$ – Poke Jan 24 '17 at 21:26
  • \$\begingroup\$ Nope, that's a typo. \$\endgroup\$ – Magic Octopus Urn Jan 24 '17 at 21:26
  • \$\begingroup\$ It's a little strange to ask for the width in px but input the font size in pt. Pixels are can vary in physical size while points are fixed at 1/72 inches. \$\endgroup\$ – Poke Jan 24 '17 at 21:29
  • \$\begingroup\$ @Poke I guess I could state that Java is using a default PPI is 96. \$\endgroup\$ – Magic Octopus Urn Jan 24 '17 at 21:31
  • \$\begingroup\$ Because I like answering challenges in java I'd be remiss if I didn't suggest adding more to this challenge such as height and other things found here but that's likely not as fun for other languages. I think the challenge does contain enough by itself. \$\endgroup\$ – Poke Jan 24 '17 at 21:41
  • \$\begingroup\$ 1. I don't think this is well defined. Different applications using the same typeface and the same point size will produce strings of slightly different widths because e.g. they don't interpret the hints in the same way. 2. Why ban Java and not e.g. the .Net languages, which have very similar library support? \$\endgroup\$ – Peter Taylor Jan 24 '17 at 22:31
  • \$\begingroup\$ Adding to Peter's point, different rendering engines display fonts differently. The default Windows GDI renderer alone knows 5 different types of anti-aliasing, any of which can be the system standard, not counting fonts rendered by Direct2D, OpenGL or GDI+. It's very easy to just render and measure a string with GDI+, but the length might be different across systems by one or two pixels because of AA. Would that be acceptable? \$\endgroup\$ – mınxomaτ Jan 24 '17 at 23:48
  • \$\begingroup\$ @PeterTaylor Maybe adding in a clause about acceptable standard deviations? \$\endgroup\$ – Magic Octopus Urn Jan 25 '17 at 15:28
0
\$\begingroup\$

Binary Grids

Consider the N-dimensional binary grid, with dimensions {d1,d2,...,dN}. Here are a few examples:

6 (N=1): 100101

3x7 (N=2):

1001001
0110110
1001001

3x3x3 (N=3):

010   001   100
100   011   110
011   110   001

What each of these example grids have in common is: they do not contain any consecutive sequences of the same digit longer than 2.

The Challenge

Write a program or function which, given a list of dimensions, outputs the number of binary grid configurations with the given dimensions that satisfy this condition.

Input

A list of positive integers (>1), either via stdin or passed as an argument. Example: 3 2 6, [3,2,6], etc.

Output

The number of valid configurations, either as a returned value or printed to stdout, or something similar.

Constraints

  • While brute-force solutions can work, their time complexity is O(2^N), which is way too long for anything but the smallest grids. Write something which will complete before my computer becomes obsolete, please!
  • Standard loopholes are forbidden, not that I think very many of them would apply here anyway.
  • This is code-golf, so the shortest code wins, with tiebreakers going to the fastest code.

Sandbox Questions

  1. Is this interesting?
  2. Is this doable?
  3. What's a better way to word the time complexity restrictions?
  4. The only example for which I actually know the answer is for [6]... do I need more? I'd have to solve this myself first...
| |
\$\endgroup\$
  • \$\begingroup\$ 1. I think "consecutive" needs clarification. I'm guessing that it's talking about horizontal and vertical lines but not diagonal ones. 2. Re whether it's doable: in 1D it's oeis.org/A128588 which is easy to calculate. In general it can be done in n-D by calculating all of the acceptable values in some (n-1)-D projection and then taking the power of an incidence graph, but I doubt that scales well beyond 3D. It may be possible with some investigation to get an n-D generating function, but it's hard to tell without spending a couple of hours on the problem. \$\endgroup\$ – Peter Taylor Jan 27 '17 at 16:25
  • \$\begingroup\$ In terms of complexity restrictions, asking the program to run in polynomial time in the number of cells in the grid seems reasonable (because exponential time is enough to brute-force it and it's very rare (impossible?) for a program to have a complexity in between). I don't know whether that's possible, though (although even if there's a chance that it isn't, it may still be worth asking the question). \$\endgroup\$ – user62131 Jan 27 '17 at 22:31
0
\$\begingroup\$

Golf Me a Bubble Sort

Your task is to create a program that performs a bubble sort.
For those who don't know, a bubble sort is a simple sorting algorithm where two adjacent items are taken & swapped if they are in the wrong order until all values are in the correct order.


Rules

  1. You must provide an explanation for how your answer does a bubble sort.
  2. You may not use built-in or standard library sorting algorithms. You must make your own code.
  3. Your program should take a group of numbers as input and output them in the correct order.
    • Input format: 10 5 9 2 . . . (and so on)
    • Output can be an array returned by the program when run.
    • Output can also be the correctly ordered values separated by whitespace.
  4. Speed does not matter as much as of the program functions.

Test Cases

  • 10 5 9 2 1 6 8 3 7 4 (you can format it differently depending on your language)
  • 1 2 5 4 3

This is , so the shortest answer in bytes wins.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ It may be a better idea to have entries do only a single iteration of bubble sort; that way it will be easy to verify their correctness. \$\endgroup\$ – ETHproductions Jan 29 '17 at 20:52
0
\$\begingroup\$

Find fixed points of the Logistic Map


Definitions

Logistic Map

A logistic map is defined as the following equation:

equation

Where the next value in the map (on the left) is determined by a function of the current value (on the right), where the constant lambda represents a set constant between zero and four (non-inclusive, along the reals).

Stable Point

A "stable point" in relation to a map is a point which is approached repeatedly by iterating the logistic map. They are distinct, and there are one to many for any given lambda.

The Task

Write a function or program which, given an input real value n between zero and four (non-inclusive), returns the number of stable points for a map where lambda is n.

Examples

Soon to be added


Meta

Main problem: Defining "stable point". Is this definition sufficient?

| |
\$\endgroup\$
  • \$\begingroup\$ The definition is wrong. A fixed point of a map is a point which is mapped to itself. For the logistic map the fixed points are 0 and 1-1/x. \$\endgroup\$ – Peter Taylor Jan 31 '17 at 8:45
  • \$\begingroup\$ If you instead look for points in stable cycles, you need to also specify that the domain is the real numbers, because stable cycles correspond to roots in the polynomial obtained by iterating the map, and over the complex numbers a polynomial always has as many roots as its order. If you specify distinct points in stable cycles of any length, that becomes a real challenge. \$\endgroup\$ – Peter Taylor Jan 31 '17 at 8:55
  • \$\begingroup\$ @PeterTaylor The second one was what I was going for. :P Got my terminology wrong. \$\endgroup\$ – Addison Crump Jan 31 '17 at 9:40
  • \$\begingroup\$ @PeterTaylor Just to verify, I'm looking for the number of distinct stable points for specific values of lambda along this graph. \$\endgroup\$ – Addison Crump Jan 31 '17 at 9:49
0
\$\begingroup\$

Language contest

Moving this here from normal question

So, I'm kind of an esolang loony so let me propose the following contest. First of all, we do not care about speed: if two algorithms safe the same problems then they are 'equally good' at least for this challenge. Also, let's think in "special case" terms. Sorting is the problem of well... sorting a list. However, an algorithm that generates permutations of lists with an abort condition equally solves the sorting problem. However, such an algorithm is more generic as the abort condition allows it to do more stuff. In other words: sorting a list is just a special case of generating permutations with an abort condition.

The idea is to concentrate on the most generic version of an algorithm that solves a problem. In other terms: Getting rid of redundant built-ins in esoteric programming languages.

The contest would go as following: The goal is to create an esoteric concatenative language (not necessarily stack based but concatenative) with the fewest built-ins that solve all problems (in some catalog). However, this would be really boring like that because a minimized version of brainfuck would pretty much win. Thus the 'score' function would likely be a function of 'amount of built-ins' and 'average program length'. One other constraint is that you are not allowed to have redundancy in your built-ins. If you have a built-in sortAsc and sortDesc and reverse then sortAsc = reverse . sortDesc thus you are disqualified. This also means that if you have too generic loops as built-ins like uhm for loops you can use these for loops to create a sort function which means you wouldn't be allowed to have a sort function.

What do you guys think?

TL;DR optimize for program length and least amount of builtins required.

| |
\$\endgroup\$
  • \$\begingroup\$ This is an interesting idea, but the rule against redundancy is problematic. It's very difficult (in fact undecidable) to say whether the built-ins of a language are redundant. It's also probable that such limitations can be circumvented with some trick, like having each function take and return a tuple (d, l), where d is some arbitrary data and l is a string that records which functions were used on the data. You might also want to define unambiguously what a "concatenative language" is. \$\endgroup\$ – Zgarb Jan 31 '17 at 13:19
  • \$\begingroup\$ I agree with all of Zgarb's comments. That said, if you enforce a language paradigm, then you could define exactly what "combining commands" means. If you do do that, then I'd highly recommend making this a code-golf challenge, and dropping "least builtins" as a scoring mechanism \$\endgroup\$ – Nathan Merrill Jan 31 '17 at 13:34
  • \$\begingroup\$ If you can formulate any built-in in terms of other built-ins then you have redundancy. Hidden state doesn't really count. But yes, there are likely loopholes nobody has thought about yet. \$\endgroup\$ – mroman Jan 31 '17 at 14:06
  • \$\begingroup\$ @mroman Yeah, that's the definition of redundancy. But given an arbitrary list of built-ins, how can you definitively say "this list is not redundant"? Particularly with the weird stuff esolangs tend to have. \$\endgroup\$ – Zgarb Jan 31 '17 at 14:17
  • \$\begingroup\$ with handwaving probably. \$\endgroup\$ – mroman Jan 31 '17 at 15:09
  • \$\begingroup\$ Hmm, I've thought about this some more, and this is what I'd probably do. Drop the non-redundancy requirement, have a lot of smallish tasks (like 20 or so), and have the scoring function be something like N * 3^B, where N is the total length of the solutions to the tasks and B the number of built-ins. Then implementing a redundant built-in would only be worth it if it cut off 2/3 of your program size across all tasks. I'll have to think about it more to see if there are obvious loopholes that I've missed. \$\endgroup\$ – Zgarb Jan 31 '17 at 16:58
  • \$\begingroup\$ And don't get me wrong, I think this is a superb challenge idea! :) It just needs to be done right to have a positive reception and good answers. \$\endgroup\$ – Zgarb Jan 31 '17 at 17:00
  • 1
    \$\begingroup\$ As I commented elsewhere, "First of all, the assumption is that every algorithm that solves the same problem is equally fast" is nonsense, and primes readers with a background in computer science to expect the whole question to be low quality. I suggest rephrasing as "First of all, the assumption is that we don't care about performance". \$\endgroup\$ – Peter Taylor Jan 31 '17 at 17:42
  • 1
    \$\begingroup\$ Okay, I think I have found another "loophole". Suppose you have K tasks. Then you can make 3 built-ins and solve each task with a program of length 1 + ceiling(log2(K)) as follows. One built-in does "encoding": it transforms the data into some more restricted format (like multiply every list element by 2 to make them even, if the data is always a list of integers). The other two built-ins work as follows. (contd.) \$\endgroup\$ – Zgarb Feb 1 '17 at 9:05
  • 1
    \$\begingroup\$ If the encoded data has been processed by fewer than ceiling(log2(K))-1 functions, they just add a unique marker to the encoding (like by appending 1 or 3 depending on the function). Otherwise, the applied built-ins (counting the current one) form a binary string of length ceiling(log2(K)), which we interpret as a base-2 number encoding the task. Then we just decode the data and solve that task. \$\endgroup\$ – Zgarb Feb 1 '17 at 9:05
  • \$\begingroup\$ @PeterTaylor It just means that for this challenge it doesn't really matter how fast your program is as long as it solves the task in a (meaningful) finite amount of time. \$\endgroup\$ – mroman Feb 1 '17 at 14:14
  • \$\begingroup\$ @Zgarb I can't really follow that. Do you have a more practical/real example of that loophole? \$\endgroup\$ – mroman Feb 1 '17 at 14:17
  • \$\begingroup\$ If that's what it's intended to mean, write that instead, because as it stands it's very easy to interpret it as meaning something different. \$\endgroup\$ – Peter Taylor Feb 1 '17 at 14:39
  • \$\begingroup\$ @mroman Here's an implementation in Python 3. I hope you can follow it. I'm using 8 tasks as an example, which results in length-4 programs. Each program has the form Eabc, where abc is the binary encoding of the task number. \$\endgroup\$ – Zgarb Feb 1 '17 at 14:47
  • \$\begingroup\$ @zgarb yeah I get it now. I guess that's legal to do. \$\endgroup\$ – mroman Feb 2 '17 at 7:44
0
\$\begingroup\$

Detect skewed exponential sequences

Observe the following sequence:

1 3 9 54 162 729 2187 6561 19683

We can see that this is equivalent to:

1 *    1
1 *    3
1 *    9
2 *   27
2 *   81
3 *  243
3 *  729
3 * 2187
3 * 6561

The sequence on the right is the first 9 values of the exponential function f(x) = 3^x, that is, the exponential function of 3. It is multiplied element-wise by 1 1 1 2 2 3 3 3 3. Now, this sequences is strictly non-decreasing.

Your challenge is to, given a sequence K of length c, determine if there is a strictly non-decreasing list of integers L such that each element ej of (K / L) (element-wise division) is equal to bj, for 0 ≤ j < c, and for some b > 1.

This is a , so the shortest program in bytes wins.

True cases

1                    (1 * 1, base = any)
1 3 9                (1 1 1 * 1 3 9, base = 3)
2 4 8 32             (2 2 2 4 * 1 2 4 8, base = 2)
1 9 27               (1 3 3 * 1 3 9, base = 3)
1 5 500 2500 13125   (1 1 20 20 21 * 1 5 25 125 625, base = 5)

False cases

1 1 1 1              (false because this would have base = 0)
1 2 3 4              (no base)
1 2 4 32 16          (decreasing multiplier)
| |
\$\endgroup\$
  • \$\begingroup\$ According to how you have it stated right now, the lists 1 1 1 1 and 1 2 3 4 can be done. It should be b>1 if you want it to not be possible. \$\endgroup\$ – fəˈnɛtɪk Feb 1 '17 at 18:07
  • \$\begingroup\$ @LliwTelracs Right you are. \$\endgroup\$ – Conor O'Brien Feb 1 '17 at 18:43
0
\$\begingroup\$

Solve for X

Given an equation using the following symbols:

  • Parenthesis: ()
  • Operators: +-/*
  • Variable: x
  • Comparators: <=>

And the following guarantees:

  • There will only ever be one x variable.
  • x / 0 will never be in the denominator.
  • Only one comparator will be used (no >= or <=).
  • All numbers used in the input will be integers.
  • Numbers in the output may be expressed as decimals, the chosen precision should be >= 3.

Output the correct reduction for the value of x.

  • Output should be in the form: x[Operator][Decimal] (E.G. x=2)
    • 2=x is not acceptable, you must have x on the left side.

Here are a few examples (The last part in bold is the part you need to output):

2+2=x 4=x x=4

x=4*3+(2-2) x=4*3+0 x=12

1+(x/4)-2=0 1+(x/4)=2 (x/4)=1 x=4

-2*(2+x)>-1*12 -2*(2+x)>-12 (2+x)<6 x<4

-2*x<(29+1)/6 -2*x<(30)/6 -2*x+2<5 -2*x<3 x>-6

(x/-1)*(10/-4)=10*5 (x/-1)*(10/-4)=50 (x/-1)=-20 x=20

(x/-5)*-1+2*8>0 (x/-5)*-1+16>0 (x/-5)*-1>-16 (x/-5)<16 x>-80

-1*(4*(6*(x/7)))<10 (4*(6*(x/7)))>-10 (6*(x/7))>-2.5 (x/7)>-0.416 x>-2.916


This is , lowest byte-count will be deemed the winner.

| |
\$\endgroup\$
  • \$\begingroup\$ I'm not convinced this can be solved faster than brute force in the general case (although a golfed solution would likely use brute force anyway). On another subject, what should be the answer for input like x>4 x<6? \$\endgroup\$ – user62131 Feb 2 '17 at 21:48
  • \$\begingroup\$ Return it, as is. \$\endgroup\$ – Magic Octopus Urn Feb 3 '17 at 3:02
0
\$\begingroup\$

A kinda different large number contest

I really like large number's and code puzzles so I really like these large number contests. And I would like to have an other even if it's a duplicate. I feel like a lot of people feel the same way.

So I had to be creative and come up with a slight variation. I had the idea of prohibiting recursion since most of the fast growing techniques require it. Practically I might a accomplish this by only allowing a single array/list for memory.

I think it's almost impossible to avoid this idea being closed as a duplicate of Largest Number Printable but if there is interest I will work it out a lot more. And maybe I will be able to convince 5 people it's an interesting competition despite of the duplicate.

(And in case this is unclear it would be a you have X bytes to make a program the outputs the largest number)

Do you have any further ideas, suggestions or tags? Or are you even interested?

| |
\$\endgroup\$
  • \$\begingroup\$ So print the biggest number you can in O(1) complexity? \$\endgroup\$ – Rɪᴋᴇʀ Feb 3 '17 at 18:57
  • \$\begingroup\$ 1. Neither the accepted answer nor the top 4 (arguably 5) voted answers in Largest Number Printable use recursion. 2. Bounding the memory is probably quite hard to specify well, but if you do manage it then essentially all you will achieve is to force all the answers to work by counting so as to go through every possible distinct state. \$\endgroup\$ – Peter Taylor Feb 3 '17 at 22:22
  • \$\begingroup\$ It's always possible to translate a recursive program into a corresponding iterative program (if the language is sufficiently powerful, but not much power is required, e.g. C is powerful enough). Depending on the language, this might or might not make the program significantly longer. Likewise, it's always possible to take a program that stores data in multiple places and change it so that it uses a single array for all storage (again, assuming appropriate language features that most languages will have). \$\endgroup\$ – user62131 Feb 7 '17 at 3:42
  • \$\begingroup\$ @PeterTaylor Hehe, I managed to squeeze some recursion up in there if you haven't checked :-) \$\endgroup\$ – Simply Beautiful Art Jul 31 '17 at 23:30
  • \$\begingroup\$ Another related proposal I just made: Can you surpass Γ<sub>0</sub>? For those serious about making extremely large numbers. \$\endgroup\$ – Simply Beautiful Art Jul 31 '17 at 23:32
0
\$\begingroup\$

Conjugate a Spanish Verb

A Little Background

I thought up this challenge, believe it or not, in a spanish class. I was thinking how simple it is to conjugate regular spanish present tense verbs and the programmer in me told me to make a question about it on PPCG

The Challenge

Given a regular Spanish infinitive and a subject, conjugate the infinitive in the present. How to do such a thing. For the sake of simplicity assume that all of the verbs are regular infinitives not irregular, stem-changing or reflexive.

Rules

-The input may be given in any reasonable format

subject verb | verb subject| subject,verb | ["subject", "verb"] etc. 

-If the input is not valid you may output anything or nothing at all

-The input is not valid if

a) It does not contain a regular, spanish, infinitive verb or a Spanish subject

b) It is not in the appropriate format, which you must specify

-The output can have any capitalization and is alowed trailing whitespace

Test Cases

Assume the input is given as "verb, subject" (Without the quotes)

comer, yo              --> como
ir, vosotros           --> Anything (Irregular)
jugar, ellas           --> Anything (Stem Changing)
                       --> Anything (Empty)
gsmkhnjkgn, tu         --> Anything (Not a verb)
sacar, ésdfgs          --> Anything (Not a subject)
| |
\$\endgroup\$
0
\$\begingroup\$

Consecutive Composites

Your task is to write a program or function which, given a positive integer N, finds the first block of N consecutive composite numbers.

This should be the first block of integers which fit the requirements, larger than 0. For example, with an input of 2, the output must be [8, 9], and not [14, 15].

Rules:

  • The numbers in the block should be printed or returned as a list, in any reasonable format.
  • Submissions may be either full programs which perform I/O, or functions - no snippets.
  • You can assume that the block of numbers your program has been request to find is within your language's standard integer range.
  • This is , so the shortest program (in bytes) wins! Standard golfing loopholes apply.

Test Cases

1 -> [1]
2 -> [8, 9]
5 -> [24, 25, 26, 27, 28]
6 -> [90, 91, 92, 93, 94, 95]
10 -> [114, 115, 116, 117, 118, 119, 120, 121, 122, 123]

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ This is essentially codegolf.stackexchange.com/q/23844/194 with a tweaked output format. \$\endgroup\$ – Peter Taylor Feb 6 '17 at 9:34
  • \$\begingroup\$ One is not a composite number, the smallest is four, so the test case for 1 should be [4]. \$\endgroup\$ – Jonathan Allan Feb 6 '17 at 20:39
  • \$\begingroup\$ @JonathanAllan i've misused the term composite there, I meant 'non-prime' - regardless, I probably won't post this anyway and Peter pointed out it's basically a dupe. \$\endgroup\$ – FlipTack Feb 6 '17 at 22:02
0
\$\begingroup\$

Fraction Frenzy!

Task:

Your task is to generate the list of reciprocals of the Fraction Frenzy function (FF(n)) given a positive integer n.

Introduction:

Before I can introduce the FF function, I have to first explain Egyptian fractions.

Egyptian fractions are a way of expressing fractions as the sum of distinct unit fractions - so one way to express the fraction 5/8 is 1/2 + 1/8. It is not other fraction sums like

1/4 + 1/4 + 1/8
1/2 + 1/16 + 1/16

because not all of their fractions are distinct (1/4 is repeated in the first example, and 1/16 in the second).


The FF (Fraction Frenzy) function is described like so:

FF(1) is the Egyptian fraction 1/2 + 1/3 + 1/5 + 1/-30.

FF(2) is equal to FF(1) "multiplied" by itself (FF(1) "squared"):

  (1/2 + 1/3 + 1/5 + 1/-30)(1/2 + 1/3 + 1/5 + 1/-30)
= 1/4 + 1/6 + 1/10 + 1/-60 + 1/6 + 1/9 + 1/15 + 1/-90 +
  1/10 + 1/15 + 1/25 + 1/-150 + 1/-60 + 1/-90 + 1/-150 + 1/900

This is not a fully reduced Egyptian fraction yet, because there are "repeats" in fractions. To reduce them, the following procedure is done:

  1. Sum all "like" unit fractions together.
  2. Reduce the sums to their simplest forms - so for example, if a sum from step 1 is 2/6, that can be reduced to 1/3.
  3. Repeat 1 and 2 until all reciprocals are distinct.
  4. If there is a pair of one positive and one negative fraction that have an equal absolute value, remove both of them (e.g. 1/-5 and 1/5 must both be removed)
  5. If fractions are not unit and cannot be reduced further, split it up into unit fractions with a equal denominator, and keep one fraction as it is. With the other ones, multiply them by (1/2 + 1/3 + 1/5 + 1/-30).
  6. Repeat until the final fraction sum is a valid Egyptian fraction.

This is the reduction of FF(2):

  1/4 + 1/6 + 1/10 + 1/-60 + 1/6 + 1/9 + 1/15 + 1/-90 +
  1/10 + 1/15 + 1/25 + 1/-150 + 1/-60 + 1/-90 + 1/-150 + 1/900
= 1/4 + 2/6 + 1/9 + 2/10 + 2/15 + 1/25 + 2/-60 + 2/-90 + 2/-150 + 1/900 (step 1)
= 1/4 + 1/3 + 1/9 + 1/5 + 2/15 + 1/25 + 1/-30 + 1/-45 + 1/-75 + 1/900   (step 2)
= 1/3 + 1/4 + 1/5 + 1/9 + 1/15 + 1/15(1/2 + 1/3 + 1/5 + 1/-30) +        (step 5)
  1/25 + 1/-30 + 1/-45 + 1/-75 + 1/900
= 1/3 + 1/4 + 1/5 + 1/9 + 1/15 + 1/30 + 1/45 + 1/75 + 1/-450 +
  1/25 + 1/-30 + 1/-45 + 1/-75 + 1/900
= 1/3 + 1/4 + 1/5 + 1/9 + 1/15 + 1/25 + 1/-450 + 1/900                  (step 4)

For all n (except for 1), FF(n) is defined by "squaring" FF(n-1).

Input and Output:

Given an integer n, you must output a list all of the reciprocals of FF(n), sorted in ascending order:

1 -> [2, 3, 5, -30]
2 -> [3, 4, 5, 9, 15, 25, -450, 900]

You are allowed to use a string with any delimiter, or your language's interpretation of a list.

Specs:

  • You must output the results of the FF(n) function exactly as specified above.
  • You are guaranteed that the input will be a positive integer - it will never be below zero, and it will never be a decimal (or fraction).
| |
\$\endgroup\$
  • \$\begingroup\$ ^vote, I'm trying to see if there's a non-recursive method, because currently it's O(n^2) according to the problem specs. \$\endgroup\$ – user42649 Feb 4 '17 at 0:52
  • \$\begingroup\$ I think step 2 ("Reduce the sums to their simplest forms") needs to be more carefully specified. What is the simplest form of a given fraction? \$\endgroup\$ – Peter Taylor Feb 4 '17 at 21:22
0
\$\begingroup\$

Goal

Take 3 inputs, and output truey or falsey depending on whether or not they make an multiplication/division fact family. (2 * 4 = 8, 4 * 2 = 8, 8 / 2 = 4, 8 / 4 = 2) Order does not matter, as long as in some way the three numbers make an fact family. Repeated numbers are allowed.

Truey Inputs

2 4 8 
100 20 5 
7 7 49

Falsey Inputs

7 8 9
12 3 0
512 600 73

Rules
The values should be passed to the program as parameters or variables. Expect that only positive integers, and only 3 of them, will be passed to the program. You may write either a full program or a function, which either prints or returns the result. This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ This is a duplicate of an existing challenge (the reason why it was closed on main) \$\endgroup\$ – user41805 Feb 6 '17 at 18:51
  • 2
    \$\begingroup\$ Were you going to change this to multiplication/division families? \$\endgroup\$ – ETHproductions Feb 6 '17 at 18:51
  • \$\begingroup\$ Changed it up. I also removed my first one from the main. \$\endgroup\$ – Feldspar15523 Feb 6 '17 at 19:51
  • \$\begingroup\$ Will the input numbers always be nonnegative integers? \$\endgroup\$ – Greg Martin Feb 7 '17 at 0:43
  • \$\begingroup\$ Edited Question \$\endgroup\$ – Feldspar15523 Feb 7 '17 at 0:46
  • \$\begingroup\$ IMO changing + to * and /2 to sqrt doesn't make this a different question and it's still a dupe. \$\endgroup\$ – Peter Taylor Feb 7 '17 at 9:53
0
\$\begingroup\$

ACME (Let's Encrypt) client

A list of ACME clients already looks a bit like a PPCG leaderboard, but I don't see the typical esolang roster there. Let's Augment.

The task is in minimum number of bytes get a valid certificate for specified domain (assuming running from a directory that is accessible from web server of this domain. Or just also embedding a web server.).

| |
\$\endgroup\$
  • \$\begingroup\$ Shall usage of openssl (libary or binary) be allowed or it should be a "hard mode" puzzle? \$\endgroup\$ – Vi. Feb 7 '17 at 2:21
  • \$\begingroup\$ What does "assuming running from a directory that is accessible from web server of this domain" mean? That we can assume Apache / nginx / lighttpd / whatever is set up to execute our script? \$\endgroup\$ – Peter Taylor Feb 7 '17 at 9:51
  • \$\begingroup\$ @PeterTaylor, No. The script contacts ACME server, gets challenge, writes it to current directory. Then ACME server downloads the file (using pre-existing web server configured for this directory) and replies with a signed certificate, which we should save or print. \$\endgroup\$ – Vi. Feb 7 '17 at 11:56
  • \$\begingroup\$ Follow-up questions: 1. Which version of ACME? 2. Which parts must be supported? 3. What will the inputs to the client be? I'm sure that detailed reading of the ACME spec will throw up more questions. \$\endgroup\$ – Peter Taylor Feb 7 '17 at 12:49
  • \$\begingroup\$ 1. -> To discretion of the answerer, 2. -> HTTP challenge. Some minimal mode to get the cert. 3. -> Domain name. \$\endgroup\$ – Vi. Feb 7 '17 at 13:46
0
\$\begingroup\$

What I'm Planning to Post:

Print the number of bytes (not characters, bytes) in the program, without hardcoding the number (i.e. code like print(8) is not allowed).

If the code is added to (e.g. with a comment) it should change automatically without needing to change anything else.

Example (un-golfed) program in Python 3:

file = open(__file__)
data = file.read()
print(data)
file.close()

This is so the shortest answer in bytes wins.

What I Want to Check/Know:

  1. Does this count as ?
  2. Has this already been done? To what extent do the rules of a 'Duplicate' question apply here? (I have done some searching...)
  3. What should my challenge title be? I cannot think of any fitting ones.
  4. Should I include the example (un-golfed) program in my post, or does that make it too easy?
| |
\$\endgroup\$
  • \$\begingroup\$ Thanks for posting in the Sandbox first. Why is hard-coding banned? If the code is added to, hardcoding may or may not help, so I don't see much point in banning this. Also, your code is wrong; that's a false-quine, not the program length. \$\endgroup\$ – wizzwizz4 Feb 9 '17 at 19:22
  • \$\begingroup\$ Sorry. I meant to put a len() in there too. Hard-coding is banned because in many esolangs, a single byte will just output the simple integer 1 (or similar). \$\endgroup\$ – retnikt Feb 9 '17 at 19:26
  • \$\begingroup\$ But if you edit the program to add comments, that program will stop working. \$\endgroup\$ – wizzwizz4 Feb 9 '17 at 19:30
  • \$\begingroup\$ Welcome to PPCG! Thanks for using the sandbox. I swear we've had a challenge similar to this, but I can't seem to find it. I'll keep looking. \$\endgroup\$ – AdmBorkBork Feb 9 '17 at 19:31
  • \$\begingroup\$ This wouldn't be a kolmogorov-complexity. That tag is for outputting some constant, predefined string. Including an example implementation is fine, it's fairly common practice, but usually it contains a very naive or brute-force algorithm for the problem that wouldn't actually make a good solution (even when golfed). \$\endgroup\$ – Business Cat Feb 9 '17 at 20:15
  • \$\begingroup\$ Yes, it has been done: codegolf.stackexchange.com/q/27079/194 \$\endgroup\$ – Peter Taylor Feb 10 '17 at 11:08
0
\$\begingroup\$

Wifi Puzzle! Crack the router [code-golf] [networking]

SITUATION

Consider that you have three wifi routers in your home , all with different SSIDs and none of them are dualband. You have invited a mischievous friend to your home who had changed the password of each router, without letting you know about it. Now to annoy you more he has set up a programming challenge.

THE CHALLENGE

Your friend has created three .txt files containing a set of passwords with only one correct among them. (i.e. each .txt file contains a correct password while all other are wrong ones. Also one .txt file contains only one correct password) and the .txt files do not specify which one may contain the correct password for a certain router (i.e. you cannot be sure that file1.txt(let us assume it is one of those .txt files) contains the password for router1( say any one of those routers). Now your friend has kept them in a certain directory( say E:\Wifi) and asked you to create a programme or function that would pick up a file and take input from it, try to connect to a random Access point ( out of the three routers) and find which password fits to which router.

Sample Input

Let us consider a file, file1.txt( or any other name you like) be like this

A12e77799U5
Pdc555089rtf
Ds442Y779#1
1&2*fe$996Yt
Uty66%92Gu4

Note that each password contains a capital letter, numbers, special characters, (of a standard keyboard) and each file contains only five unique passwords. Also all the .txt files are in the same directory and there are no subdirectories in the directory concerned. Also each .txt file contains at least one correct password.

Sample Output

Your programme or function must keep a log of its activity in a separate file log.txt which you may put in the same directory concerned or in a different directory. The log file must show which router has been cracked with which password and also the file containing it.

Example: Say that router1 ( SSID of a router) has been cracked by the password A12e77799U5 from file1.txt so the output of the log.txt must be

router1 password A12e77799U5
File: file1.txt

Also you must be sure that all the output goes into the log.txt not seperate files each time a router is cracked. You can create a programme or a function in any programming language.

Keep In Mind

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

  2. Standard loopholes apply as usual.

Discussion I feel to ask this question but the foremost problem I face is how can others test their code. Also strict I/o rules (like the log.txt I mentioned ) are not appreciated here. So please help me out!

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ So, you want us to access the network settings programmatically? Even if we disregard the difficulties in testing it, this is not a golfing challenge, but rather a challenge in convincing our OSes to let us fiddle with the settings, and then figuring out how. \$\endgroup\$ – John Dvorak Feb 12 '17 at 19:25
  • \$\begingroup\$ So is there any category I can put it in, I mean any tags. \$\endgroup\$ – jyoti proy Feb 12 '17 at 20:04
0
\$\begingroup\$

Portable bitmap checkerboard pattern

Your task is to create a checkerboard pattern and store it in a PBM.

Size of the checkerboard is passed in STDIN as two numbers. Output is written to STDOUT.

Test case:

Input:
5
5

Output:
P1
5 5
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0

This is so the shortest code wins

| |
\$\endgroup\$
1
65 66
67
68 69
100

You must log in to answer this question.

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