555
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3931 Answers 3931

1
98 99
100
101 102
132
0
\$\begingroup\$

Cologne Phonetics

From Wikipedia: Cologne phonetics is a phonetic algorithm which assigns to words a sequence of digits, the phonetic code. The aim of this procedure is that identical sounding words have the same code assigned to them. The algorithm can be used to perform a similarity search between words. For example, it is possible in a name [collection?] to find entries like "Meier" under different spellings such as "Maier", "Mayer" or "Mayr".

The Cologne phonetics matches each letter of a word to a digit between 0 and 8. To select the appropriate digit, at most one adjacent letter is used as context.

Procedure:

Processing of a word is done in three steps:

  1. Encode letter by letter from left to right according to the conversion rules below.
  2. Remove all digits occurring more than once next to each other.
  3. Remove all code "0" except at the beginning

Conversion rules

  • A, E, I, J, O, U, Y become 0
  • H becomes nothing
  • B becomes 1
  • P becomes 1, unless it's before H
  • D, T become 2, unless they're before C, S, Z
  • F, V, W become 3
  • P becomes 3, if it's before H
  • G, K, Q become 4
  • C becomes 4 in initial position before A, H, K, L, O, Q, R, U, X
  • C becomes 4, if it's before A, H, K, O, Q, U, X, except after S, Z
  • X becomes 48, unless it's after C, K, Q
  • L becomes 5
  • M, N become 6
  • R becomes 7
  • S, Z become 8
  • C becomes 8, if it's after S, Z
  • C becomes 8 in initial position except before A, H, K, L, O, Q, R, U, X
  • C becomes 8, if it's not before A, H, K, O, Q, U, X
  • D, T become 8, if they're before C, S, Z
  • X becomes 8, if it's after C, K, Q

Challenge

Implement a program or a function that takes a single string as input and returns the phonetic code according to the rules stated above. You may choose your own output format, but keep in mind that the expected output may have leading zeros. The input string is guaranteed to match /^[a-zA-Z ]*$/, this means it may contain characters from the lowercase and uppercase alphabet, as well as spaces.

Test cases

Input                 Output

[empty string]        [empty]
Kolner Phonetik       45673624
Meier                 67
Mayer                 67
Augsburg              048174
Xanten                48626
Telephon              2356
Chemie                46
Muller Ludenscheid    65752682

This is , the shortest code for each language wins.

\$\endgroup\$
4
  • \$\begingroup\$ Related: Soundex function \$\endgroup\$
    – Laikoni
    Oct 14, 2018 at 12:49
  • \$\begingroup\$ What's the difference between "initial sound" and "initial position"? \$\endgroup\$
    – Laikoni
    Oct 14, 2018 at 12:58
  • \$\begingroup\$ Apparently there is none, from what I was able to find \$\endgroup\$
    – oktupol
    Oct 15, 2018 at 7:11
  • \$\begingroup\$ Ideally there would be a test case for each conversion rule as the challenge is probably mainly about handling those edge cases in the rules. \$\endgroup\$
    – Laikoni
    Oct 15, 2018 at 13:27
0
\$\begingroup\$

Keyboard Row Shift

Given an input string of characters, output the number of times we have to shift to another row while typing that string using a qwerty keyboard.

The input string will contain lower case alphabets,numbers and spaces. The newline key(enter) must also be considered at the end (only at the end). All shifts, from any row to any other will be considered as 1 shift only.

Layout:

1234567890
qwertyuiop
asdfghjkl enter
zxcvbnm
space

Examples:

"sdkflsd" -> 0
"asdwexc" -> 3 # to end the string one enter has to pressed which is in the middle
"poierlkdjfpoeirldskjf" ->3
"123 jkjk" -> 2
"llsdkfj ldkfj" -> 2
"lkasdjmnbcv " -> 3
"jnjn 5" -> 6

This is code-golf, so shortest code wins.

\$\endgroup\$
4
  • \$\begingroup\$ You need some test cases that contain a space and numbers. I'd also make it clear in your description that a shift can go any distance (going from the top row to the bottom is only 1 shift) \$\endgroup\$ Oct 16, 2018 at 12:48
  • \$\begingroup\$ Done, @NathanMerrill \$\endgroup\$ Oct 17, 2018 at 5:36
  • \$\begingroup\$ How flexible is input? Is uppercase OK? How about an array of character strings or even an array that mixes digits and character strings? \$\endgroup\$
    – Shaggy
    Oct 18, 2018 at 21:47
  • 1
    \$\begingroup\$ I have mentioned only lower case, input has to be string only not an array. \$\endgroup\$ Oct 19, 2018 at 5:15
0
\$\begingroup\$

Given a program in your language, generate another program that do exactly the same thing so every bytes in it are prime.

Shortest generator in every language win. No acception.

Nop in languages that only allow prime bytes are legit, but just don't post them(or make a community answer to put them)

\$\endgroup\$
6
  • \$\begingroup\$ Upvote this comment if you think that the idea of the challenge is not interesting and it should not be posted. \$\endgroup\$
    – DELETE_ME
    Oct 26, 2018 at 10:46
  • 1
    \$\begingroup\$ Upvote this comment if you think that the idea is fine, but the challenge is unclear or needs fixing; in that case also leave a comment. \$\endgroup\$
    – DELETE_ME
    Oct 26, 2018 at 10:47
  • \$\begingroup\$ I made a small poll above ↑. I think the idea is interesting, and if it's poorly worded, the post can't be fixed without suggestions. Note that the challenge is already fully specified in the current state (task description, winning criteria), and it's impossible to give sample input/output to test programs (if you understand the challenge, you will see why). \$\endgroup\$
    – DELETE_ME
    Oct 26, 2018 at 10:49
  • \$\begingroup\$ Lots of languages quite rely on composite(not prime) bytes, so upvote this comment if you think it's too restrict \$\endgroup\$
    – l4m2
    Oct 26, 2018 at 12:40
  • \$\begingroup\$ I think the idea is interesting, especially in languages like Jelly which can do most anything with small subsets of its character set. My main problem is: how much of the language do we have to support in the input to our generator? Many languages which are capable of this task have far too many possible instructions, etc., every one of which would need to be remapped to an all-prime version. Unless perhaps it's possible to simply generate any given string and execute it whilst using only prime bytes... \$\endgroup\$ Oct 27, 2018 at 3:14
  • \$\begingroup\$ @ETHproductions I think a subset of an existing language can be considered another language? \$\endgroup\$
    – DELETE_ME
    Nov 11, 2018 at 4:23
0
\$\begingroup\$

Are these strings character wise translatable?

Explanation with example:

Suppose you are given two strings of the same length, e.g. "code" and "golf". Try to find a set of translation rules for characters (like "All cs are replaced by gs" , or c -> g for short) such that applying those rules on "code" yields "golf" and applying them to "golf" again yields "code".

If there is such a set of translation rules, return a truthy value. Otherwise, if no such set can exist, return a falsy value.

In our example, the translation is possible with the rules g -> c, d -> l, e -> f, c -> g, l -> d and f -> e, so a truthy value should be returned.

However, if the two strings were "code" and "meta", no such rules exist: To get from "code" to "meta" we need the rule e -> a, but to get from "meta" to "code" we would need e -> o. But e cannot be translated into two different characters! Therefore, a falsy value should be returned.

Consise mathy explanation:

Given two strings \$s\$ and \$t\$ of the same length \$n\$, decide whether the following relation is bijective: $$\{(s_i,t_i)\ |\ 1 \leqslant i \leqslant n\} \cup \{(t_i,s_i)\ |\ 1 \leqslant i \leqslant n\}$$ where \$s_i\$ denotes the \$i^{th}\$ character of string \$s\$.

Test cases

truthy:

"code", "golf"
"a", "a"
"abdabdcdacabcabd", "bacbacdcbdbadbac"
TODO: Add some more

falsy:

"code", "meta"
"aa", "ab"
"abc", "bca"
TODO: Add some more
\$\endgroup\$
3
  • \$\begingroup\$ This seems to be very similar to Check if words are isomorphs. \$\endgroup\$
    – Dennis
    Oct 28, 2018 at 2:39
  • \$\begingroup\$ @Dennis It is definitely related. However, as far as I see most answers there work by creating some sort of fingerprint and checking whether it is the same for both inputs. This approach alone won't work here as you also need to check the symmetry of substitutions. \$\endgroup\$
    – Laikoni
    Oct 28, 2018 at 11:33
  • 1
    \$\begingroup\$ Not saying this makes it a dupe, because there might be golfier ways, but s and t are character wise translatable if and only if s++t and t++s are isomorphs. \$\endgroup\$
    – Dennis
    Oct 28, 2018 at 12:54
0
\$\begingroup\$

Guess the Q in the code

A popular puzzle known to me as Codewords takes a Crossword-like grid and consistently replaces each letter with a code value, usually a number from 1 to 26, and the solver then has to work out which code value represents each letter. There are a number of approaches to this:

  • There is a web site which can search for words given the pattern of repeating letters. Since repeated letters map to repeated code values, you can sometimes use the patten of repeated code values to determine the original word. For instance, the only word with the pattern 12.312..3... is churchwarden.
  • The puzzle normally provides a few of the letters to get you started. This may be enough to use a standard crossword solver to determine the original word. For instance, .h...h...d.. would again point you to the word churchwarden.
  • You could use frequency analysis to guess which letters are likely to be the popular letters such as e or t.
  • You could look for common prefixes or suffixes such as ally or ness. (I picked those two as they have repeating letters which are easier to spot.)
  • At least in all of the Codewords puzzles I have seen, q is always followed by a u and at least one letter. This means that if there is a code that is never the last or penultimate letter of a word, and always appears followed by the same code, then this could be a q.

However, checking all the codes to see how many distinct codes follow them is laborious. We need an automatic solution for this!

Please write a program or function that will guess which code(s) could represent the letter q. The input to the function will be an array of code values in a standard format. You will need to support 27 consistent distinct values, 26 for the codes themselves and a value for the background. These values can be integers but you could also use characters e.g. 26 letters and a space, in which case you can join them into strings, and even join the strings with a 28th character.

Your output will be all of the code values that have the property that, for each occurrence in the grid, either:

  • The previous and following cells are background or would extend past the side of the grid, or
  • There are two non-background following cells, and the first of those cells always contains the same value.

These rules apply in both the horizontal and vertical direction.

This is , so the shortest solution that breaks no standard loopholes wins!

Examples needed, I guess...

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

Hack g-code parser

\$\endgroup\$
4
  • \$\begingroup\$ This could be seen as asking for malicious code, which is not on-topic. \$\endgroup\$
    – Laikoni
    Oct 25, 2018 at 17:55
  • \$\begingroup\$ @Laikoni this is not malicious\harmful code, because it don't causes harm to user. It is educational programming puzzle for white-hat hackers \$\endgroup\$ Oct 25, 2018 at 18:58
  • \$\begingroup\$ @Laikoni rm -rf / is harmful, but alert("pwned") is not \$\endgroup\$ Oct 25, 2018 at 18:59
  • 3
    \$\begingroup\$ Right, I think misread the challenge. If it is only about cracking this piece of code rather than actual implementations it's probably fine as a challenge. Any way, you need an objective winning criterion. code-golf in the sense of "the shortest input to open the alert prompt" seems like a good candidate. \$\endgroup\$
    – Laikoni
    Oct 25, 2018 at 19:47
0
\$\begingroup\$

Find the pattern v2

I feel tired to do "find the pattern" exercise such as

1 2 3 4 (5)
1 2 4 8 (16)
1 2 3 5 8 (13)

Please write a program that finds the pattern for me.

Here, we define the pattern as a recurrence relation that fits the given input, with the smallest score. If there are multiple answers with the same smallest score, using any one is fine.

Let the \$k\$ first terms be initial terms for the recurrence relation, and the \$i\$'th term be \$f(i)\$ (\$i>k,i\in\mathbb N\$).

  • A non-negative integer \$x\$ adds\$1\$ to the score
  • The current index \$i\$ adds \$1\$ to the score
  • +, -, *, / (round up, down, towards zero, go further to zero, as you decide) and mod (a mod b always equal to a-b*(a/b)) each add \$1\$ to the score
  • For each initial term \$x\$, add \$1\$ to the score
  • \$f(i-n)\$ (with \$n\le k\$) adds \$1\$ to the score. E.g. Using the latest value \$f(i-1)\$ add \$1\$ to the score, and there must be at least 1 initial term.
  • Using parentheses to change the calculation order doesn't add anything to the score.

Samples:

input   -> [score]    expression(not optimized)
1 2 3 4     -> [1]    f(i) = i
1 2 4 8     -> [3]    f(1) = 1, f(i) = 2*f(i-1)
1 2 3 5 8   -> [5]    f(1) = 1, f(2) = 2, f(i) = f(i-1)+f(i-2)

Lowest score for worse case wins. If tie, shortest program in each language wins. Your program should run in polynomial time.

If someone's score is lower than 4(currently reachable), the first lowest score will be accepted. (differ from winning criticia)

p.s. See history for v1 sandbox

\$\endgroup\$
8
  • 1
    \$\begingroup\$ I think the challenge could benefit from a precise defining grammar for a pattern. As it stands, I feel the set of all expressions that may fit is too vast. \$\endgroup\$ Oct 16, 2018 at 9:28
  • \$\begingroup\$ @JonathanFrech Looks pretty precise to me. About "too vast" - there are only 6 bullets. \$\endgroup\$
    – DELETE_ME
    Oct 17, 2018 at 10:43
  • \$\begingroup\$ @user202729 I am unsure if (round as you decide) includes the possibility of not rounding. \$\endgroup\$ Oct 17, 2018 at 15:28
  • \$\begingroup\$ Should "3 0 0 0 0 0 ..." be "f(1)=3, f(n)=0", do "for the recurrence relation" work? \$\endgroup\$
    – l4m2
    Oct 17, 2018 at 16:40
  • \$\begingroup\$ @l4m2 Yes. ----- \$\endgroup\$
    – DELETE_ME
    Oct 17, 2018 at 16:56
  • \$\begingroup\$ I don't understand the "fun fact"... \$\endgroup\$
    – DELETE_ME
    Oct 21, 2018 at 15:42
  • \$\begingroup\$ @user202729 Do you think it no fun or can't figure it out? \$\endgroup\$
    – l4m2
    Oct 21, 2018 at 19:24
  • \$\begingroup\$ The latter. ---- \$\endgroup\$
    – DELETE_ME
    Oct 22, 2018 at 0:15
0
\$\begingroup\$

User ranking in language

Challenge is:

  • You need receive the input of "language". By "language" I mean the at left of the comma in the Title of an answer on the present code-golf site.
  • The source for the data are the answers posted here on code-golf site.
  • You must present results in order. Decreasing or Increasing does not matter, it only needs to be one of those two.
  • Output is a table of two columns {User, Upvotes}. Example: User enters Java and will obtain a list as the following:

user_A 9523 user_B 6000 user_C 120

Do not care very much about the output formatting as long it is clear the separation between the two columns and each line.

The will be no winner as it is a per language question.

\$\endgroup\$
2
  • \$\begingroup\$ "The source for the data are the answers posted here on code-golf site." The answers for this challenge, or ALL challenges on PPCG? And with your example, does this mean it searches for each user all answers given in Java, and sums their total upvote count? Also, do we differentiate java/Java/Java 7/Java 10 etc as different inputs? \$\endgroup\$ Nov 1, 2018 at 12:45
  • \$\begingroup\$ @KevinCruijssen 1. Yes, the scope is all answers on PPCG. 2. Yes, it is the total upvote account. 3. This is flexible on uppercase/lowercase, but not on the rest. \$\endgroup\$
    – sergiol
    Nov 8, 2018 at 19:58
0
\$\begingroup\$

Concentration (or Memory or Match) is a game where players pick pairs of cards and try to find matches. The rules are as follows:

  1. Two of each number from 1 to N are added to the deck.
  2. The deck is shuffled and placed face-down (hidden).
  3. The player selects a card. The card is revealed.
  4. The player selects another card: The card is revealed.
  5. If the two cards are different numbers, then they are hidden again.
  6. Steps 3 through 5 are repeated until all cards are revealed.

For example, lets say I have the following cards: 1 1 2 2 3 3 4 4

Shuffle them: 1 4 3 1 4 3 2 2

Place them face down: X X X X X X X X

The player will then select a card: 1 X X X X X X X

And then another card: 1 X 3 X X X X X

The numbers don't match, so we put the cards face down, and select another card: X X X 1 X X X X

The player remembers the position of the other 1: 1 X X 1 X X X X

A match was found! These cards stay face-up, and we try again.

The challenge is to do this with limited memory. You need to write a function/program that takes two parameters:

  • A list of cards (with a constant value representing the hidden cards)
  • 32 bytes of data. This can be stored as a string, a large integer, etc.

Your function must use this data (and only this data) to select the next card to reveal, and then update the 32 bytes of data. You may use a random number generator for free (as long as you do not use the seed to store data)

After the game is over, the game is scored by counting the number of times a card was revealed.

Below, I have provided a list of test cases. Your score is the length of the first test case you complete with a score of greater than 2N+30 (N is the number of distinct cards). Hard coding is not allowed, and your function should get a similar score with a different set of test cases.

2 1 4 0 0 3 3 4 2 1
3 0 4 3 2 0 4 1 1 2
1 3 2 2 4 3 0 4 0 1
2 2 0 4 4 1 1 3 3 0
3 2 1 1 0 0 4 3 4 2
3 2 0 4 2 5 1 1 0 3 5 4
4 5 0 3 2 5 3 1 0 2 1 4
4 1 2 0 2 5 1 3 3 5 0 4
2 3 2 4 3 1 0 5 4 0 1 5
3 1 4 0 2 2 5 3 1 5 4 0
1 4 0 5 2 3 6 1 0 3 5 4 6 2
6 3 5 3 1 2 1 5 2 4 4 6 0 0
5 6 0 0 5 3 1 1 2 4 6 2 4 3
1 1 6 2 2 4 0 4 5 5 6 0 3 3
3 4 6 4 6 2 5 0 0 1 3 5 2 1
3 2 6 4 1 5 7 4 3 7 0 2 6 0 1 5
7 3 1 0 6 2 3 6 4 1 5 7 5 0 4 2
2 6 5 4 2 5 0 0 7 3 1 4 6 7 3 1
4 7 5 0 6 3 0 1 3 1 7 2 6 4 2 5
4 7 5 1 4 3 2 6 0 6 7 3 2 5 1 0
7 6 5 4 5 0 1 3 8 3 4 0 1 8 6 2 2 7
2 4 1 8 7 4 6 5 3 8 1 3 7 2 0 6 5 0
6 4 7 8 5 1 4 3 0 8 3 5 2 6 1 2 7 0
3 8 0 6 4 0 1 5 2 7 7 1 5 3 2 6 8 4
7 1 8 8 3 1 3 4 5 4 6 2 2 0 0 7 6 5
9 4 1 5 7 3 4 1 6 3 9 7 2 2 0 5 6 0 8 8
2 2 6 1 8 6 5 7 3 4 5 0 9 3 0 9 7 4 8 1
7 4 3 5 2 7 1 1 0 0 9 8 6 8 3 6 2 9 4 5
1 6 3 2 7 0 7 9 1 5 0 4 8 6 3 8 9 5 2 4
8 4 5 9 9 3 0 5 6 2 2 7 0 4 1 8 7 1 3 6
1 7 0 2 1 3 8 8 6 9 2 3 4 5 6 5 10 4 7 10 0 9
3 5 10 3 5 1 9 10 1 2 0 4 0 8 6 7 8 4 9 2 6 7
9 1 7 8 2 8 9 10 2 0 6 6 5 3 5 1 10 0 4 7 3 4
7 8 2 9 8 0 0 9 3 1 5 2 4 1 3 10 4 10 5 6 6 7
3 7 9 5 1 2 8 6 3 6 4 0 10 1 2 7 10 9 8 4 5 0
7 6 9 6 2 5 5 0 11 9 3 10 8 3 4 8 4 2 11 1 1 10 7 0
10 2 8 5 11 3 4 2 6 11 4 7 10 9 8 9 1 1 6 0 5 7 3 0
4 0 7 7 4 6 11 8 3 9 3 2 5 1 11 10 8 2 9 5 0 10 1 6
10 8 8 0 0 3 7 4 11 10 9 2 4 5 6 9 5 6 7 1 1 11 3 2
1 7 0 8 9 10 4 5 10 6 5 1 4 3 7 2 0 9 3 11 8 2 6 11
3 7 10 11 1 5 10 2 9 3 8 11 5 9 6 0 0 4 12 12 4 8 1 6 2 7
0 11 9 11 2 9 10 6 5 2 7 0 12 1 10 7 6 8 3 3 4 1 12 5 8 4
3 9 5 12 1 6 8 10 2 4 11 3 6 8 9 1 10 12 7 0 11 0 5 4 7 2
1 7 11 9 0 2 6 6 5 0 8 3 10 8 7 12 3 9 12 4 2 4 11 1 5 10
8 4 9 0 7 3 1 3 9 6 11 6 8 2 12 10 2 12 5 5 0 1 10 7 4 11
13 4 13 4 1 2 9 8 10 7 3 12 2 0 5 6 0 5 8 6 9 12 11 10 1 7 3 11
13 0 0 6 1 4 11 3 12 9 2 10 9 2 7 8 12 5 7 6 11 4 10 1 5 3 13 8
13 10 3 6 12 1 0 8 5 6 3 11 4 9 2 9 8 11 12 2 5 7 7 1 4 10 0 13
7 4 11 8 10 1 6 0 3 10 6 0 8 2 11 5 3 1 7 13 9 13 12 9 4 2 5 12
13 5 7 6 1 12 8 2 8 0 5 7 10 6 4 11 12 1 2 10 3 13 11 3 0 9 9 4
9 2 4 3 7 4 2 7 10 5 13 6 5 12 8 11 0 8 14 11 0 6 1 9 3 13 14 1 10 12
8 14 8 7 11 7 2 12 4 5 13 6 1 3 5 0 1 4 9 0 10 2 11 12 13 6 3 14 10 9
4 9 5 1 5 10 2 11 2 9 13 10 3 13 12 8 7 1 6 8 14 0 4 12 14 11 3 7 6 0
5 10 4 3 2 4 2 3 9 13 14 6 0 11 5 13 12 8 0 9 7 8 6 11 14 1 12 10 1 7
11 1 10 8 0 12 9 1 7 4 4 12 6 8 14 5 10 5 14 0 11 3 7 9 2 2 3 13 6 13
0 8 15 6 4 1 9 8 14 13 2 11 4 6 9 14 0 2 3 5 1 15 5 10 13 12 3 7 12 7 10 11
13 3 4 13 2 12 9 1 5 1 6 7 11 9 10 0 15 14 12 15 14 8 7 3 4 5 8 11 0 2 10 6
6 1 7 9 3 1 15 7 5 14 9 14 0 8 10 0 4 12 12 13 3 6 11 4 15 2 11 5 2 13 8 10
2 0 14 7 13 13 15 7 3 8 15 5 10 12 4 5 3 14 9 6 12 10 9 11 8 6 1 1 4 11 2 0
3 13 12 4 10 13 8 0 7 11 11 6 8 1 12 5 5 9 6 10 14 3 2 9 14 4 1 15 15 7 0 2
16 12 7 14 13 5 5 4 11 0 0 9 12 15 15 9 14 2 6 3 11 8 16 10 6 13 3 1 2 8 1 7 10 4
5 5 10 4 9 15 0 11 11 1 13 15 9 0 3 1 16 6 8 7 2 6 8 2 14 14 16 4 3 12 12 13 10 7
0 6 7 4 12 16 0 3 6 1 7 12 8 13 15 9 2 11 2 15 11 10 5 13 14 5 9 14 3 8 4 16 1 10
8 0 1 2 16 11 3 2 15 4 15 5 14 9 13 7 14 9 10 12 11 12 16 6 13 6 1 5 10 0 7 8 4 3
9 16 15 13 11 2 5 6 16 3 9 4 10 14 14 12 8 11 0 6 0 15 10 7 13 5 1 12 3 4 2 1 7 8
11 15 14 3 8 12 17 15 1 0 12 6 9 0 9 13 11 14 16 2 4 5 13 16 10 7 8 5 10 4 17 3 6 7 1 2
11 14 5 7 14 0 12 4 8 12 11 13 16 16 15 6 3 1 8 3 1 5 7 17 10 2 17 13 15 9 9 4 2 0 6 10
15 13 6 12 5 4 9 2 11 2 13 16 3 9 1 16 10 11 1 12 14 17 8 0 17 6 8 10 5 0 7 4 14 7 3 15
0 9 13 15 8 11 6 5 9 16 11 7 14 7 5 15 3 12 4 16 2 14 3 0 1 10 13 1 6 10 17 2 17 8 4 12
10 13 14 10 5 7 16 8 8 7 6 3 0 2 17 17 2 1 15 16 3 4 5 0 12 9 1 12 14 11 13 9 15 6 4 11
7 14 0 13 15 6 12 1 14 16 10 15 8 11 0 9 2 3 4 18 12 17 8 13 9 6 4 11 5 1 5 16 17 3 18 10 7 2
12 9 17 2 7 12 4 15 13 0 17 9 11 3 6 4 8 5 11 16 8 1 7 0 13 15 16 10 3 14 18 2 14 1 10 6 18 5
4 0 5 14 7 8 1 0 12 15 11 2 11 5 3 9 15 17 6 8 7 10 12 3 6 16 2 18 16 13 4 14 9 17 13 18 1 10
13 13 18 9 0 17 12 17 8 0 14 16 14 6 10 6 9 15 1 15 2 4 11 5 1 3 4 3 11 2 5 16 8 7 10 7 18 12
18 11 13 6 14 9 13 14 9 18 17 11 0 1 17 2 0 6 10 3 8 4 1 5 15 7 5 2 12 15 4 8 7 16 10 12 3 16
0 17 5 6 19 0 11 1 7 18 9 14 16 2 16 13 1 4 3 17 15 7 10 2 15 9 18 13 8 14 6 12 5 10 3 8 11 19 12 4
4 3 10 12 2 7 9 11 0 16 16 7 19 2 13 3 12 10 5 18 4 15 15 0 11 19 18 13 14 1 5 17 6 9 14 8 6 17 8 1
0 17 16 11 7 19 8 5 17 16 14 1 10 6 11 7 15 10 14 13 15 4 2 4 1 9 6 3 13 18 18 0 19 3 9 12 8 5 2 12
10 15 10 0 2 14 3 19 1 18 4 14 8 2 5 17 4 11 17 12 13 16 9 3 0 13 7 5 18 6 8 9 12 1 19 16 11 7 6 15
15 2 16 4 14 0 1 5 12 18 10 12 4 14 16 11 8 7 13 15 11 3 19 10 3 9 17 6 13 19 9 1 0 18 8 2 7 5 17 6
1 12 17 7 8 8 12 20 5 10 20 16 13 3 18 15 5 4 10 9 6 14 11 6 7 15 16 19 0 1 9 18 19 2 2 3 13 4 17 0 11 14
7 17 2 12 19 9 0 11 17 4 12 0 10 11 16 14 3 20 7 15 2 9 8 18 16 19 5 3 8 14 6 18 1 13 5 1 4 15 13 10 6 20
0 18 12 4 20 7 14 5 10 16 1 13 9 15 12 0 6 19 2 5 16 10 1 17 15 11 20 3 14 2 18 3 17 11 7 8 4 8 6 19 13 9
9 18 15 0 16 7 19 4 13 20 5 10 2 2 0 12 8 6 3 15 16 14 17 7 10 3 13 6 1 20 1 17 19 11 5 4 12 14 11 8 9 18
13 6 16 11 20 3 10 8 5 7 17 15 14 0 7 6 14 17 4 15 2 12 8 1 13 18 11 10 1 9 20 16 5 19 18 2 12 19 3 9 4 0
4 5 16 11 2 1 14 9 16 6 20 21 0 13 12 13 7 8 15 11 10 18 14 3 15 5 21 18 12 17 19 9 0 19 7 4 3 20 1 8 2 10 6 17
10 6 7 0 18 1 19 5 8 12 15 2 5 4 11 20 16 17 13 14 17 1 16 9 21 21 0 3 6 3 2 7 8 13 19 20 14 15 9 11 10 4 18 12
2 20 12 21 10 4 8 11 13 3 20 1 6 21 12 13 4 17 19 16 17 15 14 9 16 9 5 10 8 6 11 18 1 5 2 18 0 0 3 7 19 14 15 7
16 0 17 8 11 6 3 18 9 16 14 20 12 12 10 1 14 1 10 21 4 19 0 2 13 3 15 17 21 9 6 18 2 20 4 11 7 19 5 8 7 5 13 15
3 4 4 10 0 3 16 14 19 8 17 9 5 9 6 12 7 13 13 1 15 0 5 20 2 7 1 17 21 11 11 18 20 6 15 16 2 12 14 19 8 10 18 21
12 11 7 8 8 10 9 18 5 6 15 12 10 0 14 3 6 22 17 15 17 21 14 16 9 4 18 13 1 11 4 20 3 19 22 1 13 7 21 5 0 20 2 2 16 19
2 20 10 17 6 0 21 10 19 4 12 8 0 7 18 15 17 18 9 4 2 14 1 5 14 6 16 22 13 11 11 15 21 3 7 19 8 9 22 20 3 16 13 1 12 5
12 11 6 16 18 15 12 11 10 9 8 15 22 5 21 18 20 0 2 19 17 8 10 5 3 14 9 22 20 3 1 21 19 6 0 16 1 13 4 14 2 13 17 4 7 7
20 5 16 4 17 7 8 15 0 10 9 3 16 13 8 12 1 14 17 11 18 11 2 7 6 1 4 20 3 5 22 22 2 6 13 10 19 15 12 14 18 9 0 19 21 21
11 1 0 5 7 15 0 12 3 9 6 15 7 13 11 20 9 17 8 4 22 4 10 5 21 18 16 14 13 10 18 12 21 17 16 2 6 22 3 14 19 1 8 19 20 2
10 10 18 6 4 1 9 6 15 7 7 11 21 13 15 21 22 16 12 20 2 18 3 17 19 14 14 0 16 5 3 4 1 9 13 11 22 20 19 8 5 0 23 17 23 2 8 12
3 3 19 13 5 10 17 18 4 16 6 2 21 4 12 7 13 8 7 10 6 2 1 15 5 21 23 22 0 11 9 16 20 11 20 23 1 14 18 8 14 19 9 17 0 15 22 12
14 7 15 20 19 7 13 0 20 2 18 1 11 21 17 12 16 10 8 3 15 2 22 23 18 16 9 1 3 13 10 19 8 11 6 4 5 22 0 17 21 23 14 4 12 9 6 5
1 12 15 21 11 21 18 6 4 22 5 23 14 19 13 8 15 7 5 0 8 13 16 4 1 6 12 11 14 18 20 17 9 23 19 3 2 17 9 0 16 7 3 20 10 22 2 10
23 9 15 10 13 17 17 21 12 18 2 20 3 8 0 16 2 12 6 20 7 19 16 0 8 9 4 6 5 13 18 14 1 19 21 3 22 15 1 4 22 10 5 7 11 14 11 23
3 21 22 5 19 7 2 24 18 19 9 2 24 14 6 0 12 0 21 18 23 15 8 11 6 4 8 17 16 20 14 16 4 7 10 11 1 9 17 3 23 10 20 5 13 22 13 1 12 15
13 6 5 22 1 17 2 21 5 0 14 24 19 21 7 19 6 23 12 14 4 9 3 22 15 9 2 16 20 7 13 12 8 23 18 0 15 10 8 24 20 16 3 1 4 11 10 18 17 11
12 6 19 0 9 14 22 2 13 20 19 9 6 3 21 20 24 0 4 24 1 5 11 15 1 21 8 5 16 16 23 18 7 11 10 17 15 12 3 22 7 10 2 23 17 8 14 4 13 18
6 22 2 18 16 19 12 0 17 14 23 4 6 17 3 10 4 22 13 9 20 19 0 9 8 1 24 2 23 14 11 5 7 16 13 10 12 8 7 3 20 21 15 5 18 21 11 1 15 24
18 12 6 22 19 19 9 24 5 14 13 2 22 8 4 16 3 9 18 8 0 10 23 10 2 20 21 5 23 20 1 11 0 17 7 7 17 12 15 3 16 15 13 24 14 4 6 21 11 1
7 14 19 5 4 17 1 22 23 24 12 1 20 6 24 7 21 10 8 11 20 3 25 13 0 2 16 21 0 6 9 11 4 18 22 2 15 5 18 8 13 12 3 14 23 10 17 9 16 15 25 19
10 4 1 13 11 24 7 12 15 20 11 0 23 23 5 7 25 25 17 8 20 24 2 22 19 9 12 16 4 6 21 9 17 6 5 15 10 0 18 8 22 2 14 16 3 19 21 18 1 3 13 14
16 22 3 2 25 21 11 1 10 12 4 15 0 2 13 11 3 14 19 1 18 12 8 23 18 22 9 16 4 0 20 9 17 24 7 10 6 8 23 25 15 7 21 20 19 5 14 13 6 5 17 24
21 20 8 16 1 18 4 0 14 5 22 3 0 23 22 1 9 4 24 7 21 2 23 15 11 12 14 25 8 12 7 15 13 18 3 19 10 2 5 10 16 24 19 13 6 20 6 9 17 11 17 25
6 24 17 18 24 22 10 11 20 16 16 3 4 21 23 25 14 1 0 1 7 2 5 13 6 4 10 21 17 14 23 11 9 9 15 25 0 19 19 12 20 22 12 13 15 2 3 8 5 18 8 7
11 16 25 6 19 5 26 17 24 6 12 4 15 18 21 7 10 5 23 3 13 8 13 23 20 8 11 12 9 22 1 14 21 2 25 10 15 9 0 2 0 26 3 24 17 22 14 4 18 16 20 19 1 7
26 0 19 3 0 20 1 25 13 3 12 6 20 11 21 13 2 11 23 15 17 15 24 23 10 8 26 5 18 9 16 18 4 9 19 10 14 7 22 17 22 4 16 8 24 2 25 5 14 12 6 21 1 7
9 25 13 14 19 17 20 2 11 5 19 23 25 21 0 16 8 15 7 16 24 24 3 15 20 10 8 4 0 12 13 22 9 4 26 18 22 2 23 18 3 6 6 12 17 26 21 10 1 11 14 7 5 1
17 4 20 23 13 0 3 26 25 16 3 2 13 10 8 12 9 5 14 2 26 25 21 23 22 17 7 14 24 1 4 15 19 16 12 5 9 22 1 20 19 7 11 6 21 15 11 18 6 8 18 0 10 24
14 12 3 17 7 2 19 11 0 21 10 24 4 6 8 8 25 4 6 23 9 1 25 15 12 9 23 10 2 26 1 0 11 7 19 13 18 3 17 13 16 26 20 20 16 15 22 22 18 14 5 24 21 5
4 15 22 10 27 14 7 0 2 17 3 6 20 18 0 16 21 4 3 11 11 12 23 5 15 22 9 17 2 1 10 18 25 14 27 19 16 23 20 21 6 25 26 24 13 1 24 26 9 13 8 19 8 7 5 12
3 17 8 9 3 9 23 15 10 25 0 6 26 21 11 12 27 1 11 13 14 2 6 1 20 7 19 24 22 14 22 25 16 17 26 5 24 27 12 13 18 4 23 20 19 4 7 15 21 8 5 16 10 2 0 18
9 11 14 21 3 12 10 4 14 1 5 18 27 9 6 0 3 19 7 12 17 26 26 25 15 11 16 24 17 18 20 8 7 19 15 1 4 13 22 23 8 25 20 16 22 2 6 0 10 5 2 24 23 21 13 27
7 23 2 26 5 24 19 17 2 18 11 7 16 5 8 26 24 21 8 14 10 16 18 9 27 1 4 22 15 25 17 4 0 0 21 3 15 12 11 23 19 27 10 13 6 22 3 14 6 13 12 9 20 1 20 25
17 4 24 21 11 22 12 13 0 1 17 23 15 4 6 2 27 14 3 16 8 13 3 5 2 6 0 9 23 14 25 26 10 18 19 26 8 11 10 20 21 18 22 20 25 9 7 12 1 7 19 16 5 27 15 24
8 27 28 24 9 9 16 22 13 20 23 25 13 21 0 26 21 8 16 24 27 18 26 23 3 7 3 25 22 15 14 6 5 7 11 4 1 20 17 19 17 12 4 14 2 1 5 18 2 28 12 0 10 19 15 11 6 10
21 9 3 23 27 4 15 22 12 2 16 26 4 13 28 16 20 6 6 3 10 1 18 5 11 0 21 7 8 25 23 17 9 15 22 14 24 2 5 10 12 17 20 1 24 7 18 0 14 26 19 13 28 25 11 8 27 19
26 10 19 20 17 10 9 19 7 15 4 27 0 15 18 2 6 2 22 6 12 25 11 9 24 26 5 11 5 21 17 7 8 4 18 14 16 24 28 1 3 28 27 14 12 8 13 13 23 3 16 23 25 21 22 0 1 20
1 0 19 11 20 17 8 3 2 18 7 18 21 5 26 9 10 6 20 2 28 8 26 19 21 17 16 14 3 14 22 12 13 6 24 9 10 22 0 27 11 13 27 7 15 4 28 1 16 23 25 23 25 12 24 15 4 5
5 9 12 7 19 25 6 24 12 6 25 3 1 16 28 2 3 14 16 4 5 26 7 8 20 19 18 22 10 27 13 28 21 17 11 26 4 18 0 20 27 24 15 10 23 11 0 21 9 22 13 14 8 1 17 15 23 2
\$\endgroup\$
3
  • \$\begingroup\$ If I use an rng, I could get very different results between runs. Perhaps score based on the average of 100 runs? \$\endgroup\$ Nov 5, 2018 at 19:40
  • \$\begingroup\$ @Spitemaster It is possible that a different RNG would change the score to be +1 or -1, but as scores get larger, the RNG seed matters less. If a person posts a solution that required a very specific RNG seed, it wouldn't be reproducible, and therefore, invalid. \$\endgroup\$ Nov 5, 2018 at 20:14
  • \$\begingroup\$ This seems like a nice challenge but it's a bit vague. What do you mean by "Your function must use this [32 bytes of] data". We can't use local variables? Do we have to assign that parameter that was passed to us in the function call to another value to be able to store data? \$\endgroup\$
    – FireCubez
    Nov 8, 2018 at 18:50
0
\$\begingroup\$

Lunar Arithmetic

Lunar Arithmetic (also called dismal arithmetic, a play on decimal) is an alternative to elemental arithmetic in which only addition and multiplication is defined, and then only for non-negative integers. For single-digit numbers, addition is defined as the maximum of the two digits, and multiplication is defined as the smaller of the two digits. For example:

2 + 5 = 5 + 2 = 5
2 * 5 = 5 * 2 = 2

To extend lunar addition to multi-digit numbers, simply consider the digits individually, counting empty digit places as zeroes as required. For example, consider 169 + 84:

  1 6 9
+   8 4
  -----
  1 8 9

Lunar multiplication can now be dealt with in the same way as normal long multiplication, using the lunar rules for addition and multiplication. For example, consider 169 * 84:

    1 6 9
*     8 4
  -------
    1 4 4    (169 * 4)
+ 1 6 8      (169 * 8)
  -------
  1 6 8 4

The challenge

Write a function or program which, when given two integers, returns the result of their lunar addition and their lunar multiplication, in any order.

  • The input pair may be presented as a two-element list or array.
  • Input numbers may be provided in any reasonable format, including as a string, or as a list of digits.
  • Output may similarly be in any reasonable format.
  • The two output numbers must be separated in an unambiguous way, such as with newlines, spaces, as elements of a list or array.
  • Links to online demonstrations are appreciated, but not required.
  • Standard loopholes are disallowed.
  • This is , so shortest code in bytes per language wins!

In your submission, please specify the order in which the two results are presented, and your input and output formats if they are out of the ordinary.

Test cases

Test cases go here

Resources

Original paper outlining dismal arithmetic

Numberphile video discussing lunar arithmetic

Tags


Sandbox business

I see this as the potential starting point for a number of Lunar arithmetic challenges, such as computing the result of a longer calculation (such as 12+345*67*8), identification of lunar primes, lunar prime factorisation, methods of implementing subtraction and division... Of course that all depends on the response to this challenge. Any feedback on how to make this challenge better would be much appreciated!

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

Posted: FreeChat Online

\$\endgroup\$
3
  • 4
    \$\begingroup\$ You're posting to main way too fast. I recommend waiting for at least a couple of days; people have to read before giving you some feedback (comment, upvote, whatever) anyway. \$\endgroup\$
    – Bubbler
    Nov 14, 2018 at 4:26
  • \$\begingroup\$ okay @Bubbler I'll wait next time \$\endgroup\$
    – Michael
    Nov 14, 2018 at 5:21
  • 1
    \$\begingroup\$ After you post a challenge, please edit the post and delete it. \$\endgroup\$
    – Laikoni
    Nov 14, 2018 at 13:14
0
\$\begingroup\$

Simple ASCII Representation of a Screw Head

Inputs are a string and a number.

If the string is "Slot", the number will be 0, 60, 90, or 120. If the number is 0, output --; if 60, output /; if 90, output |, if 120, output \.

If the string is "Phillips", the number will be 0, 45, 90, or 135. If it's 0 or 90, output +; otherwise output x.

If the string is "Torx", the number will be 0, 60, or 120. Regardless of the value, output *.

If the string is "Spanner", the number will be 0 or 90. Output .. for 0 and : for 90.

Behavior for all other inputs is undefined.

[Is this challenge too simple? If so, could more test cases help?]

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think adding test cases that require modular division (so you could say Phillips 72270) and error handling (GenericScrewXyz 43 would throw an error). \$\endgroup\$
    – wizzwizz4
    Dec 2, 2015 at 18:31
0
\$\begingroup\$

Display a rational tangle [WIP]

In a quest to classify mathematical knots, J. H. Conway discovered that certain simpler knotlike structures called rational tangles can be uniquely represented by rational numbers.

A tangle is an arrangement of two strands of rope such that each of the four ends lies at one corner of a rectangle. The four exceptional tangles are 0, 1, -1, and a special case usually referred to as 0/0 or ∞. A rational tangle is a tangle that can be obtained from the exceptional tangles by the following operations.

Example of rational tangles

An example of a rational tangle, and the tangles 0/0, 0, 1, and -1 respectively.

enter image description here

The rational tangle operations

Because every rational number can be obtained by addition, negation, and reciprocal, there exists some rational tangle corresponding to every rational number.

If tangle a and b have rational number values x and `y respectively, then the operations in the diagram result in the following values.

Tangle |  Value
-a          -x
1/a         1/x
a + b      x + y
a b       -x + y
a , b     -x + -y   

Challenge

Using the below representations of the four exceptional rational tangles, display an ASCII art rational tangle corresponding to a given rational number.

Exceptional rational tangles

\_/   \ /
 _    | |
/ \   / \

3x3 ASCII art representing the rational tangles 1/0 and 0

\ /   \ /
 \     /
/ \   / \

The rational tangles 1 and -1, illustrating how to display crossings

Displaying more complex rational tangles

Adding and rotating the above 3x3 blocks and rotation can yield any rational tangle.

  • To flip a rational tangle over the line x=y, switch all instances of 1 and -1, switch all instances of 0/0 and 0, and replace all extenders (below) as appropriate.

  • To rotate a rational tangle by 90 degrees in either direction, rotate the ASCII art by 90 degrees in that direction, switch all \ and /, switch all instances of 0/0 and 0, and replace all extenders (below) as appropriate.

  • To add two rational tangles, juxtapose them in the appropriate direction and orientation, adding extenders if dimensions do not match. Then surround the result with the following.

Pattern to surround the sum of two tangles in:

\ ... /
       
⋮      ⋮
       
/ ... \

Extenders:

 \        /
  |      |
 ...    ...
  |      |
   \    /

\_..._
      \

 _..._/
/

Examples

One possible representation of the tangle obtained through the equation [...]. This tangle is congruent to [...] because =.

 \       /
  \_   _/ 
    \ /  
     /   
  __/ \_ 
 /      \
 \      / 
  \ /\ / 
   \  \  
  / \/ \
 /      \
/        \

Input

A rational number. If you instead take input as an ordered pair (numerator,denominator) of integers, you will have denominator >= 0. (Denominator 0 is necessary to represent 0/0.)

Output

An ASCII-art representation of the rational tangle corresponding to said number, where a crossing is displayed as one of the above. Whitespace can occur anywhere. Output can contain unnecessary copies of 0, or have other variations as long as the rational tangle is obtained by operations whose corresponding arithmetic operations result in the input.

Further sources

A further explanation of tangles and rational tangles: (https://rationaltangle.wordpress.com/what-are-tanglesrational-tangles/)


TODO: Reciprocal operation, better example, reference implementation

Should continued fraction representations be acceptable?

Since this is probably a difficult challenge and answers to such are undervoted, I'm prepared to award a bounty to the shortest answer and any improvement thereon.

This is getting more unwieldy. I'm thinking of simplifying into a challenge to simply add two rational tangles.

\$\endgroup\$
3
  • \$\begingroup\$ The introduction seems to be written as a reminder to someone who already knows the topic and needs a refresher. To someone who's never heard of rational tangles before, it throws up a lot more questions than answers. What's 0/0 (other than NaN)? What's ramification? What (other than a+b, which is fairly straightforward) is the diagram supposed to show? The intro says that the ends of the rope must be in the corners of a square: should that say rectangle? In the ASCII art, how do extenders cross? \$\endgroup\$ Nov 18, 2018 at 21:28
  • \$\begingroup\$ 1. Which part of the diagram corresponds to reciprocal? Does the left-hand part somehow show both negation and reciprocal at the same time? 2. Having looked at your additional reading link, the challenge turns out to be much simpler than the question made it seem. The paragraph starting "The two simplest tangles" and the subsequent one seem to be all that's needed. Perhaps you could use a simple challenge as an introduction and then have a follow-up which asks for an equality test? \$\endgroup\$ Nov 18, 2018 at 22:41
  • \$\begingroup\$ @PeterTaylor 1. Reciprocal is flipping over some axis, I forget which one. 2. Will do when I have time. I probably won't end up posting this for another month. \$\endgroup\$
    – lirtosiast
    Nov 18, 2018 at 22:52
0
\$\begingroup\$

Octonion multiplication

Background

Octonion is a further extension to the quaternion number system. An octonion can be written as

$$ x = x_0 e_0 + x_1 e_1 + x_2 e_2 + x_3 e_3 + x_4 e_4 + x_5 e_5 + x_6 e_6 + x_7 e_7 $$

where \$ x_i \$ are real numbers and \$ e_i \$ are the eight unit octonions.

Octonion multiplication has the following properties:

  • It is not commutative, i.e. \$ xy \ne yx \$.
  • It is not associative, i.e. \$ x(yz) \ne (xy)z \$.
  • But, luckily, multiplication is distributive over addition, i.e. \$ x(y+z) = xy + xz \$ and \$ (x+y)z = xz + yz\$.

The multiplication rule for unit octonions is presented below:

(will add a table from Wikipedia)

The unit octonions have several properties:

  • \$ e_0 \$ behaves like a real number 1.
  • \$ e_i^2 = -1 \$ and \$ e_i e_j = -e_j e_i \$ for \$ 1 \le i,j \le 7, i \ne j \$.

Task

Multiply two octonion numbers.

Input & output

You can accept and output an octonion as any kind of consistent structure consisting of eight real numbers (four complex numbers or two quaternions or a mixture of types is also fine).

Test cases

Coming soon.

Scoring & winning criterion

Standard rules apply. The shortest program or function in bytes for each language wins.

\$\endgroup\$
2
  • \$\begingroup\$ \$1e_0+2e_1+3e_2+4e_3+5e_4+6e_5+7e_6+8e_7\$ is written in NARS2000 as 1i2j3k4l5ij6jk7kl8. ;-) \$\endgroup\$ Nov 19, 2018 at 17:11
  • 1
    \$\begingroup\$ Somehow, I think NARS APL will win this one… \$\endgroup\$
    – Adám
    Nov 19, 2018 at 18:39
0
\$\begingroup\$

Tetris battle


I guess you know what Tetris is, but if you don't I'll try to explain:

So there is a 2 dimensional board, often with size 10x20. On the top of the board, in the middle, there is a random tetrominoe (also rotated randomly), a figure made of 4 squares. There are 7 shapes:

L    J   S    Z    T   O   I

#    #   ##  ##   ###  ##  #
#    #  ##    ##   #   ##  #
##  ##                     #
                           #

Every second, the tetrominoe (later called "block") will move 1 cell to the bottom until there is no space left. Player can control it - Move it to left, right, rotate it by 90 degrees (left or right) or speed up its fall. When it can't fall down further, a new block is created and you take the control over it, losing possibility to move the previous block.

The target is to get as much points as possible. Player can get them, by filling a line (which is then removed), for example:

        !
        !
        !
****####!$ <- user scores a point, the line is now removed
 &&&&  $$$ 

different character is a different block

Player can lose if there is no place for a new block to spawn.

You can play Tetris online here


The battle

In this challenge, you will have to create a bot to play Tetris. Unlike a normal playthrough, there will be two players playing on a single board.

Let's call the bots A and B.

Block spawning

Every block will start on the left, or right side, depending which bot's it is (left - A, right - B). There will be a 2 block margin, so the block will have some space to rotate. Block will always spawn with left/right align, not centered.

If a block can't fit, it will try to rotate, so it can be placed. If all 4 directions fail, you die.

Example for 10 width board:

--A----B--

Random size board

Width: random even number between 8 and 16.

Height: random number between 15 and 25.

It's to make it a bit harder. Try to plan your strategy so it fits all the heights!

Scoring

You gain 1 point per destroyed block. Some bonus rules apply:

Enemy's block isn't my block

You can't use blocks placed by your enemy to gain score. After adding the last block to a line, you gain as much score as much sub-blocks you placed in it. Enemy sub-blocks don't count. Example:

Player A filled the line.
AAAABBBAAB
Player A gets 6 points.
Player B doesn't earn any.

Combos

If you do a move that removes more than just 1 line, you gain x times more score. Of course, x is the amount of lines.

Player A filled the line
--ABBB
AAABBBABBB <
BBBBBBABBB <
BBBBAAABBB < 
 B AA ABBB
Player A removed 3 lines.
Player A removed 12 (4+5+3) blocks he owns.
Player A scores 36 points.

Death & Game Over

When a new fails to spawn, it tries to rotate 90, 180, 270 or 360 degrees. If it still can't spawn. You lose. Note it won't try to change it's position, so be careful and try to not put any blocks in the spawn area.

When you die, you can't place any more blocks.

  • In case your enemy has more points than you, you lose.
  • Otherwise, the game doesn't end yet – the enemy will get double points for the next 10 blocks. The game will end when the bonus ends, when he beats your score or when he dies.

When the game is over, the bot with more points win.

The game will also end automatically after 300 actions. See API > Actions section for more information.

Controller

Work in progress. https://github.com/Soaku/Tetris-KOTH

API

Can't really tell you how it's gonna look like without a controller, right?

However, there is a project of how it's gonna look like:

Actions

Every game consists of actions. Your bot function will be executed at the beginning of each action. At the end of each, active tetrominoes will move 1 cell to the bottom.

The controller will wait a configurable amount of time between actions unless the preview is disabled.

Your function should return an integer in at most 0.1 seconds, otherwise your action is terminated and ignored. If it will cross the limit repeatedly, I might remove it.

Rules

  • Default loopholes are forbidden.
  • Aggressive bots are allowed but discouraged.
  • You cannot use any external libraries. The controller uses jQuery, but you aren't allowed to use it.
  • Don't try to access the document – Don't write nor read data.
  • Don't write your bot to beat specific enemies by countering their strategies.
  • Enemy spawn works like an occupied block. You cannot place anything here.

Main scoring

Every bot will play with every other bot.

Scoring works this way:

  • Victory: 2 points
  • Tie: 1 point
  • Lose: 0 points
\$\endgroup\$
10
  • 1
    \$\begingroup\$ I feel like the last part (bonus round) there probably isn't such a good idea. especially since bots are mostly programmed to play against one enemy, so it means a regular bot needs to implement special cases for one round, which really doesn't add much. \$\endgroup\$ Nov 5, 2017 at 22:25
  • \$\begingroup\$ If you do decide to make a massively multiplayer one, it's sort of unfair to bots that will perform better at the side that end up in the middle or vice versa, so making it a cylinder (the rows wrap around into themselves) would help \$\endgroup\$ Nov 7, 2017 at 8:04
  • \$\begingroup\$ Fine, I removed it from the answer itself, but that doesn't mean I can't do it for fun ( ͡° ͜ʖ ͡°) \$\endgroup\$
    – RedClover
    Nov 8, 2017 at 19:44
  • \$\begingroup\$ Just wanted to point out that your J, L, and T tetrominoes actually have 5 squares each; I'm fairly sure that wasn't intentional. \$\endgroup\$ Nov 8, 2017 at 23:48
  • \$\begingroup\$ The question describes things that happen when "enemy is dead", but does not describe what causes that or what happens when "you are dead". \$\endgroup\$ Nov 9, 2017 at 16:12
  • \$\begingroup\$ @KamilDrakari [On spawn] If a block can't fit, it will try to rotate, so it can be placed. If all 4 directions fail, you die. \$\endgroup\$
    – RedClover
    Nov 9, 2017 at 16:13
  • 1
    \$\begingroup\$ That is an awfully small section for something quite important. I would add a distinct section on Death, clarifying "when dead, you can no longer place blocks" and some edge cases for the 10 bonus pieces, such as what happens if a player dies during their bonus pieces and if they are required to continue placing the full 10 blocks or they can stop once they have a higher score. \$\endgroup\$ Nov 9, 2017 at 16:50
  • \$\begingroup\$ @KamilDrakari Oh, you're right. I'll try to add something about that, when I have some time. \$\endgroup\$
    – RedClover
    Nov 9, 2017 at 16:51
  • \$\begingroup\$ @ETHproductions I also noticed that J and L are pentominoes. T is actually a hexomino. But... \$\endgroup\$
    – Heimdall
    Nov 11, 2017 at 9:59
  • \$\begingroup\$ @ETHproductions thanks for pointing this out. Fixed \$\endgroup\$
    – RedClover
    Nov 11, 2017 at 10:00
0
\$\begingroup\$

Make numbers inflate to full width!

Related: Full Width Text

That is a challenge that changes ALL characters into full width -- BY ADDING A SPACE AFTER EACH CHARACTER. However, in this challenge only numbers are transformed, and are transform to the REAL FULL WIDTH FORM

.

This is a short and simple challenge, so I will keep the description short.

Challenge

Write a program / function that accepts an ASCII string as input and outputs a UTF string with each number 0123456789 converted to its corresponding full width form 0123456789. The range of these full width numbers is U+FF10 - U+FF19.

You may output using the following format (As an example This is 1 apple is used):

  • A UTF-8 string (showing exactly This is 1 apple in STDOUT)
  • The same string as above but displayed in a non-UTF-8 encoding (eg. showing This is 1 apple in Windows-1252 codepage). In this case you must state the codepage of the output
  • A single list of UTF-8 bytes as integers that represents the transformed string (showing ord("T"),...,ord(" "),239,188,145,ord(" "),...,ord("e") with arbitrary delimiter)

You cannot mix integer output and character output, that is, you cannot literally change This is 1 apple to This is [239,188,145] apple. You cannot output a nested list if a list is outputted either.

Sample I/O

  • Sample 1:

    Input:  0123456789
    Output: (Format 1) 0123456789
            (Format 2) 0123456789 [CP437]
            (Format 3) 239,188,144,239,188,145,239,188,146,239,188,147,239,188,148,239,188,149,239,188,150,239,188,151,239,188,152,239,188,153

  • Sample 2:

    Input:  This is 1 apple
    Output: (Format 1) This is 1 apple
            (Format 2) This is 1 apple [Windows-1252]
            (Format 3) 0x54 0x68 0x69 0x73 0x20 0x69 0x73 0x20 0xef 0xbc 0x91 0x20 0x61 0x70 0x70 0x6c 0x65

Footnote

This is a , so shortest answer for each language wins. Standard loopholes are forbidden by default.

P.S. I would like to see both practical and esoteric language submissions. Specifically the last two output formats are especially allowed for esoteric languages.

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

Help Runbee manage the pollen! [better title needed?]

The  arsonist  friendly bee, Runbee, just finished picking up the pollen from the flower garden and now she wants to store it safely in her hive. Each pollen type is labeled with a digit (from 1 to 9). Runbee's "collection" is stored in a row of adjacent honeycomb cells, containing one grain each. For instance, this row could look like this:

1 3 2 2 4 4 4 5 3 3 3 7 8 9 9 5 

But hmm, Runbee doesn't like this order... Because she's tired after flying all day, she can now only move a run of identical adjacent pollen grains to another position in the row to make it seem more organised. Her goal is to have as many identical pollen types one after another after the reordering.

Task

Given a sequence S of digits ranging from 1 to 9, one shall:

  • Split S into (the longest possible) runs of consecutive adjacent elements. Then, one of the chunks should be moved to another position in S.
  • The resulting sequence S' should be chopped again into (the longest possible) runs of consecutive adjacent elements. Your goal is to search for the sequence S' which contains the most equal consecutive elements.
  • You can either output all such sequences S' (deduplicated or not) or just one of them.

For the example above, the possible ways to generate optimal orderings are (where (...) represent the point of removal and [...] the point of addition):

1 (3) 2 2 4 4 4 5 [3] 3 3 3 7 8 9 9 5     | 1 2 2 4 4 4 5 3 3 3 3 7 8 9 9 5 
1 (3) 2 2 4 4 4 5 3 3 3 [3] 7 8 9 9 5     | 1 2 2 4 4 4 5 3 3 3 3 7 8 9 9 5
1 3 [3 3 3] 2 2 4 4 4 5 (3 3 3) 7 8 9 9 5 | 1 3 3 3 3 2 2 4 4 4 5 7 8 9 9 5
1 [3 3 3] 3 2 2 4 4 4 5 (3 3 3) 7 8 9 9 5 | 1 3 3 3 3 2 2 4 4 4 5 7 8 9 9 5

Rules

... To be written ..

Test cases

... To be added ..

\$\endgroup\$
1
  • \$\begingroup\$ Suggested testcase: 1 3 2 2 2 2 3 3 1 \$\endgroup\$
    – Emigna
    Nov 23, 2018 at 7:59
0
\$\begingroup\$

Posted

\$\endgroup\$
1
  • \$\begingroup\$ Note. Because TSP (decision version) is NP and maximum independent set is NP-hard, it's possible to have polynomial-time complexity; however given how unrelated those two problems appear to be, the actual transformation would be nontrivial and may be interesting to optimize. \$\endgroup\$
    – DELETE_ME
    Nov 30, 2018 at 16:45
0
\$\begingroup\$

You are filling a survey. You don't like filling such thing, so you decide to automatically fill some random thing.

However, there may be some duplicated question, and some may be inverted. To simplify the question, we define:

  1. Adding or removing word "not" or "no" inverts the sentence;
  2. Adding or removing "un" at the beginning of a word inverts the sentence;
  3. Adding or removing "n't" at the end of a word inverts the sentence;
  4. Adding or removing word "any", "a" or "an" keeps (doesn't invert) the sentence;

Invertion can go through sentences even if they are not asked. E.g. "Do you own a car?" is twice inverted to "Don't you own no car?", so they should have same answer, no matter what sentences left are mentioned.

Input: A list of string, each of which is a sentence.

Output: A list of 2-possible-value, where inverted sentences are answered different and same sentences are answered same.

Sample Input:

Are you rich?
Are you unrich?
Are you poor?
Are you rich?
Are you not rich?

Possible sample outputs (assuming 0 and 1 as possible outputs)

1,0,0,1,0
1,0,1,1,0
0,1,0,0,1
0,1,1,0,1

. Decided to not have to try to have more creative solution

\$\endgroup\$
4
  • 3
    \$\begingroup\$ I would rather have this challenge something closer to just "identify duplicate questions" rather than "create a possible set of answers such that you answer duplicate questions with appropriate inversion". Something like "Given two sentences, output one of 3 distinct values to indicate whether they are "duplicate", "inverted", or "unrelated"". If you insist on keeping the output as possible answers, then your "output" line needs to say so rather than just "a list" \$\endgroup\$ Dec 5, 2018 at 17:26
  • \$\begingroup\$ @KamilDrakari If no random requirement, false relation or something else may exist. Considered \$\endgroup\$
    – l4m2
    Dec 6, 2018 at 3:01
  • \$\begingroup\$ @KamilDrakari That is a good option, because it is a large part of the challenge, and the other part is likely to be implemented using brute force ⇒ very slow, not testable. \$\endgroup\$
    – DELETE_ME
    Dec 6, 2018 at 16:19
  • \$\begingroup\$ @user202729 Nope, they'll count nos, uns and n'ts and mod2 \$\endgroup\$
    – l4m2
    Apr 22, 2021 at 10:00
0
\$\begingroup\$

Separate the syllables - in Finnish

Given a Finnish word as a string, separate each syllable.

Wait, what?

In Finnish, syllables are very important for many different things in the grammar - often, the first place a foreigner starts with the language is with the syllable structure. Your job, as a prospective learner, is to decompose the given word into its syllables. To do this, your program or function must return a string in which the syllables have been separated by a single | or -.

But how?

Given any word, you can split the syllables apart by following five simple rules. In the below mapping, V indicates a vowel (aeiouyäö), a diphthong or a long vowel (see below) and C indicates a consonant (bcdfghjklmnpqrstvwxz). '-' indicates where the word should be split. Patterns are "greedy", so the longest matching pattern is the one that should be applied.

VV -> V-V

VC -> VC

VCV -> V-CV

VCCV -> VC-CV

VCCCV -> VCC-CV

What the &@?! are diphtongs?

Because Finnish is a complex language, we can't just let foreigners get off that easy with learning the basics! So, we came up with diphtongs - pairs of vowels that are considered a single vowel when determining syllables. The list of the ones important to this challenge is as follows (in an arbitrary order):

ai, ei, oi, ui, yi, äi, öi, ey, iy, äy, öy, au, eu, ou, iu, ie, uo, yö

Furthermore, we have long vowels - these also count as a single vowel, and are simply the vowel repeated twice:

aa, ee, ii, oo, uu, yy, ää, öö

What else?

You should note that:

  • Default loopholes are forbidden.
  • Default I/O is allowed.
  • You may take input and produce output in any string encoding that contains at least the following characters: abcdefghijklmnopqrstuvwxyzåäö-| and/or their upper-case equivalents.
  • The encoding must be the same for input and for output.
  • This is . Shortest answer wins.

Give me the solutions!

Examples are given as input -> output with syllable boundaries indicated by a -.

perkele -> per-ke-le
sauna -> sau-na
koskenkorva -> kos-ken-kor-va
nopea -> no-pe-a
maa -> maa
suomenkieli -> suo-men-kie-li
esimerkki -> e-si-merk-ki
itsenäisyyspäivä -> it-se-näi-syys-päi-vä
koodigolffi -> koo-di-golf-fi
toritapaaminen -> to-ri-ta-paa-mi-nen

Finally...

Happy golfing!

\$\endgroup\$
2
  • \$\begingroup\$ I don't understand how to use the patterns. What is the point of the VC pattern if it does not have any split? \$\endgroup\$
    – feersum
    Dec 10, 2018 at 14:00
  • \$\begingroup\$ @feersum It's just there to indicate that any trailing consonants are considered part of the same syllable as the preceding vowel (i.e. the last example). \$\endgroup\$
    – user77406
    Dec 10, 2018 at 14:06
0
\$\begingroup\$

Validate a simple bell-ringing method

A simple bell-ringing method on n bells has the following characteristics.

  1. Each row exchanges at least one pair of adjacent bells. Any given bell can only take part in one exchange per row.
  2. The notation for a row lists those bells that are not exchanged. Each row is separated with a .. However, rows that exchange all bells are notated with an X and do not use . separators, so that .16..16. would actually be notated X16X16X.
  3. The first n-1 rows always exchange bell 1 with the next bell so that it becomes last.
  4. The nth row, also known has the half lead, does not exchange bell 1.
  5. The next n-1 rows are the same as the first n-1 rows but in reverse order. This brings bell 1 back to its original position.
  6. The 2nth row, also known as the lead end, also does not exchange bell 1.
  7. Up to three different lead ends may be used, being named "Plain", "Bob" and "Single".
  8. After the lead end, the 2n-1 rows are rung again, possibly with a different lead end, and this repeats according to a predetermined pattern known as a touch.
  9. The method starts and finishes with the bells in ascending order.

The following parts are intended to be submitted as separate questions.

Part 1

Given any number of rows in bell-ringing notation, return a truthy or falsy value depending on whether they represent a valid permutation.

Part 2

Given any number of rows in bell-ringing notation, convert them to permutations and output them in the most convenient format for input into subsequent parts.

Part 3

Given a list of permutations corresponding to the first n rows of a method, append the first n-1 rows in reverse order, and then output the result of combining the permutations.

Part 4

Given the permutation from part 3, and up to three different lead end permutations as output by part 2, and a string representing which the order in which the lead ends are to be used, calculate the permutations before and after each lead end, ensuring that they are all different, and that the last permutation is that the identity permutation.

Example:

Main rows: 5.1.5.1.5
Plain lead: 125
Bob: 145
Touch: PBPPBPBPPB

5.1.5.1.5 means that the permutations are (12)(34) and (23)(45) repeated, so the permutation before the first lead end in this case turns out to be just (23)(45) again. The plain lead is (34) and the bob is (23). The relevant permutations for the touch are as follows:

(23)(45)
(2453)
(25)
(235)
(245)
(2345)
(35)
(345)
(243)
(34)
(2354)
(2453)
(25)(34)
(2435)
(2534)
(253)
(354)
(45)
(23)

then finishing with the identity permutation as desired.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I have to say, I am entirely confused by this and haven't the slightest idea what any of it means to the point that I can barely even identify what things confuse me. However, I can at least ask one thing: Rule 3 states "exchange bell 1 with the next bell so that it becomes last". How does "exchange bell 1 with the next bell" result in "it becomes last"? If I have 3 bells I would expect the result to be 213. Are you using a different definition of "exchange" than me? \$\endgroup\$ Dec 11, 2018 at 21:09
  • \$\begingroup\$ @KamilDrakari There are n-1 rows, which is exactly the minimum number needed to get bell 1 into last place, as long as each row moves bell 1 a further step each time. \$\endgroup\$
    – Neil
    Dec 11, 2018 at 22:22
  • \$\begingroup\$ In point 2 should .16..16. say .16.16.? \$\endgroup\$ Dec 14, 2018 at 12:08
  • \$\begingroup\$ @PeterTaylor No, .16..16. is a list of five strings, three of which are empty. \$\endgroup\$
    – Neil
    Dec 14, 2018 at 13:23
0
\$\begingroup\$

Prime Steganography


Alice and Bob have devised a steganography encryption method where they encode the letters of their message (the "secret message") into the letters in the prime positions of the larger message (the "carrier message"). Your job is to create a program which takes a secret message as input and outputs a carrier message that hides the secret message in the letters in the prime positions.

Requirements

  • Only letter characters in the carrier message count toward positions.
  • The secret message is not case sensitive and non-letters do not need to be encoded in any way.
  • The carrier message must contain only words that can be found in this list of English words. The carrier message does not need to make sense.
  • The carrier message can contain punctuation (any of .,?!"':;-), whitespace, and letter characters only.
  • The carrier message cannot hide a message that is longer than the secret message. If it ends on a prime after the last one needed, it is invalid. For instance, if the carrier message is 38 letters long and the secret message is only 11 letters long, the carrier would encode an extra letter and therefore is invalid. (Sandbox: help me phrase this better)

Examples

Input: 'Hello world'

Possible Output:

Ah! Eels live! Oh wall! Oars will board.

Lining up all the letters, you get these positions

 A  h  E  e  l  s  l  i  v  e  O  h  w  a  l  l  O  a  r  s  w  i  l  l  b  o  a  r  d
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

All the letters in the prime positions would be extracted. h at 2, E at 3, l at 5, l at 7, O at 11, w at 13, O at 17, r at 19, l at 23, and d at 29. Thus the full message is hEllOwOrld, but case doesn't matter.

Rules

  • Standard rules and loopholes apply.
  • You can read in the word list using any method you would like, or not at all. Other word lists may be used and will not count toward byte count, but every word in your output must appear somewhere in the previously mentioned word list.
  • You may assume that the secret message only includes letters, whitespace, and punctuation.
  • Your program does not need to be deterministic, but does need to always output a valid carrier message which correctly encodes the secret message.
  • You may assume that the secret message is possible to encode with English words from the list. (Even though it may not be for one reason or another)

Sandbox note

I'm thinking this might make for an interesting popularity contest. The objective criteria is validity of the carrier message. The subjective criteria is how interesting/entertaining/convincing the messages that it outputs are.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Considering that only the letters of the secret message are encoded anyway, I think it would make more sense to only provide the letters of a secret message without punctuation. \$\endgroup\$ Dec 13, 2018 at 3:33
  • \$\begingroup\$ I'd reccomend giving the list of words as input rather than a defined word list. This makes it much easier to test \$\endgroup\$
    – Jo King Mod
    Dec 13, 2018 at 13:32
  • \$\begingroup\$ @JoKing That would be covered by "You can read in the word list using any method you would like, or not at all. Other word lists may be used and will not count toward byte count, but every word in your output must appear somewhere in the previously mentioned word list." It's a pretty massive list of words, so any subset of it will do for testing. \$\endgroup\$
    – Beefster
    Dec 13, 2018 at 22:25
0
\$\begingroup\$

Stego-nography: Hide A Stegosaurus with Steganography!

This doesn't work as a cops and robbers challenge. Leaving for possible inspiration.

Making something that converts an image with a live dinosaur into one with a dead dinosaur would be a clone of Hiding information in Cats.


Cops

Devise a method for hiding this ASCII stegosaurus in an image.

                         .       .
                        / `.   .' "
                .---.  <    > <    >  .---.
                |    \  \ - ~ ~ - /  /    |
    _____          ..-~             ~-..-~
   |     |   \~~~\.'                    `./~~~/
  ---------   \__/                        \__/
 .'  O    \     /               /       \  "
(_____,    `._.'               |         }  \/~~~/
 `----.          /       }     |        /    \__/
       `-.      |       /      |       /      `. ,~~|
           ~-.__|      /_ - ~ ^|      /- _      `..-'
                |     /        |     /     ~-.     `-. _  _  _
                |_____|        |_____|         ~ - . _ _ _ _ _>

Source: custom 'cow' for cowsay

Create an encoder and a decoder. Post the decoder and two versions of three different images, each pair with and without the encoded stegosaurus. Include hashes for each of the six images.

Rules and Scoring

  • The decoder must be able to decode any arbitrary ASCII text of at least the same size as the stegosaurus (either 677 characters or 14x63 characters if you assume the text is right-padded. Be consistent).
    • Only the part of the encoded message that actually includes the stegosaurus matters; extra bytes in the message can be ignored by the user or decoder, but must be either before/after the 677 characters or outside the 14x63 bounding rectangle, depending on how you encode it. (Sandbox: this phrasing is awkward)
    • In short, it must be possible for the robbers to kill your dinosaur (link to robber thread goes here) by replacing your stegosaurus with a dead one.
  • You may not use asymmetric encryption in your solution. (For example, encrypting the stegosaurus with your private key before hiding it and then putting the public key in the decoder)
  • You can use any lossless image format of your choice.
  • You do not need to post the source code of your decoder. Precompiled Windows or Linux binaries are allowed, but must be packaged with all of their dependencies and be able to be run without any installation. Obfuscation and minification are allowed for interpreted languages and likewise should prepackage all third-party dependencies.
  • You may not host your decoder on a webservice. The reason why is that it enables you to use symmetric encryption with no way to derive the key.
  • As an objective criteria for the encoded images to be not easily distinguishable, the maximum absolute pixel difference between the images should be less than 4/255 for each color component in the entire image.

If at least one of your dinosaurs survives after one week, your dinosaurs are safe and you earn 10 points (after which point you can explain your algorithm). If your dinosaurs are all killed within a week, you score 1 point for each 24 hour period they survived.

The cop with the most points wins.


Robbers

You're a dinosaur hunter. The cops have hidden stegosauruses in three images. It's your job to find the stegos and kill them. You are to change the message hidden in each image from the original stegosaurus to this dead one:

                         .       .
                        / `.   .' "
                .---.  <    > <    >  .---.
                |    \  \ - ~ ~ - /  /    |
                   ..-~             ~-..-~
             \~~~\.'                    `./~~~/
              \__/                        \__/
                /               /       \  "
    _____     .'               |         }  \/~~~/
   |     |  .'   /       }     |        /    \__/
  --------''    |       /      |       /      `. ,~~|
 .'  X        __|      /_ - ~ ^|      /- _      `..-'
(_____     _-~  |     /        |     /     ~-.     `-. _  _  _
 `__U___--~     |_____|        |_____|         ~ - . _ _ _ _ _>

Cracking a cop submission requires that you kill all of its hidden dinosaurs. You earn a point for each submission you crack. Note that the cop can encode garbage or null data around the dinosaur (either by bounding box or before/after the 677 characters), but you do not need to leave this data untouched.

The robber with the most cracked submissions wins.


Sandbox

Does this work as a cops-and-robbers challenge? Any problematic loopholes or ways to abuse this?

\$\endgroup\$
6
  • \$\begingroup\$ It's possible you simply considered this implied, but I would recommend indicating a timeframe after which a cop's answer is "safe", and requiring that safe answers post their encoder to prove that it can indeed hide arbitrary images. Requiring the decoder from the start seems best so that robbers can validate potential cracks. Also, each portion of the challenge needs some kind of scoring method. \$\endgroup\$ Dec 13, 2018 at 3:18
  • \$\begingroup\$ @KamilDrakari: It will probably be a week. I just wanted to test the waters on the idea first since cops and robbers challenges are hard to make. \$\endgroup\$
    – Beefster
    Dec 13, 2018 at 18:01
  • \$\begingroup\$ I'm really not sure if the stenography really adds much to the challenge. Stenography is all about hiding the fact that secrets are being transferred in the first place. Here, though, there's no reason to make the image look "normal", and so it becomes a "implement your own asymmetric crypto algorithm" \$\endgroup\$ Dec 13, 2018 at 21:11
  • \$\begingroup\$ If "implement your own asymmetric crypto algorithm" is what you want, then I don't think this should be posted. Banning crypto is fine if it is closing a loop hole, but here it's literally "Do crypto without using crypto". The line will be too hard to define IMO. \$\endgroup\$ Dec 13, 2018 at 21:14
  • \$\begingroup\$ @NathanMerrill: I'm definitely banning crypto to close a loophole because the challenge becomes trivial to make uncrackable with public key encryption. Symmetric crypto would be fine because you'd be able to reverse-engineer the decoder to derive a key. I suppose a possibility for better patching the loophole would be to require lossless images and require that changing a bit in the uncompressed pixel data changes at most one character in the output. That also effectively bans most hard-to-crack crypto. \$\endgroup\$
    – Beefster
    Dec 13, 2018 at 21:38
  • \$\begingroup\$ Hmm... Looking over the typical cops-and-robbers challenges, none of them are related to crypto... and I can see why. I like the general concept though. I think it's fun and whimsical and I think I can convert it into one or two code challenges (code-golf, code-challenge, and popularity-contest might all work) \$\endgroup\$
    – Beefster
    Dec 13, 2018 at 22:18
0
\$\begingroup\$

Buddhabrot (speed edition)

Your goal is to generate an image like this one:

Buddhabrot (Sandbox: this image will be replaced by a valid solution image for the challenge)

This is a render of a 2D histogram called Buddhabrot. The algorithm for generating it is very simple. If you have heard of (or written a program to generate) the Mandelbrot Set, this will feel familiar. The algorithm goes as follows:

  1. Generate a random complex number \$z_0\$
  2. Iteratively perform the calculation \$z_{i+1}=z_i^2+z_0\$. Do this \$N\$ times
  3. Check if the absolute value of the number \$z_N\$ is larger than 3
  4. If it is, calculate all the numbers \$z_i, 0 \leq i\leq N\$ again and map them to pixels.
  5. For each pixel that is mapped to, add \$1\$ to the counter for that pixel
  6. Repeat the 4 steps above a few million (or billion/trillion) times.

Since this algorithm depends on random sampling rather than just a single calculation for each pixel, it is not as easy to parallelize on a GPU. However, a GPU will still perform better than a CPU for this task. Since it is random, it is also dependent on having a large number of iterations to generate a smooth image. With a low number of iterations, the output image will be grainy.

To participate in this challenge, write a full program which creates a render of the Buddhabrot. For this challenge, the maximum iteration number is set to 100. That means that for every random complex \$z_0\$, you must write to the counter array if \$|z_{100}| > 3\$. Note that if \$|z_i| > 3\$ for some \$i < 100\$, then you can quit the calculation, since you know that \$|z_{100}| > 3\$.

If you want some help to get you started, I recently made an attempt to optimize this problem. You can read about my journey if you want.

Generating the image

A basic algorithm for rendering a Buddhabrot image is described above. To make it efficient, I would suggest that you use an unsigned int* to hold all the counters for the pixels. When running the program, you calculate which pixel should have its counter increased, then you add 1 to that index in the counter array. When you are done with the random number generation, you take your array of counters, divide every element by the array's maximum value. Then all values in the array will be in the range \$[0,1]\$. You can then use that value as the grayscale color of the corresponding pixel.

Specification

  1. The output image must be exactly 1024x1024 pixels
  2. The maximum iteration number is 100
  3. The complex numbers must be sampled from the rectangle in the complex plane given by \$-2.5 < Re(z_0) < 1.5, -2 < Im(z_0) < 2\$ (Sandbox: these limits are subject to change). The sampling does not have to be uniform (you might discard points which you know are not important). However, it does need to result in a picture which is visually similar to the one in the post.
  4. The output image must be a visualization of the area in the complex plane given by \$-2 < Re(z) < 2, -2 < Im(z) < 2\$ (Sandbox: these limits might change slightly)
  5. You have 20 minutes to perform the sampling and generate the image. I will assist with tweaking to maximize your score.
  6. You are free to use CUDA or OpenCL to generate the image. For any other methods of implementation, please include instructions on how yo get the environment ready.

Scoring

To ensure that we have an objective criteria for scoring, your score will be the total sum of all pixel counters. Since the Buddhabrot is a 2D histogram in its essence, this can be seen as the total number of samples. To be specific, you calculate your score before dividing by the maximum value and generating the image. The highest score wins. Note that if your approach is similar to mine, the theoretical maximum score is limited by the memory bandwidth. The bandwidth of my GPU is 484GB/s, and since each counter is 4 bytes, you can get 121 billion iterations per second. However, there might be more effective ways to save the samples using the CUDA caches, which could lead to higher performance than that. (Sandbox: I'm not 100% sure if my maximum speed calculation is valid)

Since I already have a working example for this problem, I have decided to add a further incentive. If your solution is 2x faster than my implementation, I'll reward 50 reputation once one month has passed from posting the question. If it is 5x faster, the reward goes up to 100 rep. If it is more than 10x faster, I'll award 150 rep. If you somehow manage to make your solution 30x faster, I'll throw in 200 rep. If multiple answers are eligible for the bonus, only the fastest one will be rewarded. If no answer is eligible for the bounty once one month has passed, the bounty will be rewarded to the first one who claims it. However, you can only claim one bounty, so if you have made your solution 5x faster but want to claim the 10x bounty, I will give you time to optimize your solution to reach the next bounty.

Testing machine

  • Intel 5820K 6-core 12-thread CPU running at 4.4GHz
  • 16GB DDR4 RAM
  • NVIDIA GTX 1080Ti (11 GB GDDR5X, 3584 CUDA cores)
  • CUDA 9.0 (I'll add information about C++ version and other relevant info)
  • Windows 8.1 (sorry)

For the sandbox

  • Right now there are a few things that need to be clarified in the description.
  • I will also update the post with an image that is 1024x1024 pixels. Is the question clear?
  • Do I need to clarify anything besides the information that's left out right now?
  • Is it okay to add reputation rewards from the start to attract answers?
  • Are GPU challenges welcome? A short discussion about hardware was had in the chat, and I'm aware that not everyone has a NVIDIA GPU. That's why I made sure that there are OpenCL implementations of this problem.
  • I say that the sampling should be uniform, but there have been some optimized solutions using importance sampling for this specific problem, should I allow that?
\$\endgroup\$
6
  • \$\begingroup\$ Step 6 is "repeat the 4 steps above". Does that mean "repeat steps 2-5", or is it a mistake and should be "5 steps"? \$\endgroup\$ Dec 11, 2018 at 20:37
  • \$\begingroup\$ Two parts of the challenge leave me scratching my head when combined. When describing the formula you say that "if |zi|>3 for some i<100, then you can quit the calculation, since you know that |z100|>3." which seems to imply that |zi+1|>|zi| However, in the specification you assert that the range of possible values for z0 should be identical to the range of values displayed. Either this means some samples map to pixels off-screen or... I guess I could be misunderstanding something? \$\endgroup\$ Dec 11, 2018 at 20:58
  • \$\begingroup\$ @KamilDrakari I'll address all of these points more thoroughly later today. Yes, it should say repeat the 5 steps. As for the scoring, it is random, but since a good program will perform >10^10 iterations per second, the standard deviation will be very low. To maximize your score, you want to perform steps 1-5 as many times as possible within the time limit. And yes, samples could map to pixels off-screen. Those samples do not count towards your score. It is not always true that |z_i+1|>|z_i|, but if the absolute value goes above 2, it will start growing towards infinity. \$\endgroup\$
    – maxb
    Dec 12, 2018 at 5:37
  • \$\begingroup\$ Ah, I think to resolve my confusion about the scoring method you should add somewhere "Highest score wins" or "higher scores are better". \$\endgroup\$ Dec 12, 2018 at 14:24
  • \$\begingroup\$ "The sampling must not be uniform". In that case, you need to specify what it must be. \$\endgroup\$ Dec 14, 2018 at 11:40
  • \$\begingroup\$ @PeterTaylor I'm sorry, I meant "the sampling does not have to be uniform". I have seen some work with importance sampling, but I have not implemented that myself. \$\endgroup\$
    – maxb
    Dec 14, 2018 at 12:47
0
\$\begingroup\$

A Golden March

Draw a circle whose circumference is the golden mean. Choose a point and label it 1, then move clockwise around the circle in steps of arc length 1, labeling the points 2, 3, and so on. At each step, the difference between each pair of adjacent numbers on the circle is a Fibonacci number.

from Futility Closet.

Challenge

Given some natural number \$ n \geq 1 \$, determine the first \$n\$ points as described above. Then determine all differences between pairs of adjecent numbers and return them as a list.

Details

  • The list should contain all the differences in the order in which they appear.
  • It should start with the difference between \$1\$ and one of its adjecent neighbours. Then you need to continue recording the differences in the direction you started with.

Examples

to be determined.

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

Prime number construction game

Tags: code-golf

Inspired by this post, here is A "single player" version of the prime number construction game.

The game:

  1. Start with a digit between 1 and 9.
  2. Add a digit to the end, such that the resulting number is a prime number.
  3. Repeat from step 2 until there are no more possible prime numbers.

The challenge:

Write a function (or required functions) that returns the sum of the lengths of the largest prime numbers you can get starting with each digit, following the game rules above.

The score:

Scoring will have two components:

  1. The length of the code, in bytes (it's code-golf, after all), and
  2. The sum of the length of the largest primes obtained, starting with each digit.

The total score will be the length of the code (1) minus the sum of the length of the largest primes obtained (2).

The lowest score wins.

Example:

Here's a code sample using R (verbose and non golfed):

isprime <- function(x) {
  for(i in 2:sqrt(x))
    if(x %% i == 0)
      return(FALSE)
  return(TRUE)
}

next_prime <- function(x) {
  for(i in sample(c(1,3,7,9))) {
    y <- strtoi(paste(c(x,i), collapse=''))
    if(isprime(y))
      return(y)
  }
  return(NULL)
}

longest_primes <- function(x) {
  primes <- 1:9
  for(d in 1:9) {
    y <- d
    while(!is.null(y)) {
      primes[d] <- y
      y <- next_prime(y)
    }
  }
  return(sum(nchar(primes)))
}

Here's a sample run of the code above:

 Digit | Largest prime obtained | Length
 ------+------------------------+-------
   1   | 19139                  | 5
   2   | 29399999               | 8 
   3   | 3797                   | 4
   4   | 4799                   | 4
   5   | 53                     | 2
   6   | 6173                   | 4
   7   | 719333                 | 6
   8   | 89                     | 2
   9   | 977                    | 3
 ------+------------------------+-------
 Total |                        | 38

Assuming the byte count of my code is 469, my final score is 469-38=431.

Posting your solution:

Please use the following header for your solution:
# [Language]: [Byte count] - [Sum of lengths] = [Total score].

Please include an explanation to your answer.


Miscelaneous:

I think this is a simple, yet fun, challenge. I've searched the site, and I haven't found a related challenge. If there's one, please point me.

I tried sometime ago to post a challenge, and I wasn't careful enough before posting (hence, I deleted it). I'd like to post a good first challenge. Any feedback will be appreciated.

\$\endgroup\$
2
  • \$\begingroup\$ Unfortunately, the possible results are very small, so this challenge may not be that interesting. (They are: 1979339333, 1979339339, 23399339, 29399999, 37337999, 4391339, 59393339, 6133373, 6733919, 6733997, 73939133, 839, 9719, for a total of -63.) Be aware that most golf languages will get a score near -63 just by brute forcing. \$\endgroup\$
    – japh
    Dec 22, 2018 at 14:29
  • \$\begingroup\$ @japh That may be. I just thought it would be fun. Maybe a "King of the Hill" dinámica would work? Bots competing to eliminate opponents generating primes? (Like the game mentioned in the linked post) \$\endgroup\$
    – Barranka
    Dec 22, 2018 at 19:31
0
\$\begingroup\$

Is it a D?

Given an image, check if it's a letter D.

Here D is defined as:

Let pixels labeled \$(x,y)\$ where larger \$x\$ mean at right and larger \$y\$ mean more up. If there exist \$x_0, x_1, f_0, f_1, f_2, f_3\$ such that:

  • \$ (f \rightarrow (x\rightarrow f(x+1)-f(x)))^n (f_i) (x) >0\$ for \$n>0, 0\leq i<4\$
  • \$ x_0<x_1\$
  • Pixel \$(x,y)\$ is true iff \$y>f_0(x) \text{ and } y<-f_1(x) \text{ and } (y>-f_2(x) \text{ or } y<f_3(x) \text{ or } x_0\leq x<x_1)\$
  • There should be a hole, i.e. a false pixel that can't reach border without acrossing a true pixel

Shortest code win. Don't mind if D doesn't follow the rule or a symbol which follows the rule doesn't look like a D at all

TODO: add test cases

\$\endgroup\$
2
  • 1
    \$\begingroup\$ A couple of examples would help here. Also, if I've understood the conditions correctly, I think you mean \$y>-f_2(x)\$. \$\endgroup\$
    – japh
    Dec 22, 2018 at 14:54
  • \$\begingroup\$ Also, those are some fast-growing \$f_i\$. Your font must have really, really tall D's. \$\endgroup\$
    – japh
    Dec 22, 2018 at 14:55
0
\$\begingroup\$

There are 1000 phones in a city. Add some switches so that we can freely decide linking pairs (Any amount of pairs). Two phones are connected iff some closed switches directly or indirectly link them.

In graph-theoretic terms, phones and "new points" are vertices, switches/links are edges, and you need to construct a graph with least number of edges such that for all possible list of pairs of the "phone"-vertices, there exists a configuration of the switches (subgraph), such that vertices in the same pair are in the same connected component, and vice versa.

You need to answer with:

  1. A list of links, where 0~999 are the 1000 phones, and 1000~ are just point.
  2. A program that take some pairs of phone ids, where no two numbers are same, and output the switches that need to be closed. It should run on tio in 60s.

Fewest switches win.

A sample solution may be:

1. [(i,j) for i in range(1000) for j in range(1000,1500)]
2. def f(a):
     print ([(a[i][0],1000+i)for i in range(len(a))]+[(a[i][1],1000+i)for i in range(len(a))])

Which uses 500000 switches.

SN.

  1. Should I require that when a connection is added or removed, there's a series of moves so that no other connections are affected?
  2. Directly using sorting network for \$\mathcal O(n \log^2 n)\$ seems to use more switches than \$\mathcal O(n^2)\$ solution. Should I have more phones?
\$\endgroup\$
0
0
\$\begingroup\$

I'll Just Make A Snake

I noticed a post (now deleted) that pointed out that 05AB1E (legacy), when called with no arguments and non-empty input, will make a "snake" using the input:

Not sure what to do now with the input, so I'll just make a snake:


*****
    *
    *
    *
*****
*    
*    
*    
*    

Cute, and seems simple enough. However, the snake generation has a few quirks that I thought would make an interesting challenge to replicate.

The Challenge

When given a non-empty string as input, a snake is generated using the following algorithm:

  1. If the input string is shorter than 17 characters, pad the string with duplicates of itself until its length is >= 17.
  2. Generate a snake segment by replacing the non-space characters of the pattern with characters from the input string, following the direction of the snake. (Print characters right-to-left 5, up-to-down 3, left-to-right 5, up-to-down 4.)
  3. If there is a previous snake segment generated, replace its last line with the first line of this segment.
  4. Remove the used characters from the string.
  5. Discard the first character of the remainder of the string. If there is no remainder, instead set the remainder to the original input string, minus its first character.
  6. Pad the string with copied of the original input string until its length is >= 17.
  7. Repeat steps 2-6 N times, where N = Length of input string.
  8. Return the generated snake.

You do not have to handle empty inputs or non-string inputs.

You do not have to print the beginning message "Not sure what to do now with the input, so I'll just make a snake:".

Note: 05AB1E (legacy) actually has some different behavior when given a base-10 integer as input. We will be ignoring that and treating all inputs as strings.

General rules:

  • Input and output may be in any reasonable format.
  • Trailing spaces and/or a single trailing newline are acceptable.
  • This is , so shortest answer in bytes for each language wins. No answer will be marked as the answer.
  • Standard rules apply.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (i.e. TIO).
  • Adding an explanation for your answer is highly recommended.

Test Cases

Here is an (ungolfed) Python 2 program which replicates this behavior, for clarity and generation of additional test cases.

pattern = """{0}{1}{2}{3}{4}\n    {5}\n    {6}\n    {7}\n{12}{11}{10}{9}{8}\n{13}\n{14}\n{15}\n{16}"""

def print_snake(in_str):
    print "Not sure what to do now with the input, so I'll just make a snake:\n\n"
    l = len(in_str)

    snek = [0]

    if l < 19:
        d,m = divmod(19, l)
        if m:
            d+=1
        in_str = in_str * d

    print_str, lost_char, rem = in_str, "", ""

    for i in range(l):
        print_str = rem + in_str
        print_str, lost_char, rem = print_str[:17], print_str[17], print_str[18:]
        snek.pop()
        snek += (pattern.format(*print_str)).split("\n")

    print "\n".join(snek)

Try it online!

Input: *

Output:
*****
    *
    *
    *
*****
*
*
*
*

Input: AB

Output:
ABABA
    B
    A
    B
ABABA
B
A
B
ABABA
    B
    A
    B
ABABA
B
A
B
A

Input: 123456789

Output:
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
12345
    6
    7
    8
43219
5
6
7
8

Input: sadness*and*despair

Output:
sadne
    s
    s
    *
d*dna
e
s
p
rsadn
    e
    s
    s
*dna*
d
e
s
irsad
    n
    e
    s
dna*s
*
d
e
airsa
    d
    n
    e
na*ss
d
*
d
pairs
    a
    d
    n
a*sse
n
d
*
spair
    s
    a
    d
*ssen
a
n
d
espai
    r
    s
    a
ssend
*
a
n
despa
    i
    r
    s
senda
s
*
a
*desp
    a
    i
    r
endas
s
s
*
d*des
    p
    a
    i
ndasr
e
s
s
nd*de
    s
    p
    a
dasri
n
e
s
and*d
    e
    s
    p
asria
d
n
e
*and*
    d
    e
    s
sriap
a
d
n
s*and
    *
    d
    e
riaps
s
a
d
ss*an
    d
    *
    d
iapse
r
s
a
ess*a
    n
    d
    *
apsed
i
r
s
ness*
    a
    n
    d
psed*
a
i
r
dness
    *
    a
    n
sed*d
p
a
i
adnes
    s
    *
    a
ed*dn
s
p
a
i

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

What season is it?

I don't think we have a challenge for this yet, surprisingly. The closest ones are:

Output the current season, using the astronomical definitions:

  • Spring begins on the day of the spring equinox
  • Summer begins on the summer solstice
  • Fall begins on the fall equinox
  • Winter begins on the winter solstice

You may use the northern or southern hemisphere dates.

Input

None (use the current date).

Output

One of these strings (case insensitive): spring, summer, fall (or autumn), winter.

Your program must finish in a reasonable (less than 1 day) amount of time.


Problems

  • Is calculating the dates of the equinoxes/solstices too difficult? (I don't want the best solution to involve a big lookup table)

  • What range of years should this be required to work in?

  • Should the output format be less strict? ("Any 4 distinct values" rather than the season names)

\$\endgroup\$
7
  • \$\begingroup\$ I deide to upvote the old one and downvote this one \$\endgroup\$
    – l4m2
    Dec 30, 2018 at 2:13
  • \$\begingroup\$ They're sufficiently different so I think it's ok for both to exist. \$\endgroup\$
    – DELETE_ME
    Dec 30, 2018 at 3:57
  • \$\begingroup\$ However looking at the wikipedia "Equinox" page, it mentions "However, because the Moon [...]" (second paragraph), which interpretation should be chosen? \$\endgroup\$
    – DELETE_ME
    Dec 30, 2018 at 3:58
  • \$\begingroup\$ Is there any range of date that it's ok to be wrong outside the range? (say, 1~2 century? I don't know how the motion of the Earth/Sun will change in some million years) \$\endgroup\$
    – DELETE_ME
    Dec 30, 2018 at 3:59
  • \$\begingroup\$ To your last question: I would say yes as the core of this challenge appears to be figuring out where the current date lies in relation to the solstices/equinoxes and translating that to specific strings doesn't, in my opinion, really add anything to the challenge. \$\endgroup\$
    – Shaggy
    Dec 30, 2018 at 5:33
  • \$\begingroup\$ I guess this should use the second interpretation, since it seems to be easier to calculate and more commonly used. I'll probably allow errors of a few minutes, in the event that the equinox/solstice occurs near midnight where a small rounding error might affect the result. \$\endgroup\$
    – 12Me21
    Dec 30, 2018 at 5:45
  • \$\begingroup\$ int main(){print("summer");} // guaranteed to be random \$\endgroup\$
    – Kenzie
    Aug 2, 2019 at 18:26
1
98 99
100
101 102
132

You must log in to answer this question.

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