572
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4648 Answers 4648

1
138 139
140
141 142
155
0
\$\begingroup\$

golf a range with modulus and subtraction

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

Output a 1-digit integer log table

Log tables were originally used for multiplication, since \$ x \times y = \exp(\log x + \log y) \$, superseding the use of trigonometric functions for this purpose. A log table I used in school back in the day had 900 main entries and then some interpolation entries you could use to give yourself almost an extra digit of accuracy.

However, if you were building a mechanical computer, you wouldn't need to have thousands of entries, as you could just program it to do long multiplication; the stumbling block is actually multiplying two digits together in the first place.

One approach to this is to use something called an Irish logarithm table. This is basically a pair of integer mappings \$ f \$ and \$ g \$ such that \$ g(f(x) + f(y)) = x \times y \$ for all \$ x, y \in \{ 0..9 \} \$.

For this challenge I would like you to output any two integer mappings with that property, in any reasonable format. In particular, since the length of the f mapping is always ten, there is no need to separate the f and g mappings in your output.

Note that while the f mapping maps from 0 to 9, the g mapping will have gaps because some of its indices won't correspond to the sum of two values of f. You can handle this either by outputting the mapping as a dictionary or by padding the output array with a suitable filler value.

Excluding the filler value, the g mapping only needs to output the values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36, 40, 42, 45, 48, 49, 54, 56, 63, 64, 72, 81.

This is , so the shortest program or function that breaks no standard loopholes wins!

\$\endgroup\$
9
  • \$\begingroup\$ Any potentially shorter way than log(x)*999? \$\endgroup\$
    – l4m2
    Dec 31, 2023 at 0:41
  • \$\begingroup\$ @l4m2 What integer are you using for an input of 0? \$\endgroup\$
    – Neil
    Dec 31, 2023 at 0:59
  • \$\begingroup\$ Also, I can see I should have specified non-negative integers. \$\endgroup\$
    – Neil
    Dec 31, 2023 at 1:03
  • \$\begingroup\$ And I might need to include the highest index of g in the scoring somehow. \$\endgroup\$
    – Neil
    Dec 31, 2023 at 1:04
  • \$\begingroup\$ Is there a reason for outputting mappings and not just implementing the functions? \$\endgroup\$ Dec 31, 2023 at 4:30
  • \$\begingroup\$ @CommandMaster It's to help you construct a mechanical calculator which can do lookup tables but not function calls. \$\endgroup\$
    – Neil
    Dec 31, 2023 at 8:18
  • \$\begingroup\$ I just don't think that requiring answers to do return [f(i) for i in range(10)] is interesting - do you have solutions constructing these mappings in a different way? \$\endgroup\$ Dec 31, 2023 at 9:12
  • \$\begingroup\$ @CommandMaster I wasn't expecting there to be a closed form for f and g; if you have one then this question becomes irrelevant. \$\endgroup\$
    – Neil
    Dec 31, 2023 at 9:41
  • \$\begingroup\$ There is discrete log mod 83, although that isn't really a closed form and you need to do something for 0 \$\endgroup\$ Dec 31, 2023 at 10:11
0
\$\begingroup\$

Golf golfing a range with modulus and subtraction

In this other question I asked you to golf code which finds an equation transforming a list of unique numbers down to a minimal list. For this question, I'm asking you to write code which golfs that equation. In the other question we found that ((l-5)%99-94)%98 is a valid equation that turns l=[2,1,5,3,99,7,6] into [2,1,4,3,0,6,5], but if we do some more thinking, we can see that there are shorter ways to do this: (l%91-5)%8 gives the list [5,4,0,6,3,2,1] and l%95-1 gives the list [1,0,4,2,3,6,5]. Rather than golfing the code used to generate the equation, in this question you are looking for an algorithm that produces the shortest final equation.

To be a valid answer, your code must give an equation that transforms a provided list of unique, non-negative integers into a list of unique, non-negative integers in the range 0 to len(list)-1. You are scored for the length of the equation that you output rather than the length of your code. Each operation is one point, so an output of ((l-5)%99-94)%98 would score 4, (l%91-5)%8 would score 3, and l%95-1 would score 2. In a tie, the score is the character length of the complete equation including parenthesis, so ((l-5)%99-94)%98 would score 16, (l%91-5)%8 would score 10, and l%95-1 would score 6. Lowest score wins, as with normal code golf.

Different lists may give better scores using some algorithms over others, so we need to test your code to be sure that it is the best for many different lists. The score you list on your answer is the average score your code gets on all lists of 1-15 digits with values in the range 0-63 (say the average primary and secondary score in your answer). As this question is about the algorithm rather than the code length, you should explain your method as well. If you can prove that your method will always give the best possible score, I will mark your answer as accepted and (if it's simple enough) use your method as the example explanation in the other question. If this happens, I will also edit this question to include an explanation of your algorithm and this question will become a normal code-golf question where everyone implements that algorithm or an equivalent in as few bytes as possible in each language.

As the lists your code is tested against are finite in length and have a maximum value, you could theoretically brute-force the shortest solution by trying every possible modulus and subtraction value and returning the shortest. To prevent this, your code should run in less than O(r^l) time, where r is the range and l is the length.

@sandbox, What do you think is a good range? Should it be 1-7 digits, 1-31 digits? Values from 0-31, values from 0-127? Or should it be decimal ranges, 1-9 digits ranging from 0-99?

Also, what other tags?

\$\endgroup\$
6
  • \$\begingroup\$ Is there anything preventing solutions from doing a boring, trivially optimal, bruteforce solution? \$\endgroup\$ Dec 23, 2023 at 2:48
  • \$\begingroup\$ @CommandMaster do you think that looks good for preventing bruteforce solutions? \$\endgroup\$
    – guest4308
    Dec 24, 2023 at 4:33
  • 1
    \$\begingroup\$ Requiring to build the equation one operand at a time seems overly restrictive, and it's also not very clearly defined. What kind of calculations can you do on the array, before you actually "build" the solution? \$\endgroup\$ Dec 24, 2023 at 4:56
  • \$\begingroup\$ @CommandMaster yeah, I think that worked better in my head than it would in practice. I can't think of any other way to restrict bruteforce solutions without also restricting algorithmic solutions, do you have any ideas? or if not; is it fine to just have 'the brute force solution does not count' in the question? \$\endgroup\$
    – guest4308
    Dec 24, 2023 at 5:03
  • \$\begingroup\$ I think the best way to prevent brute force would just be to restrict the runtime, and have larger inputs \$\endgroup\$ Dec 24, 2023 at 5:04
  • \$\begingroup\$ @CommandMaster do you think that works to prevent bruteforce? and also for larger inputs what were you thinking would be a good amount? I think rn it's checking around 2e14 lists \$\endgroup\$
    – guest4308
    Dec 26, 2023 at 14:59
0
\$\begingroup\$

Unnecessary fluff

Sandbox note

There is a fairly efficient way to calculate this \$h\$, which might be interesting. Do you think I should require polynomial time, or being able to calculate all the testcases in a minute?

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

Shortest path to open a letter lock

\$\endgroup\$
4
  • \$\begingroup\$ I think this is easier than you intend it to be, but fair enough. Can the input be taken as a list of indices of the alphabet rather than a string / list of codepoints? \$\endgroup\$
    – noodle man
    Jan 6 at 22:45
  • \$\begingroup\$ @noodleman i think that would ruin the theme here, i wasnt even sure if i should include the list of letters instead of the full string \$\endgroup\$
    – pacman256
    Jan 7 at 0:06
  • 1
    \$\begingroup\$ Well, taking a string as a list of characters is an I/O default on this site. I would personally recommend letting letters of the alphabet be taken as indices, as that's just an extra step that most solutions will have to use and could be very long in some languages. Alternatively, a slightly more interesting variant of this challenge would be to take an arrangement of the alphabet as input (like abc...z or azbycx... or ajoifqw...) rather than always using the same alphabet. \$\endgroup\$
    – noodle man
    Jan 7 at 1:34
  • \$\begingroup\$ @noodleman From what I have seen, allowing letters to be replaced with indices is generally not an option for input in challenges like this, especially when the whole point is to have two "words" to switch between \$\endgroup\$
    – pacman256
    Jan 7 at 4:55
0
\$\begingroup\$

Circle to split points

Given two sets of points, decide whether there's a circle that split them.

  • Treating points exactly on circle as inside or outside are allowed as radius +/-eps

  • Maybe one input forced inside and one outside?

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

The Elements Of The Periodic Table!

The challenge is to take input as an integer between 1 and 118 inclusive, then output the name of the chemical element with that atomic number.

Capitalisation as well as trailing and leading whitespace do not matter.

You should call the chemical elements by their 2024 names, for example 113 outputs nihonium and not ununtrium.

For ease of golfing, element 16 can be either sulfur or sulphur.

Test cases:

1 -> hydrogen
2 -> helium
3 -> lithium
4 -> beryllium
5 -> boron
6 -> carbon
117 -> tennessine
118 -> oganesson

Use any language, shortest code in bytes wins.

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

Find the child anagrams of a word

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

Battle Simulator KOTH

Challenge

In this king-of-the-hill challenge, each player/bot is assigned a random character and is then put in a 10x10 grid. Each character has 2 different abilities and 1 ultimate ability. The goal of each player is to be the last man standing.

Rules

At the start of each game, each bot is given 10 health and 10 points to freely distribute through these 3 categories:

Speed (for example if you have three speed you can go up 2 and left 1 in one turn)

Dexterity (the more dexterity you have the less chance you have of getting hit by an attack. For example if you have 3 dexterity and was attacked by an attack that does 4 damage, there is a 3 * 3 = 9% chance you dodge it where the second 3 is a constant.)

Defense (let's say you have 3 defense and was hit by an attack that does 5 damage. Then you will take a random amount of damage from 1 to 1 where the second 1 is attack strength - defense / 2)

Each bot is also randomly assigned one of these two characters:

Swordsman:

  • Normal ability (Stab):
    • 0 (turns of) recharge
    • does 1 damage
    • hits the three tiles in front of him
  • Special ability 1 (Circle Slash):
    • 2 recharge
    • does 2 damage
    • hits the 9 tiles surrounding him
  • Special ability 2 (Multi-Sword):
    • 4 recharge
    • does 2 damage
    • hits the three closest enemies
  • Ultimate Ability (Explosion):
    • 10 recharge (cannot be used at beginning of game)
    • does 6 damage
    • hits the first player in front of him and triggers a 6x6 explosion

Wizard

  • Normal ability (Burn):
    • 0 recharge
    • does 2 damage
    • hits the tile directly in front of him
  • Special ability 1 (Freeze):
    • 3 recharge
    • does 1 damage
    • freezes the first enemy in front of him for 2 turns
  • Special ability 2 (Zap):
    • 5 recharge
    • does 2 damage
    • zaps the five closest enemies, twice
  • Ultimate ability (Weaken):
    • 15 recharge (cannot be used at the beginning of game)
    • 0 damage
    • halves all stats of all other players (can stack)

However, there is a twist. Each bot does NOT know what character type they are.

Turns

Each turn, every player does one of the following:

  • Do nothing (lol)
  • Use an attack that is not on cooldown (attacks can miss)
  • Move

When a player is hit by an attack, their health goes down by how strong the attack is and is also hit by status effects should the attack have them. If a player's health reaches zero, they are defeated (e. g. removed from the game) and are replaced by a rock other players may not pass through. If a player tries to move through a rock or another player, they simply end up in front of it and do not go through.

The game ends in 100 turns or only one player remains, whichever comes first. If the game lasts that long, the winner is the one with most eliminations. If there still is a tie, all tied bots receive a point for that round. Of course, if only one player remains before the 100 turns, that player wins the round and gets a point.

How bots work

Bots should be written in Python, but I will try to support other mainline languages by translating them into Python.

The basic boilerplate code for a bot is this:

class MyBotThatWillHopefullyWin(Bot):
    def __init(self)__:
        super().__init__(self, <speed>, <dexterity>, <defense>)
    
    def turn():
        <insert logic>

The turn function is basically your main function and will be executed for every turn your bot is alive for. It should return one of four values:

  • return "move", <x>, <y> to move (duh.) Or in more specific terms, Tuple[Union[str, Union[int, int]]] where str must be move and abs(x + y) must be <= self.speed (the first value you put in the super definition.) If this condition is not satisfied, nothing happens that turn. Note how you cannot leave the confines of the 10x10 grid or move and attack or vice versa in the same turn.

  • return "basic attack" to do the (randomly predetermined) charector's basic attack.

  • return "ability", <ability number> to do one of the charector's abilities. 1 is the charector's first special ability, 2 is the second, and 3 is the ultimate ability. If the ability numberis not in the range 1-3 or the attack is still on cooldown, nothing happens.

  • return "nothing" to do nothing. But why tho?

Here is the list of methods bots have available to them: (accessed by self.<method name(<parameters, if any>)

\$\endgroup\$
2
  • \$\begingroup\$ What do players know? Only the location of enemies and whether they're dead, and their own health? \$\endgroup\$ Jan 18 at 3:44
  • \$\begingroup\$ @CommandMaster I'll add that in when I have the time. \$\endgroup\$ Jan 18 at 14:56
0
\$\begingroup\$

ahee bee cee dee ehee fee...

Given a string with no whitespace, replace the first letter of the string with every letter in the english lowercase alphabet. However, if the input string starts with a vowel (excluding y), then there should be an extra h after (the prefixes aeiou.)

For example, if the input string is ee, your program should output:

ahe
be
ce
de
ehe
fe
ge
he
ihe
je
ke
le
me
ne
ohe
pe
qe
re
see
te
uhe
ve
we
xe
ye
ze
\$\endgroup\$
2
  • \$\begingroup\$ Where do eht come? \$\endgroup\$
    – l4m2
    Jan 22 at 2:35
  • \$\begingroup\$ @I4m2 Should be fixed now. \$\endgroup\$ Jan 22 at 14:28
0
\$\begingroup\$

What are the current football (soccer) league positions?

English football is structured into leagues with varying numbers of clubs. For example, the EFL Championship has 24 clubs. During each season, each side will play every other side twice (once at home and once away); for a 24-club league, this gives 46 matches for each team in total. Teams score three points for a win, one for a draw and none for a loss. The ranking in the league is determined by:

  1. Points gained
  2. Goal difference
  3. Goals scored
  4. Head-to-head record
  5. Alphabetical order (unless the position is relevant for a promotion, relegation or play-off space, but this has never happened, and will not need to be handled for this challenge)

Challenge

Input

  • A list of games played so far in the league, indicating the home team, away team, score for the home team and score for the away team.

Desired output

  • A list of teams in position order, either highest to lowest or lowest to highest (but must be consistent for all inputs).

Rules and assumptions

  • Teams can be represented in whatever way the answerer prefers. You may take actual team names, integers, or any other standard input provided the team name does not somehow encode its position in the league and none of the default loopholes are violated. Team names in the output should match those in the input.
  • All teams in the league will have played at least once at the time of asking, though they will not necessarily have all played each other by that stage, nor will they have necessarily played the same number of matches. Of note, the interim league tables for English football show the number of matches played, but the relative positioning does not take into account that one team may have matches in hand.
  • You do not need to provide any of the stats typically presented in a football league table, just the ordering of teams.
  • Default loopholes and standard I/O methods apply
  • Although input is flexible, the home/away ordering should be preserved (so it is not valid to require the winning team always be listed first)
  • This is so the shortest code in bytes wins!

Example input

[
[["Leeds United",2],["Preston North End",1]],
[["Plymouth Argyle",3],["Cardiff City",1]],
[["Middlesbrough",1],["Rotherham United",1]],
[["Norwich City",2],["West Bromwich Albion",0]],
[["Stoke City",1],["Birmingham City",2]],
[["Queens Park Rangers",2],["Millwall",0]],
[["Sheffield Wednesday",1],["Coventry City",2]],
[["Blackburn Rovers",1],["Huddersfield Town",1]],
[["Bristol City",1],["Watford",1]],
[["Swansea City",1],["Southampton",3]],
[["Sunderland",0],["Hull City",1]],
[["Queens Park Rangers",1],["Watford",2]],
[["Ipswich Town",2],["Sunderland",1]],
[["Millwall",1],["Middlesbrough",3]],
[["Rotherham United",0],["Stoke City",1]],
[["Southampton",4],["Sheffield Wednesday",0]],
[["West Bromwich Albion",4],["Blackburn Rovers",1]],
[["Huddersfield Town",1],["Plymouth Argyle",1]],
[["Cardiff City",0],["Leeds United",3]],
[["Birmingham City",2],["Swansea City",2]],
[["Preston North End",2],["Bristol City",0]],
[["Coventry City",3],["Leicester City",1]],
[["Hull City",1],["Norwich City",2]],
[["Sheffield Wednesday",3],["Hull City",1]],
[["Norwich City",1],["Southampton",1]],
[["Blackburn Rovers",2],["Rotherham United",2]],
[["Bristol City",0],["Millwall",1]],
[["Leeds United",3],["Birmingham City",0]],
[["Leicester City",4],["Huddersfield Town",1]],
[["Middlesbrough",1],["Coventry City",3]],
[["Plymouth Argyle",3],["Watford",3]],
[["Stoke City",0],["Ipswich Town",0]],
[["Swansea City",1],["West Bromwich Albion",0]],
[["Queens Park Rangers",1],["Cardiff City",2]],
[["Sunderland",2],["Preston North End",0]],
[["West Bromwich Albion",1],["Leeds United",0]],
[["Ipswich Town",0],["Queens Park Rangers",0]],
[["Cardiff City",0],["Leicester City",2]],
[["Coventry City",2],["Swansea City",2]],
[["Huddersfield Town",1],["Middlesbrough",2]],
[["Hull City",3],["Blackburn Rovers",2]],
[["Rotherham United",1],["Sunderland",1]],
[["Millwall",1],["Norwich City",0]],
[["Preston North End",0],["Sheffield Wednesday",1]],
[["Watford",1],["Stoke City",1]],
[["Birmingham City",0],["Bristol City",0]],
[["Southampton",2],["Plymouth Argyle",1]],
[["Ipswich Town",1],["Leicester City",1]],
[["Birmingham City",1],["Stoke City",3]],
[["Rotherham United",1],["Middlesbrough",0]],
[["Southampton",5],["Swansea City",0]],
[["Hull City",0],["Sunderland",1]],
[["Huddersfield Town",3],["Blackburn Rovers",0]],
[["Coventry City",2],["Sheffield Wednesday",0]],
[["Cardiff City",2],["Plymouth Argyle",2]],
[["West Bromwich Albion",1],["Norwich City",0]],
[["Watford",1],["Bristol City",4]],
[["Millwall",2],["Queens Park Rangers",0]],
[["Preston North End",2],["Leeds United",1]],
[["Stoke City",0],["Millwall",0]],
[["Sunderland",0],["Coventry City",3]],
[["Sheffield Wednesday",1],["Cardiff City",2]],
[["Leicester City",3],["Rotherham United",0]],
[["Queens Park Rangers",0],["Southampton",1]],
[["Plymouth Argyle",3],["Birmingham City",3]],
[["Norwich City",2],["Huddersfield Town",0]],
[["Middlesbrough",1],["West Bromwich Albion",0]],
[["Blackburn Rovers",1],["Watford",2]],
[["Leeds United",4],["Ipswich Town",0]],
[["Swansea City",2],["Preston North End",1]],
[["Bristol City",3],["Hull City",2]],
[["Birmingham City",2],["Leicester City",3]],
[["West Bromwich Albion",1],["Stoke City",1]],
[["Plymouth Argyle",3],["Rotherham United",2]],
[["Swansea City",1],["Middlesbrough",2]],
[["Southampton",4],["Blackburn Rovers",0]],
[["Sheffield Wednesday",2],["Queens Park Rangers",1]],
[["Preston North End",1],["Watford",5]],
[["Millwall",1],["Huddersfield Town",1]],
[["Leeds United",1],["Coventry City",1]],
[["Hull City",3],["Cardiff City",0]],
[["Bristol City",1],["Sunderland",0]],
[["Ipswich Town",2],["Norwich City",2]],
[["Middlesbrough",1],["Hull City",2]],
[["Cardiff City",0],["Birmingham City",1]],
[["Coventry City",1],["Southampton",1]],
[["Norwich City",3],["Sheffield Wednesday",1]],
[["Leicester City",3],["Millwall",2]],
[["Queens Park Rangers",0],["Plymouth Argyle",0]],
[["Sunderland",1],["Leeds United",0]],
[["Watford",1],["Ipswich Town",2]],
[["Stoke City",1],["Swansea City",1]],
[["Rotherham United",0],["West Bromwich Albion",2]],
[["Huddersfield Town",1],["Preston North End",3]],
[["Blackburn Rovers",2],["Bristol City",1]],
[["Norwich City",0],["Preston North End",0]],
[["Cardiff City",1],["Millwall",0]],
[["Leicester City",4],["Plymouth Argyle",0]],
[["Middlesbrough",0],["Ipswich Town",2]],
[["Huddersfield Town",1],["Bristol City",1]],
[["Queens Park Rangers",2],["Hull City",0]],
[["Stoke City",0],["Sheffield Wednesday",1]],
[["Watford",1],["Southampton",1]],
[["Rotherham United",1],["Swansea City",2]],
[["Sunderland",2],["West Bromwich Albion",1]],
[["Blackburn Rovers",0],["Leeds United",2]],
[["Coventry City",2],["Birmingham City",0]],
[["Bristol City",1],["Norwich City",2]],
[["Millwall",1],["Sunderland",1]],
[["Birmingham City",0],["Rotherham United",0]],
[["Hull City",1],["Watford",2]],
[["Ipswich Town",2],["Coventry City",1]],
[["Leeds United",3],["Middlesbrough",2]],
[["Swansea City",1],["Huddersfield Town",1]],
[["Plymouth Argyle",2],["Stoke City",1]],
[["Sheffield Wednesday",3],["Blackburn Rovers",1]],
[["Southampton",2],["Cardiff City",0]],
[["West Bromwich Albion",1],["Leicester City",2]],
[["Preston North End",0],["Queens Park Rangers",2]],
[["Ipswich Town",3],["Millwall",1]],
[["Blackburn Rovers",4],["Birmingham City",2]],
[["Leeds United",3],["Swansea City",1]],
[["Sheffield Wednesday",1],["Leicester City",1]],
[["Southampton",1],["Bristol City",0]],
[["Sunderland",1],["Huddersfield Town",2]],
[["Watford",3],["Norwich City",2]],
[["Queens Park Rangers",4],["Stoke City",2]],
[["Middlesbrough",4],["Preston North End",0]],
[["Hull City",4],["Rotherham United",1]],
[["Coventry City",1],["Plymouth Argyle",0]],
[["Cardiff City",0],["West Bromwich Albion",1]],
[["West Bromwich Albion",2],["Ipswich Town",0]],
[["Millwall",0],["Coventry City",3]],
[["Birmingham City",2],["Sheffield Wednesday",1]],
[["Bristol City",3],["Middlesbrough",2]],
[["Huddersfield Town",1],["Southampton",1]],
[["Leicester City",2],["Watford",0]],
[["Norwich City",1],["Queens Park Rangers",0]],
[["Preston North End",1],["Cardiff City",2]],
[["Stoke City",0],["Blackburn Rovers",3]],
[["Swansea City",2],["Hull City",2]],
[["Plymouth Argyle",2],["Sunderland",0]],
[["Rotherham United",1],["Leeds United",1]],
[["Cardiff City",2],["Norwich City",3]],
[["Leeds United",2],["Plymouth Argyle",1]],
[["Coventry City",0],["Stoke City",0]],
[["Hull City",1],["Huddersfield Town",0]],
[["Ipswich Town",3],["Swansea City",2]],
[["Southampton",2],["West Bromwich Albion",1]],
[["Middlesbrough",1],["Leicester City",0]],
[["Queens Park Rangers",0],["Bristol City",0]],
[["Sheffield Wednesday",0],["Millwall",4]],
[["Watford",5],["Rotherham United",0]],
[["Sunderland",3],["Birmingham City",1]],
[["Blackburn Rovers",1],["Preston North End",2]],
[["Rotherham United",2],["Ipswich Town",2]],
[["Norwich City",1],["Blackburn Rovers",3]],
[["West Bromwich Albion",3],["Hull City",1]],
[["Swansea City",0],["Sunderland",0]],
[["Birmingham City",2],["Ipswich Town",2]],
[["Bristol City",1],["Sheffield Wednesday",0]],
[["Huddersfield Town",0],["Watford",0]],
[["Rotherham United",1],["Queens Park Rangers",1]],
[["Millwall",0],["Southampton",1]],
[["Plymouth Argyle",3],["Middlesbrough",3]],
[["Preston North End",3],["Coventry City",2]],
[["Stoke City",0],["Cardiff City",0]],
[["Leicester City",0],["Leeds United",1]],
[["Coventry City",0],["West Bromwich Albion",2]],
[["Sheffield Wednesday",2],["Rotherham United",0]],
[["Ipswich Town",3],["Plymouth Argyle",2]],
[["Blackburn Rovers",0],["Swansea City",1]],
[["Cardiff City",2],["Bristol City",0]],
[["Hull City",1],["Preston North End",0]],
[["Middlesbrough",0],["Stoke City",2]],
[["Queens Park Rangers",1],["Leicester City",2]],
[["Sunderland",3],["Norwich City",1]],
[["Watford",2],["Millwall",2]],
[["Leeds United",4],["Huddersfield Town",1]],
[["Southampton",3],["Birmingham City",1]],
[["Stoke City",1],["Leeds United",0]],
[["Rotherham United",2],["Coventry City",0]],
[["Preston North End",2],["Southampton",2]],
[["Plymouth Argyle",3],["Sheffield Wednesday",0]],
[["Bristol City",0],["Ipswich Town",1]],
[["Birmingham City",0],["Hull City",2]],
[["West Bromwich Albion",2],["Queens Park Rangers",0]],
[["Leicester City",1],["Sunderland",0]],
[["Swansea City",0],["Watford",1]],
[["Norwich City",1],["Middlesbrough",2]],
[["Millwall",1],["Blackburn Rovers",2]],
[["Huddersfield Town",0],["Cardiff City",4]],
[["Middlesbrough",1],["Birmingham City",0]],
[["Blackburn Rovers",1],["Cardiff City",0]],
[["Bristol City",1],["Coventry City",0]],
[["Huddersfield Town",2],["Queens Park Rangers",1]],
[["Hull City",1],["Southampton",2]],
[["West Bromwich Albion",0],["Plymouth Argyle",0]],
[["Norwich City",2],["Leeds United",3]],
[["Stoke City",2],["Sunderland",1]],
[["Swansea City",1],["Leicester City",3]],
[["Watford",1],["Sheffield Wednesday",0]],
[["Preston North End",1],["Millwall",1]],
[["Cardiff City",1],["Watford",1]],
[["Southampton",1],["Rotherham United",1]],
[["Sheffield Wednesday",0],["Huddersfield Town",0]],
[["Queens Park Rangers",0],["Blackburn Rovers",4]],
[["Plymouth Argyle",1],["Swansea City",3]],
[["Millwall",2],["Hull City",2]],
[["Leicester City",2],["Stoke City",0]],
[["Leeds United",2],["Bristol City",1]],
[["Ipswich Town",4],["Preston North End",2]],
[["Coventry City",1],["Norwich City",1]],
[["Sunderland",0],["Middlesbrough",4]],
[["Birmingham City",3],["West Bromwich Albion",1]],
[["Rotherham United",1],["Bristol City",2]],
[["Sunderland",2],["Watford",0]],
[["Leicester City",3],["Preston North End",0]],
[["Leeds United",1],["Queens Park Rangers",0]],
[["Coventry City",1],["Blackburn Rovers",0]],
[["Swansea City",2],["Norwich City",1]],
[["West Bromwich Albion",1],["Sheffield Wednesday",0]],
[["Stoke City",0],["Southampton",1]],
[["Plymouth Argyle",0],["Millwall",2]],
[["Middlesbrough",2],["Cardiff City",0]],
[["Ipswich Town",3],["Hull City",0]],
[["Birmingham City",4],["Huddersfield Town",1]],
[["Blackburn Rovers",1],["Leicester City",4]],
[["Huddersfield Town",1],["Ipswich Town",1]],
[["Millwall",0],["Swansea City",3]],
[["Cardiff City",2],["Rotherham United",0]],
[["Bristol City",2],["Stoke City",3]],
[["Hull City",1],["Plymouth Argyle",1]],
[["Norwich City",2],["Birmingham City",0]],
[["Queens Park Rangers",1],["Coventry City",3]],
[["Watford",2],["Middlesbrough",3]],
[["Preston North End",0],["West Bromwich Albion",4]],
[["Southampton",3],["Leeds United",1]],
[["Sheffield Wednesday",0],["Sunderland",3]],
[["Coventry City",1],["Huddersfield Town",1]],
[["Sunderland",0],["Cardiff City",1]],
[["Stoke City",1],["Hull City",3]],
[["Leeds United",3],["Watford",0]],
[["West Bromwich Albion",0],["Millwall",0]],
[["Swansea City",3],["Sheffield Wednesday",0]],
[["Rotherham United",1],["Preston North End",1]],
[["Plymouth Argyle",6],["Norwich City",2]],
[["Middlesbrough",2],["Southampton",1]],
[["Leicester City",1],["Bristol City",0]],
[["Ipswich Town",4],["Blackburn Rovers",3]],
[["Birmingham City",0],["Queens Park Rangers",0]],
[["Norwich City",0],["Leicester City",2]],
[["Watford",2],["West Bromwich Albion",2]],
[["Millwall",3],["Rotherham United",0]],
[["Hull City",0],["Leeds United",0]],
[["Huddersfield Town",2],["Stoke City",2]],
[["Blackburn Rovers",1],["Sunderland",3]],
[["Sheffield Wednesday",1],["Middlesbrough",1]],
[["Bristol City",4],["Plymouth Argyle",1]],
[["Southampton",0],["Ipswich Town",1]],
[["Queens Park Rangers",1],["Swansea City",1]],
[["Preston North End",2],["Birmingham City",1]],
[["Cardiff City",3],["Coventry City",2]],
[["Millwall",0],["Leeds United",3]],
[["Cardiff City",2],["Swansea City",0]],
[["Bristol City",0],["West Bromwich Albion",0]],
[["Blackburn Rovers",2],["Middlesbrough",1]],
[["Huddersfield Town",2],["Rotherham United",0]],
[["Sheffield Wednesday",0],["Ipswich Town",1]],
[["Norwich City",1],["Stoke City",0]],
[["Queens Park Rangers",1],["Sunderland",3]],
[["Watford",2],["Birmingham City",0]],
[["Preston North End",2],["Plymouth Argyle",1]],
[["Southampton",1],["Leicester City",4]],
[["Hull City",1],["Coventry City",1]],
[["Plymouth Argyle",3],["Blackburn Rovers",0]],
[["Ipswich Town",3],["Cardiff City",2]],
[["Leeds United",0],["Sheffield Wednesday",0]],
[["Leicester City",0],["Hull City",1]],
[["Middlesbrough",0],["Queens Park Rangers",2]],
[["Coventry City",3],["Watford",3]],
[["Rotherham United",2],["Norwich City",1]],
[["West Bromwich Albion",1],["Huddersfield Town",2]],
[["Stoke City",0],["Preston North End",2]],
[["Sunderland",5],["Southampton",0]],
[["Swansea City",1],["Bristol City",2]],
[["Birmingham City",1],["Millwall",1]],
[["Watford",0],["Blackburn Rovers",1]],
[["Ipswich Town",3],["Leeds United",4]],
[["Birmingham City",2],["Plymouth Argyle",1]],
[["Cardiff City",2],["Sheffield Wednesday",1]],
[["Coventry City",0],["Sunderland",0]],
[["Huddersfield Town",0],["Norwich City",4]],
[["Preston North End",2],["Swansea City",1]],
[["Millwall",1],["Stoke City",0]],
[["Rotherham United",1],["Leicester City",2]],
[["Southampton",2],["Queens Park Rangers",1]],
[["West Bromwich Albion",4],["Middlesbrough",2]],
[["Hull City",1],["Bristol City",1]],
[["Norwich City",3],["Millwall",1]],
[["Middlesbrough",1],["Huddersfield Town",1]],
[["Bristol City",0],["Birmingham City",2]],
[["Blackburn Rovers",1],["Hull City",2]],
[["Leicester City",2],["Cardiff City",1]],
[["Sunderland",2],["Rotherham United",1]],
[["Queens Park Rangers",0],["Ipswich Town",1]],
[["Stoke City",1],["Watford",0]],
[["Swansea City",1],["Coventry City",1]],
[["Sheffield Wednesday",0],["Preston North End",1]],
[["Plymouth Argyle",1],["Southampton",2]],
[["Leeds United",1],["West Bromwich Albion",1]],
[["Millwall",0],["Bristol City",1]],
[["Birmingham City",1],["Leeds United",0]],
[["Cardiff City",1],["Queens Park Rangers",2]],
[["Hull City",4],["Sheffield Wednesday",2]],
[["Ipswich Town",2],["Stoke City",0]],
[["Huddersfield Town",0],["Leicester City",1]],
[["Preston North End",2],["Sunderland",1]],
[["Southampton",4],["Norwich City",4]],
[["Watford",0],["Plymouth Argyle",0]],
[["West Bromwich Albion",3],["Swansea City",2]],
[["Rotherham United",2],["Blackburn Rovers",2]],
[["Coventry City",3],["Middlesbrough",0]],
[["Sunderland",1],["Ipswich Town",2]],
[["Leeds United",2],["Cardiff City",2]],
[["Leicester City",2],["Coventry City",1]],
[["Blackburn Rovers",2],["West Bromwich Albion",1]],
[["Watford",4],["Queens Park Rangers",0]],
[["Swansea City",1],["Birmingham City",1]],
[["Stoke City",4],["Rotherham United",1]],
[["Plymouth Argyle",3],["Huddersfield Town",1]],
[["Norwich City",2],["Hull City",1]],
[["Middlesbrough",0],["Millwall",1]],
[["Bristol City",1],["Preston North End",1]],
[["Sheffield Wednesday",1],["Southampton",2]]
]

Points, goal difference, goals for (don’t need to be output)

65 34 55 Leicester City
58 21 53 Southampton
58 16 50 Ipswich Town
54 24 50 Leeds United
45 13 40 West Bromwich Albion
43 13 43 Coventry City
42 4 42 Hull City
41 3 46 Norwich City
40 7 45 Watford
40 6 37 Sunderland
40 1 42 Middlesbrough
38 -12 34 Preston North End
37 0 31 Bristol City
37 -4 35 Cardiff City
33 0 47 Plymouth Argyle
33 -6 38 Swansea City
33 -12 41 Blackburn Rovers
32 -7 29 Millwall
32 -7 27 Stoke City
32 -10 34 Birmingham City
27 -18 28 Huddersfield Town
24 -15 24 Queens Park Rangers
22 -24 22 Sheffield Wednesday
19 -27 25 Rotherham United

Output for this example (from highest to lowest)

Leicester City
Southampton
Ipswich Town
Leeds United
West Bromwich Albion
Coventry City
Hull City
Norwich City
Watford
Sunderland
Middlesbrough
Preston North End
Bristol City
Cardiff City
Plymouth Argyle
Swansea City
Blackburn Rovers
Millwall
Stoke City
Birmingham City
Huddersfield Town
Queens Park Rangers
Sheffield Wednesday
Rotherham United

Alternative with integers for team names

[
[[9,2],[15,1]],
[[14,3],[4,1]],
[[11,1],[17,1]],
[[13,2],[24,0]],
[[20,1],[1,2]],
[[16,2],[12,0]],
[[18,1],[5,2]],
[[2,1],[6,1]],
[[3,1],[23,1]],
[[22,1],[19,3]],
[[21,0],[7,1]],
[[16,1],[23,2]],
[[8,2],[21,1]],
[[12,1],[11,3]],
[[17,0],[20,1]],
[[19,4],[18,0]],
[[24,4],[2,1]],
[[6,1],[14,1]],
[[4,0],[9,3]],
[[1,2],[22,2]],
[[15,2],[3,0]],
[[5,3],[10,1]],
[[7,1],[13,2]],
[[18,3],[7,1]],
[[13,1],[19,1]],
[[2,2],[17,2]],
[[3,0],[12,1]],
[[9,3],[1,0]],
[[10,4],[6,1]],
[[11,1],[5,3]],
[[14,3],[23,3]],
[[20,0],[8,0]],
[[22,1],[24,0]],
[[16,1],[4,2]],
[[21,2],[15,0]],
[[24,1],[9,0]],
[[8,0],[16,0]],
[[4,0],[10,2]],
[[5,2],[22,2]],
[[6,1],[11,2]],
[[7,3],[2,2]],
[[17,1],[21,1]],
[[12,1],[13,0]],
[[15,0],[18,1]],
[[23,1],[20,1]],
[[1,0],[3,0]],
[[19,2],[14,1]],
[[8,1],[10,1]],
[[1,1],[20,3]],
[[17,1],[11,0]],
[[19,5],[22,0]],
[[7,0],[21,1]],
[[6,3],[2,0]],
[[5,2],[18,0]],
[[4,2],[14,2]],
[[24,1],[13,0]],
[[23,1],[3,4]],
[[12,2],[16,0]],
[[15,2],[9,1]],
[[20,0],[12,0]],
[[21,0],[5,3]],
[[18,1],[4,2]],
[[10,3],[17,0]],
[[16,0],[19,1]],
[[14,3],[1,3]],
[[13,2],[6,0]],
[[11,1],[24,0]],
[[2,1],[23,2]],
[[9,4],[8,0]],
[[22,2],[15,1]],
[[3,3],[7,2]],
[[1,2],[10,3]],
[[24,1],[20,1]],
[[14,3],[17,2]],
[[22,1],[11,2]],
[[19,4],[2,0]],
[[18,2],[16,1]],
[[15,1],[23,5]],
[[12,1],[6,1]],
[[9,1],[5,1]],
[[7,3],[4,0]],
[[3,1],[21,0]],
[[8,2],[13,2]],
[[11,1],[7,2]],
[[4,0],[1,1]],
[[5,1],[19,1]],
[[13,3],[18,1]],
[[10,3],[12,2]],
[[16,0],[14,0]],
[[21,1],[9,0]],
[[23,1],[8,2]],
[[20,1],[22,1]],
[[17,0],[24,2]],
[[6,1],[15,3]],
[[2,2],[3,1]],
[[13,0],[15,0]],
[[4,1],[12,0]],
[[10,4],[14,0]],
[[11,0],[8,2]],
[[6,1],[3,1]],
[[16,2],[7,0]],
[[20,0],[18,1]],
[[23,1],[19,1]],
[[17,1],[22,2]],
[[21,2],[24,1]],
[[2,0],[9,2]],
[[5,2],[1,0]],
[[3,1],[13,2]],
[[12,1],[21,1]],
[[1,0],[17,0]],
[[7,1],[23,2]],
[[8,2],[5,1]],
[[9,3],[11,2]],
[[22,1],[6,1]],
[[14,2],[20,1]],
[[18,3],[2,1]],
[[19,2],[4,0]],
[[24,1],[10,2]],
[[15,0],[16,2]],
[[8,3],[12,1]],
[[2,4],[1,2]],
[[9,3],[22,1]],
[[18,1],[10,1]],
[[19,1],[3,0]],
[[21,1],[6,2]],
[[23,3],[13,2]],
[[16,4],[20,2]],
[[11,4],[15,0]],
[[7,4],[17,1]],
[[5,1],[14,0]],
[[4,0],[24,1]],
[[24,2],[8,0]],
[[12,0],[5,3]],
[[1,2],[18,1]],
[[3,3],[11,2]],
[[6,1],[19,1]],
[[10,2],[23,0]],
[[13,1],[16,0]],
[[15,1],[4,2]],
[[20,0],[2,3]],
[[22,2],[7,2]],
[[14,2],[21,0]],
[[17,1],[9,1]],
[[4,2],[13,3]],
[[9,2],[14,1]],
[[5,0],[20,0]],
[[7,1],[6,0]],
[[8,3],[22,2]],
[[19,2],[24,1]],
[[11,1],[10,0]],
[[16,0],[3,0]],
[[18,0],[12,4]],
[[23,5],[17,0]],
[[21,3],[1,1]],
[[2,1],[15,2]],
[[17,2],[8,2]],
[[13,1],[2,3]],
[[24,3],[7,1]],
[[22,0],[21,0]],
[[1,2],[8,2]],
[[3,1],[18,0]],
[[6,0],[23,0]],
[[17,1],[16,1]],
[[12,0],[19,1]],
[[14,3],[11,3]],
[[15,3],[5,2]],
[[20,0],[4,0]],
[[10,0],[9,1]],
[[5,0],[24,2]],
[[18,2],[17,0]],
[[8,3],[14,2]],
[[2,0],[22,1]],
[[4,2],[3,0]],
[[7,1],[15,0]],
[[11,0],[20,2]],
[[16,1],[10,2]],
[[21,3],[13,1]],
[[23,2],[12,2]],
[[9,4],[6,1]],
[[19,3],[1,1]],
[[20,1],[9,0]],
[[17,2],[5,0]],
[[15,2],[19,2]],
[[14,3],[18,0]],
[[3,0],[8,1]],
[[1,0],[7,2]],
[[24,2],[16,0]],
[[10,1],[21,0]],
[[22,0],[23,1]],
[[13,1],[11,2]],
[[12,1],[2,2]],
[[6,0],[4,4]],
[[11,1],[1,0]],
[[2,1],[4,0]],
[[3,1],[5,0]],
[[6,2],[16,1]],
[[7,1],[19,2]],
[[24,0],[14,0]],
[[13,2],[9,3]],
[[20,2],[21,1]],
[[22,1],[10,3]],
[[23,1],[18,0]],
[[15,1],[12,1]],
[[4,1],[23,1]],
[[19,1],[17,1]],
[[18,0],[6,0]],
[[16,0],[2,4]],
[[14,1],[22,3]],
[[12,2],[7,2]],
[[10,2],[20,0]],
[[9,2],[3,1]],
[[8,4],[15,2]],
[[5,1],[13,1]],
[[21,0],[11,4]],
[[1,3],[24,1]],
[[17,1],[3,2]],
[[21,2],[23,0]],
[[10,3],[15,0]],
[[9,1],[16,0]],
[[5,1],[2,0]],
[[22,2],[13,1]],
[[24,1],[18,0]],
[[20,0],[19,1]],
[[14,0],[12,2]],
[[11,2],[4,0]],
[[8,3],[7,0]],
[[1,4],[6,1]],
[[2,1],[10,4]],
[[6,1],[8,1]],
[[12,0],[22,3]],
[[4,2],[17,0]],
[[3,2],[20,3]],
[[7,1],[14,1]],
[[13,2],[1,0]],
[[16,1],[5,3]],
[[23,2],[11,3]],
[[15,0],[24,4]],
[[19,3],[9,1]],
[[18,0],[21,3]],
[[5,1],[6,1]],
[[21,0],[4,1]],
[[20,1],[7,3]],
[[9,3],[23,0]],
[[24,0],[12,0]],
[[22,3],[18,0]],
[[17,1],[15,1]],
[[14,6],[13,2]],
[[11,2],[19,1]],
[[10,1],[3,0]],
[[8,4],[2,3]],
[[1,0],[16,0]],
[[13,0],[10,2]],
[[23,2],[24,2]],
[[12,3],[17,0]],
[[7,0],[9,0]],
[[6,2],[20,2]],
[[2,1],[21,3]],
[[18,1],[11,1]],
[[3,4],[14,1]],
[[19,0],[8,1]],
[[16,1],[22,1]],
[[15,2],[1,1]],
[[4,3],[5,2]],
[[12,0],[9,3]],
[[4,2],[22,0]],
[[3,0],[24,0]],
[[2,2],[11,1]],
[[6,2],[17,0]],
[[18,0],[8,1]],
[[13,1],[20,0]],
[[16,1],[21,3]],
[[23,2],[1,0]],
[[15,2],[14,1]],
[[19,1],[10,4]],
[[7,1],[5,1]],
[[14,3],[2,0]],
[[8,3],[4,2]],
[[9,0],[18,0]],
[[10,0],[7,1]],
[[11,0],[16,2]],
[[5,3],[23,3]],
[[17,2],[13,1]],
[[24,1],[6,2]],
[[20,0],[15,2]],
[[21,5],[19,0]],
[[22,1],[3,2]],
[[1,1],[12,1]],
[[23,0],[2,1]],
[[8,3],[9,4]],
[[1,2],[14,1]],
[[4,2],[18,1]],
[[5,0],[21,0]],
[[6,0],[13,4]],
[[15,2],[22,1]],
[[12,1],[20,0]],
[[17,1],[10,2]],
[[19,2],[16,1]],
[[24,4],[11,2]],
[[7,1],[3,1]],
[[13,3],[12,1]],
[[11,1],[6,1]],
[[3,0],[1,2]],
[[2,1],[7,2]],
[[10,2],[4,1]],
[[21,2],[17,1]],
[[16,0],[8,1]],
[[20,1],[23,0]],
[[22,1],[5,1]],
[[18,0],[15,1]],
[[14,1],[19,2]],
[[9,1],[24,1]],
[[12,0],[3,1]],
[[1,1],[9,0]],
[[4,1],[16,2]],
[[7,4],[18,2]],
[[8,2],[20,0]],
[[6,0],[10,1]],
[[15,2],[21,1]],
[[19,4],[13,4]],
[[23,0],[14,0]],
[[24,3],[22,2]],
[[17,2],[2,2]],
[[5,3],[11,0]],
[[21,1],[8,2]],
[[9,2],[4,2]],
[[10,2],[5,1]],
[[2,2],[24,1]],
[[23,4],[16,0]],
[[22,1],[1,1]],
[[20,4],[17,1]],
[[14,3],[6,1]],
[[13,2],[7,1]],
[[11,0],[12,1]],
[[3,1],[15,1]],
[[18,1],[19,2]]
]

Shorter examples

All are given as [[first team, first team score],[second team, second team score]] but this order can be transposed if preferred.

[[1,1],[2,1]],[[2,2],[1,0]] -> 2,1
[[1,2],[2,3]],[[1,2],[3,2]],[[1,3],[4,1]],[[1,2],[5,1]],[[2,2],[3,4]],[[2,4],[4,2]],[[2,2],[5,2]],[[3,4],[4,2]],[[3,3],[5,2]],[[4,4],[5,2]],[[2,4],[1,2]],[[3,3],[1,3]],[[4,2],[1,3]],[[5,1],[1,2]],[[3,3],[2,3]],[[4,2],[2,3]],[[5,3],[2,1]],[[4,3],[3,1]],[[5,3],[3,2]],[[5,1],[4,3]] -> 2,1,3,4,5
[[1,3],[2,4]],[[1,3],[3,3]],[[2,0],[3,2]],[[2,3],[1,1]],[[3,4],[1,0]],[[3,3],[2,2]] -> 3,2,1
[[1,3],[2,2]],[[1,3],[3,1]],[[1,4],[4,0]],[[2,2],[3,2]],[[2,3],[4,3]],[[3,2],[4,1]],[[2,3],[1,2]],[[3,3],[1,4]],[[4,2],[1,2]],[[3,4],[2,1]],[[4,2],[2,2]],[[4,4],[3,2]] -> 1,3,2,4
[[1,0],[2,2]],[[1,2],[3,0]],[[1,2],[4,0]],[[2,1],[3,2]],[[2,2],[4,4]],[[3,3],[4,2]],[[2,4],[1,3]],[[3,2],[1,2]],[[4,3],[1,2]],[[3,2],[2,3]],[[4,2],[2,2]],[[4,4],[3,2]] -> 4,2,1,3

Questions

  1. The hardest bit seems to be checking head to head record. That’s in the rules, but does it over-complicate things?
  2. Are the examples, particularly the real-world one, too long?
\$\endgroup\$
0
\$\begingroup\$

How many ways does this string conform to this expression?

Given an expression, decide in how many ways could an inputted string consisting of only printable ascii conforms to that expression. The best way to explain how the expression works is with an example, so here is one.

Let's say the expression is a + b + c + a. That means the string should start with a contiguous substring a, then at some point split into substring b, and finally end with substring a again (is this example, a, b, and c must be distinct.) Now let's say the string is "hello world please subscribe hello". One possible way would be:

a = "hello"
b = " world "
c = " please subscribe "

You task is to find how many ways you can split up the string so that the resulting substrings conform to the expression. If no split exists, output/return 0.

[more coming soon]

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

Tile the untileable

Only triangles, squares, and hexagons can tile perfectly with no gaps. With any other polygon, there will always be gaps. But what if you could tile with say, a pentagon? You just have to cheat, with other shapes. Given two integers a and b, how many x-sided polygons where a != x and x >= 3 are needed so that you can tile b a-sided polygons perfectly with the help of x-sided polygons? You may assume it is always possible.

More constraints

  • The area and perimeter of all a-sided polygons must be equal
  • ^ must also hold for the n x-sided polygons

[example and test cases coming soon]


  • I don't know how to do this at all.
  • The wording could probably be better.
\$\endgroup\$
1
  • \$\begingroup\$ "Only triangles, squares, and hexagons can tile perfectly with no gaps" You should have the word "regular" somewhere, otherwise this is wrong and sort of confusing. It's overall not clear to me what polygons are assumed to be regular in this question. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 30 at 5:28
0
\$\begingroup\$

Solve a squared cryptarithm

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

Summarise a Long Conversation


Note: I'm aware that there's been some attempts at doing chatgpt golf on the site but there's always been the problem of subjectivity. I've come up with an idea that could maybe add objectivity to the concept of general LLM golfing

Second note: prompt golf doesn't exist as a tag yet so it'd be created upon question posting most likely if at all

Final note: this might be better as a meta discussion, but just to kick things off I've made it a sandbox post


Inspired by a real life problem

If you ever been in a busy SE chat room/discord server/whatsapp group chat or any other place where you can talk over the internet and there's lots of messages, you'll know that it can be hard to keep up with what's being discussed. Especially if you've been away for a while (e.g sleep) and there's literal hundreds of new messages.

Your task today is to take a list of messages and summarise it into a nice digestible format.

"But that's a hard problem people have spent years researching and everything like how do you expect us to write a summarisation algorithm that's actually good without using something like a LLM?"

By using a LLM, obviously.

Challenge

Given a series of messages with each individual message on a new line, write a prompt that summarises the content.

To verify that the output is actually a summary, the result will be run by an oracle prompt in <insert LLM that'll be used for testing>:

<prompt I've yet to write that outputs either yes or no depending on whether the oracle LLM would summarise in the same way>

To account for the non-deterministic behaviour of LLMs (their temperature), your prompt must return an accepted result for at least 4 out of 5 runs. required run rate subject to change. This is to establish that it's a genuinely working prompt and not a fluke.

Alternatively, if your LLM has a temperature setting you can set to 0, or is deterministic by default only one verified run is needed.

Input Format

name: message
name: message

Rules

to be finalised - I might decide to switch up how this challenge is scored

  • Inputs will not be longer than 1000 characters (to ensure no token limits are reached)
  • Prompts that try to return results that jailbreak the oracle are allowed, but note that you'll probably find better results by just doing the task legitimately.
  • LLMs you can use are Chatgpt 3.5/ 4 and Google Bard.
  • provide links to sample runs if possible.
  • The answer(s) with the shortest prompt as measured in utf-8 bytes wins.

Example Inputs

todo

Sandbox meta

  • Does this work towards solving the subjectivity problem of prompt golf?
  • Does the testing/verification method need more runs or a different set-up?
  • Is prompt golf even something that should be a challenge?
  • Are there any other things I haven't thought of?
\$\endgroup\$
3
  • \$\begingroup\$ So basically, you are given a transcript and give a prompt to an LLM to summarize the transcript, right? How do you compare how good summarizations are? \$\endgroup\$ Jan 30 at 13:11
  • \$\begingroup\$ @AlanBreadel that's what the Oracle LLM is for. It's used to determine whether an output is valid. \$\endgroup\$
    – lyxal
    Jan 30 at 13:41
  • \$\begingroup\$ How do you make sure the Oracle LLM isn't biased? (for example the oracle gives a higher score to prompts that praise it) \$\endgroup\$ Jan 30 at 14:53
0
\$\begingroup\$

bit-packing

The GSM7 03.38 protocol specifies a bit packing/unpacking algorithm, to pack septets into octets and vice-versa.

The following https://www.codeproject.com/Tips/470755/Encoding-Decoding-7-bit-User-Data-for-SMS-PDU-PDU is a reasonable reference implementation, which details the packing algorithm.

challenge

the packing algorithm - shortest code wins.

input

byte array in a style relevant to your language

output

packed byte array

You can use http://smstools3.kekekasvi.com/topic.php?id=288 to check your work - enter some text at the top, click convert, convert again, and then "User data translation (7 bit only)" for a handy comparison chart between the octets and septets.

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

The TAK function (easy mode)

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

Modular Equivalence

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

3D Hide & Seek Word Puzzle

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

Solve a logic puzzle by exhaustively applying three rules to rows and columns of a table

\$\endgroup\$
1
  • \$\begingroup\$ @noodleman Thanks for your feedback on my original post. Are the examples in this post clear enough? \$\endgroup\$
    – oldsoul
    Feb 4 at 1:03
0
\$\begingroup\$

Alternating Random Series Sum To \$N\$

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

Counting rankings

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

State compression


A long time ago in a challenge far, far away, golfers were tasked with outputting one of three different outputs, depending on whether the input was: OR, one of the other 49 American states' two-letter abbreviations, or something else entirely. The list of these letter pairs looks like this:

AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY

The standard approach to achieve the task was to search for the input in this string, bar the commas but not the spaces. If the spaces were to be removed, unintended letter pairs would appear within the string. For example, this string would start with ALAKAZ and while the newly formed LA is one of the valid pairs (and hence, did not need to appear again in the search string), the same cannot be said for KA. (And you'd probably anger some people from Kansas. I dunno, I've no idea what people from Kansas get up to.)

But, with some careful rearrangement, the technique could be used in certain places to save a handful of bytes. The string that most solutions ended up using looked like this:

MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY

Pretty unrecognizable, right? If you look at the first "word", MINCALA, it contains MI, IN, NC, CA, AL, and LA, which are all valid pairs. But if you were to remove the space after it, then you would end up with AM, which is not a valid pair.

Thing is though, I'm still not entirely certain this string is optimal, which is why I'm asking you to...

Challenge

Write a program/function that takes a list of strings of uniform length and outputs the shortest list of combinations that, when combined into a string with some delimiter, contains all the input strings, but no other string of the same length without that delimiter.

Specifications

  • Standard I/O rules apply.
  • Standard loopholes are forbidden.
  • This challenge is not about finding the shortest approach in all languages, rather, it is about finding the shortest approach in each language.
  • Your code will be scored in bytes, unless otherwise specified.
  • Built-in functions that achieve this (now that's unlikely) are allowed but including a solution that doesn't rely on a built-in is encouraged.
  • Explanations, even for "practical" languages, are encouraged.

Test cases

Yet to come.

This challenge was sandboxed.


Sandbox

  • This title still sucks.
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Is it allowed for a string to appear multiple times in the search string? I'm not sure how this could work with nonuniform lengths. What do you mean by a decision-problem? Testing if a given search string is valid? This seems very different, and IMO this question is more interesting. \$\endgroup\$ Feb 3 at 17:47
  • \$\begingroup\$ @CommandMaster I'm not against strings appearing multiple times in the output inherently but I don't know if that can happen in the optimal output. As for the kind of challenge it is, I have decided it'll be a code-golf. \$\endgroup\$ Feb 7 at 12:10
  • \$\begingroup\$ A typical solution may works in \$O((n+1)!k)\$ where \$n\$ is the number of candidate strings and \$k\$ is the size of strings. As the result, it could probably cannot handle any large testcases. \$\endgroup\$
    – tsh
    Mar 6 at 11:17
  • \$\begingroup\$ Maybe testcase "EAB ABC BCA CAB BCE" -> "EABCABCE" use "ABC" twice \$\endgroup\$
    – tsh
    Mar 6 at 11:20
0
\$\begingroup\$

Generate a sequence of \$n\$ consecutive composite numbers

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

TYPOGLYCEMIA - Cna Yuo Raed Tihs?

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

NDos' Well-Temperament

Objective

Given a positive integer \$n\$, output the ratios in the NDos' well-temperament with \$n\$ notes, as defined below.

NDos' well-temperament

NDos' well-temperament (abbr. NWT) is a musical temperament whose every step is a superparticular ratio. A ratio is superparticular if it equals \$\frac{n+1}{n}\$ for some positive integer \$n\$.

By being octave-periodic, NWT with \$n\$ notes is essentially a multiplicative partition of the rational number \$2\$ with \$n\$ entries.

There is one restriction that ensures NWT to exist uniquely. Amongst such multiplicative partitions, NWT is the partition that comes the last co-lexicographically (That is, the last ratio must be the biggest as possible, the second-to-last ratio is a tiebreaker, the third-to-last ratio is another tiebreaker, and so on) when the ratios are sorted in descending order.

I/O format

Flexible. In particular, since the outputted list consists of superparticular ratios, you can output their denominators only, or output their numerators only. Note that, by doing this, NWT becomes the first partition in co-lexicographic order when the denominators (or the numerators) are sorted in ascending order.

Notes

Musically, NWT will sound better if its ratios are rearranged in a particular way. This challenge won't ask to rearrange them.

Examples

Only denominators are shown for the ratios.

Input, Output
1, [1]
2, [2,3]
3, [3,4,5]
4, [4,5,6,7]
5, [6,6,7,7,8]
6, [6,7,8,9,10,11]
7, [8,9,9,10,10,11,11]
8, [9,10,10,11,11,12,13,14]
9, [10,11,12,12,13,13,14,14,15]
10, [12,12,13,13,14,14,15,15,16,17]
11, [12,13,14,15,15,16,16,17,17,18,19]
12, [15,15,16,16,16,17,17,17,18,18,19,19]

Ungolfed solution (Haskell)

This particular implementation is quite slow upon bigger inputs. Haven't analyzed the time complexity exactly, but I doubt this runs in polynomial time.

import Data.List

colex :: Ord a => [a] -> [a] -> Ordering
colex [] [] = EQ
colex [] _  = LT
colex _  [] = GT
colex (x:xs) (y:ys) = colex xs ys <> compare x y

ndosWT :: Int -> [Int]
ndosWT = go [1] where
    go :: [Int] -> Int -> [Int]
    go [] _ = []
    go [x] 1 = [x]
    go [x] n = minimumBy colex $ do
        m <- [2 .. n]
        let ys = take m [m*x ..]
        pure (go ys n)
    go xs@(x:xs1) n = case compare n (length xs) of
        LT -> []
        EQ -> xs
        _  -> minimumBy colex $ do
            m <- [quot (n + (length xs - 1)) (length xs) .. n - (length xs - 1)]
            pure (sort (go [x] m ++ go xs1 (n-m)))

Optimized version:

import Data.List
import Data.Maybe

colex :: Ord a => [a] -> [a] -> Ordering
colex [] [] = EQ
colex [] _  = LT
colex _  [] = GT
colex (x:xs) (y:ys) = colex xs ys <> compare x y

ndosWT :: Int -> [Int]
ndosWT n = fromJust (go [1] n)
  where
    threshold :: Int
    threshold = 2 * n

    colex_maybe_min :: Ord a => Maybe [a] -> Maybe [a] -> Maybe [a]
    colex_maybe_min Nothing mys = mys
    colex_maybe_min mxs Nothing = mxs
    colex_maybe_min (Just xs) (Just ys) = if GT == colex xs ys
        then Just ys
        else Just xs

    weave :: Ord a => [a] -> [a] -> [a]
    weave [] ys = ys
    weave xs [] = xs
    weave xs@(x:xs1) ys@(y:ys1) = if x <= y
        then x : weave xs1 ys
        else y : weave xs ys1

    go :: [Int] -> Int -> Maybe [Int]
    go [] _ = Nothing
    go [x] 1 = if x < threshold
        then Nothing
        else Just [x]
    go [x] n = foldr1 colex_maybe_min $ do
        m <- [2 .. n]
        let ys = take m [m*x ..]
        pure $ if last ys < threshold
            then go ys n
            else Nothing
    go xs@(x:xs1) n = case compare n (length xs) of
        LT -> Nothing
        EQ -> Just xs
        _  -> foldr1 colex_maybe_min $ do
            m <- [quot (n + (length xs - 1)) (length xs) .. n - (length xs - 1)]
            pure (fmap (\[xs, ys] -> weave xs ys) (sequence [go [x] m, go xs1 (n-m)]))
\$\endgroup\$
0
\$\begingroup\$

String to Lojban!

In the constructed language Lojban, you can express ASCII strings with a literal quote, for example
zoi zoi \d+(\.?\d+) zoi. However, how would you pronounce that?

zoi zoi backslash d plus opening bracket backspash dot question mark 
backslash d plus closing bracket zoi

? Non-English speakers won't understand you. However, there are several ways to assign Lojban words or phrases to ASCII characters. One is shown in the challenge.

So here is the challenge:

The input is a string. You can assume it is composed of only the 95 printable ASCII characters.

The output is a Lojban representation of the string. It should start with me'o , followed by the following substrings in order:

SP -> canlu bu
!  -> saibu
"  -> lubu
#  -> libu
$  -> meryru'u bu
%  -> ce'obu
'  -> y'y
&  -> joibu
(  -> tobu
)  -> toibu
*  -> pi'ibu
+  -> su'ibu
,  -> slaka bu
-  -> vu'ubu
.  -> denpa bu
/  -> fe'ibu
0  -> no
1  -> pa
2  -> re
3  -> ci
4  -> vo
5  -> mu
6  -> xa
7  -> ze
8  -> bi
9  -> so
:  -> zo'ubu
;  -> pi'ebu
<  -> me'ibu
=  -> dubu
>  -> za'ubu
?  -> paubu
@  -> zvati bu
[  -> veibu
\  -> lu'ebu
]  -> ve'obu
^  -> te'abu
_  -> dizlo bu
{  -> lu'ibu
|  -> jabu
}  -> lu'ubu
~  -> nabu

This is a modification of an existing system which can represent all 95 printable ASCII characters.

For lowercase letters, just add y after the letter, with these exceptions:

a  -> abu
e  -> ebu
h  -> y'y bu
i  -> ibu
o  -> obu
q  -> ky bu
u  -> ubu
w  -> vy bu

You can also use tau y'y for h.

For uppercase letters, use tau followed by the corresponding lowercase letter, however h must be
tau y'y bu.

After that, the substrings are joined with a single space, however for readability, no spaces are used between digits.

However, if the string is empty, output lo kutyuenzi.

Examples:

Input -> Output
1 2 -> me'o pa canlu bu re
Hello -> me'o tau y'y bu ebu ly ly obu
1234 -> me'o parecivo
12>1 -> me'o pare za'ubu pa
\d+(\.?\d+) -> me'o lu'ebu dy su'ibu tobu lu'ebu denpa bu paubu lu'ebu dy su'ibu toibu
 -> lo kutyuenzi

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

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

Spot The Difference

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

Infinite monkeys with autocomplete

You've probably heard of the infinite monkey theorem, which states that a monkey pressing keys on a keyboard at random will eventually type any possible string, the most well-known example being the complete works of Shakespeare. Of course, as the string grows longer and longer, the time taken to type that string becomes exponentially longer. But what if the monkey had an autocomplete?

Our hypothetical monkey starts with an alphabet, containing every possible character that it can type, and a dictionary that initially only contains every letter in the alphabet. At every step, it'll choose a random item from the dictionary and type it. But, the monkey has a helpful autocomplete guiding it to the correct string - if the last two items that were typed, concatenated, are a substring of the correct word that's not yet in the dictionary, it'll add that substring to the dictionary.

For example, let's start with the monkey trying to type the word hello, with the alphabet helo.

l o

It first types l and o and adds lo to the dictionary.

l o h lo l h e

It then types various random dictionary items before typing h and e, and adding he to the dictionary.

l o h lo l h e e e l

After some more random items, it types e and l and adds l to the dictionary.

l o h lo l h e e e l h lo o el e h el

Next, it types h and el and adds hel.

l o h lo l h e e e l h lo o el e h el lo

After typing the el, it types lo and adds ello to the dictionary.

l o h lo l h e e e l h lo o el e h el lo he hel he l o

Next, it types he and l, but because hel is already in the dictionary it's not added. For the same reason, lo is also not added.

l o h lo l h e e e l h lo o el e h el lo he hel he l o h ello

Finally, it types h and ello, creating hello after 24 attempts.

Your challenge is to, given a target word and alphabet containing only lowercase ASCII letters and spaces, simulate this behaviour, choosing random items and building up the dictionary until you eventually create the desired word. The alphabet will not contain any character more than once, and will at least contain every character in the target word.

At every step, you should choose a (not necessarily uniformly) random item from the dictionary, and the words you print should be separated by some consistent and unambigiuous delimiter. Although you do not have to uniformly randomly choose an item, it should be possible for any possible output sequence of strings to occur.

This is , shortest wins!

Examples

Note that this is just one possible output for each input.


word = "abcba", alphabet = "abc" -> "a,a,c,b,b,cb,c,bcb,bcb,a,a,b,cb,ab,cb,b,bcba,bcba,c,b,cb,c,ab,bcba,c,bcb,ab,c,bcba,bcb,bcb,b,bcb,bcba,ab,a,b,a,c,cb,c,bcba,cb,abcb,abcb,ba,ba,abc,a,b,bcb,ab,bcb,a,ba,b,bcb,abc,c,abcb,a"
word = "hello", alphabet = "helo" -> "o,l,h,o,e,e,h,l,e,o,l,o,lo,lo,l,e,h,h,o,lo,h,l,lo,h,o,llo,o,llo,e,o,llo,lo,l,e,e,o,e,o,lo,l,l,ll,llo,h,l,ll,e,h,e,l,he,llo"
word = "hello", alphabet =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ll,orl,y,o,l, ,a,g, ,x,d,e,wor,y,t,w,orl,c,f,s,i,c,hel,z,i,w,hel,f,i,y,ll,e,x,g,orld,wor,he,n,c,or,x,ll,ll,s,l,t,ll,l,p,q, ,w,worl,a,q,he,i,x,l,hel,g,o , w,m,c,o ,l,z,worl,j,i,y,n,b, w,b,wor,f,r,u,j,l,u,f,z,z,m,c,orld,c,e, w,ll,m,x,y,u,j,t,hel,o ,b,wor,he,m,d,n,f,orld,or,u,i,i,e,c,q,b,t, w,p,c,t,orl,p,c,o ,q,hel,w,orld,c,e, w,orl,b,r,u,y,ll,g,wor,hel,n,s,d,g,y,j,b,t,q,wor,hel,hel,s,y,b,a,or,n,h,orld,hel,orl,k,ll, ,f,z,o ,u,o, worl,he,o,v,e,or,r,wor,wor, worl,h,he,q,c,q,hel,orld,or,u,p,v,hel,ll,or,x,he,o ,q,ll,he,d,x,o ,orl,o ,z,o,b,world,g,or,s,v,a,o ,r,f,hel,i,r,c,s,q,ll,s,u,h,n,u, w,or,u,world,v,m,w,l,x,wor,o ,n,x, wor,a,g,orl,c, ,n,l,o ,w,k,orld,a,w,x, w,g,hel, ,k,orl,orl,r,v,l,o,o,j,orl,o worl,r,s,worl,wor,l,v,o , worl,z,n,lo ,orl,or,s,hel,world,orl,c,u,hel,z,n,z,c,orl,o w,worl,he,e,b,h,f,u,w,k,orl, wor,k,wor,c,f,orl,o worl,f,y,lo ,x,v,l,o ,c,c,z,lo,a,u,hel,orld,world, worl,orl,y,k,ll,ll,e, wor,d,h,j,a,he,j,orl, w,s, wor,he,j,orld,worl,k,hel,u,b,hel,r,w,hel,g,hel,lo, w,o worl,lo ,w,world,o ,lo w,b,t,l,b,u,q,hello, worl,or,p,hello worl,u, ,o ,o w,hel,or,or,u,z, , ,h,hello,o ,z,t,k,q,b,o w,t,m,he,m,w,worl,t,p,hello worl,k,hel,world,z,c, , w,z,b,f,hel,world,r,x,d,o worl,he,x, w,s,i,orld,o,d,t,hello,r,world,j,hello worl,o worl,he,w,f,e, worl,wor,o, worl,o w,lo, wor,lo wor,s,i,b,o worl,m,b,p,v, worl,b,lo ,worl,world,lo wor,f,orl,y,e,x,k,a,x,e,g,s,j,orl, w,d,orl,worl,s,a,worl,lo wor,lo ,o worl,s,lo worl,w,t,hel,orld,orl, worl,b,ll,g,o ,j,he,lo worl,n, ,he,c,n, worl, ,o worl,orl,p,k,b,he,o worl,z,orl,e,a,k,or,o w,z,w,lo w,z,f,u,k,s,o,he,o worl,m,h,a,k,o w,m,b,a,o,lo w,m,o w,he,a,hello,z,lo ,r,b,ll,l,he,or,hel,u, wor,he,g,t,o ,x,v,world,he,p,w,orl,lo,worl,o w, worl,lo w,b,orl,o worl, wor,r,he,h,hel,q,t,u,lo,w, w,lo wor,d,lo worl,n,hello,lo ,he,hello,lo wor,ll,lo worl,he,z,worl,orl, w, worl,lo worl,g,world,j,z,j,o, wor, wor,b,c,p,orl, wor,p,g,y, worl, ,b,k,q,g,o w,o worl,o ,p,d,orl,lo w,lo w,z,he,n,world,wor,d, worl,or,lo wor, wor,l,t,wor,worl,e,m, worl,z,j,hel,h,or,x,k, w,s,s,hello,b,p,lo w,l,g,p,o worl,j,wor,m, w,o,t,u,u,o,orld,s,u, w,orl,he,world,d,t,g,l,u,hello,n,worl,o w,lo worl,d,p,orl,q,o wor,u,v,or,q,d,c,hello worl,he,j,r,world,wor,o wor,hel,world,l,orld,q,x,wor,x,o ,ll,hello, wo,r,lo wor, ,or,j,o worl,t,hel,n,o,p, w,b,world,world,he,lo world,v,or,wor,o,lo world,lo worl,f,hello worl,u,orl,d, ,wor,z,r,lo w,p,o worl,o wor,b,he,f,hello wo,j,o ,o,or,f, ,o w,d, worl,wor,hel,k,y,hel,x,o worl, wor,g,ll, worl, wor,n, wo,orl,hel, wo,s,orld,he,lo,he, worl,o w,lo world,p,lo ,a,o ,v,c,p,t,or, w,q,f,o , wor,o worl,p,s,world,v,m,w,s,r,a,g,orl, ,z,p,v,j,o,o,r,l,c,q,orld,r,l,g,d,rl,lo wor,k,w,o , ,x,k,o,i,z,h,n,t,n, worl,w,w,s, wo,hel,he,f,lo , ,o worl,s,p,hello worl,r,o w,o worl,o w,j,c,world,lo worl,o ,wor,z,y,lo world,lo world,orld,s,u,hello,orl,lo wor,r,or,t,l,m,ll,worl,b,u, wo,o ,t, ,or,ll,ll,o,o w,llo,e,s,b,t,z,d,u,world,p,orld,wor,hello worl,lo worl,p,a,lo w,orld,w,wor,o w,lo worl,w,j,lo worl, worl,s,g,k,a,o w, ,o,hel,o,s,wor,u,w,p, wor,y,ll,he,j,orld,hello worl, worl,g,ll,o,lo worl,n,o,o worl,orld,m,lo,rl,o ,wor,hello worl,e,t,ll,g,d,d,orl,n,k,x,lo worl,a,q,wor,lo wor,lo worl,rl,o ,a,ll, wo,s,w,o w,e,h,lo,wor,o ,c,or,f,z,hel,lo worl,j,i,b,d,rl,lo ,j,j,o w,llo,i,b,z,c, worl,worl,e,o w,m, worl,wor,v,lo worl, ,r,u,y,g, w,m,r,ll,b, worl,g,o wor,b,a,m,n,orld,he,wor,hello,lo worl,orld, worl, , worl,o,q,b,o,e,rl,u,or, wo,u,o wor,hello worl,ll, ,llo,h, , ,wor,rl,y,l,z,he,orld,lo wor,x,g,n,b,world,j,ll,m,x,x,rl,n,lo worl,o worl,b, w, wo,b,z,x,o,v,or,t,hello,w,p,a,o,p,llo, ,y,d,p,h,c, wor,b,r,rl,u,c, worl,llo ,i,lo ,o ,q,p,w,he,he,b,lo,a,z,a,e, wor,v,or,hello wo,lo wor,m,hello worl,lo world,hello,v,worl,hel,s,llo ,e,d,o w,world,lo wor,lo ,hello worl,worl,w,w,orld,hello,o w,q,u,o ,worl,l,a,w, , wor,u,y,rl,s,p,o w,g,a,rl,v,y,orl,worl,o worl,rl,wor,x,u,or,s,orld,x,o ,q,p, w,z,u,t,d,a,orl,ll,o ,r,i,k,lo wor,p,b,a,ll,d,z,hello worl, ,hello worl, wor,o w,world,ll,world,hello,lo worl,k,llo ,hel,e,or,rl,hello,v,q, wo,lo wor,e,s,o,wor,lo ,o w,o ,or,x,wor,d,q,d,wor,hello wo,world, wo,a,llo ,worl,orld, wor,y,y,lo wor,o w, w,o,k,k,o ,b,llo worl,orld,worl,llo worl,ll,y,lo worl, wo,llo,hello,p, wo,u,hello worl,lo wor,m,n,orl,r,s,a, wor,wor,x,lo,u,lo world,lo world,s,o wor,o ,a,he,q,b,o,rl,o w,q,n, w, worl,e,a,k,o w, wor,a,f,o,hello worl, worl,o wor,z,g,s,o w, ,hello,hel,lo,i,lo worl,g,t,lo,lo world,rl,lo wor,o,t,ll,x,w,g,k,v,rl,he,y,hel,world,o wor,a,lo ,b,orl,lo, worl,q,o worl,world, w,hello wo,h,o ,o ,wor,hello,hel,lo ,b,q,o w,l,t,n,llo,e,q,q,q,lo worl,hello wo,orld,hello wo,h,x,p,z,hel,n,w,f,o wor,w,h,or,u,s,hello worl,hello ,d,d,rl,hello worl,wor,orl,hello,world,ll,lo,m,hello ,d,lo ,i,lo wor,orld,o ,z,m,hello wo,llo worl,ll,lo worl,world,hello ,llo,hello,e,rl,worl,h,llo worl,u,llo ,world,r,y,lo wor,g,z,d,worl,m,or,llo, wo,or,he,x,o worl,i,hello worl,k,f,w, w,o ,lo world,lo w,i,a,w,o ,z,r,hello ,hello ,hello worl,x,s,llo wo,u,worl,hello, worl,hello worl, ,world,t,llo world,rl, ,p,l,lo,lo w,worl,l, , ,rl,llo wo,h,o worl,llo worl,s,s,a,he,orld,p,lo ,i,f,hello wo,a,llo worl,llo,llo wo,he,llo ,b,ll, w,lo worl,i,t,k,world,r,llo ,lo worl,o w,d,j,lo worl,t,w,world,a,s,hello worl,or,hello wo,o ,llo wo, wo,u,orld,hello ,hello , worl,u,n,z,lo,o worl,llo , , wo,e,o wor,x,lo , w, world,s,hello ,lo world, world,worl, worl,b,h,h,q,world,s,c,lo w,d, ,l,hello worl,g,wor,or,t,x,i, worl,lo wor,s,p,s,llo worl,lo world,p,orld,f,k, w,orl, world,i,lo,orld,d,p,b, worl, ,world,b,b,ll,orl,l,a,llo ,p,k,world,i,hel,m,lo world,lo world,rl,world,d,q,r,he,j,hello worl,t,v,llo wo,p,d,g, world,world,r,hello,c,hello worl,llo world,lo world,z,m,t,q,j,t,m,d,n, worl,r,hello worl,lo worl,orl,p,hello ,g,o,rl,c,d,ll,lo w,o w,w,wor,orl, worl,llo world,y,llo world,o w, worl,c,g,lo worl, ,q,lo ,h,he,lo w,worl,lo worl,orld,m,u,wor, w,llo world,q,e,p,hello wo,hello worl,worl, world,s,o ,o ,d,o worl,n,x,world,hello worl,hello ,lo world, wo,x,rl,x,s,llo,lo ,a,hello ,e,q,lo w,world,x,i,o wor,w,z,s,o ,k,k,g,llo ,i,hello wo,lo w, worl, w,c, wor,c,c,lo , wo,lo world,lo,o wor,k,world,o wor,y,lo ,q,s,s, worl,hello ,lo , wor,orl,lo wor,llo,hello wo,wor, w,f, wo,w,k,r,j,o ,orld,i,or,p,b,rl,l,llo,e,rl,o,or,v,hello wo,lo ,w,j,w,hello,o w,hello worl,lo worl,e,i,llo,r,llo ,u,x,w,m,worl,h,wor,o, ,lo,o w,f,hel,c,lo world,b,a,llo worl,g,d,j,k,x,hello wo, world,o wor,llo world,hel,h,llo world,t,q,llo worl,x,h,lo ,v,or,b,u, wor,d,e,b,h,x,w,llo ,h,w, worl,o,hello, w, w,d,hello w,t,q,hello wo,llo wo,rl,m,lo wor,r,lo ,o w,hello,llo world,s,k,q,orld,y,v,hel,l,hello wo,w,a,orld,e, ,p, wor, wo,llo,wor,t,hello worl,f,hello w,wor,lo world,or,j,lo,d,i, worl, ,l,o ,wor,lo worl,g,b,m,s,s,ll,worl,orld,he,hello,rl,q,q,c,o worl,x,llo world,b,rl, ,d,ll,o, ,x,rl, wo,v,hel,llo world,l,hello,n,or,d,he,llo world"
word = "code golf and coding challenges", alphabet = "abcdefghijklmnopqrstuvwxyz " -> too large to fit in post
\$\endgroup\$
1
0
\$\begingroup\$

Morph a string into another

Given two strings consisting of only printable ascii, at least how many operations are needed to morph string a into string b?

The allowed operations are:

  • Take two characters x and y and make every instance of x in string a y.
  • Pick a letter l and delete all instances of it from either a or b, but not both. After deleting a letter l once, you may not delete that same letter l from either a or b again.

For instance, given a = "abc" and b = "ccc", the minimum number of operations is 2.

morph a -> b => bbc
morph b -> c => ccc

If no such sequence of morphs exists, output a value that is distinctable and would never be outputted with any possible input.

Test cases

"abc", "ccc" => 2
"abc", "abcz" => 1
"abbac", "ccbab" => -1
\$\endgroup\$
2
  • \$\begingroup\$ You should be more clear about what string a and b are in the example given. It can't be a -> b -> c if you are trying to get from a to b. also, is it really morphing a to b when you are changing both a and b? \$\endgroup\$
    – Tbw
    Feb 26 at 21:01
  • \$\begingroup\$ Also, you can do the last test case in 4 moves. "ccbab" -> "cca", "abbac" -> "bbc" -> "bba" -> "cca" \$\endgroup\$
    – Tbw
    Feb 26 at 21:03
1
138 139
140
141 142
155

You must log in to answer this question.

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