577
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29 at 13:27

4831 Answers 4831

1
6 7
8
9 10
162
5
\$\begingroup\$

BitCycle Metagolf

\$\endgroup\$
2
  • \$\begingroup\$ Since undefined behavior can have an effect on how small you can make a BitCycle program, I'd say you should either pick a specific implementation and say all answers must work on that implementation, or say that answers are allowed to work on any existing implementation. \$\endgroup\$
    – DLosc
    Commented May 14, 2022 at 17:47
  • \$\begingroup\$ @DLosc Okay, I will put in that it has to work on TIO. \$\endgroup\$
    – Aiden Chow
    Commented May 14, 2022 at 18:13
5
\$\begingroup\$

Spend maximal money

\$\endgroup\$
20
  • \$\begingroup\$ For 10.00; [5,5,10] is [5,5] an ok output? What should be the output for 10.00; [1,2,5,5,7] (and why)? Suggestion: keep the challenge within positive integers. \$\endgroup\$
    – pajonk
    Commented May 9, 2022 at 11:15
  • \$\begingroup\$ @pajonk I prioritized choosing items from left to right. \$\endgroup\$ Commented May 9, 2022 at 22:22
  • \$\begingroup\$ You may want to alter the new examples to comply with your spec ("without equaling"). Also, does the order of the output matter ([12.99, 0.99] vs [0.99, 12.99])? I also suggest explicitly stating that \$l\$ is an ordered list. \$\endgroup\$
    – pajonk
    Commented May 10, 2022 at 9:06
  • \$\begingroup\$ @pajonk YOU were the one how made me thought those were the correct answers, but ok. \$\endgroup\$ Commented May 10, 2022 at 11:26
  • \$\begingroup\$ and no, it will not be an ordered list. the output also doesn't matter. \$\endgroup\$ Commented May 10, 2022 at 19:03
  • \$\begingroup\$ If the input is not ordered, hot do we determine left-to-right? \$\endgroup\$
    – pajonk
    Commented May 10, 2022 at 19:31
  • \$\begingroup\$ aw damn you have a valid point lemme fix that \$\endgroup\$ Commented May 10, 2022 at 22:16
  • \$\begingroup\$ Your last example has an incorrect output. The answer should be [2.00, 7.00] \$\endgroup\$
    – jezza_99
    Commented May 12, 2022 at 23:31
  • \$\begingroup\$ @jezza_99 fixed. \$\endgroup\$ Commented May 13, 2022 at 0:03
  • \$\begingroup\$ You say that you want to prioritize choosing items from left to right. For the examples you have given, this only results in an ordered output, which you've said is not important. The actual possible solutions do not change. I recommend either adding an example to test this criteria or dropping it. A suitable example would be budget=10.00, prices=[1.00, 2.00, 3.00, 4.00, 8.00]. This should output [1.00, 8.00] even though [2.00, 3.00, 4.00] is also a potential solution \$\endgroup\$
    – jezza_99
    Commented May 13, 2022 at 1:03
  • \$\begingroup\$ @jezza_99 i'm sorry but you've broken my brain. I'll just leave this here to rot \$\endgroup\$ Commented May 13, 2022 at 19:06
  • \$\begingroup\$ @BowlingPizzaBall what is the point of the rule "Prioritize choosing items from left to right"? \$\endgroup\$
    – jezza_99
    Commented May 13, 2022 at 22:59
  • \$\begingroup\$ @jezza_99 Guess you could say there is no point. I'll remove that rule \$\endgroup\$ Commented May 13, 2022 at 23:11
  • \$\begingroup\$ @jezza_99 I thought this rule was to make the solution unique. Now (as in your example above) there may be multiple solutions. \$\endgroup\$
    – pajonk
    Commented May 14, 2022 at 15:31
  • \$\begingroup\$ @jezza_99, yeah, prioritizing left to right means there is only 1 valid solution. \$\endgroup\$ Commented May 14, 2022 at 16:47
5
\$\begingroup\$

Generate a Baudot punched tape segment

What is Baudot?

From Wikipedia

The Baudot code [boˈdo] is an early character encoding for telegraphy invented by Émile Baudot in the 1870s. It was the predecessor to the International Telegraph Alphabet No. 2 (ITA2), the most common teleprinter code in use until the advent of ASCII. Each character in the alphabet is represented by a series of five bits, sent over a communication channel such as a telegraph wire or a radio signal. The symbol rate measurement is known as baud, and is derived from the same name.

Task:

For this challenge, your task is to write a program or a function that takes a string as its input and generates ASCII art that looks like a roll of punched tape. For the purposes of this challenge, you should specifically use the following variant, as it just happened to be the first image I found :P

International Telegraph Alphabet 2 brightened

For example where input is "HELLO WORLD\r\n" (note that carriage return is optional)

 *    *      
  **  * **  *
.............
*    *  *    
    *  *   * 
* ***  *  *  
hello worldcl
           rf

Program Description:

  • The program/function takes the input and turns it into a sequence of Baudot words (sequences of five bits)
  • For each word, it makes a column of the first two bits, then a . then the remaining three bits
  • Optional trailing space / newline

Criteria:

  • Output may not be output as an array unless there is no other valid option in the language. Trailing spaces and newlines allowed.
  • Any acceptable input
  • Assume all input characters are valid Baudot characters
\$\endgroup\$
2
  • 2
    \$\begingroup\$ No need to specify standard loopholes and I/O, they apply by default. You also override standard I/O with your third rule, so not much of a point to linking to it. \$\endgroup\$
    – rydwolf
    Commented Jun 7, 2022 at 21:12
  • 1
    \$\begingroup\$ The Baudot code comes with the ability to switch between two modes (one for letters and one for figures). You'll have to clarify if we need to support that and how. \$\endgroup\$
    – Arnauld
    Commented Jun 12, 2022 at 20:41
5
\$\begingroup\$

Decipher a squashed sequence

\$\endgroup\$
5
\$\begingroup\$

All\$^{\dagger}\$ 3-character expressions

\$^{\dagger}\$with some exceptions

In your golfing language of choice, given no input, output all valid 3-character expressions in that language, with the conditions described below.

An expression, for the purposes of this challenge, is a string of characters that can be evaluated to some result. An example of an expression in many languages is 1+2, which evaluates to 3. If evaluation causes an error/exception/crash (e.g. 1/0 in Python), then it should not be printed.

Expressions can also have side effects (modify the state of the program), e.g. y=2 in Ruby. These are allowed to be output but are not required. (In other words, you only need to print out referentially transparent expressions.) Similarly, any expressions that rely on the evaluation of previous expressions, e.g. a+2 (which requires that the value of a be set), are optional, unless they cause an error/crash, in which case they should not be output.

Some additional notes:

  • White space and comments do not count as part of an expression - e.g. 2 or 2#a in Python are one-character expressions, so they shouldn't be printed.

Any language that does not have the concept of expressions, or has no expressions that are 3 characters long meeting the above requirements, cannot be used for this challenge.

As per usual code golf, the shortest program (in bytes) wins.

Sandbox Questions

(This is my first challenge, so I don't really know what I'm doing, and feedback is greatly appreciated.)

I'm not sure how to deal with expressions that change the results of other expressions or change what counts as a valid expression, particularly in the case of side effects. For example, if in the language, evaluating any expressions causes an "answer" variable to be set, then all expressions have side effects and the challenge is moot.

I was considering having the condition for passing be "Your program satisfies the challenge if, after running, there are no other expressions you can evaluate.", but I'm unsure if that's a good requirement.

\$\endgroup\$
17
  • 1
    \$\begingroup\$ Nice challenge! However, bonus challenges are generally discouraged when writing challenges, so either remove the bonus, or make it another challenge. \$\endgroup\$
    – Seggan
    Commented Jul 12, 2022 at 20:34
  • \$\begingroup\$ (See relevant meta post.) \$\endgroup\$
    – naffetS
    Commented Jul 12, 2022 at 21:38
  • \$\begingroup\$ Might it be possible to generate programs instead of expressions for languages that don't have expressions? Also I think, that you can use code-generation tag. \$\endgroup\$
    – Jiří
    Commented Jul 12, 2022 at 21:43
  • \$\begingroup\$ @Jiří I think that is a meaningfully different request from generating all expressions -- it could probably be a separate challenge. \$\endgroup\$ Commented Jul 12, 2022 at 22:15
  • \$\begingroup\$ @thejonymyster It doesn't lead to any footnote -- it's just indicating that there are some exceptions to the word "all" (the same way that "with an asterisk" means "some exceptions apply"). It's probably unnecessarily confusing though -- I'll change it. \$\endgroup\$ Commented Jul 12, 2022 at 22:18
  • \$\begingroup\$ I'm still concerned about how exactly to define "having side effects" -- does anyone have a better idea of how to deal with that? \$\endgroup\$ Commented Jul 12, 2022 at 22:21
  • 2
    \$\begingroup\$ Does having side effects also include printing or reading input? Also I have found following Wikipedia page which talks about expressions. Which led me to Wikipedia page about Referential transparency which had following sentence which might be the thing you are looking for: An expression is called referentially transparent if it can be replaced with its corresponding value (and vice-versa) without changing the program's behavior. \$\endgroup\$
    – Jiří
    Commented Jul 12, 2022 at 23:00
  • 1
    \$\begingroup\$ The thing is, some languages don't have something called an "expression", like golfing languages (and others). In that case, do we just output valid programs? \$\endgroup\$
    – naffetS
    Commented Jul 13, 2022 at 2:04
  • \$\begingroup\$ @Steffan I mentioned that in the description: "Any language that does not have the concept of expressions, or has no expressions that are 3 characters long meeting the above requirements, cannot be used for this challenge." \$\endgroup\$ Commented Jul 15, 2022 at 18:30
  • \$\begingroup\$ What is the definition of "expression" in regards of comments? Is it allowed to output strings that include comments? (e.g. 3#2 in python) \$\endgroup\$
    – naffetS
    Commented Jul 15, 2022 at 18:39
  • \$\begingroup\$ @Steffan Hm, I'd say that's a 1-character expression with a comment, so by the rules above it shouldn't be printed. But that's not a strong conviction on my part. \$\endgroup\$ Commented Jul 15, 2022 at 18:58
  • \$\begingroup\$ Also, is it allowed to print things with whitespace, e.g. " " or " 2"? \$\endgroup\$
    – naffetS
    Commented Jul 15, 2022 at 19:08
  • \$\begingroup\$ Also, can random warnings be spouted to stderr? \$\endgroup\$
    – naffetS
    Commented Jul 15, 2022 at 19:11
  • \$\begingroup\$ @Steffan Thank you for asking these questions :) I'd also say that white space isn't part of the expression, except in obvious cases - e.g. the expression representing the empty string " " -- so it shouldn't be allowed. For the second point: I think I'll say that expressions generating errors that don't stop execution of the program are allowed, so yes. Those expressions probably shouldn't be required to output though (?) \$\endgroup\$ Commented Jul 15, 2022 at 19:25
  • \$\begingroup\$ For the warnings, I can actually disable them with a flag (like -W0 in ruby), so it's fine either way. So as far as spaces, " 2" isn't allowed, I guess. And - 2 isn't allowed either, I guess? Welp, this is going to add some bytes lol \$\endgroup\$
    – naffetS
    Commented Jul 15, 2022 at 19:47
5
\$\begingroup\$

Have you heard of tralindromes?

\$\endgroup\$
5
\$\begingroup\$

Divisor of a string

\$\endgroup\$
4
  • 2
    \$\begingroup\$ May we assume the input string has positive length? \$\endgroup\$
    – pajonk
    Commented Aug 10, 2022 at 8:31
  • 1
    \$\begingroup\$ @pajonk yes, you can \$\endgroup\$
    – badatgolf
    Commented Aug 10, 2022 at 9:31
  • 4
    \$\begingroup\$ You may also want to specify what to expect within the string (letters, whitespace, special characters?) - I suggest only lowercase letters. \$\endgroup\$
    – pajonk
    Commented Aug 10, 2022 at 11:25
  • 1
    \$\begingroup\$ Can the output have duplicates? Can it be in any order? \$\endgroup\$
    – naffetS
    Commented Aug 10, 2022 at 21:30
5
\$\begingroup\$

Radiation Hardening Koth

\$\endgroup\$
5
  • \$\begingroup\$ Why not the mean? \$\endgroup\$
    – Seggan
    Commented Aug 9, 2022 at 18:53
  • 1
    \$\begingroup\$ You could get really luckly sometimes and get paired against "almost dead" programs giving you a very high score with no real effort. Or get really unlucky and the first program in the first round guesses the single essential character in your source code. I think the median will compensate for this randomness and give a better idea of the general performance of a program. \$\endgroup\$ Commented Aug 9, 2022 at 19:25
  • \$\begingroup\$ Ah, okay then. Got it. \$\endgroup\$
    – Seggan
    Commented Aug 9, 2022 at 19:43
  • \$\begingroup\$ I would say multi-language koth's land up bad cuz (length) 100 is a little too much already for python but 100 is like a no-go for c++ (i guess) \$\endgroup\$ Commented Aug 10, 2022 at 12:26
  • 2
    \$\begingroup\$ The 255 byte limit is not intended for it to be a challenge to fit your code in that space, that's pretty doable in most any language. The idea is you can't stuff your code with a gigabytes of comments to simply reduce the chance of a important character being deleted. \$\endgroup\$ Commented Aug 10, 2022 at 12:32
5
\$\begingroup\$

The second even sublime number

\$\endgroup\$
2
  • \$\begingroup\$ the thing is, the number is still short enough that in what I think is most languages, it's shortest to just print it \$\endgroup\$
    – naffetS
    Commented Aug 25, 2022 at 3:25
  • \$\begingroup\$ @Steffan At least 71547118063305763497095299547369280601<<126 is shorter. \$\endgroup\$
    – alephalpha
    Commented Aug 25, 2022 at 4:35
5
\$\begingroup\$

Re-Name all identifiers to a single letter

\$\endgroup\$
10
  • \$\begingroup\$ @tsh Scoping rules are more like python. Variables are implicitly declared when they are first used. \$\endgroup\$ Commented Sep 9, 2022 at 9:20
  • \$\begingroup\$ For (aa (ab ac ad) (ad ad)), should I output (a (b c d) (b b)) or (a (b c d) (e e))? \$\endgroup\$
    – tsh
    Commented Sep 9, 2022 at 9:22
  • \$\begingroup\$ @tsh (a (b c d) (b b)) since ad is defined in a scope that has closed. \$\endgroup\$ Commented Sep 9, 2022 at 9:24
  • \$\begingroup\$ I hoped the sentence "A variable is created when it first appears" would clarify this case \$\endgroup\$ Commented Sep 9, 2022 at 9:25
  • 1
    \$\begingroup\$ And then, should (aa (ab ac ad) (ad ad) ad) be (a (b c d) (d d) d) because ad is defined on the outer layer? If so, I would expect add these two as testcases. \$\endgroup\$
    – tsh
    Commented Sep 9, 2022 at 9:28
  • \$\begingroup\$ Or maybe (aa (ab ac ad) (ad ad) ad (ab ac ad) (ad ad))? \$\endgroup\$
    – tsh
    Commented Sep 9, 2022 at 9:31
  • \$\begingroup\$ @pxeger I explicitly state you are allowed to take input as a ragged list \$\endgroup\$ Commented Sep 9, 2022 at 12:23
  • \$\begingroup\$ I'm confused with the kor (2nd) and be test cases. Could you clarify rules which were used to produce those results? \$\endgroup\$
    – pajonk
    Commented Sep 10, 2022 at 19:02
  • \$\begingroup\$ @pajonk you are right the second be test case is incorrect. Fixed now \$\endgroup\$ Commented Sep 10, 2022 at 20:37
  • 1
    \$\begingroup\$ Suggested test case: ((x y) y) - is it ((a b) a)? \$\endgroup\$
    – pajonk
    Commented Sep 11, 2022 at 5:52
5
\$\begingroup\$

Implement the flip-floperator

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

Enumerate the rationals

\$\endgroup\$
7
  • 2
    \$\begingroup\$ +1 for including negative rationals. There are many one-to-one mappings from Z+ to Q+, and some of them may be better suited for golf when extended to Q. \$\endgroup\$
    – Bubbler
    Commented Sep 26, 2022 at 7:17
  • \$\begingroup\$ Possible dupe? \$\endgroup\$
    – emanresu A
    Commented Sep 26, 2022 at 9:04
  • \$\begingroup\$ Are we submitting a function that generates this mapping? \$\endgroup\$
    – pigrammer
    Commented Sep 26, 2022 at 12:51
  • \$\begingroup\$ I'd recommend providing an example mapping. \$\endgroup\$ Commented Sep 26, 2022 at 14:09
  • \$\begingroup\$ Also, to answer @pigrammer : I think so, yeah. Also, I think since it's a sequence question, there are some standard ways you can implement the challenge. However, this might not apply here because we're not just generating a sequence, so not all of the output methods listed may apply. \$\endgroup\$ Commented Sep 26, 2022 at 14:13
  • \$\begingroup\$ @pigrammer The idea is with to go with sequence defaults, but (for function submissions) allow mappings from arbitrary contiguous subsets of \$\mathbb Z\$ rather than only \$[0,\infty)\$ or \$[1,\infty)\$. Let me know if you have any suggestions on how to make that more clear. \$\endgroup\$
    – att
    Commented Sep 26, 2022 at 18:06
  • \$\begingroup\$ @emanresuA It is one way to solve this, but there exist multiple alternatives, some of which are almost certainly simpler than that. \$\endgroup\$
    – Bubbler
    Commented Sep 26, 2022 at 23:29
5
\$\begingroup\$

Traverse a rectangle's antidiagonals

\$\endgroup\$
2
  • 4
    \$\begingroup\$ Welcome to Code Golf, and nice first challenge! \$\endgroup\$
    – Ginger
    Commented Nov 5, 2022 at 20:24
  • 3
    \$\begingroup\$ Suggested title change: "Traverse a rectangle's antidiagonals" \$\endgroup\$ Commented Nov 5, 2022 at 20:24
5
\$\begingroup\$

Perceptron

There was a previous perceptron question but it was closed. Also it required a lot of extra stuff that's not normally part of the perception algorithm like I know it. This question will be much simpler

The Percepron is a extremely basic classification algorithm. While it still has some limited use it's been mostly overtaken by gradient descent based algorithms that can match much more complex functions. Still its fun and easy to implement, and is the foundation for many more complex algorithms.

The dot product is defined as follows:

$$(A_0, A_1, \dots, A_n) \cdot (B_0, B_1, \ldots, B_n) = A_0 B_0 + A_1 B_1 + \ldots + A_n B_n$$

Algorithm Description

Percepron can classify vectors into 2 categories, simply by taking the dot product with some vector. If this is positive, you are in category A, if negative, then not.

The algorithm to compute this vector works as follow:

set the initial vector to <0, 0, ..., 0>

while not every data point is classified correctly:
    let p be the first incorrectly classified point
    if the dot product is positive or zero but it should be negative:
        add p to the vector
    if the dot product is negative or zero but it should be positive:
        subtract p from the vector

Among the many weaknesses of this algorithm is that it runs forever if no solution exists, that it can only classify categories separated by a straight plane, and that that plane must pass through the origin.

You do not need to follow this exact algorithm as long as you can guarantee a correct vector in all the cases this algorithm would.

The task

Take as input a list of positive tuples and a list of negative tuples. All tuples will all be the same length, and can contain any real number representable by a 32 bit float. Then output a vector that perfectly classifies them.

This is . Shortest answer in each language wins.

You may also take input as a single list of ((x0, ..., xn), category) tuples. You may take the length of the tuples as a extra input if desired.

You may assume a solution exists for the input given.

The tuples in the input will always have 1 as their last value, representing bias.

Test Cases

Note: Many of these can be bisected by many different hyperplanes, any of them would be a valid result. Your code may still be correct if it produces very different values from this.

[
    {
        "positive": [[1,0, 1]],
        "negative": [[0,1,1]],
        "result": [1,-1,0]
    },
    {
        "positive": [[12.12958530911699, 71.71547437602891, 17.615042787292396, 1.0], [22.894324259518754, 7.747740085241489, -16.379692578583914, 1.0], [-77.19508767650036, 26.391457800328325, -34.128081828012256, 1.0], [96.46713849700853, 8.223882871718914, 95.59810235088628, 1.0], [95.47166665625838, 36.07081574287895, 20.660512993212635, 1.0]],
        "negative": [[-41.92974660410673, -42.941790456679854, 21.407959882725905, 1.0], [-99.40397441836177, 26.174868779681844, 56.51788064358769, 1.0], [34.482060088467364, -96.36102804944655, 1.5810491199434153, 1.0], [-43.06995918058733, -65.8456447109237, -99.04122951157478, 1.0], [7.7462310407688335, -10.894130800401939, 77.86204331190197, 1.0], [44.47180923569721, -93.53543659179937, 6.715910740415197, 1.0], [71.16273132699712, -80.16856861976358, 48.05726245445331, 1.0]],
        "result": [78.64936114023355, 237.2180619264857, -42.5708443640236, 10.0]
    },
    {
        "positive": [[19.891204296811196, 10.95935510782877, 25.985095341720097, -39.87626202198886, 13.054847014298801, -0.8134570474536389, -54.24129976411458, 1], [-16.576268085926657, 4.5002152868197385, 6.698984554370156, -49.780067496976976, 3.9392362908185703, -11.457246915347255, -3.84485029930714, 1], [-6.424223219895211, -67.86203596702003, 0.6670934629448197, -67.56926034741468, -34.71326779844648, -19.40781793399796, -38.93217338522913, 1], [-55.06122442753092, -46.49216596542017, -28.522294222446035, -30.89448675440849, 25.85546157303159, -28.753484757197114, -67.37074950075419, 1], [12.753734640663126, -42.688681313433065, -37.073894323478854, -22.678023584770216, -12.23724620287598, 4.467063264393019, -28.749388172615724, 1], [-25.894264060028036, -4.384289071814308, 25.545930397049247, -53.005653882689884, -17.7501576060518, -19.66585588898353, -33.29502103119091, 1], [-32.104636572417846, -61.44888846917201, -41.89407929533455, 20.32097494020971, 8.703788581939762, 12.493571659393822, -35.255247777162495, 1], [24.15536843650885, -25.610207061176325, 16.08185788882571, -34.478497500787185, -18.915615320612233, 24.782283056323323, -24.770226555932894, 1], [6.765979248514711, -1.6248990886835486, 19.091220818794667, 14.715692506417057, 7.953257187955259, 12.722665623234263, 14.914783085366352, 1]],
        "negative": [[-2.7270414497182855, 8.676310678740919, -72.98709301742022, -7.70910010724549, 10.477333664984855, -17.506198964389014, 18.233248667960424, 1], [-43.3010158973477, -20.807005424922295, -77.5083019019948, 16.126838313178908, -40.490353240152864, -11.81562605632648, -8.902497984641357, 1], [-31.71159835398403, -14.73301578999785, 13.902967116929815, -21.834371921202447, -40.86878402777407, 6.742152812766307, -16.213431636063206, 1], [-66.57071699396832, -2.6930106603672783, 24.856421108284607, 26.02555433076685, -45.195502153813656, -60.583102046347044, 18.622821621702442, 1], [-47.07567023723187, 8.668277396085415, -55.64099369519978, -24.3651014072761, -77.50500543887348, -29.67008512028478, -27.6004244984169, 1], [16.02465948636585, -64.28947887797132, -18.663992818184852, 11.001922130635734, -65.96111461946506, -70.07973218635979, -41.525576739268594, 1], [-33.6451045267202, -8.496296235717935, -20.129571219612984, 9.152732883489037, 10.242775447179753, -61.865587395289765, -32.78507965995476, 1], [-59.32306321222039, 12.522731642519034, 22.026994802405454, -18.062615366497297, -8.713470639955815, -44.04186584475624, 27.84951438666559, 1], [15.30669132488326, 4.865567302204951, -2.782248675090557, 24.252984759612147, -31.883249650258065, 0.5697927616565579, 22.431436239098076, 1], [1.0357436812954433, -32.44164907799862, 13.942522314820707, 16.30751529733827, -12.905194523861582, -22.446463524560656, 12.651474924205772, 1], [-56.03563699153419, 12.024854226295957, -39.90028407341309, 26.9268535257967, 23.808505964904285, 0.34968582027003947, -29.362006601750707, 1], [-85.14402438073334, -15.501824729148709, -63.38128746811267, -42.15734961052637, -4.1615796887736565, -7.25189532732314, -27.223088213381402, 1], [2.7529807581849184, -23.668062096200217, -9.028343561579462, 2.5495275958544283, 15.88901518194605, -59.28742737700396, 25.402434735936126, 1], [-49.514159298902705, -24.01610873489301, 19.949647054069544, -41.1158129509881, -53.808681913915706, -11.175092994514387, 16.753648710377945, 1], [13.052884356788013, -29.298799492103925, -11.675938518634197, -11.229831992030299, -82.661335125941, 0.4488670991709114, 15.5168860373427, 1], [-10.923814330565236, -44.964063927868544, -38.9909686186201, 15.763631832856007, -44.00734436715622, -54.69686019599016, -52.81999206838163, 1], [-43.815947420234714, 19.90446963235277, 4.773988726751696, -47.12560089860667, 13.028054180292472, -39.81105100874389, 16.639915018971934, 1], [-60.88215048423795, 18.63815015768826, 27.157195120177462, -31.93335885907136, -6.562377024790365, 20.3179674395969, 9.210423673803817, 1], [-20.199358866077134, -50.594347683405196, -65.49273675929138, 19.37323156150201, -13.877303200574588, 19.536120330891066, -17.908737459942998, 1], [-11.03148069515855, 18.400073052625856, -65.34212863735566, -5.32988003172234, 0.7010084382675785, 26.36787095325562, 22.718825279142763, 1], [-30.028696420764177, -20.038640467728513, -47.66006964061526, 1.669739637216125, 3.3366149257696947, -20.495524621115493, 11.79886970131642, 1]],
        "result": [53.402165827630355, -96.34048665666451, 46.75018310196545, -58.648563298215464, 167.65173848467344, 54.84963473487821, -66.47771531555354, 6]
    }
]
\$\endgroup\$
3
  • \$\begingroup\$ Are you talking about "perceptron"? \$\endgroup\$ Commented Nov 10, 2022 at 10:42
  • 3
    \$\begingroup\$ Could you add a brief explanation of what a "dot product" is? \$\endgroup\$
    – Ginger
    Commented Nov 12, 2022 at 14:25
  • \$\begingroup\$ Your second link says "Percepron", I assume it should be "Perceptron". A small error, but worth fixing. \$\endgroup\$ Commented Nov 15, 2022 at 22:48
5
\$\begingroup\$

Clutch Wordle Solver with known inputs

\$\endgroup\$
5
  • 1
    \$\begingroup\$ A couple of test cases would be most helpful. \$\endgroup\$
    – Adám
    Commented Dec 5, 2022 at 20:04
  • 1
    \$\begingroup\$ Added a use case and a table with the solution set. :D \$\endgroup\$
    – Catija Staff
    Commented Dec 5, 2022 at 22:01
  • \$\begingroup\$ Looks like a good idea, and draft, for a first challenge! My main suggestion would be this: we like to allow input/output to be as loose as makes sense, as it can often lead to creative solutions. So, I'd suggest rewording the i/o section to something along the lines of: \$\endgroup\$ Commented Dec 5, 2022 at 22:19
  • \$\begingroup\$ "Input: - A list of letters and indices (0 or 1 indexed, your choice), indicating the location of confirmed/green letters; - A list of letters and indices (consistently indexed), indicated yellow letters (i.e. the index is a known location the letter is not; - A list/string of letters that are yet to be guessed." /// "Output: All potential "words" of exactly 5 letters, such that the green letters are in the indicated indexes, the yellow letters are not in the indicated indexes, and the words consist of only the green, yellow, and remaining letters. The output may be in any order" \$\endgroup\$ Commented Dec 5, 2022 at 22:19
  • \$\begingroup\$ It's also worth including the "generic" catch-all for input/output, something along the lines of: "You may take input and output in any convenient method or format" just to cover the "weird" programming languages that treat lists, strings, and numbers differently \$\endgroup\$ Commented Dec 5, 2022 at 22:22
5
\$\begingroup\$

Salacious Bacon Tripod

\$\endgroup\$
5
  • \$\begingroup\$ So Bad Task (not saying it bad but this fits SBT) \$\endgroup\$
    – l4m2
    Commented Jan 24, 2023 at 11:19
  • \$\begingroup\$ Do I understand correctly, that acronyms at the beginning and end of the text won't be replaced (as aren't surrounded by spaces)? \$\endgroup\$
    – pajonk
    Commented Jan 24, 2023 at 13:23
  • \$\begingroup\$ @pajonk that was an unintended consequence of trying to make it so that words are "letters surrounded by a gap". I've fixed that now. \$\endgroup\$
    – lyxal
    Commented Jan 24, 2023 at 13:27
  • 1
    \$\begingroup\$ Another thing, will the acronym consist only of distinct letters? \$\endgroup\$
    – pajonk
    Commented Jan 24, 2023 at 13:42
  • \$\begingroup\$ @pajonk I've added that clarification to the challenge \$\endgroup\$
    – lyxal
    Commented Jan 26, 2023 at 0:34
5
\$\begingroup\$

Is it a valid chemical?

\$\endgroup\$
5
  • 2
    \$\begingroup\$ What if it's only possible to construct multiple distinct molecules? e.g. [1, 1, 1, 1] (2H₂) \$\endgroup\$
    – Bbrk24
    Commented Mar 13, 2023 at 16:02
  • 2
    \$\begingroup\$ Suggested test case: [0] => true (to complement [0, 0] => false) \$\endgroup\$
    – Bbrk24
    Commented Mar 13, 2023 at 16:06
  • 2
    \$\begingroup\$ This challenge will help me pass chemistry \$\endgroup\$ Commented Mar 14, 2023 at 20:22
  • \$\begingroup\$ Suggested test case: [1, 2, 2, 2, 1], representing trioxidane. Though this molecule is too unstable, it's still truthy in this regard. \$\endgroup\$ Commented Mar 15, 2023 at 11:30
  • \$\begingroup\$ Also, this is just a minor nitpick, but ozone isn't shaped like a triangle. \$\endgroup\$ Commented Mar 15, 2023 at 11:31
5
\$\begingroup\$

Meccano construct a 17-gon

I recently read an interesting manuscript: Gerard ’t Hooft, Meccano Math I (2006)

I will summarize the key bits here and then present a bit of a challenge.

Meccano bars are metal strips with holes in them at integer lengths. A bar of length \$n\$ has \$n+1\$ holes evenly spaced along it. Two bars may be attached at a two of their holes to form a joint.

Simple joint with two bars

A configuration is rigid when there is exactly one way to connect the given bars at the specified holes. For example all triangles are rigid:

Rigid triangle

However quadrilaterals are nearly universally non-rigid:

Non-rigid quad

As the joints share a degree of freedom. All configurations with a degree of freedom are not rigid, however not all zero degrees of freedom configurations are rigid. For example

EXAMPLE HERE

Task

Your task is to produce a set of bars, along with their lengths and which holes are attached such that it forms a rigid construction, and 17 of the Meccano bars in your solution form the edges of a regular 17-gon.

Scoring

Your score will be the number of Meccano bars used in your solution, with ties being broken by the sum of their lengths. Your goal is to minimize your score.

\$\endgroup\$
1
  • \$\begingroup\$ Your example of a 0 dof system that isn't rigid can be a flattened triangular prism with all strips of equal length. There is some theory behind this – cf. Laman graphs. \$\endgroup\$ Commented May 10, 2023 at 10:46
5
\$\begingroup\$

How many sorting networks?

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

Sum of a range of a sum of a range of a sum of a range of a sum of a range of a sum of...

\$\endgroup\$
5
  • \$\begingroup\$ You'll probably get a comment saying "please add a description in plain English". \$\endgroup\$
    – Bubbler
    Commented Jul 5, 2023 at 1:09
  • \$\begingroup\$ @Bubbler oeis should have a good explanation \$\endgroup\$ Commented Jul 5, 2023 at 12:00
  • \$\begingroup\$ @Bubbler status-completed (tag rendering isn't that good) \$\endgroup\$ Commented Jul 5, 2023 at 12:04
  • \$\begingroup\$ <s>Then you can denote \$T(T(T(\cdots T(n)\cdots )))\$ into \$T^n(n)\$.</s> \$\endgroup\$
    – tsh
    Commented Jul 12, 2023 at 2:50
  • \$\begingroup\$ @tsh I forgot to link to the posted challenge… \$\endgroup\$ Commented Jul 12, 2023 at 7:34
5
\$\begingroup\$

Compute the convolution of two strings

\$\endgroup\$
1
  • \$\begingroup\$ I don't think it's been done or that it's too easy. I probably wouldn't tag it polynomials. It's enough to note the similarity in the problem description. It might be a good idea to have a test case with two non-empty inputs of non-equal lengths. \$\endgroup\$
    – chunes
    Commented Aug 2, 2023 at 8:16
5
\$\begingroup\$

Output an inversely proportional sequence

Inspired by Wheat Wizard's comment on my previous challenge. While that challenge requires having the ratio of consecutive integers grow arbitrarily large, this challengne requires the ratio growing arbitrarily small, a change that at first glance looks trivial but substantially changes the challenge. While most answers to the previous used a simple recursive formula, I haven't been able to find any simple closed-form formula for this.

In this challenge, an inversely proportional sequence is defined as a infinite sequence of positive integers such that:

  • All positive integers are contained infinitely many times within the sequence.
  • As more and more terms are added to the sequence, for all positive integers \$n\$, the ratio of the number of \$n+1\$s to the number of \$n\$s in the sequence must grow arbitrarily large.

I haven't been able to find a closed-form formula for such a sequence, but one possibility is the following (newlines added for clarity):

1,
1, 2, 2,
1, 2, 2, 2, [9 3s]
1, [4 2s], [16 3s], [64 4s]
...

Each line number \$n\$ contains \$1 \text{ 1}, n \text{ 2s}, n^2 \text{ 3s}\$ etc up to $n$. It's pretty easy to see why this satisfies the requirements: for example, the number of 1s in the first \$n\$ lines is \$n\$, and the number of 2s in the first \$n\$ lines is \$\frac{n(n+1)}{2} - 1\$. The quotient of these is \$\frac{\frac{n(n+1)}{2} - 1}{n} = \frac{(n+1)}{2} - \frac{1}{n}\$, which clearly grows arbitrarily large as \$n\$ goes to infinity. A similar argument can be made for all other pairs.

An example of an invalid sequence is this:

1,
1, 2, 2
1, 2, 2, 3, 3, 3, 3,
1, 2, 2, 3, 3, 3, 3, [8 4s]

Each line number \$n\$ contains \$1 \text{ 1}, 2 \text{ 2s}, 4 \text{ 3s} ... 2^n \text{ ns}\$. While this does contain every positive integer infinitely many times, and contains each positive integer less than the previous, it does not contain each integer infinitely less than the previous. In the limiting case, the sequence contains twice as many 2s as 1s, twice as many 3s as 2s, and so on.

Your challenge is to output any inversely proportional sequence. Standard rules apply - you may output as a function that takes \$n\$ and outputs the \$n\$th or first \$n\$ terms, or output an infinite sequence in some form. You may use 0-indexing or 1-indexing.

This is , shortest wins!

Meta

  • If you've found a closed-form (ish) formula for such a sequence I'd appreciate if you comment it.
  • Is this sufficiently different from the previous challenge? 6 people seemed to think it was.
\$\endgroup\$
2
  • 2
    \$\begingroup\$ The number of prime divisors is such a sequence. \$\endgroup\$ Commented Dec 30, 2023 at 8:31
  • 2
    \$\begingroup\$ As is the sum of digits (in any base \$\geq2\$) \$\endgroup\$ Commented Dec 30, 2023 at 8:47
5
\$\begingroup\$

Dedekind, cut!

Objective

Given a Dedekind cut of a real number \$x\$ and a positive integer \$n\$, print the real number represented by the Dedekind cut up to \$n\$ precisions, rounded.

Dedekind cut

A Dedekind cut representing a real number \$x\$ is a boolean-valued function on a dense set that gives a falsy value for rational numbers under \$x\$, and a truthy value otherwise. In this challenge, the dense set is \$\mathbb{Z}[0.1]\$, the rational numbers with terminating decimal expansion.

Note that Dedekind cuts can represent arbitrary real numbers. Irrational, nonconstructible, transcendental, or even uncomputable numbers.

Rules

  • Direction of rounding is implementation-defined.

  • For the inputted Dedekind cut, it shall be a black-box function accepting the decimal expansion (which is a string with an implementation-defined format) of elements in \$\mathbb{Z}[0.1]\$.

  • Invalid inputs fall in don't care situation. This also applies to the rational numbers the Dedekind cut accepts.

  • Output format is flexible. Outputting leading or trailing whitespaces is permitted.

  • For the output, all digits after the decimal point shall be considered significant in this regard. The amount of significant digits after the decimal point must be exactly \$n\$. Trailing zeros cannot be discarded.

Examples

  • For \$x = 0\$ and \$n = 2\$, output \$0.00\$.
  • For \$x = \frac{1}{4}\$ and \$n = 1\$, output \$0.2\$ or \$0.3\$.
  • For \$x = \frac{1}{2}\$ and \$n = 3\$, output \$0.050\$.
  • For \$x = \sqrt{2}\$ and \$n = 3\$, output \$1.414\$.
  • For \$x = -\pi\$ and \$n = 3\$, output \$-3.142\$. Note the rounding.

Ungolfed solution

Haskell

An implementation with exponential time complexity.

import Text.Printf

showDedekind :: (String -> Bool) -> Int -> String
showDedekind x n = go2 0 where
    go1 :: Int -> Int -> String
    go1 m i = let
        s1 = printf "%+0*d" m i
        (s2, s3) = splitAt (length s1 - m) s1
        in s2 ++ (if elem (last s2) "0123456789" then "" else "0") ++ '.' : s3
    go2 i = case (x (go1 (n + 1) (10 * i - 5)), x (go1 (n + 1) (10 * i + 5))) of
        (False, False) -> go2 (i + 1)
        (False, True) -> go1 n i
        (True, True) -> go2 (i - 1)
        _ -> error "This is not a Dedekind cut"
\$\endgroup\$
2
  • 3
    \$\begingroup\$ So to be precise, the input value x is actually given as a black-box function, right? For output format, I recommend to keep it simple. You can even omit it entirely so that we can assume a convenient format for each language in use (under default I/O rules). Should the solutions theoretically support arbitrarily large x (with both signs)? \$\endgroup\$
    – Bubbler
    Commented Mar 2, 2021 at 9:08
  • \$\begingroup\$ 1. Your first and 3rd test cases with n=0 don't fit the specification ("positive integer n"). 2. What is the scoring criterion? \$\endgroup\$
    – pajonk
    Commented Apr 20, 2023 at 7:45
5
\$\begingroup\$

Ways to paint a backbone on a tree

\$\endgroup\$
10
  • \$\begingroup\$ last sentence doesn't end but presumably you at least want to allow adjacency lists and maybe graph objects/classes too? \$\endgroup\$
    – RubenVerg
    Commented Aug 1 at 7:17
  • \$\begingroup\$ @RubenVerg Adjacency matrices, built-in graph objects, lists of vertices/edges - I'm not sure if there's anything else I could allow specifically for unlabelled graphs \$\endgroup\$
    – emanresu A
    Commented Aug 1 at 7:24
  • \$\begingroup\$ Adding common representations should work fine. \$\endgroup\$
    – Bubbler
    Commented Aug 1 at 8:01
  • \$\begingroup\$ Is there a standard definition of what it means for a backbone to be "the same up to rearrangement"? \$\endgroup\$ Commented Aug 2 at 21:12
  • \$\begingroup\$ @shapewarriort That one graph can be rearranged into the other by moving its nodes around. \$\endgroup\$
    – emanresu A
    Commented Aug 2 at 21:16
  • \$\begingroup\$ @emanresuA By moving the nodes around? I can kind of see what that means, assuming moving the nodes around keeps the node connections and colours the same, though it's not the easiest to visualize. Seems like something vaguely connected to graph isomorphism. \$\endgroup\$ Commented Aug 2 at 21:25
  • 1
    \$\begingroup\$ @shapewarriort It is graph isomorphism, yes, just only distinguishing nodes by whether they're coloured or not \$\endgroup\$
    – emanresu A
    Commented Aug 2 at 21:26
  • \$\begingroup\$ Not sure if this is common practice, but now that the challenge is no longer WIP, I've reset my voting standards accordingly. The biggest thing right now is that, in the vertex pairs for the last test case, [9,12] should be [11,12]. Other than that, matching up the vertex pairs with the images was not terribly hard, though it took me some time to find vertex 1 in the second test case, especially since [3,7] comes so late in the list. I'm assuming the specific data types for the input don't matter, and we are allowed to, say, use a dict[tuple[str, str], bool] as an adjacency matrix? \$\endgroup\$ Commented Aug 14 at 3:13
  • 1
    \$\begingroup\$ @shapewarriort a) fixed b) the vertex pairs are mostly meant to be a machine-readable format c) Yes, and that's allowed in general under standard I/O. \$\endgroup\$
    – emanresu A
    Commented Aug 14 at 3:16
  • \$\begingroup\$ In that case, no further suggestions from me! \$\endgroup\$ Commented Aug 14 at 3:20
5
\$\begingroup\$

Simplified canvas builtin

\$\endgroup\$
2
  • \$\begingroup\$ Instead of [0-7] can we use the numpad or vi keys? \$\endgroup\$
    – roblogic
    Commented Sep 29 at 5:03
  • 1
    \$\begingroup\$ @roblogic Numpad, sure (I've allowed any subset of [0, 10]), vi keys no because a) I can't see how it'd be useful/golfy b) I'm avoiding allowing taking arbitrary inputs for directions because it's exploitable c) I'm trying to keep the challenge spec somewhat tight \$\endgroup\$
    – emanresu A
    Commented Sep 29 at 5:17
5
\$\begingroup\$

Bouba or Kiki

In Psychology, the Bouba/Kiki Effect refers to the non-arbitrary associations between sounds and shapes. The traditional example shapes are a spiky blob, an a rounded blob ~Image of Spiky and Round Blobs~ Source: Wikipedia CC BY-SA

Humans seem to have an innate understanding of what should be Bouba and what should be Kiki, and our machines deserve the same insights.

The challenge

Given two images, determine which of the two images is more "Bouba", and which is more "Kiki".

As this is a non-objective property of the images, users are encouraged to vote for answers which they feel are most correct for any given images.

As this is , the answer with the most votes wins!

Test Cases

Sandbox Notes

  • Will this get crushed like many other pop-cons?
\$\endgroup\$
4
\$\begingroup\$

BlackJack Part II

Repost from the original sandbox

As I had a blast working on the original KOTH challenge, I wanted to come up with another. For me, the fun of these AI challenges is in refining a comparatively simple bot which plays a very simple game subtly. Due to the probabilistic nature of card games, I think that blackjack could be an interesting KOTH game just like TPD.

Rules

  • Bots play at tables of four (4) competitors and one (1) dealer
  • One (1) shoe is shared by all players and the dealer until it is exhausted, at which point a new randomly shuffled deck will be added and play will continue. The bots ARE NOT (at present) NOTIFIED of the addition of this new deck. [TODO? would make card-counting a LOT harder...]
  • There is a buy-in of 10 per round, and cards are free
  • There is no bet maximum as bets are between the player and the house, yet the bot must have sufficient chips to immediately finance the bet.
  • Perfect/ideal hand has a score of 21
  • All face cards have a value of 10
  • All numeric cards are worth their number
  • Aces are worth 11 or 1. this will be dealt with automatically by the framework, not the bots.
  • Scores in excess of 21 which use an ace as 11 force the ace to reduce in value to 1 scores in excess of 21 which cannot be coerced below the threshold of 21 "bust" the bot
  • The dealer draws until he busts, or excedes a score of 17.
  • The stake is subtracted from chips, so the chips value is the number of credits which are available to the bot for betting.

Dealing and Bot Moves

  1. When the game starts, each player is iteratively dealt one card, and has the $10 buy-in fee/minimum bet subtracted from their chips.
  2. Then (in the same order as they were dealt to) each bot is executed as described in the "Programmer's Interface" section and must make a move or stand. Betting is considered a move. NOTE THAT BETTING DOES NOT AFFECT BOTS' ABILITY TO MAKE FURTHER MOVES. It is very possible to bet and then draw a card, and it is possible to draw multiple cards and them bet before standing.

Programmer's Interface and Legal Moves

As documented in the CardShark class:

#   DOCUMENTATION
#       INPUT SPECIFICATION
#          $ ./foo.bar <hand-score> <hand> <visible cards> <stake> <chips>
#          <hand-score>     is the present integer value of the player's hand.
#          <hand>           is a space-free string of the characters [1-9],A,J,Q,K
#          <visible cards>  every dealt card on the table. when new shoes are brought
#                           into play, cards drawn therefrom are simply added to this list
#                           !!! THE LIST IS CLEARED AT THE END OF HANDS, NOT SHOES !!!
#          <stake>          the  number of chips which the bot has bet this hand
#          <chips>          the number of chips which the bot has
#       SAMPLE INPUT
#          $ ./foo.bar 21 KJA KQKJA3592A 25 145
#
#       OUTPUT SPECIFICATION
#          "H"|"S"|"D"|"B"  (no quotes in output)
#          "H"              HIT - deal a card
#          "S"              STAND - the dealer's turn
#          "D"              DOUBLEDOWN - double the bet, take one card. FIRST MOVE ONLY
#          "B 15"           BET - raises the bot's stakes by $15.

Winner Selection

The winner would be the author of the bot which consistently accrued the most chips over a yet-to-be determined number of tables and rounds.

Code Review github

Issues & ToDo

None! (no known problems at least)

PS. How do I tag questions/answers? thanks @dmckee [ai-player] [card-game] [koth]

Version History

5/25 - 0020 - v1 - updated code on GitHub which fixes a bug with the dealer. DD still scores monstrously for unknown reasons. tagged this post (with any luck).

5/25 - 0800 - v2 - bugfix on github which correctly implements DoubleDown, resulting in drastically reduced scores from the double-nut bot.

5/25 - 0920 - v3 - updated the test case to match the input specification. Added the rules for the dealer.

5/25 - 1100 - v4 - added a description of the table and shoe system.

5/25 - 1620 - v5 - added an explanation of the betting and card-dealing system, major status update.

5/27 - 1700 - v6 - ready to roll the contest...

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Tags: [ai-player] and [card-game] seem naturals, though neither exists on the site as yet. What else? \$\endgroup\$ Commented May 25, 2011 at 4:00
  • 1
    \$\begingroup\$ The SAMPLE INPUT isn't consistent with the INPUT SPECIFICATION - do the args include the current score or not? How many decks of cards should we assume to be used? Does <chips> include <stake>? How does the AI dealer play? Is each bot-dealer pair using a separate shoe (so that when I stand the dealers cards are drawn fairly from all those not included in <hand> and <visible-cards>)? When does betting occur? \$\endgroup\$ Commented May 25, 2011 at 12:17
  • \$\begingroup\$ should players be notified of the number of decks in play, or not? The issue is that decks are dealt from until the deck is exhausted, then the "cannot pop from empty list" error signals the creation of a new shuffled deck then continues drawing as if nothing had happened. This means that multiple decks can be in play at once, but the statistical worst-case is that each player has three or four cards, which makes between fifteen and twenty samples split between two decks of 52. It shouldn't make a difference to score-based bots, but card-counters will need to detect or be notified of the chage \$\endgroup\$
    – arrdem
    Commented May 25, 2011 at 15:16
4
\$\begingroup\$

Given a text, determine the language it is written in. The possible languages are: English, Danish, Romanian and Hungarian. The shortest program wins.

Some examples of text in each language can be found at Project Gutenberg

You are required to include examples of runs on text files other than the ones provided here.

The input file name is given as a command line argument. Except the input text, you are not allowed read additional files (e.g. to train your program) so please encode any data in your program.

Your program must output on of the following words English, Danish, Romanian, Hungarian.

Examples

$ ./language pg2600.txt
English
$ ./langauge pg12167.txt
Danish
$ ./language 11756-0.txt
Romanian
$ ./language 30163-0.txt
Hungarian
\$\endgroup\$
6
  • \$\begingroup\$ Another source of plain text passages might be the Gutenburg project. They do have books in languages other than English. \$\endgroup\$ Commented Jun 22, 2011 at 14:53
  • \$\begingroup\$ Thanks. I updated the text problem to include some books from Gutenberg. \$\endgroup\$
    – Alexandru
    Commented Jun 22, 2011 at 15:04
  • \$\begingroup\$ Related \$\endgroup\$
    – Beta Decay
    Commented Sep 7, 2016 at 10:32
  • \$\begingroup\$ Looks pretty trivial to me. Any sufficiently long text will have ă if Romanian, ő if Hungarian, å if Danish, and neither if English. None of the special characters occur in any other of the four languages. \$\endgroup\$
    – Adám
    Commented Jun 5, 2017 at 10:45
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$
    – user58826
    Commented Jun 9, 2017 at 15:20
  • \$\begingroup\$ @programmer5000 The OP hasn't been seen since 2011, I think you're fine. \$\endgroup\$ Commented Jul 21, 2017 at 13:21
4
\$\begingroup\$

Metagolf: Catlike Piet

The goal of this is to write a catlike program, which would be executed (in a Unix environment, though you needn't stick to that) by the following:

yourprogram < file > output
piet output

where piet output writes the contents of file to stdout. That is, you're to generate a Piet program which prints the input to yourprogram.

One-liners

Straight line programs can be written in Piet... in straight lines. If you're willing to take a hit to your score, your output can take the form of a string of commands:

=  none (continue color block)
|  push
^  pop
+  add
-  subtract
*  multiply
/  divide
%  mod
~  not
>  greater
.  pointer
\  switch
:  duplicate
@  roll
$  input number
?  input character
#  output number
!  output character

which is trivial to convert to a Piet program with the following (partially golfed) Python code:

def P(s):
 h=v=0;l=len(s)+1;R="P3 %i 2 255 192 0 0 "%(l+2)
 C=[1,3,2,6,4,5];V=[0,192,192,255,0,255]
 for x in map("=|^+-*/%~>.,:@$?#!".find,s):
  C=C[x//3:]+C[:x//3];V=V[x%3*2:]+V[:x%3*2]
  for i in [1,2,4]:R+="%i "%V[(C[0]//i)%2]
 return R+"255 "*4+"0 0 "+"255 "*l*3+"255 0 0 "*2

The dimension of said program is (n+3) x 2 if there are n characters in the string.

Scoring

Your code will be judged on the maximum dimension of the images that it outputs.

  • Part 1: Take the maximum score taken over all ascii codes (that is, single-character inputs), discounting EOF.

  • Part 2: Take the score for the input "Hello. My name is Inigo Montoya. You killed my father. Prepare to die."

Your score is the product of the scores in part 1 and part 2.

Punishment: Double your score if you write one-liners as above (that is, if you don't output an image).

Bonus: If your program is written in Piet, take the square root of your score above.

\$\endgroup\$
4
  • 4
    \$\begingroup\$ It took me a while to understand the task as "Write a program taking INPUT which produces as output a piet program that takes no input but produces INPUT." I think it is a interesting and challenging, but it's reception will depend entirely on how many people are willing to learn/futz-around-in/deal-with piet. And I have no feel for how many that is. \$\endgroup\$ Commented Jul 7, 2011 at 3:12
  • \$\begingroup\$ @dmckee; would it be better if I just used a reduced instruction set, and only ask for the instruction stream? I think this is still challenging with {push 1,duplicate,add,subtract,multiply,output}. Come to think of it, if I restrict to {push 1,duplicate,add,output}, there's a reduction to some awesome algorithms. \$\endgroup\$
    – boothby
    Commented Jul 7, 2011 at 4:48
  • \$\begingroup\$ I did this in piet some time ago: craigoclock.blogspot.com/2011/05/metaprogramming-in-piet.html \$\endgroup\$
    – captncraig
    Commented May 21, 2012 at 18:31
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$
    – user58826
    Commented Jun 9, 2017 at 15:22
4
\$\begingroup\$

Count unique characters in text.

Given a string for input, output the unique non-whitespace characters in that string along with a count of their occurrences. The list should be sorted in ascending order of ASCII code.

Examples

Input:

Hello, World!

Output:

Character    Count
!            1
,            1
H            1
W            1
d            1
e            1
l            3
o            2
r            1

Input:

The quick brown fox jumps over the lazy dog.

Output:

Character    Count
.            1
T            1
a            1
b            1
c            1
d            1
e            3
f            1
g            1
h            2
i            1
j            1
k            1
l            1
m            1
n            1
o            4
p            1
q            1
r            1
s            1
t            1
u            1
v            1
w            1
x            1
y            1
z            1

The actual formatting (headers, spacing, etc) of the on-screen output is up to you. The only conditions are that it must be sorted in ascending order by ASCII code, and it must be easy to tell what represents a character from the string and what represents a count of a given character. (For example, given a string of 99999999, the output should be explicit so that it is not confused as saying I have 9 8s.)

Ultimate challenge (taken from here):

JKqdJg+oJgiowgyIJgkS+gyxJdeS+gyxJ4yoJdybJdioJdqIJ4kS+KwFJ4QS+gzYJg+ow4vIJ4yxvd+IJgy=+dv=JdQx+gzbJrzx24zYJgkxJ4qLJKQxJ4yxJKqx+KqdJKqdJg+oJgiowgyIJgkS+gyxJdeo24yxJm+xJdybJdioJdqIJKi=J4wF+dvS+gzYJg+ow4zYJ4yxvdy=J4i=+Kv=JdQo+KqxJrzdJKzYJgkxJ4qLJgkxJ4yxJKvSJ4qbJKqdJg+oJgiowgyIJgkdJgyxJdeo24yxJm+xJdybJd+oJd+S+dz=J4wF+dvS+g+SJg+ow4vIJ4yxJ4voJgy=+dv=+dzdJgqxJrzdJKzYJgkS+dweJKQxJ4yxJKvSJ4qbJKq=24yYJgiowgyIJgkdJgzdJryo24yxJm+d24zxJd+oJdqIJ4kS+KwFJ4QS+gzYJ4y=2gzYJ4yxJ4voJgy=+dv=+dzdJgqxJrzx24zYJgkS+dweJKQxJ4fK+dQSJ4qbJKq=24yYJgiowgyIJgkS+gzdJryS+gyxJ4yoJdybJd+oJd+S+dz=J4wF+dvS+gzYJ4y=2gvIJ4yxJ4voJgy=+dv=JdQo+KqxJrzx24zY+dzS+dweJKQxJ4yxJKqx+KqbJKq=24vbJdyowgyIJgkdJgzdJryS+gyxJm+d24zxJdioJd+S+dz=J4wF+dvS+gzYJg+ow4vIJ4yxJ4voJgy=+Kv=JdQx+gzbJrzx24zYJgkS+dweJgkxJ4yxJKvSJ4qdJKq=24yYJgiowgyIJgkdJgzdJryS+gyxJ4yoJdybJd+oJdqIJKi=J4wF+dvS+gzYJg+ow4vIJ4yxJ4v=J4i=+Kv=+dzdJgqxJrzx24zYJgkS+dweJgkxJ4fKJ4qx+KqdJKqdJg+SJdyowg+oJgkS+gyxJdeS+gyxJ4yoJdybJd+oJdqIJ4kS+KwFJ4QS+g+SJ4y=2gzYJ4yxJ4v=J4i=+Kv=JdQo+KqxJrzx24zY+dzS+dweJKQxJ4yxJKvSJ4qbJKqdJg+oJgiowg+oJgkS+gzdJryo24yxJ4yoJdybJdioJdqIJ4kS+KwFJ4QS+g+SJg+ow4vIJ4yxvd+IJgy=+dv=JdQo+KqxJrzdJKzY+dzxJ4qLJKQxJ4yxJKqx+KqdJKq=24vbJdyowg+oJgkS+gzdJryo24yxJ4yoJdybJdioJd+S+dz=J4wFJ4QS+gzYJg+ow4zYJ4yxvd+IJgy=+Kv=+dzdJgqxJrzdJKzYJgkxJ4qLJgkxJ4yxJKvSJ4qbJKq=24vbJdyowgyIJgkdJgyxJdeo24yxJm+xJdybJd+oJdqIJKi=J4wF+dvS+g+SJ4y=2gvIJ4yxvd+IJgy=+dv=+dzdJKzbJrzdJKzY+dzS+dweJgkxJ4yxJKvSJ4qbJKq=24yYJgiowg+oJgkS+gyxJdeo24yxJ4yoJKzxJd+oJdqIJKi=J4wF+dvS+gzYJg+ow4vIJ4yxJ4v=J4i=+dv=+dzdJgqxJrzx24zYJgkxJ4qLJKQxJ4fKJ4qx+KqdJKqdJg+oJgiowgyIJgkS+gzdJryS+gyxJm+d24zxJd+oJdqIJKi=J4wFJ4QS+gzYJ4y=2gzYJ4yxvdy=J4i=+Kv=+dzdJKzbJrzx24zY+dzxJ4qLJKQxJ4yxJKqx+KqdJKqdJg+SJdyowg+oJgkdJgzdJryo24yxJm+d24zxJd+5

\$\endgroup\$
5
  • \$\begingroup\$ This isn't really an interesting problem. The shortest answer is almost certainly going to be fewer than 10 characters. \$\endgroup\$ Commented Dec 11, 2013 at 12:19
  • \$\begingroup\$ @PeterTaylor While I mostly agree with your comment - already the header line may contain more than 10 characters. \$\endgroup\$
    – Howard
    Commented Dec 12, 2013 at 6:15
  • \$\begingroup\$ "The quick brown fox jumps over the lazy dog." contains "e" three times. \$\endgroup\$
    – Howard
    Commented Dec 12, 2013 at 6:16
  • \$\begingroup\$ @Howard Thanks. I must be blind - it took me about five times of reading your comment to find it. Also, do remember that the header is optional to a certain degree - you just need to make sure the output is unambiguous as to which items are characters from the string, and which are character counts. \$\endgroup\$
    – Iszi
    Commented Dec 12, 2013 at 7:02
  • \$\begingroup\$ My brain instantly went into bash mode. wc and uniq practically solve half of this, but not in any particularly short manner. \$\endgroup\$
    – Rob
    Commented Dec 17, 2013 at 20:31
1
6 7
8
9 10
162

You must log in to answer this question.

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