540
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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

3554 Answers 3554

1
30 31
32
33 34
119
2
\$\begingroup\$

Calculate the integer square root of a matrix

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Should really be "Calculate the integer square root of a matrix", because there acan be multiple square roots. E.g. [[18, 63], [14, 67]] also has as square root, the given solution divided by 11. \$\endgroup\$
    – Adám
    Jul 31 at 23:16
  • \$\begingroup\$ I think it should be "Calculate an integer square root of a matrix", since "the integer square root" is the language you would use if there were only one. If you find combining "Calculate" with "an" a bit awkward, you could substitute "Determine" or "Find". \$\endgroup\$
    – theorist
    Aug 4 at 2:22
2
\$\begingroup\$

Pinpoint the typo!

Task

Write a program that finds the location of an error in its own code!

The program itself must output either nothing or an empty string (or an appropriate equivalent in your language).

Let n be the length of the program in bytes, which must be at least 2. For an integer k with 1<=k<=n, if the kth byte of the source code is deleted, then the resulting program should output the integer k (and nothing else), in as many cases as possible.

Outputs may be 0-indexed if preferred, so that omitting the kth byte outputs k-1, but the choice of indexing must be consistent across all k.

Error messages do not count as valid output unless they are of exactly the required form.

Your score is the number of integers k for which the above condition is satisfied, divided by n. Highest score wins, with ties broken by smallest n.

Example

Consider the program blob() in a fictitious language. Suppose that:

blob() outputs nothing (this is a requirement)

lob() outputs 1 (right)

bob() outputs 2 (right)

blb() outputs 3 (right)

blo() outputs 4 (right)

blob) outputs nothing (wrong)

blob( outputs 6: Syntax error (wrong)

Then the score would be 4/6 = 0.66666667

\$\endgroup\$
7
  • 1
    \$\begingroup\$ This might be abused by simply making a very long answer. \$\endgroup\$
    – rues
    Aug 5 at 20:06
  • 1
    \$\begingroup\$ Related. Related. Related \$\endgroup\$ Aug 5 at 20:11
  • \$\begingroup\$ @user Yes, I did wonder about that, although such answers might still be interesting. Ideas for a better scoring system? Number of 'wrong' answers is not great, because of very short answers.... \$\endgroup\$
    – aeh5040
    Aug 5 at 20:12
  • 1
    \$\begingroup\$ What I did with my 'Quantum quine' question, which is similar, is for the scoring system count the number of chars that it doesn't work for. \$\endgroup\$
    – emanresu A
    Aug 6 at 11:23
  • \$\begingroup\$ @emanresu A The problem I see with that is that very short programs would get an unreasonable advantage. E.g. any 4-byte program that does nothing gets 4 without even trying to accomplish the task... \$\endgroup\$
    – aeh5040
    Aug 6 at 13:24
  • \$\begingroup\$ Perhaps it would be better if the unaltered program must output Hello World or something... \$\endgroup\$
    – aeh5040
    Aug 6 at 13:27
  • \$\begingroup\$ @aeh5040 I also ruled that each answer had to have at least one functional result... Then again, quines do have to be at least a certain size. Your choice. \$\endgroup\$
    – emanresu A
    Aug 7 at 10:45
2
\$\begingroup\$

Radiation hardening up to order \$n\$

We'll call a program radiation-hardened of order \$n\$ if the output remains unchanged when any \$k\$ characters are removed from the program, for all \$1 \le k \le n\$. For example, a radiation hardened program of order \$2\$ would produce the same output when run as when run with any single character removed, or with any pair of characters removed.

As an example, consider the program abcde which outputs 123 in some language. This would be radiation-hardened of order \$2\$ if:

  • All of bcde, acde, abde, abce and abcd output 123, and
  • All of abc, abd, abe, acd, ace, ade, bcd, bce, bde and cde output 123

If any of the second bullet point didn't output 123 (but all of the first still did), this would only be of order \$1\$.

Your task is to write a radiation hardened program of order \$n \ge 2\$ that outputs Greetings, Earth! exactly, with an optional trailing newline.

Your score is equal to \$n\$, with a higher score winning, with code golf being the tie breaker.


Meta

\$\endgroup\$
6
  • \$\begingroup\$ If you find a language that outputs something no matter the program's contents, then you can get infinite score. I'd suggest requiring some specific output. Also infinite score is likely possible in a whole host of other cases so maybe also make the score the ratio of k to code length? \$\endgroup\$
    – pxeger
    Aug 6 at 16:54
  • \$\begingroup\$ @pxeger The point about output is a good one, I'll need to think about that. I doubt that an infinitely large score is possible (assuming I add in a specific output), as it'd require a language where either one character outputs the required string exactly once no matter how often it is repeated, or that every program in that language is equivalent to a one byte program, and that all one byte programs are the same that output the specific string \$\endgroup\$ Aug 6 at 17:01
  • \$\begingroup\$ I would add a tie breaker, since answers beyond n=1 are brutally difficult, so at least you can improve your score without having to jump up to n=3. \$\endgroup\$
    – Grain Ghost Mod
    Aug 6 at 18:08
  • \$\begingroup\$ Also source-layout is a good tag. (And it's not just that I am working towards that tag badge or something) \$\endgroup\$
    – Grain Ghost Mod
    Aug 6 at 18:13
  • \$\begingroup\$ DeadPig, order ∞. \$\endgroup\$
    – emanresu A
    Aug 7 at 2:16
  • \$\begingroup\$ I believe Backhand can make an infinite score. \$\endgroup\$
    – Bubbler
    Aug 11 at 23:37
2
\$\begingroup\$

Sum of 3 Vectors

Question

Given 3 vectors a, b, c

Find integer (n, m, r) where a*n+b*m+c*r = 0 and n,m,r are all not equal to 0.

your answer group (n, m, r) must be the closest valid group to 0, calculate by adding abs value together: |n|+|m|+|r|

You can assume that 3 vectors do not parallel

Test case

work in progress

Rules

  • no Standard loopholes
  • any I/O case allowed, as long as it's clear and mostly understandable.

Score

  • Lowest byte count per language wins!

Meta

any extra tag?

suggestions?

Rename question?

\$\endgroup\$
3
  • \$\begingroup\$ this looks like a 3d linear equation solving problem. \$\endgroup\$
    – Razetime
    Aug 19 at 4:02
  • \$\begingroup\$ Are the vectors 2-dimensional with integer components? \$\endgroup\$
    – Nitrodon
    Aug 27 at 14:53
  • \$\begingroup\$ @Nitrodon those are 2D vectors currently. \$\endgroup\$
    – okie
    Sep 1 at 1:33
2
\$\begingroup\$
\$\endgroup\$
1
  • \$\begingroup\$ Why radiation-hardening? This is the opposite, isn't it? \$\endgroup\$
    – pxeger
    Aug 21 at 14:21
2
\$\begingroup\$

Unfudge my terminal!

Intro

Today I fiddled around with termios for a program. The only thing I managed to do so far is fundging my terminal... can you help me out?

Challenge

Given a terminal input that contains fudged special chars, output the string that should be displayed if the terminal worked correctly. Here's a list of the broken special chars:

^B -> Backspace
^J -> (Fwd-) Delete
^W -> Discard
^D -> Cursor left
^C -> Cursor right
^F -> End
^H -> Start

How the special characters work

  • Backspace deletes the character behind the cursor and moves it one step back. Has no effect on the start of the string.
  • Delete deletes the character in front of the cursor. Has no effect on the end of the string.
  • Discard deletes the string typed up to this point.
  • Cursor left/right moves the cursor to the left/right by one. Has no effect on the end/start of the string.
  • End/Start move the cursor to the end/start of the string.

Undefined special characters are to be removed.

Input

  • Any represetation of a string/list of characters
  • Single lines only
  • The special characters may be either all capitalized or all not capitalized
  • The input will not contain a sequence that will result in a ^ in the output, nor will it contain a single ^ at the end.

Output

  • The unfudged input.
  • No leading/trailing whitespace that isn't part of the string.

Examples

abcd^B^B^B --> a

abcd^We^Af^Lgh --> efgh

 gof^D^D^D^Dcode^C^C^Cl --> code golf

ocde gol^H^J^Jco^Ff --> code golf

edgecase^H^D^B^J^F^C^J^B --> dgecas

Rules

  • This is , shortest answer wins
  • Standard loopholes are not allowed
  • A submissiom may be a program/function/link/lambda/chain/etc.

Tags:

Sandbox things

  • Is anything unclear?
  • Should any special char be added or removed?
  • Is there an edge case not covered by the examples?
  • Are the rules and I/O restrictions fine or should I change anything?
\$\endgroup\$
2
\$\begingroup\$

Snap (card game)

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

Greedy queens sequence

\$\endgroup\$
1
2
\$\begingroup\$

Part 1 has been posted!

Best response to Evolution of Trust? - Part 2

This is a sequel to the first Evolution of Trust question, except it's a game!

The Game

This is a Prisoner's Dilemma question.

Make a strategy that cooperates (puts in a coin) and cheats (doesn't put in a coin). If one player puts a coin into the machine (that was mentioned before in the Part 1 question) the other player gets 3 coins.

However, either player has a 5% chance to make a mistake and do the opposite of what it meant to do.

I go into more detail about how to figure out moves below.

Code / API

For ease of judging, submissions are restricted to Python (but I'll add JavaScript soon).

A bot is a Python file that has 2 functions: move() and turn(state). move() will be called for the first move, and turn(state) for subsequent moves.

state is a list with 5 elements - the move number, your move without and with mistakes, your opponents moves with mistakes, your points, and your opponent's points.

state[0] is the move number. This will always be at least 2, as turn(state) is first called on the second move.

state[1] is a list of your intended moves so far. This does not take mistakes into account.

state[2] is the same as state[1] with one exception - this takes mistakes into account.

state[3] is your opponent's moves with mistakes taken into account. You don't know for which moves your opponent intended to do them or just made a mistake.

state[4] is your points. Similarly, state[5] is your opponent's points.

Here's an example submission that's my only submission:

Python 3.8, "alwayscheat", 20 bytes

move=turn=lambda*a:0

Yes, I know it's simple, but it's a start.

If you have time and you submission isn't 3.8, please put a 3.8 version below your main submission. In this case, your byte count will be for your non-3.8 solution, in case you're using an older version for less bytes.

Code Submission

To make a bot submission, simply post your submission here.

Each user may only make one submission, but you are allowed to edit your submission. Please don't do this too much though, as I'm manually putting all of the submissions in.

Leaderboard and Scoring

Every time you get an amount of (possibly negative) coins you have at the end of a round, they are added to your points.

<...just waiting for a few answers...>

How are the bots put against each other?

There's a tournament, the same kind as the official site's one.

We start with 10 of each bot in a tournament. Each pair of bots play 1 game against each other. The points of a bot are added up. The 5 bots with the least amount of points are deleted (if there are multiple, pick randomly). Then, the 5 bots with the most amount of points are duplicated (pick randomly - if there are still multiple). This is repeated until there is an equilibrium. The bots are ranked in order of how many of them remain when I stop the program.

If 2 bots tie for 1st place, the shortest one wins and gets accepted (it's , after all)

If you want to see the inner workings, here’s the judging source code

Sanbdox sandbox things

  • Anything that needs to be changed?
  • Any unclear bits? Probably a lot...
  • Any other things?
  • Any reason all my sandbox questions start with "Any"?
  • Any idea whether I should remove the "Any" before every sanBDox thing?

WD

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

Khinchin's constant bad estimate

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

Unicode Calendar Generator

Rules

Your program will receive a valid date in the format relevant to your language (date object or three int for year, month, day or whatever) and should returns a fancy unicode calendar as such (note that the title is right/left aligned):

Given Y-M-D as 2021-10-13
Then

╔════════════════════╗
║ October ░░░░░ 2021 ║
╟──┬──┬──┬──┬──┬──┬──╢
║░░│░░│░░│░░│░░│01│02║
╟──┼──┼──┼──┼──┼──┼──╢
║03│04│05│06│07│08│09║
╟──┼──┼──╔══╗──┼──┼──╢
║10│11│12║13║14│15│16║
╟──┼──┼──╚══╝──┼──┼──╢
║17│18│19│20│21│22│23║
╟──┼──┼──┼──┼──┼──┼──╢
║24│25│26│27│28│29│30║
╟──┼──┼──┼──┼──┼──┼──╢
║31│░░│░░│░░│░░│░░│░░║
╚══╧══╧══╧══╧══╧══╧══╝

Given Y-M-D as 2021-11-13
Then

╔════════════════════╗
║ November ░░░░ 2021 ║
╟──┬──┬──┬──┬──┬──┬──╢
║░░│01│02│03│04│05│06║
╟──┼──┼──┼──┼──┼──╔══╗
║07│08│09│10│11│12║13║
╟──┼──┼──┼──┼──┼──╚══╝
║14│15│16│17│18│19│20║
╟──┼──┼──┼──┼──┼──┼──╢
║21│22│23│24│25│26│27║
╟──┼──┼──┼──┼──┼──┼──╢
║28│29│30│░░│░░│░░│░░║
╚══╧══╧══╧══╧══╧══╧══╝

Given Y-M-D as 2021-06-15
Then

╔════════════════════╗
║ June ░░░░░░░░ 2021 ║
╟──┬──┬──┬──┬──┬──┬──╢
║░░│░░│01│02│03│04│05║
╟──┼──┼──┼──┼──┼──┼──╢
║06│07│08│09│10│11│12║
╟──┼──╔══╗──┼──┼──┼──╢
║13│14║15║16│17│18│19║
╟──┼──╚══╝──┼──┼──┼──╢
║20│21│22│23│24│25│26║
╟──┼──┼──┼──┼──┼──┼──╢
║27│28│29│30│░░│░░│░░║
╚══╧══╧══╧══╧══╧══╧══╝

This is , so you the shortest bytes of each language will be the winner.

Inspired by qwerty.dev

\$\endgroup\$
9
  • 1
    \$\begingroup\$ What does it need the day for? If you want to include the selection of the given day, perhaps you should include that in the challenge post in an example, to keep it self contained. also is the 00 intentional? \$\endgroup\$ Oct 13 at 20:29
  • \$\begingroup\$ @thejonymyster fixed. And the 00 was a mistake. Thank you :) \$\endgroup\$
    – aloisdg
    Oct 13 at 20:32
  • \$\begingroup\$ Are the month/year always to be left/right aligned, like ` May ░░░░░░░░░ 2021 `? What input formats (string, 3 integers, list, built-in date object, ...) are allowed? \$\endgroup\$
    – Dingus
    Oct 13 at 22:04
  • \$\begingroup\$ month year should be left/right aligned. For the inputs formats, what would be the most popular? \$\endgroup\$
    – aloisdg
    Oct 14 at 6:37
  • 1
    \$\begingroup\$ I'd recommend allowing any sensible input format (because the challenge is more about producing the calendar than parsing dates). You should explain the alignment rules in the post. Maybe it would be enough to swap one of the examples for a month with a shorter name, but probably better to be explicit. \$\endgroup\$
    – Dingus
    Oct 15 at 1:03
  • 2
    \$\begingroup\$ What date range is required to support? 1970~2038? Or maybe larger? \$\endgroup\$
    – tsh
    Oct 18 at 3:54
  • \$\begingroup\$ @Dingus lets use any sensible input format \$\endgroup\$
    – aloisdg
    Oct 18 at 12:31
  • \$\begingroup\$ @tsh I dont have a strong opinion about that. \$\endgroup\$
    – aloisdg
    Oct 18 at 12:32
  • \$\begingroup\$ tsh's question needs a definite answer because the date range could influence the input method and/or implementation. You should also mention that the Gregorian calendar is used. \$\endgroup\$
    – Dingus
    Oct 21 at 23:57
2
\$\begingroup\$
\$\endgroup\$
1
  • \$\begingroup\$ Name suggestion: Wheatian group :) \$\endgroup\$
    – Bubbler
    Oct 15 at 6:01
2
\$\begingroup\$

Pretty print a grid of polyominoes

\$\endgroup\$
3
  • \$\begingroup\$ For challenges which require Unicode, it's generally a good idea to let people count those characters as a single byte each. Aside from that, looks good! \$\endgroup\$
    – emanresu A
    Oct 24 at 23:04
  • \$\begingroup\$ @emanresuA Thank you very much for your feedback! Is there an easy way to make TIO count like that? Or perhaps as a workaround allow defining the special characters as constants in the header? \$\endgroup\$
    – loopy walt
    Oct 25 at 0:17
  • \$\begingroup\$ You just generally get people to count, I think. Or you could allow people to use any set of distinct characters instead of the box-drawing characters, or allow both. \$\endgroup\$
    – emanresu A
    Oct 25 at 0:28
2
\$\begingroup\$

Fast Matrix Multiplicator Evaluator

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

Find the k-th order summary of a number

Posted

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

Consider all arrays of \$\ell\$ non-negative integers in the range \$0,\dots,m\$. Consider all such arrays whose sum is exactly \$s\$. We can list those in lexicographic order and assign an integer to each one which is simply its rank in the list.

For example, take \$\ell=7, s=5, m=4\$, the list could look like:

(0, 0, 0, 0, 0, 1, 4)  rank 1
(0, 0, 0, 0, 0, 2, 3)  rank 2
(0, 0, 0, 0, 0, 3, 2)  rank 3
(0, 0, 0, 0, 0, 4, 1)  rank 4
(0, 0, 0, 0, 1, 0, 4)  rank 5
(0, 0, 0, 0, 1, 1, 3)  rank 6
(0, 0, 0, 0, 1, 2, 2)  rank 7
(0, 0, 0, 0, 1, 3, 1)  rank 8
(0, 0, 0, 0, 1, 4, 0)  rank 9
[...]
(3, 2, 0, 0, 0, 0, 0) rank 449
(4, 0, 0, 0, 0, 0, 1) rank 450
(4, 0, 0, 0, 0, 1, 0) rank 451
(4, 0, 0, 0, 1, 0, 0) rank 452
(4, 0, 0, 1, 0, 0, 0) rank 453
(4, 0, 1, 0, 0, 0, 0) rank 454
(4, 1, 0, 0, 0, 0, 0) rank 455

This challenge requires you to produce two pieces of code/functions.

  • Given a rank, compute the corresponding array directly. Call this function unrank()
  • Given an array, compute its rank. Call this function rank()

Your code should run in polynomial time. That is it shouldn't be brute force and more specifically it should take \$O(\ell^a s^b m^c)\$ time for fixed non-negative integers \$a, b, c\$. Any non-brute force method is likely to satisfy this requirement.

Examples

unrank((7, 5, 4), 9) = (0, 0, 0, 0, 1, 4, 0)
rank((7, 5, 4), (4, 0, 0, 0, 0, 1, 0)) = 451
unrank((14,10, 8), 100000)  = (0, 0, 0, 1, 0, 0, 1, 3, 1, 2, 0, 0, 2, 0)
rank((14, 10, 8), (2, 0, 1, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0)) = 1000000

Your score will be the total size for your code

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

Convert codepoint to UTF-9

\$\endgroup\$
4
  • 5
    \$\begingroup\$ For clarity, I'd start octal constants with 0o. Also, an explanation of how UTF-9 works should probably be included here. \$\endgroup\$ Jun 19 at 1:39
  • 2
    \$\begingroup\$ Could you include the basic algorithm to encode UTF-9 in your post instead of require an external resource? So this question can be made self contained. \$\endgroup\$
    – tsh
    Oct 12 at 6:27
  • \$\begingroup\$ @tsh Should I do with actual program source or in pseudo code? \$\endgroup\$ Oct 12 at 12:26
  • \$\begingroup\$ first challenge that made me LOL \$\endgroup\$
    – don bright
    Oct 18 at 3:12
2
\$\begingroup\$

Lexigolf: Is this number a prime?

Write a program that, given a strictly positive integer n as input, determines whether n is prime and prints a truthy or falsy value accordingly.

For the purpose of this challenge, an integer is prime if it has exactly two strictly positive divisors. Note that this excludes 1, who is its only strictly positive divisor.

Goal

Competing programs are compared lexicographically. The program that is lexicographically less than all other programs is the winner.

If a program begins with a prefix that may be removed without altering the program's behavior, it is disqualified. This is to discourage adding meaningless whitespace or comments to change the first character (consider int main(){} or /**/int main(){}).

For example,

abc < def
aa < ba
aaaaaaa < aba
aa < aaaa
Zzz < aaa
012 < AAA

Meta

This is essentially an earlier classic code-golf challenge, Is this number a prime?, except with a different goal, which I propose is called lexigolf.

I'm not sure whether lexicographic order should entirely be based on UTF-8 (for languages that can be expressed in bytes). It seems to massively favor weird esolangs that rely on characters with small ASCII codes. There is also a loophole in prefixing the program with noop characters, e.g. placing a arbitrary amount of whitespace before a C program: int main() {} > int main(int, char**) {} > int main(int argc, char **argv) {} (fixed? probably still a loophole somewhere)

\$\endgroup\$
7
  • 1
    \$\begingroup\$ For the scoring favoring weird esolangs that rely on certain characters, the scoring here is typically a per-language comptition, so Java and GolfScript wouldn't be competing. The null byte prefixing is a bit of an issue, so you might want to require that you can't take any number of characters off the left side of the program without making it stop working (so prefixing a null byte wouldn't be allowed unless it actually affected how the program ran). Also, primality testing might not be the best challenge for this idea, since many golfing languages have it as one or two byte built-ins. \$\endgroup\$ Nov 16 at 17:42
  • \$\begingroup\$ @Fmbalbuena The < are to indicate which is lexicographically smaller, not which is winning \$\endgroup\$ Nov 16 at 17:43
  • 2
    \$\begingroup\$ You might want to allow language with SBCSs (custom code pages, instead of UTF-8 or ASCII) like Jelly to use those for the lexicographic order instead, since that would make it more interesting to try to find the lexicographically smallest program in those languages. \$\endgroup\$ Nov 16 at 17:46
  • \$\begingroup\$ @RedwolfPrograms, I've updated the post \$\endgroup\$
    – OLEGSHA
    Nov 16 at 17:51
  • 1
    \$\begingroup\$ In some languages (for example, Befunge) you could probably detect whether the leading spaces were removed... \$\endgroup\$
    – NieDzejkob
    Nov 16 at 22:19
  • 3
    \$\begingroup\$ Removing only prefixes isn't enough: I could add a test at the end to check whether that prefix is present. Maybe you should require the code to be irreducible instead? \$\endgroup\$
    – Dingus
    Nov 16 at 22:55
  • 4
    \$\begingroup\$ It seems like this challenge is entirely about finding the lexicographically smallest prefix that can be extended arbitrarily far in a way that removing a prefix of it will be invalid syntax or fail. The prime-finding task doesn't really matter -- any code is equivalent if put after arbitrarily much prefix padding. \$\endgroup\$
    – xnor
    Nov 17 at 2:12
2
\$\begingroup\$

Following the theme of strange kitchen appliances, let's talk about my microwave.

Introduction

My microwave has a keypad that is laid out like this:

30  >  15
1   2   3
4   5   6
7   8   9
+/- 0 S/M
  • I can press the +/- and S/M keys to switch between adding and subtracting minutes or seconds.
  • The 0-9 keys add or subtract 1-10 minutes/seconds to the time (0 adds 10.)
  • The 30 and 15 keys always add or subract 30 or 15 seconds.
  • The > key starts the microwave.

Example

If I pressed 0 3 +/- 15 S/M 4 > I would microwave my food for 12 minutes and 41 seconds..

  1. 0: Add 10 minutes
  2. 3: Add 3 minutes
  3. +/-: Switch to subtract mode
  4. 15: Subtract 15 seconds
  5. S/M: Switch to seconds
  6. 4: Subtract 4 seconds
  7. >: Start the microwave

The Challenge

Write me a program that takes as input a string of button presses (separator doesn't matter) and outputs how long my microwave will run for. This is code-golf, so shortest code in bytes wins!

Button Codes

These are the button codes your program should accept: (I should be able to input exactly these strings):

  • 0 1 2 3 4 5 6 7 8 9 (0 equals 10)
  • 30
  • 15
  • +/-
  • S/M
  • >
New contributor
GingerIndustries is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
4
  • \$\begingroup\$ I'd recommend getting rid of the bonuses, they're pretty strongly discouraged \$\endgroup\$ Dec 3 at 17:32
  • \$\begingroup\$ @RedwolfPrograms I do like the bonus challenge, however I'm not sure what to do with it. \$\endgroup\$ Dec 3 at 17:33
  • 1
    \$\begingroup\$ You could just turn the bonus challenge into a separate question \$\endgroup\$
    – pxeger
    Dec 3 at 17:41
  • \$\begingroup\$ @pxeger I'll make it a seperate question and post it later. \$\endgroup\$ Dec 3 at 17:49
2
\$\begingroup\$

Sum powers to n

Posted to main

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

I've Got The Key, I've Got The Secret

A cryptography challenge in 2 parts.

Part 1

Implement a pair of programs in any language (the two programs could be in different languages if you wanted) to encode and decode a string of plaintext.

Input and Output

The encoder must take the plaintext (and an optional key) and return an encoded string. The decoder must take the cyphertext (and an optional key) and return the plaintext exactly as it was given to the encoder.

Restrictions

  • The encoding and decoding code must be entirely implemented in the language - no libraries or cryptography functions may be used.
  • The code (encoder+decoder) cannot be longer than 1024 characters.

Part 2

Implement programs (multiple programs per answer, one answer per entrant) which crack your opponents encryption algorithms.

Input

The cyphertext.

Output

The plaintext that generated the ciphertext.

Scoring

I will upvote all answers to part 1 which have working encryption and have obviously made an attempt at golfing their answer.

In order to be eligible to win, an entrant will have to have taken part in both parts of the question. Overall score will be (length of shortest program that cracks your code-(length of encoder+length of decoder)). Highest score wins and winning entrant's entries will be accepted on both questions.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ The obvious place for this to fall flat on its face is if someone is able to implement AES or something similar within the 1024 character restriction. \$\endgroup\$
    – Gareth
    Jun 13 '12 at 13:06
  • 1
    \$\begingroup\$ Probably better if the methods of the part one programs are disclosed in non-obfuscated language, though with the short length restriction this may not be necessary. \$\endgroup\$ Jun 13 '12 at 15:23
  • 2
    \$\begingroup\$ Forget AES: RSA is easily doable. That aside, you need to define "crack" in part 2. \$\endgroup\$ Jun 13 '12 at 15:35
  • 1
    \$\begingroup\$ Also, it's not clear whether "optional key" means that it's optional to make the algorithm unkeyed (doesn't make much sense, I admit) or optional to supply it, in which case it uses a default key. \$\endgroup\$ Jun 13 '12 at 15:42
  • 1
    \$\begingroup\$ @PeterTaylor I just put optional in to leave it up to the implementer whether or not they wanted to have the key input or hard-coded (or use no key). I'd have thought everyone would have the key input into their program, but I didn't want anyone to feel forced into it by the spec. Hmm, if RSA is doable within the character restriction I'll end up with a load of unbreakable codes which would make for a pretty crap part 2. By crack I meant cyphertext goes in, some time later plaintext comes out. Would restricting the character count further help, or is this question beyond help? \$\endgroup\$
    – Gareth
    Jun 13 '12 at 16:05
  • 3
    \$\begingroup\$ On that definition of crack, I can brute force for the length of the decoder plus a few bytes to iterate over all keys of the right length and some heuristics to check plausibility of the plaintext. The brute force cracker might even be shorter than the decoder if the decoder wasn't written in GolfScript... I think this question may be beyond help. \$\endgroup\$ Jun 13 '12 at 16:28
  • 3
    \$\begingroup\$ @PeterTaylor Okay, thanks. I like the 'build your own - knock everyone else's down' aspect of this question though. I'll have to find another area where it could apply. \$\endgroup\$
    – Gareth
    Jun 13 '12 at 16:34
  • 2
    \$\begingroup\$ @Gareth I too like the competitive nature of this idea. I'm looking forward to a question with this plan in mind! \$\endgroup\$
    – Gaffi
    Jun 13 '12 at 19:31
  • 2
    \$\begingroup\$ I think it would be better to split this into a "cops" post and a "robbers" post. \$\endgroup\$
    – wizzwizz4
    Feb 16 '17 at 9:46
  • 1
    \$\begingroup\$ @wizzwizz4 Wow, this is another blast from the past. I think this pre-dates the cops-and-robbers tag. I always seem to be ahead of my time. :-) \$\endgroup\$
    – Gareth
    Feb 16 '17 at 9:49
1
\$\begingroup\$

Countability of Sets of Finite Sets

The aim of this challenge is to code-golf a program which returns an iterator that will iterate over all possible non-empty finite sets of positive integers.

So if running long enough, this iterator should eventually touch on {1}, {2, 5}, {3, 6, 112} (ie none of these should occur "at infinity")

You may choose the order in which you iterate over these sets, but the order must satisfy the following requirement:

Under a particular ordering, if S is the i'th set to be returned by the iterator, then we shall call i the index of set S.

Let a restriction (k,T) be an assertion about a set S that says S has size k and T is a subset of S.

For a given restriction (k,T) and iterator IT, let the restricted iterator be the iterator which takes sets returned by IT and filters out sets that don't satisfy the assertion, iterating only over the ones that do. In other words, if IT iterates over the sequence of all sets, the restricted iterator iterates over the subsequence satisfying (k,T). Now if S is the n'th set returned by the restricted iterator, then we'll call n the restricted index of S with respect to (k,T)

Your ordering must satisfy the property that for any restriction there exists a polynomial P(x) such that for any set satisfying the restriction (with index i and restricted index n), i < P(n)

Note that the following ordering is not acceptable:

{1} {2} {1, 2} {3} {1, 3} {2, 3} {1, 2, 3} {4} {1, 4} {2, 4}...

This is the sequence that comes from counting 1, 2, 3, 4, 5, 6... and listing the set bits in the binary representation of each number.

This is because the restriction (1, {}) satisfies only the sets {1}, {2}, {3}, {4}... whose index i as a function of their restricted index is i=2^(n-1) which is not bounded by any polynomial


Sandbox Questions

The reason for the strange requirement at the end is to disqualify any variants on the most natural ordering which simply counts upwards from 1 and enumerates the set bits in each number. In this ordering, the n'th set of length-one occurs at index 2^n which is non-polynomial.

I posted this problem originally, but didn't think of the obvious solution and so I left out the final restriction. I'd like to re-post it with the extra restriction. But first I'd like to know what people think. Is there a better way I can word that restriction or a more natural restriction I could impose instead?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I don't understand the extra restriction, so I can't suggest a rewording, but I can say that it needs one. (In particular: what is k? And what function does T serve? Is it really a parameter of the property?) \$\endgroup\$ Jun 18 '12 at 8:25
  • 1
    \$\begingroup\$ I don't understand it either. Maybe a sample of an ordering, satisfying the requirement, and another one, violating it, would help. \$\endgroup\$ Jun 18 '12 at 15:31
  • 1
    \$\begingroup\$ I understand the restriction now, although I haven't worked through the full implications. Does allowing T to be non-empty make a significant difference at all? \$\endgroup\$ Jun 19 '12 at 6:52
  • 1
    \$\begingroup\$ I don't know. It may not. I guess the size part is the important part. I was just thinking that the ordering should be such that you run into all kinds of sets frequently. \$\endgroup\$
    – dspyz
    Jun 20 '12 at 7:17
1
\$\begingroup\$

The One with Two Parts

The aim of this challenge is to create a pair of functions which scramble and unscramble any given piece of text.

Part 1

In part one you post your scrambling function, along with the length in characters and language of your unscrambling function (but NOT its code). The length of the scrambler does not affect your score so you needn't golf it unless you want to. The two functions may be written in different languages if you wish.

Input/Output

The scrambling function should take one argument only - a string containing the input text - and return a string containing the scrambled text. The unscrambling function should also take only one argument - the scrambled text - and return the original text. The input text will be limited to characters in the ASCII set range from 0 to 127.

Part 2

In part two you try to beat your opponents' scores for their unscrambling functions. You MUST use the language they specify for their unscrambler in part one. Please give just one answer to this question containing all your unscrambling functions making it clear which question in part one each function unscrambles (maybe each answer in part one should give its scrambler a name for identification?).

Once the closing date (TBA) has passed all participants should post their unscrambling functions in their answer to part one to prove the length, language and functionality of their function.

Scoring The participants score will be calculated as follows: (unscrambler length from part one) - (shortest unscrambler length from part two). The participant with the lowest score wins and will have their answers accepted on both parts of the challenge. To be eligible to win a participant must have taken part in both parts of the question.

Example

In part 1:

  • Bob posts a Python answer and says his unscrambler is a 165 character Python function.
  • Fred posts a GolfScript answer and says his unscrambler is a 59 character GolfScript function.
  • Joe posts a JavaScript answer and says his unscrambler is a 180 character PHP function.
  • Jim posts a Ruby answer and says his unscrambler is 163 character Ruby function.

In part 2:

  • Bob posts an 82 character GolfScript function to unscramble Fred's scrambled text. He also posts a 175 character PHP function to unscramble Joe's scrambled text.
  • Fred posts a 181 character PHP function to unscramble Joe's scrambled text.
  • Joe posts a 150 character Python function to unscramble Bob's scrambled text.
  • Jim posts a 156 character Python function to unscramble Bob's scrambled text. He also posts a 91 character GolfScript function to unscramble Fred's scrambled text.

The scores:

  • Bob scores 165 - 150 = 15
  • Fred scores 59 - 82 = -23
  • Joe scores 180 - 175 = 5
  • Jim scores 163 - 0 = 163

so Fred wins.

Miscellaneous

I suggest that the closing date be two weeks after the challenge begins, and that unscramblers be posted to part one within 48 hours of closing date in order to be eligible.

\$\endgroup\$
6
  • \$\begingroup\$ Are there any rules regarding scrambling? i.e. is "Stockholm"->"Stockhoml" a valid scramble? (it may not matter, but I'm curious. And to be clear, the scoring is the difference between your opponent's unscrambler length and your own for the same language? \$\endgroup\$
    – Gaffi
    Jul 16 '12 at 16:39
  • \$\begingroup\$ @Gaffi No, you scramble however you want. If you want to just output the text as given that's ok, but you probably won't win with that strategy. The aim is to do it in a way that is easy for you to unscramble but difficult for all the others. That way your score will be smaller. Yes, the score is the difference between your score and the score of the best of your opponents' attempts. I'll add an example to make that bit clearer I think. \$\endgroup\$
    – Gareth
    Jul 16 '12 at 21:27
  • \$\begingroup\$ I think this gives an advantage to people who use (relatively) obscure languages. If the scrambler is written in J and the descrambler in GolfScript then only people who know both can realistically attempt a descrambler. (NB the rules don't say how the score works if no-one attempts a particular unscrambler). \$\endgroup\$ Jul 17 '12 at 6:59
  • \$\begingroup\$ I did consider saying that programs that had no attempts at beating them were not eligible to win, but then I thought that if they were scored as though the shortest attempt to beat them was 0 then they wouldn't have much of an advantage. I'll add that into the example scoring. What do you think? I want to encourage answers that are clever or well obfuscated rather than written in Malbolge or something like that. \$\endgroup\$
    – Gareth
    Jul 17 '12 at 7:28
  • 1
    \$\begingroup\$ Does it mean that since no one attempts to solve Jim's Ruby challenge his chances are minimal that he'll win? That would discourage complicated scramblers or difficult languages. \$\endgroup\$
    – Howard
    Jul 17 '12 at 17:12
  • \$\begingroup\$ @Howard As it stands, yes that's how it would work. The alternative, as Peter Taylor points out, is that people using obscure languages have an advantage. I'm not sure how else I might score unscramblers that no-one has attempted to beat. Maybe give them a score of 0? Please, if you or anyone else has any suggestions for making the challenge as inclusive as possible, let me know. \$\endgroup\$
    – Gareth
    Jul 17 '12 at 17:51
1
\$\begingroup\$

Compile BF to TM

Your task is to write a compiler accepting a Brainfuck program (previous challenge: Interpret Brainfuck, wikipedia: Brainfuck) as input and outputting a Turing Machine which produces identical output when supplied with the same (correct) input.

You may select the output format from among the various formats accepted by the answers to Turing Machine Simulator.

The following links may also be useful.
An introduction to programming in BF
BF is Turing-complete
Programming a Turing Machine
Programming Praxis: Turing Machine Simulator

Equivalently, you may write a Brainfuck interpreter in TM, or any partial compilation/interpretation which results in a TM program as described above.

If we consider squares of the TM tape to represent bits (blank=0, mark=1) of the BF memory, then eight squares represent a cell. Each BF instruction translates to a minimum of 8 states of the Turing Machine.

'>' "advance" (++ptr) could be implemented by eight states (sixteen transitions):

adv8 _ adv7 R _
adv8 1 adv7 R 1
adv7 _ adv6 R _
adv7 1 adv6 R 1
adv6 _ adv5 R _
adv6 1 adv5 R 1
adv5 _ adv4 R _
adv5 1 adv4 R 1
adv4 _ adv3 R _
adv4 1 adv3 R 1
adv3 _ adv2 R _
adv3 1 adv2 R 1
adv2 _ adv1 R _
adv2 1 adv1 R 1
adv1 _ link R _
adv1 1 link R 1

where 'link' represents the first state of the following instruction.

'<' "rewind" (--ptr) can be implemented similarly by making leftward movements and rewriting the same symbol just read.

'+' "increment" (++*ptr) can be implemented by a ripple-carry from the Least Significant Bit to the Most Significant Bit, borrowing "rewind" states to back-up to normal position. If the LSB is on the left, it would look something like this:

inc8 _ link N 1
inc8 1 inc7 R _
inc7 _ rew1 N 1
inc7 1 inc6 R _
inc6 _ rew2 N 1
inc6 1 inc5 R _
inc5 _ rew3 N 1
inc5 1 inc4 R _
inc4 _ rew4 N 1
inc4 1 inc3 R _
inc3 _ rew5 N 1
inc3 1 inc2 R _
inc2 _ rew6 N 1
inc2 1 inc1 R _
inc1 _ rew7 N 1
inc1 1 overflow N 1

where overflow is a HALT state.

For I/O, the simplest way I can think is to place all input on the tape after the memory area, and expand the alphabet to include a symbol indicating the dividing line between the memory portion and the input portion of the tape. In fact, by expanding the cell size to nine squares, this symbol can serve as an input pointer, advancing as the input is consumed. (So "advance" and "rewind" now need 9 states each.) And another new symbol is written in front of the current memory cell to serve as the memory pointer. Inputting a byte therefore consists of schleping each bit over the entire space between the two tape positions with something like this:

input _ set-memptr L _
input 1 set-memptr L 1
set-memptr _ find-inptr R *
find-inptr _ find-inptr R _
find-inptr 1 find-inptr R 1
find-inptr $ schlep-bit R $
schlep-bit _ schlep-blank L _
schlep-bit 1 schlep-one L 1
schlep-blank $ schlep-blank L $
schlep-blank _ schlep-blank L _
schlep-blank 1 schlep-blank L 1
schlep-blank * deposit-blank R *
schlep-one $ schlep-one L $
schlep-one _ schlep-one L _
schlep-one 1 schlep-one L 1
schlep-one * deposit-one R *
deposit-blank _ etc R _
deposit-blank 1 etc R _
deposit-one _ etc R 1
deposit-one 1 etc R 1

where "etc" represents going to get the next bit in similar fashion.

To perform a loop (all BF loops are "while" loops, so the exit control is at the beginning and the end has a simple goto back to the beginning), we need first to check is the current cell is zero,

zero8 _ zero7 R _
zero8 1 body R 1
zero7 _ zero6 R _
zero7 1 left1 L 1
zero6 _ zero5 R _
zero6 1 left2 L 1
zero5 _ zero4 R _
zero5 1 left3 L 1
zero4 _ zero3 R _
zero4 1 left4 L 1
zero3 _ zero2 R _
zero3 1 left5 L 1
zero2 _ zero1 R _
zero2 1 left6 L 1
zero1 _ exit-loop R _
zero1 1 left7 L 1
left7 _ left6 L _
left7 1 left6 L 1
left6 _ left5 L _
left6 1 left5 L 1
left5 _ left4 L _
left5 1 left4 L 1
left4 _ left3 L _
left4 1 left3 L 1
left4 _ left3 L _
left4 1 left3 L 1
left3 _ left2 L _
left3 1 left2 L 1
left2 _ left1 L _
left2 1 left1 L 1
left2 _ loop-body L _
left2 1 loop-body L 1
...
loop-body-final _ zero8 N _
loop-body-final 1 zero8 N 1

So assuming the machine starts at tape-location 0, and the input is on the tape starting at 0 and going to the right, the "startup code" for this arrangement would be

startup _ place$ L _
startup 1 place$ L 1
place$ _ left270000 L $
left270000 _ left269999 L _
...

Jeez! The output is going to be HUGE! It might be better to treat the BF memory as negative-indexed and reverse all the _L_s and _R_s in 'advance', 'rewind', 'increment', and 'decrement'.


Questions:

Bonuses for optimizations? If I can implement this myself and provide a complete example output, The bonus could be "subtract the difference between your program's output for the example input with the example output". So eliminating states would be far more valuable than shrinking the code. One could possibly achieve a negative score!


Edit: Actually I think this is unreasonable unless the Turing Machine is augmented with non-reading (movement-only or epsilon) transitions. Duplicating every letter of the alphabet just to move over one square is just ridiculously painful. That means this challenge won't link-up nicely with the other one. :(

What about, instead of implementing the compiler, just devise a translation scheme (as above) that leads to a smaller output for a trivial sample program (based on calculating, rather than coding)? "Back of the envelope" compiler.

\$\endgroup\$
8
  • \$\begingroup\$ "How much detail on BF do I need to supply? Can I simply reference the BF question?" A link to almost any site that describes the language will do. \$\endgroup\$ Nov 5 '12 at 16:52
  • \$\begingroup\$ Winning condition? \$\endgroup\$ Nov 6 '12 at 13:43
  • \$\begingroup\$ "Longest prefix containing syntactically-correct Malbolge!" :) ... I'd say have none at all. Perhaps the questioner should be required to accept their own example answer? \$\endgroup\$ Nov 6 '12 at 18:08
  • \$\begingroup\$ @PeterTaylor Apologies for my last comment. I thought we were on my other answer about the [fun] tag. . . . This one would be a golf: shortest code by character count. But I think a clever system of bonuses could make it interesting. \$\endgroup\$ Nov 7 '12 at 10:06
  • \$\begingroup\$ The "Equivalently, you may write a Brainfuck interpreter in TM" option doesn't play very well with being a code golf - how are you going to count the length of the TM? \$\endgroup\$ Nov 7 '12 at 11:15
  • \$\begingroup\$ @PeterTaylor Since the TM question specified 5-tuples, I think it's sufficient to count the tuples (== transitions). You can reduce states by increasing the alphabet (or vice versa), but the transitions would remain constant, I think. \$\endgroup\$ Nov 8 '12 at 5:25
  • \$\begingroup\$ I'd like to adopt (work on and post) this challenge if you don't want to. Would I be able to? If you do not respond to this message within two weeks, by community guidelines, I am allowed to take it over. \$\endgroup\$
    – MD XF
    Aug 18 '17 at 3:23
  • \$\begingroup\$ Yes, please. If you can do something with it, strike while the iron is hot. \$\endgroup\$ Aug 18 '17 at 4:19
1
\$\begingroup\$

Graphical Output -- Esoteric Artifacts -- The Glass Bead Game

Draw the Cabalistic Tree of Life

Simply described, the Tree of Life is an undirected network of nodes representing the conduit between matter and higher forms of spiritual energy. It has an upper face arranged in a hexagon, and a lower fact built from equilateral triangles adjacent to the lower two edges of the upper face. Don't label the paths, paths may overlap however you wish, may be single (thick) lines, even. Code Golf. Bonus -100 for labels on the Sephiroth (nodes); Bonus -150 for Hebrew labels.

Tree of Life after Kirtcher

Draw a Mandala for each Natural Number

Draw a circle with interesting visual patterns using the input N [ 1 .. \inf ) to determine the number of points around the circle to anchor figures whose shape is also modified by the input N. Actually, 12 seems like a good max: they're pretty much a blur after that no matter what.

Eg. http://code.google.com/p/xpost/downloads/detail?name=ve6a.ps
//lotsoflines n = 1 ..12

Mandalas 1 - 12

(doesn't need to be this elaborate, This is >600 lines of showing-off.).

. . . need good images for these . . .

Draw the Ptolemeic System of the Universe

All the stuff I could find is animated already. Maybe this one's done-to-death. :(

Update: Found good stuff on Alchemy. The "Keplar Platonic" model could be fun (3D and all). This one looks good, too. And this.

Draw the Pythagorean Monochord

aka pre-classical nomogram. I misplaced my Pythagoras books, I know I've got a picture somewhere.

This is the one I was thinking of.

But I think this one's even cooler

Draw the I-Ching Hexagrams in King Wen Sequence.

I suppose I need to implement this first to avoid copyright issues! :)

\$\endgroup\$
3
  • \$\begingroup\$ The I-Ching one would have to be in standard order to be remotely interesting, and then becomes as much about kolmogorov-complexity as graphical-output \$\endgroup\$ Nov 22 '12 at 21:24
  • \$\begingroup\$ For the others: images, please! \$\endgroup\$ Nov 22 '12 at 21:25
  • \$\begingroup\$ I've emailed the owner of the Alchemy pages asking for permission to use his copyrighted images. Awaiting response. \$\endgroup\$ Jan 28 '13 at 8:25
1
\$\begingroup\$

Polygon prefixes

Polygons are named after the number of sides that they have. A pentagon has 5 sides, an octagon has 8 sides. But how are they named? What's the name for a 248-sided polygon?

All polygons are suffixed with -gon. There are specific prefixes for each polygon depending on the number of sides. Here are the prefixes for the lower numbers:

3 - tri
4 - tetra
5 - penta
6 - hexa
7 - hepta
8 - octa
9 - nona
10 - deca
11 - undeca
12 - dodeca
13 - triskaideca
14 - tetradeca
15 - pentadeca
16 - hexadeca
17 - heptadeca
18 - octadeca
19 - nonadeca
20 - icosa

Polygons with 21 to 99 sides have a different system. Take the prefix for the tens digit (found on the left column), the ones digit (right column below), and then stick a "kai" between them to get (tens)(ones)gon.

20 - icosi       | 1 - hena
30 - triaconta   | 2 - di
40 - tetraconta  | 3 - tri
50 - pentaconta  | 4 - tetra
60 - hexaconta   | 5 - penta
70 - heptaconta  | 6 - hexa
80 - octaconta   | 7 - hepta
90 - nonaconta   | 8 - octa
                 | 9 - nona

The 3-digit sided polygons are named in a similar fashion. A 100-sided polygon is called a hectogon. Take the hundreds digit, find it on the column for ones digits, then stick a "hecta" to its right. Now number off the tens and ones like above: (hundreds)hecta(tens)(ones)gon. If the hundreds place digit is a 1, don't put the prefix behind "hecta".

So, given an integer (3 <= n <= 999), return the name of an n-sided polygon. n-gon is not a valid answer :P

As with all code golf, shortest code wins.


Is the description good? Would it be harder if I instead asked for the number of sides, given a name?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ What is a 101-sided figure called? "hectahenagon"? Is "hena" from the column for ones digits you mention? If so, then what is a 111-sided figure called? I'd say "hectaundecagon", but then that comes from a column where "hena" is not present. \$\endgroup\$
    – Gaffi
    Feb 11 '13 at 11:15
  • \$\begingroup\$ @Gaffi: Yep, it's hectahenagon, from what Google says. \$\endgroup\$
    – beary605
    Feb 11 '13 at 16:03
  • \$\begingroup\$ I am going to take this if you allow me or if you don't respond \$\endgroup\$ May 30 '17 at 1:13
1
\$\begingroup\$

Self-Golfing Code?

I don't know if I just didn't search hard enough, but I couldn't find any challenge regarding self-golfing code, or rather, any code that can deterministically reduce another set of text code to a much smaller program, yet still compile/run.

For example, take this:

int main() {
std::cout<<"Hello world 1!"<<std::endl;
std::cout<<"Hello world 2!"<<std::endl;
std::cout<<"Hello world 3!"<<std::endl;
std::cout<<"Hello world 4!"<<std::endl;
std::cout<<"Hello world 5!"<<std::endl;
}

And output this (as one possible solution):

#define A std::cout<<"Hello world 
#define B !"<<std::endl;
#define C B A
int main() {
A 1 C 2 C 3 C 4 C 5 B
}

Alternative:

Sub MySub()
Dim aNumber As Integer
Dim someString As String
aNumber = 123
someString = "abc"
MsgBox aNumber
MsgBox someString
End Sub

into (again, as one possible solution)

Sub m()
Dim a As Integer
Dim s As String
a = 123
s = "abc"
MsgBox a
MsgBox s
End Sub

Do we have a challenge for this?

If not, here are some rules I envision:

  • Golfing code need not be in the same language as code to be golfed.
  • Since compilers/running of code varies, newly golfed code must still run under same environment.
  • Possible challenge scoring (multiple options -- thinking code golf):
    • 1: Shortest golfing code wins (not my favorite, since you can minimally shorten the base code, yet still write the shortest program).
    • 2: Shortest output of a set of pre-defined code (potentially limiting if participants are unfamiliar with the options available)
    • 3: Combination of length of golfing code and the output result of the same as input. (Ratio, summation, etc.) -- This I think is my preferred option.
    • 4: Multi-player Ratio of golfed size of other participants' own code versus their original submission. (Similar limitations to that of point #2.)
\$\endgroup\$
8
  • 1
    \$\begingroup\$ Sounds more like an auto-golfer than obfuscation. Seems like it would be very hard to make it a fair contest unless you pick a language to golf, and even then it had better be a simple language (no platform dependency issues or compiler options). \$\endgroup\$ Feb 13 '13 at 15:15
  • \$\begingroup\$ @PeterTaylor My examples are golfing, but either would work. Perhaps golfing would be simpler, then? I agree that the options for usable languages makes this a bit messy... Would one challenge per language be acceptable? (i.e. aligned with most challenges that are language-agnostic) \$\endgroup\$
    – Gaffi
    Feb 13 '13 at 17:36
  • 2
    \$\begingroup\$ Language-agnostic to mean means that you can write a program to do it in any language. Since the language to be golfed can be different from the submitted program, I don't see any incompatibility between making the problem "Write a program to golf Piet" and being language-agnostic. \$\endgroup\$ Feb 15 '13 at 0:18
  • \$\begingroup\$ @PeterTaylor So then you see no problem with one question per language on which to operate? Are there any proposed scoring algorithms you particularly like/dislike? \$\endgroup\$
    – Gaffi
    Feb 15 '13 at 12:02
  • \$\begingroup\$ That depends on what you mean. If you're planning to post 10 questions at once, yes, that would be a problem. But I don't see a problem with posting a well-defined "Auto-golf Piet" and following it up two months later with "Auto-golf Perl 5". \$\endgroup\$ Feb 16 '13 at 10:19
  • \$\begingroup\$ Scoring is an issue. The halting problem means that it's impossible to write an optimal solution, so the scoring must take into account how good the solution is. I think option 3 is the best, and you'll want a big test set (maybe a few kB taken from a real-world open source project) with coverage of the language features. \$\endgroup\$ Feb 16 '13 at 10:22
  • \$\begingroup\$ Btw, your first example doesn't work. You can't have unmatched quotes in preprocessor directives. Don't know why. \$\endgroup\$
    – MD XF
    Jan 13 '18 at 18:03
  • \$\begingroup\$ I honestly think this would be fine if you did something like solely maco-golfing, making it somewhat language agnostic because of gcc -E. \$\endgroup\$
    – Adalynn
    Nov 10 '18 at 14:36
1
\$\begingroup\$

DeCSS

It is known that the DVD Content Scrambling System can be deciphered with a rather short program (434 bytes of C, 472 bytes of Perl). Can you do better?

<< Test cases go here >>


I don't plan to include a more detailed spec, because it will just wind up duplicating some of the code. The test cases would be in the form of (key, link to data file, md5sum of the deciphered stream).

\$\endgroup\$
4
  • 2
    \$\begingroup\$ And the winning criterion is who is the first to get post from the courts? \$\endgroup\$
    – celtschk
    Oct 3 '15 at 20:18
  • \$\begingroup\$ @celtschk, I think that would be unfair. Winning criteria shouldn't really depend on where people live... \$\endgroup\$ Oct 10 '15 at 20:56
  • 3
    \$\begingroup\$ I think you should at least explain the general concept of the spec. \$\endgroup\$ Aug 2 '16 at 22:53
  • \$\begingroup\$ This actually sounds interesting. @PeterTaylor Perhaps you could use (and link to) Charles Hannum's explanation of the algorithm and post this. (It would be fun to have it as a popularity contest for a program that looks like it's nothing DeCSS related, or a program that furthers the gallery's point about the text vs source code arbitrary distinction - but I don't know if popularity contests are popular any more!) \$\endgroup\$ Jun 25 '18 at 8:25
1
\$\begingroup\$

Write a compiler/interpreter for ...

Inspired by the lisp challenge here.
It is a series of puzzles.

I don't like to see a simple eval solution, so:

  • interpreting the language is fine
  • translating the language to a different language is fine.

I think this is specific for each language.

Only the syntax and the basic commands.
Also specific.

Winning criteria should not be code golf.
The goal should be that you can "learn" an other language by looking at the code.

Languages that might be good candidates:

  • Lisp
  • APL
  • J
  • Brainfuck (already posted)
  • Whitespace
  • Forth
\$\endgroup\$
6
  • 1
    \$\begingroup\$ This only works for languages which are small and well defined. BF fits those criteria. Whitespace does too. The others may not. Lisp and Forth have so many dialects that you would have to specify exactly which dialect to support; Lisp, Forth, APL and J might have too many built-ins to fit in an answer: there are character limits. \$\endgroup\$ May 12 '13 at 15:16
  • \$\begingroup\$ You don't have to provide all the built-ins, but that is why it is here. \$\endgroup\$ May 12 '13 at 15:38
  • \$\begingroup\$ What defines the "basic commands"? \$\endgroup\$ Aug 31 '15 at 17:54
  • \$\begingroup\$ I don't know? Maybe that you can do the basic stuff with it like +,-,print,... \$\endgroup\$ Aug 31 '15 at 18:22
  • 1
    \$\begingroup\$ I suggest a programmer can implement the tiniest subset of those languages in order to be Turing-complete, as these are non-trivial subsets that can theoretically simulate the rest of the language... \$\endgroup\$
    – user85052
    Jun 28 '19 at 4:17
  • \$\begingroup\$ Which human is learning the programming language by looking at the code? \$\endgroup\$
    – MilkyWay90
    Aug 26 '19 at 3:23
1
\$\begingroup\$

Missile Command

I'm making this CW, because it needs lots of help. I've been toying with this idea for a while. Think "battleship" to get in the right mind-frame. But, instead of ships, what you lay down are tiles which represent a Befunge-style program. This program controls the behavior of guided missiles ejected from the spawn tile. The goal is to program a missile which will obliterate an opponent's program block, as well as guard its own control block.

Haven't nailed-down the board size. 20x20 seems a little cramped.

         1         2
12345678901234567890
____________________1  4x20 program block
____________________2
____________________3
_______@____________4
....................5  12x20 arena
....................6
....................7
....................8
....................9
....................01
....................1
....................2
....................3
....................4
....................5
....................6
___________@________7  4x20 program block
____________________8
____________________9
____________________02

Tiles

@ spawn

Program control.

I'm imagining these to change direction of the code for "boustrophedon" writing.

this,then\
 txen,siht

haven't thought it all though, yet.

/

\

Movement.

F forward move forward one square

B back move back one square

L left turn left 90°

R right turn right 90°

So the submissions would be 4x20 code blocks which compete in a king-of-the-hill style.

\$\endgroup\$
2
  • \$\begingroup\$ If this is deterministic, won't it be "Last person to submit their program wins"? \$\endgroup\$ Jun 7 '13 at 8:39
  • \$\begingroup\$ That is a danger, yes. I'm hoping ways around it can be found. There could be a random operator. And proximity detection, or something. \$\endgroup\$ Jun 7 '13 at 8:46
1
30 31
32
33 34
119

You must log in to answer this question.

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