460
\$\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\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – JL2210 Sep 26 at 15:57
  • 1
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 at 13:43

2579 Answers 2579

0
\$\begingroup\$

Roman Dates

The Romans measured dates based on three days every month:
The Kalends, or the 1st
The Nones, which was usually on the 5th,
and the Ides, which was usually on the 13th.

In March, May, July, and October the Ides and Nones fall two days later, on the 7th and 15th.

Months

There are two forms of the months that matter for this challenge:
Ablative:

  1. Ianuariis
  2. Februriis
  3. Martiis
  4. Aprilibus
  5. Maiis
  6. Iuniis
  7. Iuliis
  8. Augustis
  9. Septembribus
  10. Octobribus
  11. Novembribus
  12. Decembribus

And Accusative:

  1. Ianuarias
  2. Februarias
  3. Martias
  4. Apriles
  5. Maias
  6. Iunias
  7. Iulias
  8. Augustas
  9. Septembres
  10. Octobres
  11. Novembres
  12. Decembres

Calculation of dates

On the day of one of them, they used the ablative of the day (Kalendis, nonis, or Idibus) combined with the ablative of the month (e.g. Idibus martiis)

One day before one of them they used pridie with the accusative of the day (Kalendas, Nonas, and Idus) and month (e.g. pridie nones septembres)

The Romans calculated the date as how many days until the next one of these, counting inclusively. They used a.d. and the number of days until the next one in lowercase roman numerals, and then the day and month in accusative (e.g. a.d. xxii Kalendas Iulias)

Years

The years are counted since the Founding of the city of Rome in 753 B.C.E., with A.U.C. appended to the end of it.

http://novaroma.org/nr/Roman_dates

The challenge is, give an input of a day, month, and year in any preferred format, to return a string given the Roman date.

As this is code-golf, the code with the shortest bytes wins, and the standard loopholes are disallowed.

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

Milking the cows

When I was a kid, we used to play a card game called "Milking the cows". I have no idea why it was called that, as it had nothing to do with said activity, but whatever. For months we would play furiously, seeing who was best at this game.

It wasn't until years later that I realized the game is completely deterministic. All my hours of practice turned out to have been pointless. But now it does make for an interesting code-golf.

Rules of the game

There are two players. Each is dealt half of a standard pack of shuffled cards. Every round, both players draw the top two cards from their respective decks and compare values. The highest scoring pair wins, and that player adds all captured cards to his stack of cards (at the bottom). In case of a draw, both players draw one additional card and compare again (If this is again a draw, another card is drawn, etc)

The game continues with both sides drawing cards until one player is unable to draw another card, at which point they lose and their opponent wins the game.

Card values are equal to the printed number for number cards, Aces are 11 points and J/Q/K are all 10.

The challenge

Given an input string of 52 characters representing the cards (without suit, since it doesn't matter in this game), deal the first 26 to player 1, the rest to player 2, and then determine who wins that match of Milking the cows.

The characters sent are 2,3,4,5,6,7,8,9,T,J,Q,K,A for the numbers, Ten, Jack, Queen, King and Ace. It can be assumed that the input string is correct and contains exactly 4 of each character.

The top of the stack is on the right side; the bottom of the stack is on the left side. Cards are always drawn or put back on the bottom one at a time

When a round is won, cards are added to the bottom of the winner's stack, starting with the opponent's cards and then the own cards, in the order they were drawn.

When the winner is determined, output the number of the player that won. It is possible (but phenomenally unlikely) for the game to end in a draw, because both players are unable to draw a card. In this case, output 0.

Example of a round:

Player 1's stack: QTKJ42336K59QKJ77T8J953485

Player 2's stack: JTK676ATQ8A576429Q2A948A23

Player 1 draws: 5, 8

Player 2 draws: 3, 2

Player 1 wins the round (13 points vs 5)

Player 1's new stack: 8523QTKJ42336K59QKJ77T8J9534

Player 2's new stack: JTK676ATQ8A576429Q2A948A

Testcases:

69K9A9QJ8TT33A88KQ685J97AQK224Q2726T73547K6J554J4AT3 -> 2
98JK947A5K283A5A2TAJ6K278T4TQT73674Q956JK94Q68QJ3352 -> 2
9T87J2K38KJT846558A2Q4A95395T67936A7Q2J4TQAK623JKQ74 -> 1
J67835828K48KA45TQ546JQ479TA2JT2Q933K27JT69KA9735QA6 -> 1
23456789TJQKA23456789TJQKA23456789TJQKA23456789TJQKA -> 0

Scoring

This is code-golf, so the shortest code in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! Thanks for using the sandbox. Can you elaborate a bit on what makes this much different than Determine the winner of a game of War? Is it just the fact that the top two cards are compared instead of only the top card? \$\endgroup\$ – AdmBorkBork Feb 14 '17 at 15:37
  • \$\begingroup\$ Ah, they're very similar indeed - I didn't know this game had different names in other languages. The biggest difference is probably checking for ties (which almost never happens) but I'm not sure if it's worth a new challenge. \$\endgroup\$ – Erik Feb 14 '17 at 15:40
0
\$\begingroup\$

Convert to polynomial base numbers


Background

Base Representation

Bases may be written with the following generalization (let concatenation just represent adjacency in digits; 10 = ab when a = 1, b = 0):

abcdex = ax^4 + bx^3 + cx^2 + dx^1 + ex^0

Essentially, we can write in any base we want such that the last digit is base to the power 0, penultimate digit is base to the power 1, etc. When we make the base a variable (x), we can represent a polynomial with a number.

Representation Overflow

Let's take our example before with abcdex. What happens when our representation for numbers (base 10 for our case) becomes too large to represent with a single character? Why, we use the tilda (~) on both sides of the value.

Thus, if we had the conditions a = 9, b = 32, c = 2, d = 43, e = 10 and were restricted to writing with base 10 representations for each value, our number may be represented as 9~32~2~43~~10~x.

Minimized Polynomials

For this challenge, I will occasionally refer to "Minimized Polynomials". When I say this, I mean that there will be no spaces in the polynomial string, terms with coefficients of zero will not be shown, and polynomials will be written in terms of greatest term first.

For example, the following is not a minimized polynomial:

x^2 + x^0 + 5 * x^4 + 0x^1

The following is the first example's minimized form:

5x^4+1x^2+1x^0

The Task

Given a valid minimized polynomial string input n, write a function or program which returns or prints the polynomial base representation of the value in base 10, allowing for representation overflow.

Examples

Let f be the function described in the task:

>>> f("1x^4+1x^3+1x^2+1x^1+1x^0")
1111

>>> f("6x^3+1x^1+5x^0")
6015

>>> f("20x^4+4x^3+1x^1")
~20~4010

>>> f("300x^6+30x^4+40x^3+2x^2+1x^0")
~300~0~30~~40~201
\$\endgroup\$
  • \$\begingroup\$ The introduction seems backwards to me. I think that what it's trying to express is that by representing numbers in base b you can show a bijection between the ring of natural numbers N and the ring of polynomials over the integers modulo b, (Z/bZ)[x], but that's not what it really communicates. In particular, "we can represent a polynomial with a number" seems to be talking about an injection Z[x] -> N (or maybe Z[x] -> Z), and while they do exist they're more complicated than anything described in this question. \$\endgroup\$ – Peter Taylor Feb 15 '17 at 16:55
  • \$\begingroup\$ In fact, the section on overflow explains why the ideas in the introduction break down. Once the coefficients cease to be elements of 0..b-1 base conversion gives aliasing. The workaround of introducing tildes means that what you have is no longer a base-b number, so the title is wrong. \$\endgroup\$ – Peter Taylor Feb 15 '17 at 16:58
  • \$\begingroup\$ @PeterTaylor I have no idea what your first comment is saying. Is your second comment suggesting that I rename this to "Convert minimized polynomial to shorthand polynomial" or similar? \$\endgroup\$ – Addison Crump Feb 15 '17 at 18:17
  • 1
    \$\begingroup\$ Really the whole stuff about base conversion is a red herring: the task consists in parsing a polynomial, filling in the zero coefficients, and then rendering them with conditional wrapping in tildes. \$\endgroup\$ – Peter Taylor Feb 15 '17 at 21:45
0
\$\begingroup\$

Multiplication puzzle using digits 1-9

The puzzle is to use the digits 1-9 inclusive, exactly once, to fill in the blanks such that:

_ _ _ _ * 3 = _ _ _ _ _

Your task is to create the shortest program that finds all solutions to the equation.

\$\endgroup\$
  • \$\begingroup\$ Is this exactly 4 characters * 3 = 5 characters? or is this any amount * 3 = any amount? \$\endgroup\$ – ATaco Feb 16 '17 at 0:12
  • \$\begingroup\$ Thanks for your comment. It's a 4 digit int multiplied by 3 = a 5 digit int \$\endgroup\$ – harryscholes Feb 16 '17 at 8:38
  • \$\begingroup\$ You should give the output list for reference. Submissions can hardcode an output, so if there's few solutions, you should change the problem so that there's many. \$\endgroup\$ – xnor Feb 16 '17 at 11:13
  • \$\begingroup\$ There are two solutions. It's not clear what output format is expected, but if 5823 5832 is acceptable output then hardcoding that is likely to be much shorter than any approach which uses calculation. \$\endgroup\$ – Peter Taylor Feb 16 '17 at 11:20
  • \$\begingroup\$ Should I edit the rules to say that the solutions can't be hardcoded and that the program must output both the 4 and 5 digit numbers? \$\endgroup\$ – harryscholes Feb 16 '17 at 14:15
  • \$\begingroup\$ You could for example change the hardcoded 3 to a number N which should be received as input. This way hardcoding the output becomes much less desirable. EDIT: Actually, I don't know if this puzzle also has solutions for other values of N \$\endgroup\$ – Leo Feb 16 '17 at 14:21
  • \$\begingroup\$ @Leo, yes, and it has loads for N=8. That's a great suggestion. \$\endgroup\$ – Peter Taylor Feb 16 '17 at 14:50
0
\$\begingroup\$

Mathematical Creativity

At our workplace we are so creative that sometimes we decide that today the number 2=9, 0=231 or 67=5... just for the sake of it. So for that day everyone in the workplace must consider that fact.

Your task is to write a full program or function that takes as input today's value of the decided number, which operation to perform and output the result, of course the new number's value affects also the result.

Input:

  1. Only positive integers >= 0and <= 1000000.
  2. The math operations to perform are only sum +, subtraction - or multiplication *.
  3. The input is taken from standard input in any reasonable format for example: [N V X + Y], N,V,X,+,Y, NVX+Y, ("N","V","X","+","Y"), ['N','V','X','+','Y'], etc.
  4. First parameter N is the choosen number.
  5. Second parameter V is new value of N.
  6. Third parameter X is the first number of the math operation.
  7. Fourth parameter is the math operation to perfom, can be only +, -, *.
  8. Fifth parameter Y is the second number of the math operation.

Explained example:

  1. Input 5,27,252,+,3.
  2. All the 5's becomes 27 so 254+3 -> 2272+3=2275 but the result is 2275, it contains 5 so it becomes 22727.
  3. No recursive substitution or infinite loop is needed. The substitution must be performed only once on X,Y and on the result.

Example inputs / outputs:

Input              > Output
----------------------------------------------
5,27,252,+,3       > 2272+3=22727 
45,0,237456,-,4567 > 23706-067=23639
9,7,349,*,7        > 347*7=2427
121,1,1212121,+,0  > 121+0=1
5,55,555,+,5555    > 555555+55555555=556111110
10,5,11000,*,10    > 1500*5=7500
1,2,3,+,4          > 3+4=7
4,4,3,+,4          > 3+4=7

Rules

  1. The number substitution must be performed only once on the first two numbers X,Y and only once on the final result. No recursive substitution or infinite loops are needed.
  2. The output must contain the full math operation, not only the final result, for example: 2272+3=22727.
  3. This is so the shortest code wins.
  4. Standard loopholes are forbidden.

Sandbox questions:

  1. Is this a duplicate of another question? I thought it would already exist but couldn't find any challenge by searching. If you know of it please let me know.
  2. Is the input enough clear or is it possible to improve in some way?
  3. Is the challenge clear?
  4. Tags:
  5. Suggestion for title?
\$\endgroup\$
  • \$\begingroup\$ Should the substitution be performed only once, or once for each occurrence, or recursively until no occurrence remains? Consider, for example, 121,1,1212121,+,0. Then you should also specify what happens with infinite loops. Compare with this proposal and my comment there. \$\endgroup\$ – Zgarb Feb 14 '17 at 14:32
  • 1
    \$\begingroup\$ What will the output be for input 5,55,555,+,5555? \$\endgroup\$ – Kritixi Lithos Feb 14 '17 at 14:32
  • \$\begingroup\$ @Zgarb thanks for pointing that out, only one-time substitution is needed on the first numbers and the result, no recursivity or loops. I added your example in the test cases. \$\endgroup\$ – Mario Feb 14 '17 at 14:46
  • \$\begingroup\$ @KritixiLithos I added your suggested example in the test cases. \$\endgroup\$ – Mario Feb 14 '17 at 14:47
0
\$\begingroup\$

Associativity Conversion

Operators that aren't associative usually come with some implicit associativity which let you omit parentheses in some expressions for readability. E.g. for a left-associative operator $, the following parentheses are assumed:

a $ b $ c $ d ≡ ((a $ b) $ c) $ d

But for a right-associative operator, the implied parentheses are these:

a $ b $ c $ d ≡ a $ (b $ (c $ d))

For this challenge, we will use an "invisible" operator (that is, we'll simply write abcd for ((ab)c)d or a(b(cd))). Your task is to take some valid expression of that operator as input, where the operator will be assumed to be left-associative. You should then output an equivalent expression, where the operator is assumed to be right-associative.

Example

Consider the input:

a(bc)(d(efg))

First, let's insert all parentheses that are implied by the operator's left-associativity:

(a(bc))(d((ef)g))

Now we want to rewrite this in a right-associative fashion. Therefore, we drop all parentheses start at the right end of a subexpression:

(abc)d(ef)g

We cannot remove any further parentheses because that would change the implied parentheses.

ToDo

small print and test cases

\$\endgroup\$
  • \$\begingroup\$ I'm not sure quite how to correct "Therefore, we drop all parentheses start at the right end of a subexpression". To make it parse it would suffice to change start to starting, but doesn't every parenthesis start at the right end of a subexpression? Perhaps it would be simpler to just add a tree diagram instead of adding parentheses? \$\endgroup\$ – Peter Taylor Feb 21 '17 at 22:51
  • \$\begingroup\$ @PeterTaylor I guess I meant "starting at the right end of the surrounding subexpression" but that's not much clearer. I'll think about it. \$\endgroup\$ – Martin Ender Feb 23 '17 at 16:05
0
\$\begingroup\$

Starry Starry Night

This challenge needs a lot of work in my opinion, especially refining rules on input-output, I want to leave it as open as possible, while excluding unfair methods such as pre-drawn graphs etc.

some parts of this are currently extremely vague, please ask any questions you believe might be important.

i'll be adding some graphics in to help explain what the challenge is about at a glance though.


Does anyone else sometimes looks up at the stars and ponder the great mathematical questions of our time, Does P=NP if you just want to check a bus timetable, can a 'try/catch' block solve the halting problem, and how far would that star need to move to form an equilateral triangle..


given an array of 6 numbers, consisting of 3 arrays containing two numbers between 0-255 each, i.e.

[[35,185],[141,8],[192,223]]

return the change required to be made to a single point, to have the three points form an equilateral triangle.

Input-

  • Can be taken as 6 distinct integers, an array of arrays, a single array, or a set of three objects with x/y as named/default properties,
    • these input formats are loose and whatever best suits your language should be used, within reason (i.e. - mathematica cannot use a pre-drawn graph as input)
  • no two points will be on the same x/y, and 0 will never appear as any single x or y co-ordinate

Output-

  • Only one out of the three co-ordinates can be modified, the other two must remain unchanged
  • Can be given graphically on a grid, a returned 'modified' version of the original input, or as an output of the values changed (i.e. 40->55;30->99)
  • you're looking up at the sky, your numbers can easily be off by a bit, the returned values are only required to be accurate to the whole number, rounding up or down is allowed
  • you do not have to achieve the smallest distance, or smallest/largest resulting triangle, any mathematically equilateral triangle will be correct

Examples:(still have to actually calculate these) [[20,113],[63,17],[40,161]] [[43,119],[183,197],[103,86]] [[144,216],[108,203],[113,199]] [[197,131],[217,7],[13,77]] [[100,60],[26,107],[130,241]] [[209,61],[208,98],[47,94]] [[48,78],[179,135],[52,119]] [[93,148],[124,226],[137,118]] [[65,21],[168,167],[221,56]] [[89,118],[48,181],[29,98]]

\$\endgroup\$
  • \$\begingroup\$ When you say "rounding is not strict, and can be 1 number either side of a resulting decimal value" does that mean that the output can be a whole number obtained by rounding up or down? \$\endgroup\$ – Peter Taylor Feb 21 '17 at 12:28
  • \$\begingroup\$ @PeterTaylor that's correct, i'll clarify it a bit further, would the returned values are only required to be accurate to the whole number, rounding up or down is allowed be a bit more specific? \$\endgroup\$ – colsw Feb 21 '17 at 14:38
  • \$\begingroup\$ Yes, that's fine. The really ambiguous part was "1 number", where it wasn't clear how many decimal places were expected. \$\endgroup\$ – Peter Taylor Feb 21 '17 at 14:43
0
\$\begingroup\$

Triangular Numbers

Compute the nth triangular number. Triangular numbers are the number of things in a size x triangle (n(n+1)/2).

Testcases:

0 0
1 1
2 3
3 6
7 28
34 595

IO in any allowed form, standard loopholes apply.

\$\endgroup\$
  • 1
    \$\begingroup\$ This would make for an interesting challenge, but the question is highly unlikely to receive many upvotes without more explanation (clearer spec, test-cases, the definition of the triangular numbers, etc. The definition is important because we require that challenges should require as little knowledge/research to solve as possible) \$\endgroup\$ – ETHproductions Feb 23 '17 at 23:45
  • 1
    \$\begingroup\$ Also, this is a subset of Polygonal Numbers! (though that may not matter as there may be different golfy approaches in various languages, and also that challenge wasn't taken very well and has few answers) \$\endgroup\$ – ETHproductions Feb 23 '17 at 23:47
0
\$\begingroup\$

Ultimatum Game

You and a (not so) friendly bot have a chance to play a game. There is 100 dollars on the table. One person, suggests a split, and the other can accept the split, or force each individual to accept absolutely nothing. You will alternate being able to give the ultimatum for a substantially large number (1000) rounds. This process will proceed in a round robin fashion till every bot has played all the others exactly once. Your score in this manner, will just be the total amount of money you collect.

Now your job is to write a bot that will play this game. You will be provided with needed information as command line arguments.

A sample invocation will look like this if you are giving the ultimatum. When you receive an invocation like this, you would be the one propsing a split.

foolanguage myBot.foo 4 ultimatum 1 reject 10 reject 20 reject 25 accept 

Or, like this if you are the one considering the ultimatum. You will be tasked with either accepting the split, or rejecting it (both bots get 0).

foolanguage myBot.foo 4 accepting 1 reject 10 reject 20 reject 25 accept 1

The first number represents the number of rounds played (n). The second will be a string either "Ultimatum" or accept/ reject. Next will follow 2n+1 strings. The first 2n will be offers and what the choice was. The last string will be the current offer.


Entering

You will provide a command stem and a unique bot name. So the sample bot can be called fooBot, and the command stem (after which arguments are appended) looks like "foolanguage myBot.foo"

Your bot will then output either the number it will offer, or (if they are the one who has to consider the offer), ("a" for accept/ "r" for reject) within 50 ms.

Your bot must be be able to make both choices (accept or reject). No locking in to just one choice.

Also, your bot must be deterministic (prng's may be seeded with a private seed. If you wish to do this, insert a dummy seed, and change it right before the competition) please publish the hash to ensure you don't tweak it in light of other submissions.

In the spirit of fair competition, no access to the file system (or OS calls). I will allow the option to write to a maximum of one text file which can have a maximum size of 8 megabytes. Solutions will be tested within a virtual machine imaged with the latest version of linux on my home desktop which has an Intel i7-4770 quad core 3.4 gHZ cpu.

\$\endgroup\$
  • \$\begingroup\$ I believe we already have had a prisoners dilemma KOTH... \$\endgroup\$ – fəˈnɛtɪk Feb 25 '17 at 21:34
  • \$\begingroup\$ @LliwTelracs I do believe the strategy here is entirely different, and brings up some interesting effects. Most notably, the asymmetry of the situation, and the information which you have. \$\endgroup\$ – Rohan Jhunjhunwala Feb 25 '17 at 21:55
  • 1
    \$\begingroup\$ 1. I suggest rewriting the input spec to pass via stdin instead of the command line. Some shells have command line length limits: e.g. on most versions of Windows you'll only be able to get up to about 820 rounds with the current format. Using stdin would also allow newlines, which would make the format easier for humans to read and understand. Also, what does the accepting in the second example mean? 2. I presume that the score is the total amount of money you make over all rounds and all games, but this should be made explicit. \$\endgroup\$ – Peter Taylor Feb 26 '17 at 8:52
  • \$\begingroup\$ I fear this challenge would be dominated by bots offering a 99/1 split and accepting any offer of at least 1 dollar, with no consideration for the history \$\endgroup\$ – Leo Feb 26 '17 at 13:57
  • 1
    \$\begingroup\$ @Leo I plan on creating a few sample bots, which will mimic human behavior. For example, one bot might reject offers less than 25. Another, might grew more and more likely to reject offers based on the average money allocated. Another might only offer (and accept) splits of 50/50 (or better). This way, good solutions will cater to such bots. \$\endgroup\$ – Rohan Jhunjhunwala Feb 26 '17 at 14:07
  • \$\begingroup\$ I was going to write a 50/50 bot, so I would be sad if that's already taken by a sample bot - unless the samples are clearly only for development and not participating in the final contest. \$\endgroup\$ – Peter Taylor Feb 27 '17 at 9:26
  • \$\begingroup\$ @PeterTaylor sure, I could make it that way, sample bots are only for developement \$\endgroup\$ – Rohan Jhunjhunwala Feb 27 '17 at 11:50
0
\$\begingroup\$

Board Game Breaking - The Front Nine W.I.P.

Eventually I will make a post here for each of the challenges. This post is for discussing them as a series. If you have an idea for a good board game breaker, please share!

Introduction

Board Game Breaking is a series of challenges that harness computing power in order to 'break' a game (i.e. ensure no one will play with you). Each challenge will revolve around creating a tool that analyzes the board game in a way that will give you some advantage. There are nine challenges total.

BGB #1 - Number Rings

  • Input: Int
  • Output: Likelihood of creating that int with 3d6 & +-*/

Number Rings

BGB #2 - Can't Stop!

  • Input: 1-3 Ints
  • Output: Likehood 2 (of 4) d6 will add up to one of the inputs

Can't Stop

BGB #3 - Axis & Allies

  • Input: # of units on each side
  • Output: Probability of winning the fight

Axis & Allies

BGB #4 - Labrynth

  • Input: Image
  • Output: Image re-arranged in labrynth-like way to make gradient

Labrynth

BGB #5 - Scrabble

  • Input: Word list
  • Output: Word with most subwords

Scrabble

BGB #6 - ??

BGB #7 - ??

BGB #8 - ??

BGB #9 - ??

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

Penrose Triangle Codegolf

The Penrose triangle, also known as the Penrose tribar, or the impossible tribar, is an impossible object. - Source

The goal in this challenge is to display a Penrose triangle in the fewest bytes possible.

Rules:

  1. You must display the Penrose Triangle digitally after generating it.

Good luck and have fun!

\$\endgroup\$
  • \$\begingroup\$ Rule 2 is unnecessary because it applies by default. Rule 1 is a disaster which is guaranteed to prompt arguments over which minimalist ASCII art answers actually represent a Penrose triangle. \$\endgroup\$ – Peter Taylor Feb 27 '17 at 9:24
  • \$\begingroup\$ @PeterTaylor I guess that makes sense. \$\endgroup\$ – arodebaugh Feb 27 '17 at 11:28
0
\$\begingroup\$

BGB #1 - Number Rings

Goal: Take an int, output the probability of creating that int with 3d6 & +-*/.

Number Rings

Introduction

Check here

Background

Number Rings (or Sector 18) is a board game where up to 4 players take turns rolling a set of 3 six-sided dice. Then then using +-*/ to combine all three of those numbers to get a number, x. They then place (or remove) a ring on a x peg. First player to have a ring on each of his pegs, wins. That is the basic idea of how the game works.

For any number a, I want to know the probability that I will be able to create a with a random roll.

Specification

  • Input
    • One integer, i, such that 0<i<19
    • The input is flexible
  • Output
    • The probability of being able to create i with a random roll
    • At least 5 digits of accuracy
    • Ex: 0.12345. .12345, 12.345
    • Or exact rational number
    • Ex: 145/1023
    • Leading/Trailing whitespace is acceptable
  • Scoring
    • Shortest program/function in bytes wins

Test Cases

ToDo

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

BGB #2 - Can't Stop!

Goal: Take 3 ints, output the probability 2 of 4d6 will sum to one of the ints.

Can't Stop

Introduction

Check here

Background

Can't Stop is a board game. There are columns for the numbers 2 through 12, each having a number of rungs that must be climbed into to win the column. On a player's turn, they receive 3 white pieces and 4d6. They roll the dice, sum two of the values and either move a placed white piece up a rung or place a white piece in a column. First player to win 3 columns, wins the game.

For any numbers, a or a,b or a,b,c, I want to know the probability that I will roll at least two numbers that sum to a, b or c

Specification

  • Input
    • One to three integers between 2 and 12 inclusive
    • Taking 3 integers that aren't necessarily distinct is also acceptable
    • The input is flexible
  • Output
    • The probability of being able to create one of the inputs with a random roll
    • At least 5 digits of accuracy
    • Ex: 0.12345, .12345, 12.345
    • Or exact rational number
    • Ex: 145/1023
    • Leading/Trailing whitespace is acceptable
  • Scoring
    • Shortest program/function in bytes wins

Test Cases

ToDo

\$\endgroup\$
  • \$\begingroup\$ What about output as exact rational number? Is input flexible enough to say that there are always three numbers but they don't have to be distinct? \$\endgroup\$ – Peter Taylor Feb 27 '17 at 0:07
  • \$\begingroup\$ @PeterTaylor Great questions! Yes to both. I modified the challenge to make that clear. \$\endgroup\$ – NonlinearFruit Feb 27 '17 at 0:28
0
\$\begingroup\$

Unschedule my tasks

Intro

I have a scheduler that uses priority scheduling on my PC so there are several tasks with a definite priority. All that i still remember is that every task runs cyclically forever with an also definite period. I can see which tasks are running from t=0 to now, but i need to know the priority and the period time of every task.

Input

The input is a string with the length n showing the last n timestamps. We give the tasks uppercase letters from A...Z, where the amount of different tasks k is given as 0<k<27. If one tasks is chosen, it will need one time stamp long to finish and will start after it's period time T again. Example:

not given:
task A: priority=2, T=7
task B: priority=1, T=2
task C: priority=3, T=5

results in:
A      A      A      A      A      A      A
B B B B B B B B B B B B B B B B B B B B B B
C    C    C    C    C    C    C    C    C
_____________________________________________
BABCBCBAB BCB BABCB BABCBCB BABCB BABCB BCBA

The last line will be your input and the goal is to get every task with the corresponding priority and period time.

Output

So for the input

BABCBCBAB BCB BABCB BABCBCB BABCB BABCB BCBA

You should output

A 2 7
B 1 2
C 3 5

The output should have the format [task name] [priority] [period time] with one task per line.

Rules

  1. All tasks will always start at t=0
  2. If multiple tasks are ready to run, the one with the lower priority will run first, the other one will move one slot to the right
  3. The priority of one task is always the same, so no dynamic priorities will be used
  4. The processor will never have to run at 100%, or as formula: 1/TA + 1/TB + ... + 1/Tk < 1. In the example it's 1/7 + 1/2 + 1/5 = 0.84 < 1
  5. If there are multiple solutions, output only one of them
  6. The input string will show every task at least 3 times

Test cases

in:
A  A  A  A
out:
A 1 3

in:
CBA   CBA   CBA   CBA   CBA   CBA   CBA   CBA
out:
A 3 6
B 2 6
C 1 6

in: 
//A      A      A      A      A      A
//B   B   B   B   B   B   B   B   B   B
//C    C    C    C    C    C    C    C
//D             D             D
//E        E        E        E        E
  ABCDBCEABEC B ACBDE BAC BC EABCDB  ABCE
out:
A 1 7
B 2 4
C 3 5
D 4 14
E 5 9

Thoughts

Still thinking about turning the question around. Just turning input and output around but i like this way more because i think it's more challenging.

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

Effective street lighting


You are the operator of a town's street lamps. Each road has one or more lamps. When it's night, every part of the road must be lit, which means that either the lamp above it, or both lamps next to it must be on. Your job is to light each street in the most energy-efficient way. The problem is, each lamp has its own power consumption.

Your task:

  • Take an input consisting of the consumption of each lamp in a single street;

  • Output the minimal consumption of the street so that all spaces are lit;

  • And have your program calculate this in a reasonable time (will be specified) for at least 50000 lamps with a maximum consumption of under 1000.

Notes:

  • Input can be taken in any simple list format (e.g. newline-separated; space-separated; as an array)

  • There will be at least one lamp

  • Each lamp's consumption will be a positive integer

  • An alternative statement of the condition for a valid subset of lamps is that the first and last lamp must be lit, and no two consecutive lamps may be unlit

  • The output is a single integer (and will fit in a 32-bit signed integer type)

  • Trailing spaces and newlines are allowed in output


Test cases:

10 -> 10

15 20 -> 35

10 20 40 30 30 40 -> 100

534 954 444 154 431 818 550 486 294 449 247 766 216 400 924 728 821 845 724 807 585 555 379 939 591 601 263 76 976 567 -> 7646

12 357 925 826 727 565 444 897 474 546 564 306 931 293 503 895 320 79 790 241 441 301 423 290 390 556 529 797 123 292 692 653 648 336 480 95 619 923 710 93 188 992 118 120 5 339 733 324 417 242 284 857 542 706 866 651 262 395 448 103 686 858 756 54 195 954 866 813 877 295 625 784 287 461 903 291 799 636 334 216 878 617 791 139 323 657 789 303 770 956 406 176 814 880 229 727 834 813 260 711 108 884 495 394 64 117 404 862 472 737 796 69 354 587 207 676 963 715 697 733 671 103 908 204 982 855 931 535 668 909 247 775 793 460 888 575 296 292 437 767 747 951 835 101 538 42 495 220 756 192 672 146 14 580 350 714 155 999 250 822 908 215 317 420 674 923 994 969 933 150 455 680 101 290 780 357 332 993 577 806 185 249 671 916 547 21 631 701 738 880 243 646 95 278 66 487 201 778 176 852 927 630 532 746 920 31 103 970 24 398 495 926 365 166 843 912 186 474 332 642 73 293 288 167 570 72 653 489 849 547 341 776 178 591 241 98 340 344 786 363 741 281 9 825 447 570 456 351 44 787 993 116 799 281 1 88 353 372 577 920 919 636 697 97 946 937 912 286 999 698 368 460 978 95 285 425 664 740 495 707 246 488 541 763 487 260 851 558 631 147 479 550 782 894 365 447 550 277 452 550 974 819 10 672 913 13 815 296 471 310 721 435 516 262 199 4 240 50 561 870 196 40 140 696 652 504 862 203 500 314 752 193 133 480 864 764 211 399 60 681 708 499 834 225 479 33 946 718 800 226 307 714 984 446 411 636 669 273 838 887 305 590 80 437 788 663 919 998 780 697 398 488 196 233 431 674 983 96 392 784 322 698 217 306 863 346 941 251 337 780 138 641 89 935 796 877 598 715 594 378 131 992 585 326 943 734 718 926 830 828 429 870 246 365 176 109 710 835 359 48 615 215 688 423 150 485 19 467 918 612 844 50 323 148 94 984 601 531 630 431 359 59 20 323 142 195 150 852 748 227 899 83 441 306 505 591 509 523 58 147 853 620 914 895 487 8 879 88 257 509 237 335 287 256 657 428 450 807 280 916 34 897 998 475 922 503 784 431 744 841 577 317 180 210 212 666 936 91 753 193 319 989 527 605 245 903 751 413 710 750 330 462 647 328 655 288 550 439 719 294 998 15 610 179 943 821 844 879 631 598 72 949 587 318 273 551 221 24 963 649 773 12 111 140 340 766 427 889 923 864 901 922 598 512 101 541 52 944 139 401 542 210 69 848 527 60 399 466 802 81 115 294 93 944 433 151 710 579 40 633 162 659 555 478 171 374 737 941 319 875 61 579 804 130 146 50 189 263 516 709 344 349 4 155 293 436 305 721 733 63 74 614 721 347 92 611 721 548 271 758 423 331 337 227 179 483 277 87 745 511 795 807 859 798 961 153 953 984 592 686 47 665 300 487 13 111 98 452 658 368 210 799 417 546 27 596 747 22 682 493 532 477 300 391 994 980 262 947 964 854 633 730 519 652 217 250 481 314 701 139 400 910 937 535 457 682 131 204 703 531 415 235 727 434 345 721 414 606 668 97 460 20 826 698 671 43 947 152 75 649 9 193 559 665 728 16 347 577 938 769 109 72 722 835 505 67 556 637 673 942 453 851 961 279 549 633 41 497 503 833 146 231 745 704 895 473 439 960 768 96 729 876 167 452 430 672 237 704 28 909 646 480 761 608 478 310 959 237 806 181 70 670 411 533 375 25 6 532 985 493 627 433 369 793 603 518 465 840 222 212 749 868 691 229 195 169 539 154 405 64 334 194 734 464 726 827 488 451 359 473 943 985 625 31 778 228 548 962 68 489 174 536 357 583 764 551 471 22 423 875 804 475 787 257 938 233 84 427 402 161 618 345 146 243 94 642 190 361 604 975 849 496 230 924 80 994 194 550 734 616 144 257 91 650 232 748 882 315 893 284 194 511 347 339 473 159 981 381 519 304 356 368 519 586 11 317 299 204 585 751 538 447 727 348 97 958 96 697 274 988 699 467 499 764 525 690 923 225 71 161 247 146 248 765 731 258 82 748 462 666 499 999 114 226 347 928 185 161 345 177 149 762 362 367 527 605 57 169 829 846 329 77 991 576 560 441 553 642 189 15 27 687 732 858 632 80 506 816 240 850 711 108 612 73 474 857 678 249 26 226 813 355 302 523 649 581 963 202 223 152 934 967 558 667 826 190 465 332 724 423 900 435 530 512 226 722 89 622 690 114 848 503 187 868 27 555 449 989 756 390 860 410 358 418 77 184 326 260 234 50 682 852 484 931 83 428 653 171 51 343 285 898 565 190 485 310 744 934 299 220 324 877 629 400 295 424 302 339 683 535 388 84 387 590 15 189 19 387 359 69 448 643 685 13 833 170 322 296 822 340 515 147 935 862 265 949 286 567 288 687 820 676 490 926 984 504 115 3 609 473 789 58 835 474 788 387 363 829 682 185 887 916 50 822 778 315 771 783 600 60 470 420 454 678 346 438 183 460 160 791 933 948 567 768 142 356 155 504 185 555 407 72 471 176 612 250 209 384 33 808 162 221 228 615 899 574 53 800 752 212 310 685 879 877 172 21 233 45 243 136 600 368 925 71 543 537 39 751 920 789 278 82 11 506 415 628 798 187 147 550 117 456 954 995 52 844 16 3 889 976 856 208 345 781 278 887 319 317 358 -> 245300

Standard rules apply.

[Sandbox note: I'd be grateful for any help on this challenge. It looks trivial - that's what I think caused the negative feedback. Any help or notice accepted! (ungolfed Java program)]

\$\endgroup\$
  • 1
    \$\begingroup\$ There are quite a few minor improvements which could be made in the explanation: I'll edit in a rewrite proposal, which you can revert if you don't like it. As for being trivial: it is sufficiently trivial that I personally wouldn't upvote it on main (basically it's folding min, and the first version I wrote in CJam worked first time and is probably as short as it gets in CJam - your example Java code is far more complicated than it needs to be), but there are plenty of questions which are more trivial. \$\endgroup\$ – Peter Taylor Dec 20 '16 at 11:41
  • 1
    \$\begingroup\$ For "reasonable time", I think 1s would be reasonable in most languages, and I don't think anyone's likely to attempt the challenge in a language in which it wouldn't be reasonable (because working with arrays in those languages is not fun). \$\endgroup\$ – Peter Taylor Dec 20 '16 at 11:51
  • \$\begingroup\$ @PeterTaylor Firstly, thanks for the edit; I might edit again later though. As to your comments: I had designed my Java code example to give me results for 1'000'000-lamp streets, and also somewhat complicated the code before posting it here. Finally, 1s for 50000 lamps seems too much for me, but I don't think I'll put a time limitation into the final challenge. TL;DR: thanks for the help! \$\endgroup\$ – RudolfJelin Dec 20 '16 at 14:34
  • 1
    \$\begingroup\$ 1s for ten million lamps is generous in languages like C and Java (I get 50ms for ten million in C#), but less so for languages which run on multiple layers of interpreters. I like having a time limit, because it pushes people to think about their approach rather than brute-forcing (which is usually shorter but takes time exponential in the size of the input), but the point is to cut out exponential time solutions rather than to make the constant in linear-time solutions significant. \$\endgroup\$ – Peter Taylor Dec 20 '16 at 15:01
  • \$\begingroup\$ @PeterTaylor I'll consider that, thanks for informing. \$\endgroup\$ – RudolfJelin Dec 20 '16 at 15:55
0
\$\begingroup\$

Schedule my tasks

Intro

Inverse challenge to Unschedule my tasks.

I don't have a scheduler that uses priority scheduling on my PC but i want one. I have several tasks which all start at t=0 and each has a priority and a period time. So your task is to schedule my tasks.

Input

The input is a string including the different tasks, the priority and the period time of each task. We give the tasks uppercase letters from A...Z, where the amount of different tasks k is given as 0<k<27. If one tasks is chosen, it will need one time stamp long to finish and will start after it's period time T again. The input has the format [task name] [priority] [period time] with one task per line. Example:

A 2 7
B 1 2
C 3 5

Output

So for the input

A 2 7
B 1 2
C 3 5

you should output (only the last line):

A      A      A      A      A      A      A
B B B B B B B B B B B B B B B B B B B B B B
C    C    C    C    C    C    C    C    C
_____________________________________________
BABCBCBAB BCB BABCB BABCBCB BABCB BABCB BCBA

Rules

  1. All tasks will always start at t=0
  2. If multiple tasks are ready to run, the one with the lower priority will run first, the other one will move one slot to the right
  3. The priority of one task is always the same, so no dynamic priorities will be used
  4. The processor will never have to run at 100%, or as formula: 1/TA + 1/TB + ... + 1/Tk < 1. In the example it's 1/7 + 1/2 + 1/5 = 0.84 < 1
  5. If there are multiple solutions, output only one of them
  6. The output string has to show every task at least 3 times, but the the output has to be finite
  7. Priority and period time are unsigned integers in the range 0<x<50

Test cases

in:
A 1 3
out:
A  A  A  A

in:
A 3 6
C 1 6
B 2 6
out:
CBA   CBA   CBA   CBA   CBA   CBA   CBA   CBA

in:
A 1 7
B 2 4
C 3 5
D 4 14
E 5 9
out: 
//A      A      A      A      A      A
//B   B   B   B   B   B   B   B   B   B
//C    C    C    C    C    C    C    C
//D             D             D
//E        E        E        E        E
  ABCDBCEABEC B ACBDE BAC BC EABCDB  ABCE
\$\endgroup\$
0
\$\begingroup\$

You Jelly?

In this code challenge you are here to explain Jelly code for us simple-minded plebeians. To simplify things we are working in a restricted subset of Jelly.

Details

The input will be a Jelly leading constant chain matching the regex `/([01H+] )+/. For full explanation, see the Jelly tutorial, but as a quick summary each symbol in Jelly represents a function with an arity of 0 (is a nilad), 1 (a monad) or 2 (a dyad). A chain is a sequence of symbols. A leading constant chain is a chain whose first element is a nilad and is followed by any number of subsequences that are any of a monad, a dyad followed by a nilad or a nilad followed by a dyad. Jelly is parsed left to right.

As implied by the regex restriction, the source consists of four symbols: 0, a nilad whose value is the integer 0; 1, a nilad whose value is the integer 1; H, a monad whose value is the function x -> x / 2; or +, a dyad whose value is the function x, y -> x + y.

A leading constant chain over the above symbols is evaluated into an equivalent infix formula by the following rules (where $d represents 1 or 2).

eval("$d $chain") = eval_i("$chain", "$d")
eval_i(""           , expr) = expr
eval_i("+ $d $chain", expr) = eval_i("$chain", "($expr + $d)")
eval_i("$d + $chain", expr) = eval_i("$chain", "($d + $expr)")
eval_i("H $chain"   , expr) = eval_i("$chain", "($d / 2)")

Your task is to take a Jelly program under the following restrictions (only the three symbols above used, always separated by exactly a single space and forming a leading constant chain) and to output a string representing a traditional infix-notation representation of the input. The output of your solution may be equivalent the specified output up to whitespace and PEMDAS rules (i.e. parentheses may be dropped when it does not change the meaning).

Examples

Jelly Program ->      Infix Notation
1             ->                   1
0 H           ->             (0 / 2)
1 0 +         ->             (0 + 1)
1 + 0         ->             (1 + 0)
0 H 1 +       ->       (1 + (0 / 2))
1 1 + H       ->       ((1 + 1) / 2)
1 0 + + 0     ->       ((0 + 1) + 0)
1 0 + H + 0   -> (((0 + 1) / 2) + 0)

Judging

This is code-golf, so lowest byte count wins. Standard loopholes are disallowed. Standard input-output formats (function-or-program) are in play.

\$\endgroup\$
  • \$\begingroup\$ "You Jelly?" is not >= 15 characters, unfortunately \$\endgroup\$ – MildlyMilquetoast Mar 1 '17 at 5:02
  • \$\begingroup\$ @MistahFiggins oh drat :P. I created this challenge entirely for the title... \$\endgroup\$ – walpen Mar 1 '17 at 5:14
  • 1
    \$\begingroup\$ "Are you Jelly?" is 14... maybe a sneaky space or question mark \$\endgroup\$ – MildlyMilquetoast Mar 1 '17 at 5:23
0
\$\begingroup\$

Creative Title about the Moser-de Bruijn

The Challenge

Calculate the Moser-de Bruijn (A000695) sequence for all integers up to the input value N.

Each term of the sequence is defined as the sum of distinct powers of four arranged in ascending order. This means in base 4 every number of the sequence only has ones or zeroes.

You are to print a list of the sequence where all values are less than N. Output is to be separated by either commas, tabs, or spaces. Trailing/Leading commas or whitespace are not permitted. having a comma followed by whitespace is allowed, but the reverse is not. You must use standard output for your language. You are to take input from your language's standard input. Exclude the sequence's first term of zero as it isn't relevant to the game's rules. You may assume the input will always be a positive non-zero integer.

Test Cases

5  => 1,4
6  => 1 4 5
22 => 1, 4, 5, 16, 17, 20, 21
1105 => 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85, 256, 257, 260, 261, 272, 273, 276, 277, 320, 321, 324, 325, 336, 337, 340, 341, 1024, 1025, 1028, 1029, 1040, 1041, 1044, 1045, 1088, 1089, 1092, 1093, 1104

Sandbox Notes

This is my first challenge, so input would be greatly appreciated!

\$\endgroup\$
  • \$\begingroup\$ The stuff about "subtract a square" is completely irrelevant and distracting. After reading the introduction I expected the challenge to be finding the best move given the current size of the pile. IMO it would be a notable improvement to remove all mention of the game and just talk about the sequence which the question is actually about. \$\endgroup\$ – Peter Taylor Feb 28 '17 at 22:11
  • \$\begingroup\$ @PeterTaylor Thanks for the input :) \$\endgroup\$ – Zavada Mar 1 '17 at 1:37
  • \$\begingroup\$ Equivalently, this challenge is to find all integers up to N whose base-4 representation contains only 0s and 1s. Include this explicitly? \$\endgroup\$ – Greg Martin Mar 5 '17 at 20:01
  • \$\begingroup\$ @GregMartin Good idea, I'll add that in! \$\endgroup\$ – Zavada Mar 5 '17 at 21:25
0
\$\begingroup\$

Lost in Space: Help me get back to civilisation

Your spaceship's radio receives a transmission from an unknown location:

To anyone who picks up this transmission, I need help!
My hyperdrive malfunctioned during a routine jump to 
the PPCG Planet. I survived the drop from hyperspace,
but now my ship's positioning system is broken. And 
worse, I can't seem to access Hyperdrives Stack
Exchange to fix it!

I've tried to triangulate my position using local
satellites. I can send a 'ping' to them, and then the
satellite will report how long the ping took to reach
it. But the results don't make any sense! Some of the
satellites must be broken and are feeding me false
data...

I've attached the read-out of all the satellites I
pinged to this transmission. Can you work out which
ones are faulty?

You examine the data that was attached to the transmission. Your spaceship's computer analyses the data and notes that it is a list of tuples, each tuple which contains:

  1. The known position of a satellite as a coordinate pair;
  2. The distance from the lost spaceship that that satellite reported.

A majority of satellite data will support the spaceship being at a certain location -- this is the correct location of the lost spaceship. Write a program or function that outputs this location.

Sample Inputs and Outputs

todo

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

Battle of the Algorithms, Kruskal vs Prim

This will be a challenge similar to a challenge. There will be two threads each with a winner.

This challenge is about minimum spanning trees. I might include a introduction to the topic, but for now I am working under the assumption that you are at least vaguely familiar with the subject.

Two of the most famous algorithms for finding a minimum spanning tree are Kruskal's Algorithm and Prim's Algorithm.

Explanation of the Algorithms to go here

Now the question is "Which one is golfier"?

In order to figure this out are going to implement each of these two algorithms in as many languages as possible. Each algorithm will have its own thread where it can be implemented in as many languages as possible. Each thread will act as a team scoring points for the algorithm in question. For each language a point will be given to the team with the shorter implementation in that language.

For example if the submissions look like this:

Kruskal

  • Python, 136 bytes

  • Bash, 215 bytes

  • Brain-Flak, 3144 bytes

Prim

  • Python, 152 bytes

  • Bash, 211 bytes

  • Perl, 98 bytes

Kruskal would score 2 points, one for having the shortest Python answer and one for the shortest Brain-Flak answer, and Prim would score 2 points one for having the shortest Bash answer and one for having the shortest Perl answer.

At the end of the week two winners will be declared, these will be the two persons that scored the most points for each team. Additionally a winning team will be announced. You can compete for both teams.

Specifications

You will create a program or function that takes a graph in any reasonable form, implements one of the two algorithms and outputs the minimum spanning tree in any format that uniquely represents the spanning tree.

Sandbox

  • How can I make this clearer?

  • What is confusing?

  • Would this be fun?

\$\endgroup\$
  • \$\begingroup\$ I/O formats could make a significant difference. \$\endgroup\$ – Peter Taylor Mar 7 '17 at 21:33
  • \$\begingroup\$ @PeterTaylor I don't care about IO any form is fine \$\endgroup\$ – Wheat Wizard Mar 7 '17 at 21:37
  • \$\begingroup\$ Implementing a given algorithm is tricky to define. To what extent can the method deviate from the algorithm? \$\endgroup\$ – xnor Mar 9 '17 at 22:23
  • \$\begingroup\$ @xnor Each of the two algorithms build the trees in a deterministic order. In order for it to match the given algorithm it must add the edges in the same order. I will add this to the question. \$\endgroup\$ – Wheat Wizard Mar 9 '17 at 22:26
  • \$\begingroup\$ @WheatWizard That's a good idea, and I think it can be made into an observable requirement by requiring the algorithm output the correctly-ordered list of edges in the tree. Otherwise, I don't think the internal adding order is necessarily well-defined -- consider for example a functional-language recursive implementation. \$\endgroup\$ – xnor Mar 9 '17 at 22:30
  • \$\begingroup\$ This is basically just two different challenges which happen to be connected. I'd recommend posting it as two challenges, and then adding a snippet to compare the two challenges to see which problem is terser in the most languages. \$\endgroup\$ – user62131 Mar 14 '17 at 4:57
0
\$\begingroup\$

Painter's Partition Problem

Description

You have to paint N boards of length {A0, A1, A2, A3 … AN-1}. There are K painters available and each painter takes unit time to paint 1 unit of board. You have to get this job done as soon as possible under the constraints that any painter will only paint contiguous sections of board.

Rules

  • 2 painters cannot share a board to paint. That is to say, a board cannot be painted partially by one painter, and partially by another.

  • A painter will only paint contiguous boards. Which means a configuration where painter 1 paints board 1 and 3 but not 2 is invalid.

  • N boards have length given in integers.


Input

K : Number of painters

L : A List which will represent length of each board

Output

Return minimum time to paint all boards

Sample Input/Output

K = 2

L = [1, 10]

Output = 10

\$\endgroup\$
  • \$\begingroup\$ not sure why painters would only paint contiguous boards. But, without that the problem sounds like knapsack. \$\endgroup\$ – John Dvorak Mar 9 '17 at 17:21
  • \$\begingroup\$ What is the point of T? \$\endgroup\$ – Peter Taylor Mar 9 '17 at 17:25
  • \$\begingroup\$ @JanDvorak Contiguous boards is creating a possibility of a solution other than DP (which is also more optimal). \$\endgroup\$ – hashcode55 Mar 9 '17 at 17:27
  • \$\begingroup\$ @PeterTaylor Actually yes, I should remove it, I'll just make the time cost 1 unit. \$\endgroup\$ – hashcode55 Mar 9 '17 at 17:28
0
\$\begingroup\$

find the set of Sets in a subset of Set.

the Set game is a one-player card game using a deck of 81 cards. Derivatives - primarily those that remove most of the cards - exist. We shall be using one of such derivatives today.

a card in the deck is defined by four properties of the symbol(s) depicted on it. Each of these has one of three values:

  • Count (1, 2 or 3); in this version, the count is always 1.
  • Color: red, green or blue.
  • Fill: hollow, striped or filled.
  • shape: a square, a triangle, or a circle.

A card shall be represented as a using those properties: rhs is a red hollow square, while gsc is a green solid circle.

a Set of cards is a triplet of cards such that for each property, the value of that property is either the same for all three cards or different for each of the three cards. For example:

  • rhs, gst and bfc form a Set. Each property value is different.
  • rss, gss and bss form a Set. They are solid squares of different colors.
  • bsc, bhs and bft form a Set. The colors are the same, the fills are different, and the shapes are different.
  • gst, bst and bst do not form a set, because there are two blue cards.
  • rss, bss and rst do not form a set, because there are two red cards as well as two squares.
  • gft, gft and gft do not form a set, because it's not a triplet of cards. It's the same card listed three times.

Your input shall be a set of 9 (distinct) cards from the deck. You may optionally accept a flat string or list of 27 symbols without any separator instead of a list of 9 strings or lists. You may also accept the number of Sets that can be found within this set as a part of your input. You may assume there's at least one Set in your input.

Your output shall be a set of all Sets that can be found among the cards given to you. You may output the Sets in any order, but each Set must only be output once. You may output the cards in each Set in any order as well. You may flatten the output at any level.


How many test cases should I generate? What format is the best? I could provide a test case generator in Ruby, if that's desirable.

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

In our language, we use language of S for basic encryption for avoid something from children if we do not wish that children know about what we are talking about.

So here is how it works.
Lets take "Hello there" for example. So its encryption using language of S is Hesmello Thesmere

Step to understand

Step 1: take string, in our example its "Hello There"
Step 2: add S and M after first character's vowel and add vowel of that first character after M.
You no need to repeate this for other characters of that word. So in our example, we add SM for he so no need to do that for remain llo.

So as per our example for "Hello There" is Hesmello thesmere

What you have to do
1. User add input (or pre defined string in variable) and its output should be as per Output String below

Input : Hello World
Output: Hesmello Wosmorld

This is so lowest number of bytes wins!

Consider these as vowels:A, E, I, O, U, Y

\$\endgroup\$
  • \$\begingroup\$ This isn't encryption. It's obfuscation. \$\endgroup\$ – John Dvorak Mar 10 '17 at 9:52
  • \$\begingroup\$ Welcome to PPCG! This would probably make for an interesting challenge, but I would suggest removing the "pre-defined string in variable" option: our standard ways of taking input are STDIN or an argument to a function. Also, what characters can be part of a word? A-Z and a-z only? \$\endgroup\$ – ETHproductions Mar 10 '17 at 15:26
0
\$\begingroup\$

Find a basis for each eigenspace!

Related

The challenge is just as it seems; you are to find a basis for each eigenspace of a matrix. If you have taken Linear Algebra 1, you'll understand what this means, but this is an attempted full explanation of eigenvalues, eigenvectors, eigenspaces, what a basis is, and how to obtain all of these.

This is the challenge; the explanations are below so you can skip them if you already know how to do this.

Input

The input will be a single matrix given in any reasonable format according to PPCG conventions.

Output

The output will be an array of bases. There will be one basis for each eigenspace. You can choose whether or not to repeat eigenvalues with an arithmetic multiplicity of more than 1. This can be output in any reasonable format, probably a 3D array.

Vectors

In Computer Science terms, a vector is an array of values. For the purposes of this, we are assuming that all of these values are in Q; that is, they are all rational numbers. Wikipedia: Vector space

Matrices

In Computer Science terms, a matrix is a 2D array of values. For the purposes of this, we are assuming that all of these values are in Q; that is, they are all rational numbers. Wikipedia: Matrix

Terminology

Let A be an m x n matrix (with m rows and n columns) and let x be a size-k vector. Then, Aij is the element in the i-th row in the j-th column of A with 0 < i <= m and 0 < j <= n (they are 1-indexed). Also, xi is the i-th element of the vector x with 0 < i <= k.

The Zero Vector and the Zero Matrix

The zero vector is the vector containing all zeros. Similarly, the zero matrix is the matrix containing all zeros. It is important to note that the size still needs to be considered.

Scalar Multiplication

Scalar multiplication by a value s (again we are assuming it is rational) is quite easy to understand; simply multiply each element by s. Thus, we say that x is a scalar multiple of y if and only if x = sy. Note that the zero-vector is a scalar multiple of any vector but all non-zero vectors are not scalar multiples of the zero vector.

Matrix-Vector Multiplication (MathInsight)

Let A be an m x n matrix (with m rows and n columns) and let x be a size-n vector. Then, Ax = y where y is a size-m vector defined as such:

yi = Ai1*x1 + Ai2*x2 + ... + Ain*xn

That is, the i-th element in the result is the dot product of the i-th row of A and x.

Eigenvalues and Eigenvectors

Let λ != 0 be any real number, A be an m x n matrix, and x != 0 be a size-n vector (not the number 0, but the 0-vector, which contains all zeros). Then, if Ax = λx, we say that x is an eigenvector of A corresponding to λ, and similarly, we say that λ is an eigenvalue of A corresponding to x.

Determining Eigenvectors

It's easy to determine if x is an eigenvector of A. Simply check if Ax is a scalar multiple of x, which also gives us the corresponding eigenvalue λ. However, it is harder to find eigenvectors than to check it a vector is one.

Finding Eigenvalues

Conversely, it's easier to find the eigenvalues but harder to check if a value is one, which is fortunate for this challenge. Firstly, we must look at determinants.

Determinants

The determinant of a 2 x 2 matrix [[a, b], [c, d]] is ad - bc. This is a specific definition of the determinant, so in order to explain the recursive definition of a determinant, I will say that the determinant of a 1 x 1 matrix is that value. Note that only square matrices have a determinant.

The recursive definition of a determinant

In order to give the recursive definition of a determinant, I first need to explain what A(i,j) means. A(i,j) is the matrix formed by removing the i-th row and the j-th column from A; thus, if A is an n x n matrix, A(i,j) is an n-1 x n-1 matrix. Thus, we recursively define the determinant of an n x n matrix A, which we call det A, as sum x=1->n (-1)^(x+1)*(det A(1,n)). In other words, we go down the left-most column and take the values obtained from multiplying this value with the matrix formed by taking out the row and column it is in, and then alternate adding and subtracting those values. See the Wikipedia link for more information. This definition is recursive.

Also note that we do not have to expand on the left-most column, we can also expand on any column or any row.

So, how do determinants help us?

Well, I'm not going to prove it, but if we have C(λ) = 0, then λ is an eigenvalue of A. C is the characteristic polynomial function, which is gives the determinant of A - λI, where λI is scalar-multiplication between scalar λ and the Identity Matrix I, which has all 1s on its main diagonal and 0s everywhere else.

So, given an eigenvalue λ, we can find the RREF of A - λI. Let this matrix be M. Then, the eigenspace of λ corresponding to A is the set of all vectors x such that Mx is the zero-vector.

We have finally arrived at the task. Your task is to output, for each eigenvalue, a basis of the corresponding eigenspace.

Linear Combination

A linear combinations of vectors x1, x2, ..., xn with scalars s1, s2, ..., sn is s1x1 + ... + snxn. When adding vectors, you add each individual element.

Spanning Set

S is a spanning set of B if and only if every vector in B can be written as a linear combination of S with any real numbers as scalars.

Linearly Independent Set

L is a linearly independent set if and only if no vector is a linear combination of the other vectors (thus L cannot contain the zero-vector), and it is linearly dependent otherwise.

Basis: a linearly independent spanning set

A basis is simply a spanning set that's linearly independent. All possible bases will have the same number of vectors (proof omitted).

The Challenge

Now that you hopefully understood my explanations, we arrive at the following challenge:

Given an n x n matrix with 0 < n <= 20, for each eigenvalue (there will be at most n distinct ones), output a basis for the eigenspace of the eigenvalue. You can choose whether or not to output duplicates. You can choose the format for input and output within reasonable conditions. My recommendation is a 2D array for input and a 3D array for output. The input matrix is guaranteed to have only real eigenvalues, and is guaranteed to be square.

I will add test cases if this challenge is posted because test cases are quite hard to create for this challenge!

Fun Fact: "eigen" means "special" in German!

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

Find all the triples!

Your task is, given a number n, find all the Pythagorean triples containing that number, and output a list of the terms in each Pythagorean triple which is not n, without repeats and in ascending order.

For example, given 8 as an input, there are two Pythagorean triples which contain 8:

6 8 10
8 15 17

The terms in each Pythagorean triple (without 8) are:

6 10 15 17

Because this set doesn't have repeats and is in ascending order, we can output just that.

You must write a program or function that takes one input, and your output can either be your language's representation of a list, or a string with any delimiter. So these outputs for 8 are all valid:

[6 10 15 17]    (Clojure list)
[6, 10, 15, 17] (Python list)
6 10 15 17      (uses space delimiter)
6#10#15#17      (uses "#" delimiter)

Rules and Specs:

  • You are guaranteed that the input is a positive integer.
  • Your program must return the correct output for 3600 in 60 seconds. This is the same amount of time as TIO timing out. The output for 3600 should be:

    147 380 425 660 810 1008 1050 1204 1342 1500 1755 1920 2160 2240 2415 2700 2880 2886 3190 3250 3456 3570 3603 3620 3625 3660 3690 3750 3780 3796 3842 3900 4005 4080 4125 4240 4335 4352 4500 4559 4614 4800 4810 4850 5049 5070 5220 5460 5475 5648 5809 5980 6000 6201 6270 6540 6750 6980 7068 7230 7595 7650 7700 7932 8265 8405 8500 8640 9015 9360 9676 9805 10324 10445 10500 10962 11100 11538 11730 12270 12710 13210 13260 13740 14175 14625 14784 15216 16000 16400 16683 17067 17820 18180 19838 20090 20162 20410 21450 21750 22356 22644 23865 24135 25795 26045 26880 27120 29892 30108 32300 32500 33654 33846 35910 36090 39919 40081 40420 40580 43125 43275 44928 45072 50561 50689 53940 54060 59946 60054 64750 64850 67452 67548 71955 72045 80960 81040 89964 90036 101218 101282 107970 108030 119973 120027 129575 129625 134976 135024 161980 162020 179982 180018 202484 202516 215985 216015 269988 270012 323990 324010 359991 360009 404992 405008 539994 540006 647995 648005 809996 810004 1079997 1080003 1619998 1620002 3239999 3240001
    

This is , so shortest code in bytes wins!

\$\endgroup\$
  • \$\begingroup\$ 1) What should be returned for numbers which don't show up in any Pythagorean triple? 2) I'm not sure the sorting adds anything to the challenge. 3) You didn't state a winning criterion yet. \$\endgroup\$ – Laikoni Mar 12 '17 at 18:38
  • \$\begingroup\$ @Laikoni 1) All numbers (except for 1 and 2) should have Pythagorean triples. 2) I can get rid of it, if you want. 3) Fixed. \$\endgroup\$ – clismique Mar 13 '17 at 8:43
  • \$\begingroup\$ What about 0? With the current spec I think it should be in every output. \$\endgroup\$ – Peter Taylor Mar 13 '17 at 13:58
0
\$\begingroup\$

Make a 'Logical' interpreter

'Logical' is an esoteric language I am working on.

It involves 4 logic gates, AND(&), OR(|), NOT(!) and XOR(^).

Since only having 4 logic gates, the IO is only true or false (We are not discussing Qubits here :P)

It will have some lines in the format [input 1] [(not included in not gates) input 2] [output] [gate], showing which node is connected to which logic gate. For example, 1 2 3 & would mean node 1 and 2 are connected to an AND gate, and the output goes to node 3.

During the interpretation, it should get the status of the input nodes(nodes which are only connected to an input of a logic gate) as an array of tuples. For example, [[1,true][2,true]] is a valid input for the program 1 2 3 &.

Then the interpreter should output the result of the output nodes(nodes which are only connected to an output of a logic gate), also as an array of tuples. For example, [[3,true]] is the output for 1 2 3 when given the input [[1,true],[2,true]].

Examples

[Too long, pastebin coming soon]

Rules

  • No logic gates will be given one or more input nodes as same as their output nodes.
  • A blank program is invalid, thus will not be given.

OP's note

I have clearly made this esolang for fun, but I hope it will be on some challenges, or make people understand more on logic gates.

\$\endgroup\$
  • \$\begingroup\$ The language is missing quite some specification. You give syntax for a program consisting of one gate, but how do programs with multiple gates look? \$\endgroup\$ – Laikoni Mar 13 '17 at 12:52
  • \$\begingroup\$ 1 2 3 & 3 2 ! doesn't violate the constraint "No logic gates will be given one or more input nodes as same as their output nodes" but it does give an unstable circuit. \$\endgroup\$ – Peter Taylor Mar 13 '17 at 14:51
  • \$\begingroup\$ @PeterTaylor Is that a flip-flop? \$\endgroup\$ – fəˈnɛtɪk Mar 13 '17 at 15:41
  • \$\begingroup\$ @fəˈnɛtɪk, no. A flip-flop settles into a stable state, whereas an AND whose output feeds via a NOT into one of its inputs can only settle into a stable state when the other input is 0. \$\endgroup\$ – Peter Taylor Mar 13 '17 at 16:08
0
\$\begingroup\$

All your base are belong to us 6 * 9 = 42

When Douglas Adams wrote THHGTTG, he just made up a formula for the answer to Life, the Universe and Everything. And then some spoilsport pointed out that it was a valid formula... when interpreted in base 13.

Given an input formula, please output as many bases as you can find where the formula is valid.

You must at a minimum support base 10 to base 16 inclusive, but you are strongly recommended to support base 2 to at least base 36.

You must at a minimum support the ()*+= operators, but you are strongly recommended to support - and /, and either ** or ^ for exponentiation. Note that the division will always be exact in valid bases, but may not be exact in invalid bases, so for 11/2=8 you should only output 15.

Examples

11/2=8
15

10+10=10*10
2

6*9=42
13

11**11=2101
3

This is , so the shortest answer that breaks no standard loopholes wins.

\$\endgroup\$
  • \$\begingroup\$ As Many Bases as possible seems, annoying... \$\endgroup\$ – ATaco Mar 14 '17 at 1:52
  • 2
    \$\begingroup\$ "You must at minimum do this, but you are strongly recommended to also do that" doesn't sound like a great formula for challenges... I'd try to choose a fixed set of requirements and stick to that. \$\endgroup\$ – Leo Mar 14 '17 at 10:26
0
\$\begingroup\$

Monitor your ARP table

This is

The Address Resolution Protocol is used to associate IP addresses on the local network with hardware addresses (aka MAC addresses). In its most basic form, ARP can be very insecure in the sense that your computer will believe anyone on the local network that says "Hey, this IP and this MAC go together!". This can be used maliciously, so we want to keep an eye on our ARP caches.

Your task is to create a program that monitors your ARP cache and alerts you when changes have been made.

Task

Write a program that does the following:

  • On initial execution, reads in the operating system's ARP table.
  • With a frequency between once per second and once per ten seconds (inclusive), checks the operating system's ARP table for changes and prints something, as described immediately below:

-- If there is no change, print this exact string (with one or two trailing new lines):

No Change

-- If a new entry has appeared in the cache, print the string (with one or two trailing new lines):

New Entry: <IP ADDRESS> --> <MAC ADDRESS>

where <IP ADDRESS> is the IP address of the new entry (formatted as described below) and <MAC ADDRESS> is the MAC of the new entry (formatted as described below).

-- If any entry has changed to a new MAC (meaning an IP address is now being associated with a different MAC address) print the string (with one or two trailing new lines):

!!! Possible Malicious Change: <IP ADDRESS> --> <NEW MAC ADDRESS> from <OLD MAC ADDRESS>

where <IP ADDRESS> is the IP whose entry has changed (formatted as below), <NEW MAC ADDRESS> is the new MAC (formatted as below), and <OLD MAC ADDRESS> is the old MAC (formatted as below)

-- If any entry has changed to a to <incomplete> (meaning an IP address is now being associated with nothing) print the string (with one or two trailing new lines):

Entry incomplete: <IP ADDRESS> --> <incomplete> from <OLD MAC ADDRESS>

where <incomplete> is a literal.

--- If an entry is now missing, print the string (with one or two trailing new lines):

Entry for <IP ADDRESS> (<MAC ADDRESS>) is gone.

  • The program repeats until terminated.

Formatting

IP addresses have 4 octets that are dot separated. They may be formatted in either of the following fashions:

  • in hex: e.g. 02.22.DC.FD, leading zeros MUST be included, alphabetical digits may be capital or lowercase, as long as cases are not mixed within a single IP address.
  • in decimal: e.g. 22.54.198.9, leading zeros MUST NOT be included.

MAC addresses have 6 octets that are colon separated and must be formatted in the following fashion:

  • in hex: e.g. 0F:CD:12:44:22:F1, leading zeros must be included, alphabetical digits may be capital or lowercase, as long as cases are not mixed within a single IP address.

A MAC address can also be a string literal to the effect of "incomplete" or "unknown" if that is what is in your arp cache. If it is, this should be used literally instead of an actual MAC address.

Operating System Differences

The three major operating systems (Mac, Linux, Windows) all use ARP and I'm fairly certain that all other modern OS's do as well. Your program need only run on a SINGLE operating system, to be specified in your submission header by its main type (e.g. Linux) and in your submission body by a fuller identifier (e.g. Centos 6.5). We will view each OS as it's own competition.

Testing things

The following commands will change your ARP table on Linux (and Mac?).

Add a (static) entry or overwrite an existing entry: arp -s <IP> <MAC>, e.g. arp -s 2.2.2.2 ab:cd:ef:12:34:56

Delete an entry: arp -d <IP>, e.g. arp -d 2.2.2.2

Flush all: ip neighbor flush all

\$\endgroup\$
  • \$\begingroup\$ Is there an easier way to test submissions than building a local network with multiple devices? \$\endgroup\$ – Laikoni Mar 12 '17 at 18:48
  • \$\begingroup\$ @Laikoni yes (at least on linux), static entries can be added to the table using arp -s. I'm sure there is something similar on other OS's. \$\endgroup\$ – Liam Mar 12 '17 at 18:51
  • \$\begingroup\$ That's good to know. You could add a test script which triggers the different outputs to make the challenge a bit more accessible. \$\endgroup\$ – Laikoni Mar 12 '17 at 18:58
0
\$\begingroup\$

Golf you a make you an N-quine for great good for great good

Introduction

Although quines are interesting on their own, they've been explored to death. Quines with strange properties, such as palindromic quines, are also pretty interesting, but each of those challenges are basically one-shots. How about a challenge to create a program that creates quines?

Instructions

Let's call an N-quine a program that prints its source code N times. The program is allowed to print newlines between each copy of the program. For example, any normal quine is a 1-quine. In python 3,

s='s=%r;print(s%%s);print(s%%s);';print(s%s);print(s%s)

is a 2-quine.

The challenge is to write a program that takes a number as input (call it N) and outputs the source code for an N-quine in the same language.

Programs will be scored by their length plus the length of the output when you put in 1. This is , so the shortest program wins.

Example

One virtually ungolfed Python 3 answer (69 characters):

n=int(input());print("s='s=%r;"+"print(s%%s);"*n+"'"+";print(s%s)"*n)

If you input 1, it prints (32 characters):

s='s=%r;print(s%%s);';print(s%s)

So the final score is 69+32=101.

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

Nearly-match a string

Our near miss algorithm is too slow. The boss is blaming the Levenshtein distance builtin for being overkill for our purpose as we're only interested in a distance of 1. Please code something leaner.

Input: Two different strings, in any reasonable format. At least 36 different characters should be supported.

Output: A truthy/falsy value which distinguishes between strings with a Levenshtein distance of 1 or more than 1.

This is , so the shortest program or function that breaks no standard loopholes wins! Builtins that calculate the Levenshtein distance are not allowed.

\$\endgroup\$
  • \$\begingroup\$ What's the rationale for choosing 36 in "at least 36 different characters"? \$\endgroup\$ – DLosc Mar 18 '17 at 20:29
  • \$\begingroup\$ [a-z0-9], perhaps? \$\endgroup\$ – Greg Martin Mar 18 '17 at 22:01
  • \$\begingroup\$ The back story actively contradicts the scoring criterion. Golfed answers are likely to be much slower than the builtin. \$\endgroup\$ – Peter Taylor Mar 22 '17 at 14:52
  • \$\begingroup\$ @PeterTaylor Surely that depends on the language. I suspect a C answer for the specific challenge would outspeed any generic library. \$\endgroup\$ – Neil Mar 22 '17 at 16:41

You must log in to answer this question.

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