490
\$\begingroup\$

What is the Sandbox?

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

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

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

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

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

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

| |
\$\endgroup\$

2970 Answers 2970

1
82 83
84
85 86
99
0
\$\begingroup\$

Where am I?

Given an input folder structure (i.e. a tree data structure with named nodes), and a pointer to a directory (a specific node) within that tree structure, the program should output the full path to the directory the pointer is pointing at (in linux format, so /var/log for example), without ever inspecting the name of the current node or its ancestors; only its descendants.

The rules of the challenge are the equivalent of:

"you can cd and ls but not pwd" if this was being run on a live linux files system

but I feel I should expand on that a bit regarding how it works for a tree:

  • The method starts with the pointer, and it can ls to see what is contained within this directory (i.e. view the immediate child nodes in the tree structure, but not its own name)
  • the method can also cd dirname into any directory (i.e. move the pointer to any immediate child in the tree from the current node), and cd .. to go to a previous directory (i.e. move the pointer to the immediate previous child in the tree)
    • cd .. leaves you in the same directory (node), if there is no parent
    • cd invalidDirNameleaves you in the same directory (node), if there is no immediate child with that name
  • Any directory can contain any number of other directories, or none.
  • You are forbidden to do the equivalent of cd /

Inputs

A tree-structure representing a file system and a pointer to a node in that tree

Assumptions 1. There are no duplicate folder names in the same parent folder (so ls can't return folder, folder; for example) - but there may be other folders with the same name elsewhere in the tree structure; in which case it doesn't matter which your program outputs (as it has no way of knowing which is correct) 2. ...Therefore, it may not be possible to determine which folder you started in - in which case a best-guess is fine (see examples 3, 4) 3. Symlinks and cyclical trees are not a part of this challenge - it will always be a simple parent-child tree structure - so you are always guaranteed to find the root by doing cd .. enough times.

Output

The path that the pointer was pointing at, as a string or char array (or equivalent for your language).

Scoring

scoring is used, so shortest bytes wins.

Example 1

input map: /var/ftp/in, /var/ftp/out/child, /var/etc/test/child/etc, /var/etc/test/c2/etc2, /var/etc/test/c3

input pointer points at: c2

sample working:

  1. ls -> "etc2"
  2. cd .., ls -> "child","c2", "c3" - three options, need to find which is correct
  3. cd child, ls -> "etc2" - this doesn't match 1, so go back
  4. cd .., cd c2, ls -> "etc2" - this is correct, so I know my path ends with "/c2"
  5. cd .., cd .., ls -> "test" - only one folder, so I know my path ends with "/test/c2"
  6. cd .., ls -> "ftp", "etc" - two options, need to find which is correct
  7. cd ftp, ls -> "in", "out" - incorrect, so go back
  8. cd .. -> there was only two options, so "etc" must be correct. my path ends with "/etc/test/c2"
  9. cd .., ls -> "var" - only one folder, so path ends with "/var/etc/test/c2"
  10. cd .., ls -> "var" - same option, so assume we're at root.
  11. Output "/var/etc/test/c2"

Example 2

input map: /app/data/dir/in

input pointer points at: /app/data

Output: "/app/data"

Example 3

input map: /var, /app, /test

input pointer points at: /app

Output: "/var", "/app" or "/test" are all valid outputs.

Note that there is no way for the program to differentiate between the three folders; and so any of the three are a valid answer for the purposes of this application.

Example 4

input map: /var/etc/test, /app/etc/two

input pointer points at: /app/etc

Output: "/app/etc"

Questions

  1. Does the spec make sense?
| |
\$\endgroup\$
  • \$\begingroup\$ Nice idea for a challenge, but: I would remove the free cd and ls helpers for it only creates problems, you can (partially) solve the issue of using system built-ins by just allowing the directory-structure as input and not a directory-node (there will still be one or two solutions like eval mkdir -p $1;eval $2;pwd) but they are not really interesting and need to create the directories which is a penalty). I would also remove the explanations of examples 2-4, one suffices and more makes the post hard to read. \$\endgroup\$ – ბიმო Dec 13 '18 at 22:24
  • \$\begingroup\$ Thanks for your comments! I think I'll remove the cd/ls stuff and the file system input, like you suggest. What would you recommend for the examples 2-4 then - just show the input and output? Or just show the working but not the text explanations? Should I include the result of "ls" each time also in that case? \$\endgroup\$ – simonalexander2005 Dec 14 '18 at 9:49
  • \$\begingroup\$ Just input and output should suffice imo. Maybe you want to exchange 1 and 2 such that there is the more thorough explanation of 2 and 1 just i/o. \$\endgroup\$ – ბიმო Dec 14 '18 at 10:26
  • \$\begingroup\$ done :) Thanks for your input. How does it look now? \$\endgroup\$ – simonalexander2005 Dec 14 '18 at 13:16
0
\$\begingroup\$

Title: The Liquorice All-sort

I have just invented a new sorting algorithm, which I would like you to implement in the smallest number of bytes... The Liquorice All-sort

Given that the individual sweets are (or were) named: chips, rocks, Buttons[sic], nuggets, plugs, twists, spogs (https://en.wikipedia.org/wiki/Liquorice_allsorts), we can say that:

A bag (multiset) of Liquorice allsorts is comprised of 0..n of each item chip, rock, Button, nugget, plug, twist, spog, plus a bonus of 1..2 Bertie.

Given an input of an arbitrary array characters (A-z, 0-9, space), and a bag of Liquorice allsorts, sort as follows:

For each input character, from last to first:
    Is the bag empty?
           Yes: Exit the sort
    Else, Is the input equal to a letter (case-sensitive) that is contained in the name of one or more of the sweets in the bag?
       Yes: The number of items it matches is the number of positions it moves up the list (can't move past the top of the list).
            Take a bite out of each of the used sweets, by removing the letter we used. 
            Have we used all the letters in any item?
               Yes: Remove that item from the bag
    Else: move to the bottom of the list.

Inputs

two inputs - the numbers to sort, and the list of sweet names. Both are guaranteed to be non-empty bags (sets that can contain duplicates; or an equivalent in your language), and the bags of sweets contains a minimum of one Bertie.

Outputs

The sorted numbers

Examples

  1. {Bertie},{B} -> {B}
  2. {Bertie},{X,B} -> {B,X}
  3. {chip, rock, Button, nugget, plug, twist, spog, Bertie}, {A,B,C,k,e,r,w} -> {B,C,k,e,r,w,A} -> {B,C,k,e,r,w,A} -> {B,k,e,r,w,A,C} -> {k,B,e,r,w,A,C} -> {e,k,B,r,w,A,C} -> {e,r,k,B,w,A,C} -> {e,r,k,w,B,A,C}
  4. {Bertie, rock}, {r,o,c,k,r,o,c,e} -> {r,o,c,k,r,o,c,e} -> {o,r,c,k,r,o,c,e} -> {o,c,r,k,r,o,c,e} -> {o,c,k,r,r,o,c,e} -> (remove rock from the bag) -> {o,c,k,r,o,c,e,r} -> {o,c,k,r,c,e,r,o} -> {o,c,k,r,e,r,o,c} -> {o,c,k,e,r,r,o,c}

Sandbox Questions

I really like the idea of doing something with this (I like the wordplay of bag, etc.); but I don't know if the algorithm is just too arbitrary. Any thoughts or alternatives would be appreciated!

| |
\$\endgroup\$
  • \$\begingroup\$ Absolutely not. (although you're encouraged to post your sandbox challenges when they're ready) \$\endgroup\$ – user202729 Apr 10 '18 at 14:56
  • 1
    \$\begingroup\$ You only have 3 challenges in the Sandbox at the moment; some people have north of 30 - You don't have to worry. \$\endgroup\$ – caird coinheringaahing Apr 10 '18 at 15:43
0
\$\begingroup\$

Title - Fix the note

Given a musical note letter (A to G), followed by any number of accidentals (either 0..n # or 0..n b, not a combination of both); output a representation of the same note with the least possible number of accidentals.

A # means "shift the note one semitone up", and a b means "shift the note one semitone down".

All valid output notes are as follows (in order, then loops):

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

So a sharp would move to the right along that list (and loop); and a flat would move you to the left.

Examples

  • A -> A
  • B# -> C
  • Fb -> E
  • A##### -> D
  • Dbbb -> B
  • Gbbbbbbbbbbbb -> G
  • Bb -> Bb
  • F# -> F#
  • E## -> F#
  • E# -> F

You can assume that the length of the input won't overflow your language.

Where the input has sharps, the output can also only contain 0..1 sharps; and vice-versa for flats.

This is , so shortest bytes wins. Standard rules apply

| |
\$\endgroup\$
  • \$\begingroup\$ These accidentals aren't even correct. There's no such thing as E sharp sharp. \$\endgroup\$ – S.S. Anne Sep 25 '19 at 20:42
  • \$\begingroup\$ Also, should E sharp be simplified to F? Is this bass, treble, or tenor? \$\endgroup\$ – S.S. Anne Sep 25 '19 at 20:43
  • 1
    \$\begingroup\$ @JL2210 sure there is - any note can be represented as accidentals of another note, in theory. I know that in practise you wouldn't do so. \$\endgroup\$ – simonalexander2005 Sep 26 '19 at 8:26
  • \$\begingroup\$ E# should be simplified to F, yes, because the aim is to reduce the number of accidentals where possible \$\endgroup\$ – simonalexander2005 Sep 26 '19 at 8:27
  • 1
    \$\begingroup\$ I'm not sure what you mean by "is this bass, treble or tenor?" - The instrument shouldn't matter for the purposes of this - this is purely theoretical (they're notes, not chords, if that helps) \$\endgroup\$ – simonalexander2005 Sep 26 '19 at 8:28
0
\$\begingroup\$

Title: Score my Tarok hand

Inspired by this challenge

In Slovenia (and elsewhere in central Europe), the card game Tarok is very popular. See here for a complete list of rules, but essentially it is a trick taking game, played in teams that change per round.

This challenge is a challenge, concerning the scoring of a hand, at the end of a round.

In a normal round, the game is played in partnerships. Any one player could decide the "contract" for the round, and that player (plus anyone on their team) either wins or loses the round, giving them a positive or negative score. They are known as the "Declaring team". The "Opposing team" cannot score in that round.

The input for this challenge will therefore be the Declaring team's cards, plus the contract type they bid for.

The cards

In a game of Tarok, there are 54 cards; as follows (shown as highest to lowest in each suit - names in brackets after a card are local names given to certain cards):

  • Spades, Clubs: King, Queen, Knight, Jack, 10, 9, 8, 7
  • Diamonds, Hearts: King, Queen, Knight, Jack 1, 2, 3, 4
  • Taroks: Joker (škis), XXI (mond), XX, XIX, ... III, II, I (pagat)

The point value of the cards are as follows:

  • kings, škis, XXI and I - 5 points each
  • queens - 4 points each
  • knights - 3 points each
  • jacks - 2 points each
  • all other cards - 1 points each

Scoring a hand

This is what I believe makes this challenge interesting.

  • For each set of three cards in your hand, add up their values and subtract 2.
  • If you end up with one or two cards left over after making the sets of three, add up their values and subtract 1.
    • So, a pair or a set of three one-point cards are both worth 1 point; but a single one-point card is worth nothing.

The total value of the pack comes to 70 card points.

In most contracts (see below), the declarer's side wins if at the end of the play they have at least 36 of the available 70 points; otherwise they lose. Because of this, the members of each team pool their cards for scoring; and so if you know the score of one team, you can calculate the score of the other.

Once the hand value has been calculated, the difference from 35 is taken (i.e. handValue - 35), and this difference is rounded to the nearest 5 points.

Contracts and Bonuses

Once the hand score is known for the declaring team, the final score is calculated based on the "contract" that was chosen at the start of the round (where "difference" is the rounded hand difference from 35, calculated above. Note this may be negative, if the opposing team got more points):

Contract Name          | Scoring (+ if contract won, - if lost)
------------------------------------------------
Three                  | difference +/- 10
Two                    | difference +/- 20
One                    | difference +/- 30
Solo Three             | difference +/- 40
Solo Two               | difference +/- 50
Solo One               | difference +/- 60
Beggar*                | 70 (fixed)
Solo without           | 80 (fixed)
Open Beggar*           | 90 (fixed)
Colour Valat Without** | 125 (fixed), no bonuses
Valat Without**        | 500 (fixed), no bonuses

With the exception of those marked, all contracts are "won" if the difference is 36 or higher; otherwise it was "lost".

* - to win the points, you must win no tricks (and therefore no cards)

** - to win the points, you must win ALL the tricks (and therefore all the cards). In this case, no other scoring bonuses are applied.

Bonus points are awarded to the declaring team, or subtracted from the declaring team if the opposing team complete the criteria. Bonuses are only awarded on contracts where the difference is taken into account. (i.e. from "Three" to "Solo One" only, in the above table)

Bonus Criteria                                | Bonus Points
-----------------------------------------------------------------------------------
Take škis, XXI and I ("the Trule") in tricks  | 10
Take all 4 kings in tricks                    | 10
Take all the tricks ("Valat")                 | 500, no other scoring is applied

(note that in Tarok, there are some actions that take place during play which give additional bonuses, such as announcing at the start of the game your intention to get a certain bonus; but as those would require more inputs to calculate, I will leave these out of this challenge.)

Some Examples

All 54 cards, any contract -> +500 points

No Cards, called Beggar -> + 70 points

king, king, king, king, škis, XXI, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, 2H; called "One" -> 30 points for contract + 20 points difference (hand score is 56 which is 21 different from 35, so round to 20) + 10 points kings bonus + 10 points Trule Bonus = 70 points

No cards, called "Solo One" -> -500 (opposing team got Valat bonus)

KS,8S,7S, called "Two" ->failed contract, so -30 (difference), -20 (contract), -10 (opponents got Trule bonus) = -60 points

KH, KD, škis, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, 2H, 7C,1D,2D,4D; called "Solo Without" = +80 points

KH, KD, škis, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, X, III,II,2D,KS; called "Three" = +15 difference (49-35, rounded) + 10 contract = +25

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

Spreadsheet Columns

In most spreadsheet programs, columns go A, B, C, ... X, Y, Z. After this comes AA, AB, AC ... AX, AY, AZ, BA and so on.

Your task is to convert one of these strings in to a column number. You must support inputs up to the maximum length of your language, to a minimum of 3.

Test Cases:

A   => 1
B   => 2
Z   => 26
AA  => 27
AC  => 29
AZ  => 52
BA  => 53
FC  => 159
ID  => 238
AAA => 703

Standard loopholes are forbidden.

Sandbox:

  1. Are my test cases correct? They were done of the top of my head, so they may not be accurate.
  2. Is this a duplicate? My searching suggests otherwise, but it may not be comprehensive.
  3. Are there any other tags I could add?
| |
\$\endgroup\$
  • \$\begingroup\$ As far as I can tell, your test cases are correct. I would specify how long the input can be (e.g. max of two characters) and provide some slightly larger test cases. Also, maybe the arithmetic/math tag? \$\endgroup\$ – caird coinheringaahing Sep 29 '19 at 13:40
  • \$\begingroup\$ @cairdcoinheringaahing Edited. \$\endgroup\$ – gadzooks02 Sep 29 '19 at 13:56
  • \$\begingroup\$ I feel as though this may be a dupe of one of the various base-conversion questions. Do you expect there is a better way to solve this than converting the letters to numbers and then interpreting them as a base 26 number? (Even if that is the best approach it won't necessarily mean it is a duplicate, I haven't checked through them yet, but I wanted to make sure you had considered it) \$\endgroup\$ – FryAmTheEggman Sep 29 '19 at 17:39
  • \$\begingroup\$ @FryAmTheEggman I had considered it. In fact, I was going to make some test cases that way, but I realised that a) I would have to convert by subtracting 10 and b) that conversion would most likely be too costly. I mean, how would you actually do that? Interpret as base 36, subtract ten, convert to string, interpret as base 26, convert to base 10? Doesn't seem feasible. \$\endgroup\$ – gadzooks02 Sep 29 '19 at 18:03
  • \$\begingroup\$ I didn't mean using builtins for base conversion, though they may be problematic too, but just literally doing base conversion. \$\endgroup\$ – FryAmTheEggman Sep 29 '19 at 18:27
  • \$\begingroup\$ @FryAmTheEggman Congratulations, you have the first answer! While good, I'm certain 63 bytes can be improved, and would be about standard for a Python answer. \$\endgroup\$ – gadzooks02 Sep 29 '19 at 18:38
  • \$\begingroup\$ Sorry, I think I haven't explained myself well. I was trying to show that base conversion questions might be a duplicate target for this one since this challenge can be solved directly with a base conversion after a very minor transformation. I haven't actually found a question that seems like a good enough target yet, but I wanted you to be aware of it (and perhaps look yourself :) ). \$\endgroup\$ – FryAmTheEggman Sep 29 '19 at 19:18
  • \$\begingroup\$ I think I found a duplicate, though it has some annoying extra bits of copying over the row number. \$\endgroup\$ – xnor Sep 29 '19 at 23:05
  • 2
    \$\begingroup\$ Duplicate \$\endgroup\$ – Jo King Sep 30 '19 at 1:57
0
\$\begingroup\$

DayByte Savings

Input: Any positive integer 1..n; or a year in the future (e.g. 2025)

Output: The date-times (UTC) that Britain will change to/from daylight savings times (i.e. 1am on the last Sunday in March and 2am on the last Sunday in October) between now (according to the machine running the code) and the current date in the year specified in the input. We can assume this rule won't change in the future.

Any valid list of date-time formats is fine for the output (e.g. "28th October 2018 2am" or "28-OCT-18T02:00:00" or "1540692000" [epoch time])

inspired by https://stackoverflow.com/questions/50839863/future-list-of-daylight-savings-changeover-date-times-uk

You could store all the data in your program (it counts towards your byte count), or just call a builtin that calculates it - your choice.

You can assume that 2099 (however far ahead that is) is the largest input.

, usual rules and exclusions apply. You won't have to deal with invalid inputs.

Example (assuming today is 23rd September 2019):

2020 or 1 -> 27th Oct 2019 2am; 29th Mar 2020 1am

2099 or 80 -> 27 October 2019 02:00:00
      29 March 2020 01:00:00
      25 October 2020 02:00:00
      28 March 2021 01:00:00
      31 October 2021 02:00:00
      27 March 2022 01:00:00
      30 October 2022 02:00:00
      26 March 2023 01:00:00
      29 October 2023 02:00:00
      31 March 2024 01:00:00
      27 October 2024 02:00:00
      30 March 2025 01:00:00
      26 October 2025 02:00:00
      29 March 2026 01:00:00
      25 October 2026 02:00:00
      28 March 2027 01:00:00
      31 October 2027 02:00:00
      26 March 2028 01:00:00
      29 October 2028 02:00:00
      25 March 2029 01:00:00
      28 October 2029 02:00:00
      31 March 2030 01:00:00
      27 October 2030 02:00:00
      30 March 2031 01:00:00
      26 October 2031 02:00:00
      28 March 2032 01:00:00
      31 October 2032 02:00:00
      27 March 2033 01:00:00
      30 October 2033 02:00:00
      26 March 2034 01:00:00
      29 October 2034 02:00:00
      25 March 2035 01:00:00
      28 October 2035 02:00:00
      30 March 2036 01:00:00
      26 October 2036 02:00:00
      29 March 2037 01:00:00
      25 October 2037 02:00:00
      28 March 2038 01:00:00
      31 October 2038 02:00:00
      27 March 2039 01:00:00
      30 October 2039 02:00:00
      25 March 2040 01:00:00
      28 October 2040 02:00:00
      31 March 2041 01:00:00
      27 October 2041 02:00:00
      30 March 2042 01:00:00
      26 October 2042 02:00:00
      29 March 2043 01:00:00
      25 October 2043 02:00:00
      27 March 2044 01:00:00
      30 October 2044 02:00:00
      26 March 2045 01:00:00
      29 October 2045 02:00:00
      25 March 2046 01:00:00
      28 October 2046 02:00:00
      31 March 2047 01:00:00
      27 October 2047 02:00:00
      29 March 2048 01:00:00
      25 October 2048 02:00:00
      28 March 2049 01:00:00
      31 October 2049 02:00:00
      27 March 2050 01:00:00
      30 October 2050 02:00:00
      26 March 2051 01:00:00
      29 October 2051 02:00:00
      31 March 2052 01:00:00
      27 October 2052 02:00:00
      30 March 2053 01:00:00
      26 October 2053 02:00:00
      29 March 2054 01:00:00
      25 October 2054 02:00:00
      28 March 2055 01:00:00
      31 October 2055 02:00:00
      26 March 2056 01:00:00
      29 October 2056 02:00:00
      25 March 2057 01:00:00
      28 October 2057 02:00:00
      31 March 2058 01:00:00
      27 October 2058 02:00:00
      30 March 2059 01:00:00
      26 October 2059 02:00:00
      28 March 2060 01:00:00
      31 October 2060 02:00:00
      27 March 2061 01:00:00
      30 October 2061 02:00:00
      26 March 2062 01:00:00
      29 October 2062 02:00:00
      25 March 2063 01:00:00
      28 October 2063 02:00:00
      30 March 2064 01:00:00
      26 October 2064 02:00:00
      29 March 2065 01:00:00
      25 October 2065 02:00:00
      28 March 2066 01:00:00
      31 October 2066 02:00:00
      27 March 2067 01:00:00
      30 October 2067 02:00:00
      25 March 2068 01:00:00
      28 October 2068 02:00:00
      31 March 2069 01:00:00
      27 October 2069 02:00:00
      30 March 2070 01:00:00
      26 October 2070 02:00:00
      29 March 2071 01:00:00
      25 October 2071 02:00:00
      27 March 2072 01:00:00
      30 October 2072 02:00:00
      26 March 2073 01:00:00
      29 October 2073 02:00:00
      25 March 2074 01:00:00
      28 October 2074 02:00:00
      31 March 2075 01:00:00
      27 October 2075 02:00:00
      29 March 2076 01:00:00
      25 October 2076 02:00:00
      28 March 2077 01:00:00
      31 October 2077 02:00:00
      27 March 2078 01:00:00
      30 October 2078 02:00:00
      26 March 2079 01:00:00
      29 October 2079 02:00:00
      31 March 2080 01:00:00
      27 October 2080 02:00:00
      30 March 2081 01:00:00
      26 October 2081 02:00:00
      29 March 2082 01:00:00
      25 October 2082 02:00:00
      28 March 2083 01:00:00
      31 October 2083 02:00:00
      26 March 2084 01:00:00
      29 October 2084 02:00:00
      25 March 2085 01:00:00
      28 October 2085 02:00:00
      31 March 2086 01:00:00
      27 October 2086 02:00:00
      30 March 2087 01:00:00
      26 October 2087 02:00:00
      28 March 2088 01:00:00
      31 October 2088 02:00:00
      27 March 2089 01:00:00
      30 October 2089 02:00:00
      26 March 2090 01:00:00
      29 October 2090 02:00:00
      25 March 2091 01:00:00
      28 October 2091 02:00:00
      30 March 2092 01:00:00
      26 October 2092 02:00:00
      29 March 2093 01:00:00
      25 October 2093 02:00:00
      28 March 2094 01:00:00
      31 October 2094 02:00:00
      27 March 2095 01:00:00
      30 October 2095 02:00:00
      25 March 2096 01:00:00
      28 October 2096 02:00:00
      31 March 2097 01:00:00
      27 October 2097 02:00:00
      30 March 2098 01:00:00
      26 October 2098 02:00:00
      29 March 2099 01:00:00
| |
\$\endgroup\$
  • \$\begingroup\$ p.s. how do people add formatted tags to answers? \$\endgroup\$ – simonalexander2005 Jun 13 '18 at 15:17
  • 1
    \$\begingroup\$ [tag:<name>], e.g. [tag:code-golf] (in comments, it looks like code-golf) \$\endgroup\$ – wastl Jun 13 '18 at 17:56
  • \$\begingroup\$ You can click at the "edited..." link and click "source" to view markdown source. \$\endgroup\$ – user202729 Jun 14 '18 at 11:29
  • \$\begingroup\$ Should the output be accurate to the date the challenge is posted, the date a solution is posted or the date that solution is run? Or, to put it another way, if I post a solution now it should, obviously, include 27/10/19 in the output but, if that solution is run after that date, should it still be included? \$\endgroup\$ – Shaggy Sep 27 '19 at 22:25
  • \$\begingroup\$ My thinking is, the date the challenge is run (i.e. whatever date is set on the machine the code is run on) \$\endgroup\$ – simonalexander2005 Sep 30 '19 at 8:01
  • \$\begingroup\$ Would this challenge be better if it was just "print the next time after "today" on your local system"? or "print the next time after the input date"? \$\endgroup\$ – simonalexander2005 Oct 4 '19 at 14:50
0
\$\begingroup\$

Golf a new OEIS sequence.

This is a challenge. The goal of this challenge is to create an integer sequence that is not in the OEIS using the fewest possible number of bytes.

Your program can either output an infinite list, or it can be a function from the natural numbers to the integers, which when evaluated on 1, 2, 3, 4,... gives a sequence that is not in the OEIS.

Restrictions

Without any restrictions, this is a very easy challenge, we can simply write a program that prints out the constant sequence consisting of 33, for example.

In order to avoid accepting "easy" sequences like this, your proposed sequence cannot be a finite linear combination or entrywise product of existing sequences or any rows or columns of existing tables in the OEIS.1

Also, I want to avoid submissions that take an otherwise disallowed sequence and prepend some list (e.g. 3,1,1,1,1,1,1,1,1,1,1). Thus the above rule must stand even after ignoring the first N terms of the sequence.2

Challenge

Post your source code, the first few terms of the sequence, and an explanation of what your source code is doing.

It's okay if your submission is not very mathematically interesting, but I'm hoping that one or two will be.

(Lastly, if your sequence is disqualified by someone writing is as linear combinations of existing sequences, feel free to modify/fix it, but please don't delete it.)


1 This rule disallows all polynomials in n, for example, since these can be written as finite linear combinations of columns in A009999 read as a square array.

2 This rule also disallows all finite-length sequences.

Meta

Note: I don't know if this challenge is totally silly, or if it has obvious loopholes, or if closing loopholes results in a challenge that is too difficult or arbitrary.

  • Tags: ,
  • Is this a duplicate?
  • Any other restrictions? Any loosening of current restrictions?
| |
\$\endgroup\$
  • 3
    \$\begingroup\$ I like the idea, but checking if an answer is valid seems really hard. For example, take n mod 13. It's not in OEIS (single-digit moduli are). But, there may well be 13 period-13 sequences in OEIS that are linearly independent, which would disqualify it. Maybe this could be a cops-and-robber style challenge where robbers try to invalidate answers, but the robber's task doesn't seem than fun. \$\endgroup\$ – xnor Oct 5 '19 at 18:31
  • 2
    \$\begingroup\$ What's to stop people from using the output of a seeded PRNG? It would be trivial to find a sequence from a seeded PRNG that doesn't exist on OEIS. The restriction of no linear combinations or entrywise products makes it more difficult to validate, but it is almost certainly still possible. \$\endgroup\$ – user45941 Oct 5 '19 at 18:38
  • 1
    \$\begingroup\$ @Mego, exactly the sort of feedback I was hoping for. I don't know how to elegantly work around that sort of answer—especially since a PRNG from a library wouldn't be in the spirit of the question, but a PRNG written by the user would be a great answer. I think I'll avoid submitting this question. \$\endgroup\$ – Peter Kagey Oct 5 '19 at 18:59
  • 1
    \$\begingroup\$ In addition to what has been said, ideas like linear combinations etc. start to break down when the sequences end. All (or at least most) OEIS sequences only have a finite number of terms present, some only even have a finite number of terms that can be calculated with modern computing power. So how do we deal with the finiteness of the sequences? \$\endgroup\$ – Wheat Wizard Oct 7 '19 at 4:12
  • 1
    \$\begingroup\$ I don't know whether the issues raised in earlier comments can be fixed, but if they can then there's another which can and should be: OEIS isn't static. If someone comes up with an interesting answer, it may well be submitted to OEIS. There are various ways to solve this problem: the easiest to verify would be to say that OEIS sequences beyond Axxxxxx can be ignored, where the sequence chosen is e.g. the highest numbered one with no assigned but unpublished gaps below it. \$\endgroup\$ – Peter Taylor Oct 7 '19 at 10:54
0
\$\begingroup\$

Draw a CE mark

Your input is the scaling factor n. You must output an image of width 82n and height 48n (if you are generating a vector image, it should have that as its default size). The image will be either transparent or white, with the following regions in black:

  • The segment of a ring centred at 24n,24n of outer radius 20n and inner radius 14n that is left of the vertical line at 26n.
  • A copy of that segment displaced 34n to the right. The original rings would therefore exactly overlap if they were not segments.
  • A rectangle with upper left corner at 44n,21n and lower right corner at 56n,27n.

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

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

moved

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ It's better to specify exactly what constitutes a valid output, rather than just saying "you can make up your own." That way we know what golfing tricks are permitted and what aren't. \$\endgroup\$ – Esolanging Fruit Jun 11 '19 at 4:49
  • \$\begingroup\$ @EsolangingFruit Okay. Since it is code-golf, not popularity contest, that would be better. I'll fix that. \$\endgroup\$ – LegenDUST Jun 11 '19 at 8:06
  • 2
    \$\begingroup\$ Bonuses/penalties in code-golf is not okay \$\endgroup\$ – MilkyWay90 Jun 11 '19 at 14:59
  • \$\begingroup\$ @MilkyWay90 Thank you for your advise. \$\endgroup\$ – LegenDUST Jun 12 '19 at 10:18
  • \$\begingroup\$ Can this be more self-contained? It seems that the majority of the question is hidden behind links to other sites. \$\endgroup\$ – Peter Taylor Jun 12 '19 at 10:52
  • \$\begingroup\$ @PeterTaylor I wanted to, but if I contain Korean character ascii arts in article, it gets so long. So I separated it. I though too long question is not good. If long question is okay, then I'll change it. \$\endgroup\$ – LegenDUST Jun 12 '19 at 11:09
  • \$\begingroup\$ @LegenDUST You could put all input-output in the same code-block, then a scrollbar is added automatically and the challenge is still self-contained. Then again, in the link you provided I only see ASCII arts for single or combinations of 2 Korean characters, whereas the examples have 3 Korean characters combined, so if all triplet-Korean characters are added as ASCII art it's quite a big list to scroll through.. \$\endgroup\$ – Kevin Cruijssen Jun 12 '19 at 12:17
  • \$\begingroup\$ @KevinCruijssen Thanks for tip! \$\endgroup\$ – LegenDUST Jun 12 '19 at 12:19
  • \$\begingroup\$ Seconding the recommendation against bonuses, I would make proper indentation required. \$\endgroup\$ – lirtosiast Jun 16 '19 at 8:03
  • \$\begingroup\$ @lirtosiast I'll think about it. Thanks. \$\endgroup\$ – LegenDUST Jun 17 '19 at 8:03
0
\$\begingroup\$

Typhoon: Where am I from?

Introduction

A typhoon is basically a hurricane in the northwestern Pacific region. Unlike hurricanes, typhoons are named by 14 regions, each providing 10 names, adding up to 140 names. The 140 names are used in a cyclic pattern; after the last name is used, the first one will be used again. The names may sometimes be retired, mainly because of the devastation the typhoon with those names have made.

Here are the 140 names.

enter image description here

[Text-only]

Region             Column 1   Column 2   Column 3   Column 4   Column 5   Column 6   Column 7   Column 8   Column 9   Column 10
-------------------------------------------------------------------------------------------------------------------------------
Cambodia           Damrey     Ampil      Kong-rey   Krosa      Nakri      Maysak     Krovanh    Chanthu    Trases     Nesat
China              Haikui     Wukong     Yutu       Bailu      Fengshen   Haishen    Dujuan     Dianmu     Mulan      Haitang
DPR Korea          Kirogi     Jongdari   Toraji     Podul      Kalmaegi   Noul       Surigae    Mindulle   Meari      Nalgae
Hong Kong, China   Yun-yeung  Shanshan   Man-yi     Lingling   Fung-wong  Dolphin    Choi-wan   Lionrock   Ma-on      Banyan
Japan              Koinu      Yagi       Usagi      Kajiki     Kammuri    Kujira     Koguma     Kompasu    Tokage     Yamaneko
Lao PDR            Bolaven    Leepi      Pabuk      Faxai      Phanfone   Chan-hom   Champi     Namtheun   Hinnamnor  Pakhar
Macao, China       Sanba      Bebinca    Wutip      Peipah     Vongfong   Linfa      In-fa      Malou      Muifa      Sanvu
Malaysia           Jelawat    Rumbia     Sepat      Tapah      Nuri       Nangka     Cempaka    Nyatoh     Merbok     Mawar
Micronesia         Ewiniar    Soulik     Mun        Mitag      Sinlaku    Saudel     Nepartak   Rai        Nanmadol   Guchol
Philippines        Maliksi    Cimaron    Danas      Hagibis    Hagupit    Molave     Lupit      Malakas    Talas      Talim
RO Korea           Gaemi      Jebi       Nari       Neoguri    Jangmi     Goni       Mirinae    Megi       Noru       Doksuri
Thailand           Prapiroon  Mangkhut   Wipha      Bualoi     Mekkhala   Atsani     Nida       Chaba      Kulap      Khanun
U.S.A.             Maria      Barijat    Francisco  Matmo      Higos      Etau       Omais      Aere       Roke       Lan
Viet Nam           Son-Tinh   Trami      Lekima     Halong     Bavi       Vamco      Conson     Songda     Sonca      Saola

[JSON]

{"Cambodia":["Damrey","Ampil","Kong-rey","Krosa","Nakri","Maysak","Krovanh","Chanthu","Trases","Nesat"],"China":["Haikui","Wukong","Yutu","Bailu","Fengshen","Haishen","Dujuan","Dianmu","Mulan","Haitang"],"DPR Korea":["Kirogi","Jongdari","Toraji","Podul","Kalmaegi","Noul","Surigae","Mindulle","Meari","Nalgae"],"Hong Kong, China":["Yun-yeung","Shanshan","Man-yi","Lingling","Fung-wong","Dolphin","Choi-wan","Lionrock","Ma-on","Banyan"],"Japan":["Koinu","Yagi","Usagi","Kajiki","Kammuri","Kujira","Koguma","Kompasu","Tokage","Yamaneko"],"Lao PDR":["Bolaven","Leepi","Pabuk","Faxai","Phanfone","Chan-hom","Champi","Namtheun","Hinnamnor","Pakhar"],"Macao, China":["Sanba","Bebinca","Wutip","Peipah","Vongfong","Linfa","In-fa","Malou","Muifa","Sanvu"],"Malaysia":["Jelawat","Rumbia","Sepat","Tapah","Nuri","Nangka","Cempaka","Nyatoh","Merbok","Mawar"],"Micronesia":["Ewiniar","Soulik","Mun","Mitag","Sinlaku","Saudel","Nepartak","Rai","Nanmadol","Guchol"],"Philippines":["Maliksi","Cimaron","Danas","Hagibis","Hagupit","Molave","Lupit","Malakas","Talas","Talim"],"RO Korea":["Gaemi","Jebi","Nari","Neoguri","Jangmi","Goni","Mirinae","Megi","Noru","Doksuri"],"Thailand":["Prapiroon","Mangkhut","Wipha","Bualoi","Mekkhala","Atsani","Nida","Chaba","Kulap","Khanun"],"U.S.A.":["Maria","Barijat","Francisco","Matmo","Higos","Etau","Omais","Aere","Roke","Lan"],"Viet Nam":["Son-Tinh","Trami","Lekima","Halong","Bavi","Vamco","Conson","Songda","Sonca","Saola"]}

This chart is based from that on the Japan Meteorological Agency website, retrieved on 10 October 2019. Conventionally the list is divided into 5 columns, but in order to list all the names by region, I have organized them into 10 columns, so that each row fits all names from the same region. Moreover, two of the names, Mangkhut and Rumbia are retired and are still pending for replacement. Here I will keep these 2 names for integrity.

Challenge

Write a program or function, that receives a name in the list above as input, and returns or outputs which region it is named after.

The input and output formats are flexible. For input, you may omit the hyphens and/or receive all uppercase or lowercase input. For output, you may also instead return an element from a set of 14 distinct values of your choice, each representing a region.

Your program does not need to deal with invalid inputs.

Sample I/O

Input: Chan-hom (exact wording)
Output: Lao PDR (exact wording)

Input: Kongrey (Kon-grey; without hyphen)
Output: KH (Cambodia; ISO 3166 code, uppercase)

Input: atsani (Atsani; all lowercase)
Output: th (Thailand; ISO 3166 code, lowercase)

Input: LAN (Lan; all uppercase)
Output: 12 (U.S.A; 0-indexed)

Input: choiwan (Choi-wan; without hyphen & all lowercase)
Output: 4 (Hong Kong, China; 1-indexed)

Input: INFA (In-fa; without hyphen & all uppercase)
Output: Macau (Macao, China; common name) 

Again, you may have different output formats, but the input and output formats you use must be stated.

Winning Criteria

The shortest submission in each language wins. No loophole is allowed.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Please add a table in a machine readable format. \$\endgroup\$ – Adám Oct 10 '19 at 9:51
  • \$\begingroup\$ @Adám Added just below the image. \$\endgroup\$ – Shieru Asakoto Oct 10 '19 at 9:56
  • \$\begingroup\$ How about CSV or JSON? \$\endgroup\$ – Adám Oct 10 '19 at 9:56
  • 1
    \$\begingroup\$ @Adám I think I will add a json version. \$\endgroup\$ – Shieru Asakoto Oct 10 '19 at 9:58
  • \$\begingroup\$ @Adám Added the corresponding JSON for the table. \$\endgroup\$ – Shieru Asakoto Oct 10 '19 at 10:32
  • \$\begingroup\$ Unfortunately, this challenge becomes more about compressing the table than anything else :-( \$\endgroup\$ – Adám Oct 10 '19 at 10:52
  • \$\begingroup\$ @Adám I know that's just some reverse lookup, but well my intent is to see how this can be golfed smartly actually hmm.. \$\endgroup\$ – Shieru Asakoto Oct 11 '19 at 1:18
  • 1
    \$\begingroup\$ Without compression, the best I came up with was to take input without dashes, but with capitals, then remove "rona" and look it up in a string of first-three-letters-except-"rona". You could give the table as an input… \$\endgroup\$ – Adám Oct 11 '19 at 1:20
0
\$\begingroup\$

How often does the word sixty-eight (68) appear in numbers from 1 to N. The upper limit for N to which the program needs to be able to perform is 100 000 000.

The program will take N as input and return every number in which the word sixty-eight appears from 1 to N, and a sum of all appearances of sixty-eight at the end.

I'm looking for the spoken form, so the word sixty-eight appears in

68 000 000 - sixty-eight million - once

68 680 000 - sixty-eight million six-hundred thousand - once

68 068 068 - sixty-eight million sixty-eight thousand and sixty-eight - three times

and so on. The shortest implementation that gives a correct result wins.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Thank you so much for using the sandbox. \$\endgroup\$ – Adám Oct 10 '19 at 13:48
  • \$\begingroup\$ Alright, no tie-breaker then \$\endgroup\$ – mag Oct 10 '19 at 14:10
  • \$\begingroup\$ What, exactly, is a "sum of all appearances of sixty-eight at the end"? Also, there is a typo in your second test case I think (should be six-hundred eighty thousand, right?). \$\endgroup\$ – FryAmTheEggman Oct 10 '19 at 18:34
  • 1
    \$\begingroup\$ 68 680 000 should be sixty-eight million six-hundred eighty thousand, right? \$\endgroup\$ – u-ndefined Oct 13 '19 at 7:14
0
\$\begingroup\$

Golf you a co-quine for greater good!

Build a program that halts if and only if the input matches the source code.

| |
\$\endgroup\$
  • \$\begingroup\$ A superset of this. \$\endgroup\$ – user85052 Oct 16 '19 at 10:41
0
\$\begingroup\$

Doing something with Haifu

Haifu is an esoteric programming language by David Morgan-Mar, which, in addition to having a very weird control scheme also has the requirement that each program should be in the form of Haiku.

Maybe it would be possible to do a -like challenge with it. The robber's task is to write a Haifu program doing something non-trivial, using a shorthand code, where each command/variable is replaced by a unique single- or two-character identifier, and ignoring the haiku structure demand (The language is weird enough that even "Hello World" isn't a trivial task). The cop's task is to take a robber's code and turn it into a valid Haiku. However, this would either be a , or maybe even outsourced to a different SE site.

Meta questions:

Is this a feasible concept and does it fit into the spirit of CodeGolf.SE?

The Haifu specification is not quite complete. If I'd be doing this, I'd need first some sharp eyes to help me spot all the holes and fill them. Then, the shortened syntax for the coding part would need to be designed. If enough people say it might be feasible, I'll probably open a chat room to discuss this.

Lastly, of course, what to do with the turning code into Haiku part of the challenge?

| |
\$\endgroup\$
  • \$\begingroup\$ Is there an implementation of Haifu already? Regardless, based on the allowance of comments in the poems it does not appear difficult to produce any particular program in Haifu (though golfing is a different matter). Making this a popularity contest sounds like a rather bad idea - what objective voting criterion would you be considering? Of course, if you make one yourself you could probably post it to puzzling. \$\endgroup\$ – FryAmTheEggman Oct 17 '19 at 19:47
0
\$\begingroup\$

Intersect the integer ranges

Integer ranges take one of four forms:

  1. A start, a step and an end. Both ends are included in the range. The difference between the end and start is guaranteed to be a multiple of the step. The step is guaranteed to be positive, even if the start is equal to the end (it may not be greater).
  2. A start and a step. This is a half-infinite range.
  3. A step and an end. This is also a half-infinite range.
  4. An empty range. You can decide how you want to represent this, but you must accept as input any empty range you can output.

Given two integer ranges, please output their intersection.

  1. If the two ranges are disjoint, return an empty range.
  2. If the two ranges are identical, simply output one of them.
  3. If one range completely subsumes the other, output the latter.
  4. Determine the values common to both ranges, and output a range that represents these values.

Examples:

[1, 1, 6] ∩ [3, 1, 9] = [3, 1, 6]
[1, 2, 9] ∩ [2, 1, 8] = [2, 2, 8]
[1, 2, ~] ∩ [2, 3, ~] = [5, 6, ~]
[~, 2, 9] ∩ [1, 3, ~] = [1, 6, 7]
[1, 2, 3] ∩ [2, 2, 2] = []

If would be nice if you could indicate any preconditions that your answer doesn't require (e.g. if it works for a step of zero when the start and end are the same).

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

| |
\$\endgroup\$
  • \$\begingroup\$ [] v [] makes it look like you want the union () instead of intersection () \$\endgroup\$ – Kroppeb Oct 17 '19 at 15:53
  • \$\begingroup\$ @Kroppeb Whoops, I was so lazy that not only didn't I look up the right character but I used the wrong ASCII character too... sorry about that. \$\endgroup\$ – Neil Oct 17 '19 at 17:47
0
\$\begingroup\$

Can I run this?

I'm a big fan of challenges, and an idea recently struck me. Suppose you're on a *nix system and you want to know how many executable programs you have installed that you can run. Given a file with mode mode, you can run it if it is a normal file (mode & S_IFMT == S_IFREG) and any of the following are true:

  • Its owner is equal to your effective user id and 0100 & p != 0 (user executable bit is set)
  • Its group is a group you are a member of and 0010 & p != 0 (group executable bit is set)
  • 0001 & p != 0 (world executable bit is set)

Rules:

TODO: See below.


For Sandbox

Writing a good challenge is hard. I have some ideas, but I've brainstormed some easy solutions and I want to know which challenge and restrictions would be most well-received.

There are three possible challenges I am considering:

  • single file: Given a path as input, output truthy/falsy whether the path is a path to a file the user can run.

  • count in directory: output the number of files the user can run at any depth underneath the current working directory (or a provided directory, should you prefer that)

  • count in PATH: output the number of files the user can run immediately under any directory in the environment variable PATH. The value of PATH may also be given as input to the program/function.

Potential restrictions (I marked as spoilers since these can provide solutions if I don't ban them):

  • Banning the use of access()/os.access()/etc.

  • Banning the use of the which executable typically found on *nix machines (which is exactly the solution to the first challenge)

  • Banning the use of any external executables

I am currently inclined to choose the second challenge, allow all solutions, but award a bounty to the shortest program which follows the above restrictions.

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

Universal duct tape programming

The task is to write a program that [TODO: insert simpleish task here] that works in as many languages as possible, while only using code that was already written before by someone else at http://stackoverflow.com. To minimize time, you are trying to use as few snippets as possible. Therefore, they must be as long as possible.

Code from http://stackoverflow.com is defined as substrings of code blocks in questions, answers and comments created before this challenge [TODO: or perhaps this sandbox post?]. You must link to the source of the code in your answer. You can concatenate multiple snippets, optionally inserting newlines.

Your code must work in at least two different languages.

Your score is equal to the minimum of the number of languages your code works in and the length of the shortest snippet you use. Highest score wins.

Sandbox stuff

  • Is this a good idea?
  • How simple should the simpleish task be?
  • Can the scoring system be abused?
  • Does the "multiple languages" part need clarification?
  • Does the "stackoverflow snippets" part need clarification?
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ Is this supposed to be a polyglot or just multiple versions of the same problem? Why require 2 snippets? I think a better scoring system would be language_count/number_of_snippets. The best way to abuse the scoring system right now is to copy from overly verbose languages like Java. \$\endgroup\$ – Beefster Sep 13 '19 at 20:25
  • \$\begingroup\$ @Beefster This is supposed to be a polyglot. Will try to fix all 3 points in a few hours. \$\endgroup\$ – the default. Sep 14 '19 at 0:03
  • \$\begingroup\$ Can we use snippets from code review as well? \$\endgroup\$ – Lyxal Sep 15 '19 at 4:21
  • \$\begingroup\$ -1 duct-taping and polyglotting are mostly incompatible goals. This will tend to result in a lot of C/C++ solutions and not much else. \$\endgroup\$ – Beefster Sep 16 '19 at 0:52
0
\$\begingroup\$

Title: Station Codes

Background

In the UK, railway stations are assigned three-letter "CRS" codes (e.g. "Chester" = CTR, "Caterham" = CAT). Something similar is also used for airports worldwide (IATA codes).

Challenge

The challenge is to take in the three letter code as the input, and present the name of the station as the output.

The codes are always in upper-case; the outputs are as shown in the link above.

Usual IO rules, exclusions; code-golf rules apply.

Examples

  • CAT -> Caterham
  • CCH -> Chichester
  • HHY -> Highbury & Islington
  • HOP -> Hope (Derbyshire)
  • AUW -> Ascott-under-Wychwood
  • CSD -> Cobham & Stoke d'Abernon
  • HID -> Hall-i'-th'-Wood
  • HXX -> Heathrow Airport Terminals 1, 2 and 3
  • ELY -> Ely
  • anything else listed in the link above - the correct station name
  • anything not listed in the link above -> no preference

Sandbox Query

Is this boring? - does it add anything to the existing gamut of "compress a load of data and index it" -type questions?

| |
\$\endgroup\$
  • \$\begingroup\$ I'm not sure if this challenge is going to be interesting or not, as there are so many codes and I'm not sure if most of them can be formulated. But anyways I think you need to list all of the codes in your question as the link can go down or change. Generally challenges should be self containing without the need to open any external links or resources. \$\endgroup\$ – Night2 Oct 18 '19 at 14:53
  • \$\begingroup\$ Is their any logic to the limited subset of stations you've chosen for the challenge? This isn't, strictly, KC, by the way. \$\endgroup\$ – Shaggy Oct 19 '19 at 23:00
  • \$\begingroup\$ @Night2 Thanks, I'll list out the codes. \$\endgroup\$ – simonalexander2005 Oct 20 '19 at 13:37
  • \$\begingroup\$ @Shaggy the codes I used in the examples were chosen because they cover the all the non-alpha characters in the station names. The challenge, though. uses the entire set of CRS codes, as published by Network Rail. Are there some other codes you're thinking of that aren't covered by that list (now included in the question also)? \$\endgroup\$ – simonalexander2005 Oct 20 '19 at 13:38
  • \$\begingroup\$ @Night2 actually I can't include the codes, it's too many characters so it exceeds the limit of 30,000 characters \$\endgroup\$ – simonalexander2005 Oct 20 '19 at 13:43
  • \$\begingroup\$ That is a problem for itself, about 40k characters for a code golf challenge. Even if there was a formula to 100% of the times, match an input code to a station name, there would still be around 30k characters for station names to store. \$\endgroup\$ – Night2 Oct 23 '19 at 3:23
0
\$\begingroup\$

Implement Or

or is a dubious esoteric programming language. The author is unknown but it is known that fungot (a chatbot) is currently learning or but it remains unknown how it does it and where it receives the required material to learn or. Check out this IRC log to see fungot revealing part of the language.

Instruction reference

It is only known that a space followed by an f pushes false to the stack. The false value may by any falsy value of your choosing. Since this language does not support output, in order to make verifying answers possible, you should output the resulting stack in the end of the program.

Test cases

Expects one false to the stack

 f

Expects 2 falses on the stack

m f ma f

Expects 1 false on the stack

 f a lf 

Expects 2 falses on the stack

a f fa

Scoring

This is , so shortest answer in bytes wins.

Meta

  • Is this clear enough?
  • I haven't found a duplicate, but anything?
  • Tags are code-golf, string and interpreter. Anything else?
  • Any further feedback?
| |
\$\endgroup\$
  • \$\begingroup\$ Duplicate of this. \$\endgroup\$ – user85052 Oct 21 '19 at 14:01
  • \$\begingroup\$ Duplicate of this. \$\endgroup\$ – user85052 Oct 21 '19 at 14:02
  • \$\begingroup\$ Duplicate of this. \$\endgroup\$ – user85052 Oct 21 '19 at 14:03
0
\$\begingroup\$

Make a karaoke machine

Given a list of lines and a set time (in seconds) which those lines appear, output those lines after that specific amount of seconds.

Example input:

0 Hello there!
5 This line should come up after 5 seconds.
10 This line should come up 5 seconds after that one.
20 There's a 10-second delay here.

Every line will be preceded by an integer, separated from the rest of the line by a string. The number indicates when the line should come up - the first line should be outputted instantly, followed by the next few lines like so:

Hello there! (output instantly)
(wait 5 seconds)
This line should come up after 5 seconds.
(wait 5 seconds)
This line should come up 5 seconds after that one.
(wait 10 seconds)
There's a 10-second delay here.

Assumptions:

  • You're guaranteed that the lines are in order - i.e. this doesn't happen:
    5 Hello there!
    0 Oops, this is meant to happen before the first line.
    
  • You're also guaranteed that no two lines share the same time.

Winning criteria:

This is , so shortest code in bytes wins!

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ No problem in particular. However I'd expect that many solution will have unbounded drift when the number of lines increases, so you may ban that (w. r. t. the system clock if there's one, for example) plus, I suppose that lines are short enough such that printing them takes a negligible time. \$\endgroup\$ – user202729 Oct 28 '19 at 10:59
  • \$\begingroup\$ I found several related challenges: 1 2 3. None of them were quite the same, but I think they all suffered from some of the problems that user202729 mentioned. Most of them still went well, but I think being more rigorous won't hurt. \$\endgroup\$ – FryAmTheEggman Oct 28 '19 at 15:15
0
\$\begingroup\$

Interpolate between binary images

While there are various ways to interpolate between images with a large color space where for each color there are many similar other colors, it is not so straightforward to do that in a (heavily) quantized color space where you only have few colors available. We now take that to an extreme:

Given two black and white image of the same size as well as a number \$N\$, output a sequence of \$N\$ images that "interpolate" between the two input pictures.

The goal here is coming up with an "interpolation" algorithm that allows you to smoothly transition between two images. But how you define this smoothness is up to you. The more aesthetically pleasing the better.

Details

  • "black and white" here means the images consist only of the colors black and white, no grays.
  • Validity criteria:
    • The first image in the sequence must be the first input image, and the last image in the sequence must be the second image.
    • All images must have the same size and consist of only black and white pixels. Furthermore the output must be deterministic in the sense that if you repeatedly call the program with identical inputs, you must get identical outputs.
  • Please post the sequence of images as an animation in your answer, for any \$N\$ you choose.

Examples

To be defined...

| |
\$\endgroup\$
  • \$\begingroup\$ popularity contests are at this point considered almost considered "historical". You need a clear scoring criterion for a valid challenge, which in your case means defining smoothness as something better than just "It's up to you" \$\endgroup\$ – AlienAtSystem Nov 19 '19 at 12:10
  • \$\begingroup\$ @AlienAtSystem The popularity contests need validity criteria, but no scoring criteria - we discussed this quite thoroughly about 2 years ago. The problem is that you cannot force people to vote according to a specific way, but you have to design the contest in a way that the desired output is something people will like anyway. It is not really historical, it is just rare that good popularity contests are written. Check out the discussions linked here. \$\endgroup\$ – flawr Nov 19 '19 at 13:19
0
\$\begingroup\$

Mahjong bot

It seems there isn't a challenge about mahjong bot...

Basic idea is a simplified mahjong rule:

Rules for beginners

Mahjong game use 136 mahjong tiles (similar to poker cards). There are 4 players in a game.

Tiles

There are 136 tiles in total.

There are 3 simple suits. Tiles numbered from 1 to 9 in each simple suit. There are 4 identical copies of each tiles in simple suits. That is \$3\times 9\times 4=108\$ tiles. These 3 simple suits are donated as m, p, s. For example, m1 means a tile with number 1 in m suit.

There are also 7 honors tiles. And there are also 4 copies of each honors tile. That is \$7\times 4=28\$ tiles. These tiles are donated as z1 ~ z7. Don't be confused with m, p, s, honors tails are not numbered. Donating as z1 ~ z7 just make it easy.

Game

  1. All 136 tiles are shuffled first;
  2. Each player receives 13 tiles at the beginning (These tiles are kept secret to others); Starting from the first player...
  3. The player draw a tile (secret to others), and then
    • Claim win, or
    • Kong, or
    • Discard a tile
  4. After someone discard a tile, others may
    • Claim win, or
    • Pong, or
    • Kong, or
    • Do nothing (pass)
  5. If anyone win, the game ends;
  6. If anyone Pong, the player have to discard a tile and continue to step 4;
  7. If anyone Kong, the player draw a tile and continue to step 3;
  8. Otherwise, next player draw a tile and the game goes on to step 3;
  9. When someone try to draw a tile but there are no more tiles left, the game draw (no winner).

Win

A player can claim win if tiles in his hand meet requirements (known as self-pick). A player may also declare win if others discard the last tile he need to complete the hand (known as feed). In case two or three players claim win after a single discard, only the one closest player win.

A winning hand must consist of four melds and a pair.

Melds includes Pongs, Kongs, or Chows:

  • Pong: A set of three identical tiles.
    • Example: m1m1m1, p8p8p8, z3z3z3
  • Kong: A set of four identical tiles. (Read more details in Kong section)
    • Example: m1m1m1m1, p8p8p8p8, z3z3z3z3
  • Chows: A meld of three suited tiles in sequence. Only simple suits may in a Chows.
    • Example: m1m2m3, p5p6p7, s7s8s9
    • Invalid: m8m9m1 (no wrap), m1p2s3 (no mixed suit), z1z2z3 (no honors tails)

A pair is two identical tiles.

Any tile may only be used in one Meld / Pair. It should not be reused.

Pong

When someone discards a stail, other players may teal the tile to complete a Pong.

  • The player claim Pong;
  • The player got the discarded tile;
  • The player expose two more identical tiles to others and place all these three tiles in the front;
  • The player must discard a tile, and the game continue;

Kong

When a player

  • Collect all 4 identical tiles in his hand;
  • Collect 3 identical tiles, and others discard the last one;
  • Collect the last one, while the other 3 are already exposed as Pong by him

The player may claim Kong. When someone claim a Kong

  • Expose all 4 tiles to others, and put them in the front;
  • Draw another tile;
  • The game goes on;

Tiles used in exposed Pong / Kong may not be changed or discarded later. When declare win, tiles used in exposed Pong / Kong must not be reused in other Chows.

Points

  • If a player win by self-pick: The winner got 3 points, others lost 1 point;
  • If a player win by feed: The winner got 3 points. The one who discard that card lost 3 points. Others neither got or lost points.
  • In case a player try some illegal moves: The player lost 9 points. All others got 3 points. And the game ends;
  • Once the game draw by run out of tiles, no points got or lost.

Rules if you already know mahjong

  • Use 136 tiles, no bonus tiles (花牌, flowers) included;
  • 13 / 14 tiles each player at beginning, 4 players;
  • Win only if 4 meld (面子, set), and 1 pair (对, 頭, head, eye);
    • no seven pairs (七对, 七対子), thirteen orphans (十三幺, 国士無双), nagashi mangan (流し満貫), Knitted Straight (组合龙), ect.
  • Pong (碰, ポン, pon), Kong (槓, カン, kan) exists, but not Chow (吃, チー, chii);
  • Both self-pick (自摸, ツモ), feed (食糊, 出铳, ロン) exits; But not robbing a Kong (搶槓)
  • All winning hands worth 1 point (分, 点), no yaku (役, pattern), faan (番, han), fu (符), starting dealer (莊, 庄) calculated;
    • self-pick: winner +3, others -1
    • feed: winner +3, loser -3
    • Replacement tile (嶺上牌, rinshanpai) after open Kong (大明槓) count as self-pick
    • A bot try to act some invalid moves lose the game, which -9, and others +3
  • At most one winner each game (盘, 局). No Sichuan rule, nor multiple feed;
  • No need to claim riichi (立直, リーチ), no furiten (振聴 or フリテン), no abortive draws (途中流局, tochuu ryuukyoku), no not-waiting penalty (ノーテン罰符), no joker tiles (百搭);
  • Starting dealer changed every game no matter who won the last game or draw;

Winning

The player who got most points after certain times of games win.

Controller

Later, it should be in Python 3 as it is popular here.


Sandbox: Is the rule given above suitable? (Since no one want to change rules after writing controller...)

| |
\$\endgroup\$
  • \$\begingroup\$ 1. How will you organize the games between multiple bots, e.g. a tournament or a league? 2. A regular mahjong match usually consists of multiple games (east-wind match or south-wind match). I think you'll need to specify how long each match will be (single-game matches will be fine though). 3. After four kans, no one can declare another kan, right? 4. Just a matter of preference: when you explain the mahjong rules, using pure English terms might be easier to read. \$\endgroup\$ – Bubbler Oct 31 '19 at 9:40
  • \$\begingroup\$ The simplified rules themselves are fine I guess. I can think of a general strategy: go for riichi-style, try to maximize the number of remaining winning tiles, go for a pon when I have multiple pairs, and kan whenever possible. I don't think I can set up a reliable defense because no riichi and no furiten. I just can't imagine how to write these into code... \$\endgroup\$ – Bubbler Oct 31 '19 at 9:47
  • \$\begingroup\$ @Bubbler 1. Run Combination(n, 4) times (Assuming n > 4, otherwise maybe I need to duplicate every bots); 2. Maybe 100 games should be fine. (Starting dealer always change, so nothing east-wind / south-wind would include.) Running only 16 games seems not enough. (This will depends on how many answers then). 3. The 5th, 6th kan are also valid, since we do not include abortive draws nor dora here; 4. I will describe the rules for beginners later. And it would be in English. Current rule is for players who already know how to play. \$\endgroup\$ – tsh Oct 31 '19 at 10:06
  • \$\begingroup\$ @Bubbler I comment these words in brackets since I cannot find any stander translations. And translations vary from one to another (for example, all Chow / Chii / Chi spelling are exists... \$\endgroup\$ – tsh Oct 31 '19 at 10:11
0
\$\begingroup\$

Draw a hexagonal grid n×m of ascii hexagons

  ____
 /    \
/      \
\      /
 \____/

with numbers somewhere within each of them, such as numbers goes in snail order starting in the center (but without empty hexagons):

  ____        ____        ____        ____        ____        ____
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/      \____/      \____/      \____/      \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/      \____/  25  \____/      \____/      \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/      \____/  26  \____/  24  \____/      \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/  27  \____/  11  \____/  23  \____/      \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/  28  \____/  12  \____/  10  \____/  22  \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/  13  \____/  3   \____/  9   \____/  40  \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/  29  \____/  4   \____/  2   \____/  21  \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/  14  \____/  1   \____/  8   \____/  39  \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/  30  \____/  5   \____/  7   \____/  20  \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/  15  \____/  6   \____/  19  \____/  38  \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/  31  \____/  16  \____/  18  \____/  37  \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/  32  \____/  17  \____/  36  \____/      \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/      \____/  33  \____/  35  \____/      \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/      \____/  34  \____/      \____/      \____/
 /    \      /    \      /    \      /    \      /    \      /    \
/      \____/      \____/      \____/      \____/      \____/      \
\      /    \      /    \      /    \      /    \      /    \      /
 \____/      \____/      \____/      \____/      \____/      \____/
| |
\$\endgroup\$
  • 4
    \$\begingroup\$ 1. Can you provide examples for smaller various n,ms? Especially, I want to see examples for odd and even widths. 2. Should the numbers be distinct in every cell? 3. Assuming the answer to 2 is true, What should we do if the number doesn't fit in a single line inside the hexagon (i.e. 7 digits or higher)? \$\endgroup\$ – Bubbler Nov 11 '19 at 4:17
  • \$\begingroup\$ Maybe we should assume n,m to be odd. \$\endgroup\$ – Alexey Burdin Nov 12 '19 at 18:17
0
\$\begingroup\$

Monokeyed Words

(Based on https://what-if.xkcd.com/75/)

Old mobile phones had letters and numbers assigned to the same key, as follows:

  • 1
  • 2abc
  • 3def
  • 4ghi
  • 5jkl
  • 6mno
  • 7pqrs
  • 8tuv
  • 9wxyz
  • 0 [space]

From any given list of words or phrases (arbitrary number of inputs, formed of 0-9 a-z and space), find the word which has the most consecutive characters on the same key, and output the key and the count (in any reasonable format)

for example:

  • [nonmonogamous],[qwerty],[false] -> 7, 6 (seven times on the 6 key - nonmonogamous)
  • [tutu],[cat],[mouse] -> 4, 8 (four times on the 8 key - tutu)
  • [cab],[mon],[tin],[tom] -> 3,2 (cab) or 3,6 (mon) - either answer is valid
  • [#],[!!!],[is this valid?] -> any output or error - doesn't fit valid inputs. 2,4 would also be acceptable, for hi in is this valid?
  • bacmon, habitat, fringe, be, test, valid -> 3,2 or 3,6 as it's a tie between those keys
  • 01452301146 -> 2,1 (two in a row on the 1 key)

The output format isn't fixed, so you could also output [3][6] or 3.6 or 6,3 - anything you like, as long as it's consistent which is the key and which the number of repetitions. You could also use one of the letters to represent the key, if you wanted - e.g. instead of 3,6 you could output 3,m

This is , usual exclusions etc. apply

| |
\$\endgroup\$
  • \$\begingroup\$ I don't think I understand what you mean by "wordlists." You don't appear to want us to check a lexicon (as 9wxyz9wxyz isn't a word in any language I know). If you just mean an input which is a list of strings then you don't need to do anything besides say that - the default rules will handle that no problem. Aside from that, this seems to have some "fluff" in that I think you'd be better off asking for just a summary (i.e. the longest chain of what button) of one input word or just finding the maximal word(s) from a list. Once you have one, getting the other is more or less trivial. \$\endgroup\$ – FryAmTheEggman Nov 11 '19 at 20:25
  • \$\begingroup\$ Thanks, that makes sense. I was originally wanting to do exactly the same as the link (i.e. look up based on a whole dictionary), but I changed my mind part way through. As for the "fluff", yes OK I can see that; I'll edit my question \$\endgroup\$ – simonalexander2005 Nov 12 '19 at 9:17
  • \$\begingroup\$ I think changing your mind halfway has happened to all of us at least once :) That said, I find your edits somewhat confusing - you seem to have changed it to just be one word in the new test cases but have kept the old ones. \$\endgroup\$ – FryAmTheEggman Nov 12 '19 at 20:50
  • \$\begingroup\$ @FryAmTheEggman yes, the program should be able to take an aribtrary number of inputs \$\endgroup\$ – simonalexander2005 Nov 13 '19 at 9:35
0
\$\begingroup\$

Description

Cornhole is a game in which players take turns throwing bags filled with corn kernels(or other fillers) onto a wooden board with a hole in the far end. If a bag goes through the hole, it counts as 3 points. If a bag stays on top of the board without falling off it counts as 1 point.

Score is taken at the end of each round in which the two players throw 4 bags (alternating). Only the net score is calculated.

The first to exactly 21 points is the winner. If a player were to score points in a round that would bring them to exceed 21 points, the points for that round are subtracted from the players score.

Rule

  1. Given an array of scores from multiple rounds of Cornhole, determine the current score of the game.

Input

The input will be an array of one or more rounds of scores for each bag throw by both players alternating. (you may choose any 3 distinct symbols to cover the scenario of misses, 1 point, or 3 points)

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

  • In this scenario
    • Player A missed the first shot, Player B missed their first shot, Player A landed the bag on the board for their second shot, Player B missed their second shot, Player A made it in the hole for their third shot, Player B made it in the hole for their third shot, Player A landed on the board for their fourth shot, and Player B landed on their board for their fourth shot.
    • In the next round of play, Player A missed the first shot, Player B missed their first shot, Player A landed the bag on the board for their second shot, Player B missed their second shot, Player A made it in the hole for their third shot, Player B made it in the hole for their third shot, Player A landed on the board for their fourth shot, and Player B landed on their board for their fourth shot.

Output

The score of the Cornhole match as an array of two numbers. From the input above, the output would be:

[2,0]

Examples:

 Insert multiple samples of scoring, including one example of a player scoring over 21 and losing points

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

SandChallenges for Proposed box [draft]

In this challenge you should simulate how "challenges" interact with each other. (You need to output how many iterations have the "challenges" done.)

Symbols used in the documentation

SandChallenges is played on a 3x3 grid.

  • X represents a challenge. It challenges the grid next to its position.

  • represents an empty sandpile. This is what the "challenges" move in their actions.

  • . represents moving sandpiles and is only used in this documentation. Input will never contain those characters; it instead will only contain X and .

A closer look at X challenges

There are sandpiles between those "challenges". When a "challenge" is active, it pushes sand towards the next grid. The next grid is described as the following:

  • The next grid is usually the grid on the right.
  • If the grid is on the right edge, the next grid becomes the first grid of the next line.
  • If the grid is on the last line, the next grid becomes the first grid of the first line.
ABC
DEF
GHI

The next grid of A is B, the next grid of C is D, and the next grid of I is A.


Another rule: they can get buried by active sandpiles. This makes them fail to function.

Test cases

Spaces are replaced with semicolons for readability problems.

X;;
;;;
;;;

-> (Affecting the next cell)

X.;
;;;
;;;

->

X..    X..    X..           X..
;;; -> .;; -> ..; -> ... -> ...
;;;    ;;;    ;;;           ...

After that the "challenge" gets buried by active sandpiles, which results in the following state:

...
...
...

This box had went through 9 changes before it stops.

XXX    ...
XXX -> ...
XXX    ...

This means that the challenge had went through 1 change before it stops. All of them push active sand and buries themselves simultaneously.

X;;    X.;
;X; -> ;X.
;;X    ;;X

The bottom-right challenge shoots active sand, which buries the active challenge in the same iteration:

..;    ...    ...    ...
;X. -> ;X. -> .X. -> ...
;;X    .;X    ..X    ...

This goes through 4 iterations.

X;;    X.;    X..    ...
X;; -> X.; -> X.. -> ...
X;;    X.;    X..    ...

This goes though 3 iterations.

X;X    X.X    ...    ...
;X; -> .X. -> ... -> ...
;X;    ;X.    .X.    ...

This goes through 3 iterations.

X;X    ..X    ...
;X; -> .X. -> ...
X;X    X.X    ...
This goes through 2 iterations.

Rules

  • Input/output can be given by any convenient method.
  • You can print it to STDOUT or return it as a function result.
  • Either a full program or a function are acceptable.
  • Any amount of extraneous whitespace is permitted, provided the characters line up appropriately.
  • Standard loopholes are forbidden.
  • This is so the shortest code wins.

Meta

  • Is this clear enough? Any better wordings for sections?
  • Is this a duplicate?
  • Tags are and and . Any suggestions?
  • Any further feedback?
| |
\$\endgroup\$
  • \$\begingroup\$ As posed the challenge appears too simple. The wrapping method of the grid means you can just save it as a 1d object and reshape it for the output alone. There is no reason why the challenge should be restricted to a 3x3 grid either. Also, you're not clearly stating what you want the output to be. And lastly, that pun for the sake of pun is horrible and will just confuse people. \$\endgroup\$ – AlienAtSystem Nov 18 '19 at 18:48
  • \$\begingroup\$ I mostly agree with the other comment. This seems to be a lot of fluff for "find the longest substring of semicolons in the input." It may even wind up being a dupe because of that - I was going to suggest having them propagate both ways, but I'm pretty sure that is a duplicate as well! If you allow the grid to be any size and make the sandboxes propagate in more directions you may have a good base to build off of. \$\endgroup\$ – FryAmTheEggman Nov 20 '19 at 18:59
0
\$\begingroup\$

Sandbox reviewers, thanks for checking this out. I posted this question (after a few revisions) as a code challenge and pretty much no one likes it. Please give some feedback as to why it's not appropriate, clear, fun, or whatever other criticism you have. I think it's a very interesting problem and I'd love to see some other approaches to it along with some interesting language choices :).

I think the main criticism is how to measure accuracy. I've added a script to calculate a score between the competition video and whatever video contestants submit. Please tell me why that is insufficient, or unfair, unclear, etc.

Again, any feedback for improvement is welcome! I really want to see some interesting solutions :).

Thanks again for reviewing!

TITLE: Reconstruct a video where the frames' pixels have been shuffled

Given a video where all the pixels of every frame have been scrambled with some image scrambling function T(frame), reconstruct the original. T only operates on one frame at a time and has no persistent state between invocations. It's just a constant random map that shuffles pixels to new locations each frame. T is constant and performs the same permutation each frame.

Essentially you have to recover all of the spatial information that's been removed.

Prepare to bake your noodle golfers, this is a doozy!

Background

Since the spatial mapping needs to be determined, the scrambled video source needs to be something with significant motion. An example would be an episode of your favorite sitcom. Lots of colors, lots of movement between and around frames.

Simple example of the scrambling function T(frame):

SourceImage = [44,22,33,55]

T(SourceImage) = [33,44,22,55]

T maps {0:2, 1:0, 2:1, 3:3}

This example has the image in a 1D array. For the problem however, the image would be a 2D RGB image.

Rules

  • You are allowed to process the entire video to determine Ti.
  • Ti does not have to be a 100% perfect inverse, which my not even be possible depending on the input.
  • No loopholes. Your program should at a minimum take the example scrambled video as input ('scrambled_city.mp4' below) and output the unscrambled video that is as close to the original as possible ('city.mp4').
  • After producing the output video, calculate your score with the provided average MSE python script below.
  • Submit your unscrambled program source, your average MSE score and your calculated unscrambled video file, see Submission below.
  • Providing your source code and unscrambled video lets the hivemind confirm your submission is honest.

Scoring

The answer which most accurately reconstructs the video is the winner. Accuracy will be calculated as the avgerage of Mean Squared Error (MSE) of all hidden source and corresponding reconstructed frames, nothing fancy, and should be as close to 0 as possible.

Notes

  • Unscrambling a randomly shuffled image by itself is impossible. A video is different, it's possible to some degree.
  • Feel free to post any algorithms already known to accomplish this.
  • This problem is very difficult so if you can generate any unscrambled images that don't look like pure garbage consider yourself a success.

Competition Videos

Hidden source video 'city.mp4': Full Hidden Source Video Your algorithm should work without access to this! Frame 250

Scrambled video (seed 9001) 'scrambled_city.mp4': Full Scrambled Video - 2GB Frame 250 - Scrambled

source webpage for other videos to use

Python code to generate test cases for you:

This will take a video (infile) and output it's scrambled version (outfile).

Dependency: opencv2+ (pip3 install opencv-python)

import cv2

infile = 'city.mp4'
outfile = 'scrambled_city.avi'
seed = 9001

def scramble(image):
    copy = image.copy()
    # reset the seed each frame so we have constant transform function.
    cv2.setRNGSeed(seed) 
    cv2.randShuffle(copy)
    return copy

# Open video, read first frame
vidcap = cv2.VideoCapture(infile)
success,image = vidcap.read()

# Create video writer with same dimensions
h,w,layers = image.shape
size = (w,h)
outvideo = cv2.VideoWriter(outfile,cv2.VideoWriter_fourcc(*'MPEG'), 30, size, True)
print( 'videosize: %s\n'%repr(size))

count = 0
while success:
    scrambled = scramble(image)
    # DUMP SCRAMBLED JPG
    #cv2.imwrite("frame%d.jpg" % count, scrambled)

    # VIDEO FRAME OUTPUT
    outvideo.write(scrambled)

    print( 'frame: %d   %s'%(count,str(success)) , end='\r') 
    count += 1
    success,image = vidcap.read()

outvideo.release()
vidcap.release()

Python code to calculate avg Mean Square Error over two videos

import cv2
import numpy as np

infile1 = 'city.mp4'
infile2 = 'scrambled_city.avi'

# https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
def mse(imageA, imageB):
    # the 'Mean Squared Error' between the two images is the
    # sum of the squared difference between the two images;
    # NOTE: the two images must have the same dimension
    err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
    err /= float(imageA.shape[0] * imageA.shape[1])
    
    # return the MSE, the lower the error, the more "similar"
    # the two images are
    return err

# Open video, read first frame
vid1 = cv2.VideoCapture(infile1)
success1,image1 = vid1.read()
vid2 = cv2.VideoCapture(infile2)
success2,image2 = vid2.read()
count = 0
sumMSE = 0
while success1 and success2:
    sumMSE += mse(image1,image2)
    count += 1
    print( 'frame: %d    avgMSE=%f'%(count,sumMSE/float(count)) , end='\r') 
    success1,image1 = vid1.read()
    success2,image2 = vid2.read()

print("\n[Frames: %d] Avg MSE = %f"%(count,sumMSE/float(count)))
vid1.release()
vid2.release()

Example output avgMSE of city.mp4 and scrambled_city.avi:

[Frames: 5113] avg MSE = 18079.870445918445

Example output avgMSE of city.mp4 and city.mp4:

[Frames: 5113] avg MSE = 0.000000

SUBMISSION + HIDDEN TEST CASES

When you're ready to submit your solution, please score your submission against the example video and for fun include unscrambled versions of the three test cases below.

First (required):

  • Your solution code. No code provided is disqualification.
  • Submit the avg MSE for your reconstructed 'scrambled_city.mp4' and the first example video, 'city.mp4', you calculate from the provided python script.
  • Your unscrambled video file (suggestion: host on youtube or G-drive).
  • You do not need to include your calculation of T or Ti, the visual media you provide (step above) will be enough to prove your algorithm works and score it.

~~ Lowest score wins. Good luck! ~~

Second (optional for fun): You can submit your completely unscrambled videos OR you can submit the unscrambled frames 250,500,750,1000 for all 3 of the test cases below. It will be pretty clear if you solved it or not. They're very recognizable scenes.

Note: The youtube preview is terribly distorted. The downloaded files are much better quality.

video 1

video 2

video 3 - HARD

| |
\$\endgroup\$
  • \$\begingroup\$ The issue I see is the ambiguity of the sentence "T only operates on one frame at a time and has no persistent state between invocations." If T does not perform the same permutation on all frames, the challenge is simply impossible. In addition, the test cases are all ridiculously huge. 2GB of data for a simple test case is way too much. \$\endgroup\$ – AlienAtSystem Nov 18 '19 at 18:55
  • 2
    \$\begingroup\$ I don't think this one is solvable even if T did perform the same permutation on all frames. Its like the Auditors atomizing paintings to try and figure out why they're beautiful. Also holy hell that test case is literally the worst: a collection of short, unconnected, sequences that are only a few seconds long at best. How is any algorithm supposed to find any patterns in that? \$\endgroup\$ – Draco18s no longer trusts SE Nov 19 '19 at 4:53
  • \$\begingroup\$ T is constant. I clarified the phrasing. Ok I'll add a second smaller video. Maybe 100MB? It's difficult to get smaller because the compression algorithms don't like it when the frames are noisy. Compressing the scrambled version too much would actually make it impossible. \$\endgroup\$ – extracrispy Nov 19 '19 at 8:30
  • \$\begingroup\$ duplicate \$\endgroup\$ – Beefster Nov 19 '19 at 22:49
  • \$\begingroup\$ @Beefster I think you have referred to a similar but different problem. In that problem there is a simple reversible algorithm and you (as in the person reading this) get to decide how to map/unmap the values. However, in this problem the only thing you are presented with is a scrambled video and the knowledge that it's scrambling function is constant. You don't know anything else. Now try your best to unscramble the video. \$\endgroup\$ – extracrispy Nov 20 '19 at 6:02
  • \$\begingroup\$ @extracrispy are you going for a cops-and-robbers then? \$\endgroup\$ – Beefster Nov 20 '19 at 20:29
  • \$\begingroup\$ Adding a sentence is not the same as clarifying. The misleading information is still the first thing people read. And I think before asking people to perform a task like this, you should consider how you would go about it yourself. Here is a very small (32x32x32) and easy (3d perlin noise: it's smooth in all dimensions) test case for you. Show me that you could unshuffle it successfully. \$\endgroup\$ – AlienAtSystem Nov 21 '19 at 10:10
0
\$\begingroup\$

How long should this song last?

Enter the world of sheet music. A composition (the musical piece, which may or may not be a song) is divided into bars. The length of a bar is defined by the time signature. The time signature states how the bar is divided into beats, and what length of note carries the beat.

Note lengths are always powers of 2. 4 means a quarter note, 2 a half note, 8 an eighth note (or a quaver if you're a snob), etcetera. A half note (2) is twice the length of a quarter note (4), which is itself twice the length of a quaver (8), and so on.

A time signature may look like this: 3/4. The 4 means that the quarter note carries the beat, and the 3 means that there are 3 of them in one bar. 3/2 means there are three half-notes in a beat, 7/8 means there are seven quavers, and so on.

Now, the actual speed at which a piece is to be performed depends on the tempo. That is usually expressed in beats per minute (bpm). The tempo also defines the note carrying the beat (usually the same as the one in the time signature but not always). So, you can have the time signature be 8=150, meaning there are 150 quavers in a minute (in the sheet music it would be notated ♪=150).

Both tempo and time signature can change throughout the composition.

Challenge

Use the following format for your input (or something very similar). It is a list of events:

[1,"4/4"],
[1,"4=120"],
[521,""]

This is the simplest form. It is a list of integer-string pairs (you're obviously free to go with string-string pairs if it makes your program simpler). The integer defines at which bar the event happens (starting from 1), and the string defines what happens there. If it is in the form of x/y, then it is a new time signature. If it is in the form of x=y, you have a new tempo. Lastly, an empty string designates the end of the score (exclusive, so the above example has 520 bars).

With changes, the format may look like this:

[1,"4/4"],
[1,"2=120"],
[46, "4=155"],
[67, "5/4"],
[68, "4/4"],
[152,""]

The output of the program should be the duration of the entire piece in "xm ys" (where x is the number of minutes and y is the number of seconds. You can leave out the "ys" part if there's no spare seconds, but it is not necessary).

This is , so shortest code wins!

Important note!

Real artists do not follow the tempo exactly. Only beginners use a metronome to match the exact number of seconds as notated; more experienced musicians know to dynamically speed up or slow down depending on the mood, their personal preference, etcetera. Therefore, it is perfectly acceptable for your answer to be up to 34% higher or lower than the "correct" answer. Also, the minimum length of a composition is 2 minutes and 30 seconds.

Test cases

1.

[1,"4/4"],
[1,"4=120"],
[521,""]

The time signature has 4 quarter notes a bar, and 520 bars, so 4*520=2080 quarter notes. There's 120 quarter notes per minute, so 2080/120=17.333 minutes, or 17m 20s.

2.

[1,"4/4"],
[1,"8=120"],
[46, "4=155"],
[66, "5/4"],
[76, "6/8"],
[152,""]

For the first 45 bars, there's 4 quarter notes a bar, so that's 45*4=180 quarter notes. Now the tempo is 120 8th notes per minute, which is 60 quarter notes per minute, meaning the first bit lasts 180/60=3 minutes.

Then a tempo change: from bar 46 to 67 there's 20 bars of 4/4 (thus 4*20=80 quarter notes), and at 155 quarter notes per minute you add 155/80=1.94 minutes = 1m 56s. Total is 4m 56s.

Then a time signature change: 10 bars of 5 quarter notes per bar = 50 quarter notes. 155/50 = 3.1 minutes = 3m 6s. Total is 8m 2s.

Then another time signature change. 6 eighth notes per bar for 76 bars is 76*6=456 eighth notes. Tempo is still 155 quarter notes per minute, which is 310 eighth notes per minute. 456/310=1.471 minutes = 1m 28s. Total comes down to 9m 39s.

3. (The third movement of Shostakovich's second piano concerto, you get 5 bytes off if you listen to this while programming (not really but more people need to listen to Shosty dammit))

[1, "2/4"],
[1, "4=176"],
[75, "7/8"],
[102, "6/8"],
[103, "7/8"],
[106, "3/8"],
[107, "7/8"],
[109, "2/4"],
[112, "3/4"],
[113, "2/4"],
[116, "3/4"],
[117, "2/4"],
[120, "3/4"],
[121, "2/4"],
[124, "3/4"],
[125, "2/4"],
[155, "7/8"],
[160, "2/4"],
[175, "7/8"],
[180, "2/4"],
[181, "6/8"],
[182, "2/4"],
[186, "7/8"],
[188, "2/4"],
[222, "7/8"],
[225, "2/4"],
[286, "7/8"],
[308, "9/8"],
[309, "7/8"],
[314, "2/4"],
[317, "3/4"],
[318, "2/4"],
[321, "3/4"],
[322, "2/4"],
[325, "3/4"],
[326, "2/4"],
[329, "3/4"],
[330, "2/4"],
[356, ""]

Calculation is too long to show here, but it comes down to 4m 47s. The video is 5m 24s, proving my point that this is not an exact rule but rather a guideline.

Tags

Sandbox

Does this look like an interesting puzzle? Any tags I miss? Is the +/-34% allowance large enough to matter, or should it be more?

| |
\$\endgroup\$
  • \$\begingroup\$ The "+- 34%" and "at least 2:30 min" are unneccessary for the challenge. They may be relevant for music, but not for programming. I doubt that this allowance will allow you to shave bytes off the task, given that it's straightforward parsing + arithmetic otherwise. \$\endgroup\$ – AlienAtSystem Nov 21 '19 at 11:31
  • 1
    \$\begingroup\$ @AlienAtSystem I want to make the allowance relevant, both because it is musically appropriate, and because it would elicit different kinds of answers that approximate the solution. I suppose the arithmetic needs to be more complex before approximate solutions can be made with shorter programs? How about adding accelerando events that change the tempo over time? \$\endgroup\$ – KeizerHarm Nov 21 '19 at 11:41
  • \$\begingroup\$ Or maybe I should make a hilariously long list of possible events (e.g. fermata changing the length of a single note, all the different types of ritardando with slightly different slowing down behaviours, etc.) and make it part of the challenge to sort out which ones are relevant to get close enough to the solution? \$\endgroup\$ – KeizerHarm Nov 21 '19 at 11:44
  • 2
    \$\begingroup\$ I'm not an expert golfer, so I can't say at what level of complexity an approximation gets shorter than just the straightforward calculation. I think the site consensus is for approximative approaches to use precision scoring (How many out of this long list of test cases do you get accurately), because otherwise there is the hidden condition of "for all possible valid inputs", which is hard to prove for approximation algorithms. \$\endgroup\$ – AlienAtSystem Nov 21 '19 at 11:51
  • \$\begingroup\$ @AlienAtSystem Very well, I could generate a list of 100 "compositions" and make the % of properly solved cases part of the score. I guess that would mean adding a different tag? I couldn't find one for "approximation" or direct synonyms of that. \$\endgroup\$ – KeizerHarm Nov 21 '19 at 11:55
  • 1
    \$\begingroup\$ If you go for the fraction of cases correct method, the tag you want is test-battery. \$\endgroup\$ – FryAmTheEggman Nov 21 '19 at 19:46
  • \$\begingroup\$ So, we wont include 𝄆 repeat sign 𝄇 in this challenge. Am I right? \$\endgroup\$ – tsh Nov 27 '19 at 3:35
  • \$\begingroup\$ @tsh Not at this stage. And if I do, it definitely won't be using the unicode token. \$\endgroup\$ – KeizerHarm Nov 27 '19 at 10:38
0
\$\begingroup\$

Deathmatch Football (Soccer)

Idea:

2 Teams each of 11 Players and 3 Bank Players compete in a match of 90 minutes to find out who's the best. But... it wouldn't be deathmatch with no casualties, so after scoring, there is a chance to die. Better think twice before you shoot...

Teams:

Each Team is represanted as a String of 14 chars (11 + 3). Every char az-AZ is unique to the whole match. So 2 teams could look like this

Team1: {"a","c","f","g","j","k","A","D","E","H","I","k","n","o"} //bank: k, n, o
Team2: {"b","d","e","h","i","l","B","C","F","G","J","l","m","P"} //bank: l, m, P

The Game:

The game lasts for 90 (+3) minutes. Every minute each team has one chance to score a goal. The player who's shooting gets randomly selected. The chance of a player to score a goal is the byte value of the char.

Example: "z" has a value of 122, so he has a chance of 122% (>=100%) means he will definetely score

If he scores he will die with a chance of his byte value / 2

Example: "z" has a value of 122, so he has a chance of 61% to die.

Special Events:

  • At minute 45, 60 and 75 a random player from the bank comes into the team (teams are not limited to 11 players, if no one has died yet)
  • If there is a draw at minute 90 OR both teams have less than 5 players, the game lasts for additional 3 minutes (90 + 3)
  • If a team has 0 players the game is over

Result and Rating:

Once a match is over. Display both teams, the final score, and the top scorer including goals.

Team1: {"a","f","A","D","p"}
Team2: {"b","e","h","P"}
Score: 20:18 // So Team1 won
Top Scorer: A=>5

The code with less bytes is the winner.

Extra Notes:

You are free to choose the form of the output as long as you can clearly see the remianing teams, who won and the top scorer. No loopholes, do i need to say that?

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

Multiplicative Digital Root

The Digital root of a number is found by iteratively summing its digits until you end up with a single number (e.g. 99 -> 18 -> 9)

The multiplicative digital root is found by iteratively multiplying the digits (e.g. 99 -> 81 -> 8)

The Challenge

Print out the digital root of all numbers 0..99 inclusive. Note that this is based on https://oeis.org/A031347, and the first 10 numbers (0-9) are treated without leading 0s.

Input

None

Output

In any sensible format:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 
0, 3, 6, 9, 2, 5, 8, 2, 8, 4, 
0, 4, 8, 2, 6, 0, 8, 6, 6, 8, 
0, 5, 0, 5, 0, 0, 0, 5, 0, 0, 
0, 6, 2, 8, 8, 0, 8, 8, 6, 0, 
0, 7, 4, 2, 6, 5, 8, 8, 0, 8, 
0, 8, 6, 8, 6, 0, 6, 0, 8, 4,
0, 9, 8, 4, 8, 0, 0, 8, 4, 8,

Sandbox comments

  • this is the only related challenge I could find, but it doesn't ask the same thing.

  • Would this be better/more interesting as a "calculate the multiplicative digital root of the input" challenge?

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ no, because 0,1..9 are single-digit numbers. 00, 01..09 would make the first row zero, but based on the OEIS sequence (oeis.org/A031347) I want to treat them as shown \$\endgroup\$ – simonalexander2005 Nov 25 '19 at 11:14
  • \$\begingroup\$ Ah ok, I misread it as a multiplication table instead of just a sequence of 0..n. Ignore my now deleted comment. So we just output the first 100 numbers in the (0-based) sequence? Would outputting the 1-based sequence be allowed (1..100 instead of 0..99)? If not np, but I could save a byte in my prepared solution if it would be allowed. :) \$\endgroup\$ – Kevin Cruijssen Nov 25 '19 at 11:48
  • \$\begingroup\$ Sorry yeah, I've just formatted it that way for clarity. No, 0-99 was the challenge I had in mind. Alternatively would this be a better challenge if you had to calculate the multiplicative digital root given an input (arbitrary-length integer)? Or should I just propose both challenges? \$\endgroup\$ – simonalexander2005 Nov 25 '19 at 12:52
  • \$\begingroup\$ Either is fine by me, but not both. If the single input would already exist as challenge, this ranged one would simply use those answers with a 0..99 map around it (which is also what I do in my current answer in my language of choice: calculating the multiplicative digital root of an input is 3 bytes; adding a range 0..99 map around it is 4 more bytes). \$\endgroup\$ – Kevin Cruijssen Nov 25 '19 at 12:58
  • \$\begingroup\$ The challenge you linked to is the same except that it doesn't require wrapping the thing in a for loop. I believe this is a duplicate. \$\endgroup\$ – the default. Nov 25 '19 at 13:40
  • \$\begingroup\$ @mypronounismonicareinstate it wouldn't be a for loop, but rather recursion (or a while), right? Anyway, the challenge as written here currently asks for the whole set - so I'd say that's substantially different to the linked challenge \$\endgroup\$ – simonalexander2005 Nov 25 '19 at 13:47
  • \$\begingroup\$ I personally see it as closely related instead of a dupe @mypronounismonicareinstate, although I agree parts of the answers could be reused. That other challenge asks: remove all zeroes, and take the product of the remaining digits. Whereas this challenge asks: for the numbers in the range 0..99; reduce by taking the product of its digits until a single digit remains. In 05AB1E for example, that other challenge is 0KSP and this challenge is т<ÝεΔSP. The SP part (split to digits, take product) is similar. Both challenges are rather trivial in most languages, though - even non-golf langs \$\endgroup\$ – Kevin Cruijssen Nov 25 '19 at 14:35
0
\$\begingroup\$

Double an infinitely long number

You are given a non-negative real number strictly less than 0.5 as an endless stream of digits. Output twice of it in an endless stream of digits.

The exact format is flexible. You may separate digits by any reasonable separator, or don't use separators. You may prepend something representing "0" or "0.", or just omit the integral part. The input and output don't have to be in the same format. But everything must be in base 10, from the most significant digit to less significant digits.

Your code doesn't have to print anything immediately. But if each digit in the input would be given in a finite amount of time, and it is in a state allowing output in your chosen I/O method (so that if you are using a generator, you may assume some code is repeatedly accessing the generator), each digit in the output should also be printed or returned in a finite amount of time.

Shortest code wins.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I presume the stream of digits is given from largest to smaller place? I think this would be cleaner if we didn't have to deal with a decimal point, say by saying the input starts after the decimal point and is less than 0.5. \$\endgroup\$ – xnor Nov 25 '19 at 10:10
  • \$\begingroup\$ Would it be a valid submission to give a stateful function that takes in a digit, and outputs some a string of digits, so that repeatedly calling it with digits from the stream gives the desired output if concatenated? Or does our code have to handle the read-and-output loop itself? \$\endgroup\$ – xnor Nov 27 '19 at 1:30
  • \$\begingroup\$ @xnor Not sure. I'll accept it if it becomes a standard I/O method for reading/writing lists. \$\endgroup\$ – jimmy23013 Nov 27 '19 at 10:52
1
82 83
84
85 86
99

You must log in to answer this question.

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