457
\$\begingroup\$

What is the Sandbox?

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

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

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

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

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

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

\$\endgroup\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 at 15:19

2528 Answers 2528

0
\$\begingroup\$

Make a bigger number

Each answer on this question must be a complete program (not a function) that outputs a positive integer in decimal (trailing newlines are permitted). Output should be either passed to STDOUT or displayed on the screen. The output number must also be larger than all the numbers output by all the valid answers at the time of posting. One person may not post two consecutive answers.

Scoring

Your answer will be scored with the following formula

\$\dfrac{B'+1}{B+1}\$

Where \$B\$ is the number of bytes in your answer and \$B'\$ is the number of bytes in the longest answer before your answer posted by someone other than yourself. Lower scores will be better.

\$\endgroup\$
  • \$\begingroup\$ Could you please clarify some more rules? E.g, in these sorts of challenges, using the same languages twice is prohibited. Even if you're fine with it, just clarify that to avoid confusion. Also, state when it will end and whether a lower/higher score is better. Further, some languages don't have an 'integer' type, while others have many - how could they get around this? \$\endgroup\$ – Geza Kerecsenyi Jul 9 at 20:19
  • \$\begingroup\$ @GezaKerecsenyi Prohibiting double language use is only used in specific scenarios it is in general it tends to be very bad rule to have as it only causes confusion. I definitely do not see it as the default and I don't want to give the impression that it is. Since programs have to be complete for this challenge (we are viewing programs as black boxes) types should not be a problem. Maybe I need to make this clearer in the post. And on the lower vs higher, that is definitely something important I was missing. Thanks! \$\endgroup\$ – Sriotchilism O'Zaic Jul 9 at 21:08
  • \$\begingroup\$ Answer chaining questions should have some inherent mechanism whereby it gets harder to answer over time. As it stands, this can run forever. \$\endgroup\$ – Peter Taylor Jul 10 at 13:43
  • \$\begingroup\$ @PeterTaylor I was under the impression that later answers would get harder because those challenges have scoring mechanisms that benefit later answers. \$\endgroup\$ – Sriotchilism O'Zaic Jul 10 at 13:51
  • \$\begingroup\$ I'm not certain that I'm interpreting that comment correctly. The answer chaining challenges I've participated in didn't have scoring per se, but "the penultimate answer wins". \$\endgroup\$ – Peter Taylor Jul 10 at 15:01
  • \$\begingroup\$ @PeterTaylor I was being a bit more general in my statement but that is the specific mechanism that I see a lot. \$\endgroup\$ – Sriotchilism O'Zaic Jul 10 at 15:01
  • \$\begingroup\$ Hm... actually, Peter Taylor's point isn't entirely wrong. An issue I can see is that the scoring formula will probably end up making each answer at least exponentially longer than the previous one, and that two or more people could actually duel just by adding more bytes to their code, e.g. A: 50000 9s, B: 5E50 9s, A: 5*10^99E99 9s, etc. In my opinion, the previous scoring formula (\$\frac{B_{n-1}+1}{B_n+1}\$) was much better, but with the highest score being the leader. \$\endgroup\$ – Erik the Outgolfer Jul 10 at 17:24
  • \$\begingroup\$ I think I can parse that response, but I don't get the subtext at all, so I'll rephrase my point as a question in the hope of eliciting a concrete response: what prevents two people from spinning this out to infinity just by copying the previous answer and adding +1? \$\endgroup\$ – Peter Taylor Jul 12 at 10:49
  • \$\begingroup\$ @PeterTaylor In my mind two things 1) it probably won't get them better scores 2) it wouldn't be very fun. I am a little concerned though since these are not excellent motivators. I am going to think about other scoring mechanisms that might further disincentivise this. Or perhaps some restrictions on answers. \$\endgroup\$ – Sriotchilism O'Zaic Jul 12 at 13:34
0
\$\begingroup\$

Output Ordinal Numbers up to n

Moved to Output Ordinal Numbers up to n.

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

Write an X-SAMPA Interpreter

Tags:

Write an X-SAMPA interpreter that, when given an X-SAMPA string, outputs an IPA string.

Some Background

SAMPA is a system for encoding sounds from various languages into a computer-readable ASCII format. X-SAMPA is a descendant that encodes the International Phonetic Alphabet (IPA) instead. The IPA is a character set that represents (almost) all sounds that a human can make. A large majority of IPA is based on the usual Latin character set (a-z), along with some supplementary characters (θ ʌ ŋ χ, etc.).

The Challenge

  • Input is a string of X-SAMPA.
  • Translate the X-SAMPA string into IPA.
  • Output is a string of IPA.
  • Input and output can be given using any convenient method.
  • Standard loopholes are forbidden.
  • X-SAMPA charts can be found here.
  • Characters not defined in X-SAMPA should be ignored.
  • You must implement the entirety of X-SAMPA.
  • This is so lowest in bytes wins.

Samples

this is a test input --> this is a test input
THIS IS A TEST INPUT --> θɥɪʃ ɪʃ ɑ θɛʃθ ɪŋʋʊθ
H\El\L\0 W@R1d --> ʜɛɺʟ0 ʍəʁɨd
123456789 --> ɨøɜɾɫɐɤɵœ
d_"i_+a_-c_/r_/i_0t_hi_=c_>s_?\ --> d̈i̟a̠čři̥tʰi̩cʼsˤ
Code GO\lf & CodI\ng Challen\ges\ --> çode ɣʘlf ɶ çodᵻnɡ çhallenɡeɕ
clicks O\|\ǃ\=\|\|\ --> clicks ʘǀǃǂǁ
mixed~!@#$%^&*(){}[]<>,.?/:;"' --> mixed#$ˌ^ɶ*(͡æʉ[]<>,.ʔ
impl ejec b_<p_> --> impl ejec ɓpʼ
\$\endgroup\$
  • 3
    \$\begingroup\$ Way too many edge cases here: What about supporting impossible diacritics i.e. a character marked both syllabic and nonsyllabic? The charts should be included so the challenge is self-contained. \$\endgroup\$ – lirtosiast Jul 17 at 15:49
  • 1
    \$\begingroup\$ I was considering omitting You must implement the entirety of X-SAMPA and instead needing to implement only a subset, namely not the diacritics. \$\endgroup\$ – bigyihsuan Jul 17 at 16:11
  • 1
    \$\begingroup\$ "Input is a string of X-SAMPA" makes "characters not defined in X-SAMPA should be ignored" redundant \$\endgroup\$ – trichoplax Jul 28 at 19:27
0
\$\begingroup\$

The Acrobat Competition

Anyone may post this to main once this question is done. I only care about people enjoying solving problems. (I do not want the reputation for this question.)

After someone cloned so many Jimmy's to disrupt the world, Jimmy started to be stressed about the existence of his dwarf forms; his circus leader started to ignore him, focus on the dwarves, and gradually gave him less salary.

He has to win an acrobat competition to gain attention from his leader again. (He does care about his salary.)

Input/Output

The first line of input will contain the acrobatic power of Jimmy; it is represented as Jimmy's (/o\) separated with spaces; invalid Jimmy's should be ignored.

After this line, there are two lines of dwarf Jimmy's also represented by their shapes: (o); invalid dwarf Jimmy's should be ignored.

The combined power between two dwarf (x as the top line of dwarf Jimmys and y as the bottom line of dwarf Jimmys) is √x²+y² (the exact floating-point number).

If Jimmy's acrobatic power is larger than the two dwarf Jimmy's, output a truthy value. Otherwise, output a falsy value.

Example input/outputs

This outputs a falsy value:

/o\ // o /o\ o o\ //o\\ /o\ /o\ /o\
o o o o
/o\ l o j oe o lo . o aso o feo o

This outputs a truthy value:

/o\/o\ /o\ /o\ /o\ /o\ /o\ /o\
o	o o 	 o
o	o o o	o o oo o o o o
\$\endgroup\$
  • \$\begingroup\$ two dwarf Jimmy's should be two lines of dwarf Jimmy's? \$\endgroup\$ – bigyihsuan Jul 22 at 19:40
  • \$\begingroup\$ You should probably work through an example because I'm not sure what x and y relates to. Is x the number of dwarves in the top line, and y the number in the bottom? \$\endgroup\$ – Veskah Jul 23 at 19:55
  • \$\begingroup\$ @Veskah It looks that way. \$\endgroup\$ – wizzwizz4 Jul 24 at 18:37
0
\$\begingroup\$

Insert an exclamation mark between everything

This challenge is highly "distilled" from this question. Special thanks to Akababa!

In this task, you should insert an exclamation mark at the start of the string and after every character.

Rules

  • There will always be a non-empty-string input. The input will not contain tabs either. You can assume that the input only contain non-extended ASCII printable characters and newlines.
  • This is a contest; the shortest answer should win.

Examples

  • 4 newlines result in 5 newline-delimited exclamation marks. It is very hard to put this as a Markdown text, so this is stated instead.
1 2 3 4 5 6
129591 129012 129127 129582

0

Outputs

!1! !2! !3! !4! !5! !6!
!1!2!9!5!9!1! !1!2!9!0!1!2! !1!2!9!1!2!7! !1!2!9!5!8!2!
!
!0!
asd afjoK ak:e
kPrLd
    fOJOE;
    KFO
KFkepjgop sgpaoj   faj

Outputs

!a!s!d! !a!f!j!o!K! !a!k!:!e!
!k!P!r!L!d!
! ! ! ! !f!O!J!O!E!;!
! ! ! ! !K!F!O!
!K!F!k!e!p!j!g!o!p! !s!g!p!a!o!j! ! ! !f!a!j!

A base test case with only one character:

a

Outputs

!a!

(Auto-completion! Just kidding, there is no such thing.) Contains exclamation marks:

!!
!!
!!
!!
!!

Outputs:

!!!!!
!!!!!
!!!!!
!!!!!
!!!!!


\$\endgroup\$
  • 2
    \$\begingroup\$ "replace the null character with an exclamation mark" is misleading. Better wording is "insert an exclamation mark at the start of the string and after every character", though there could be something more concise. The challenge is rather simple but viable. \$\endgroup\$ – lirtosiast Jul 28 at 4:37
  • 2
    \$\begingroup\$ You seem to have issues with markdown in the examples: One of your examples have tabs, but they render as four spaces which is very confusing. You can have actual tabs render by using &#9; instead of literal tabs. Your empty input collapses to zero lines which you can fix by inserting a space which won't render. The output for that case does have a space, which is wrong. \$\endgroup\$ – Adám Jul 28 at 7:17
  • 1
    \$\begingroup\$ For the 3rd example, which shows no visible input, it's worth specifying what the input is so it's obvious at a glance. Also, the output contains only one exclamation mark, suggesting there are zero characters in the 3rd input, which appears to conflict with "There will always be a non-empty input". Could you clarify what "non-empty" means? Depending on their programming language background, some people will not regard the empty string as "non-empty" so this could be confusing. \$\endgroup\$ – trichoplax Jul 28 at 18:14
  • 1
    \$\begingroup\$ If the input can contain newlines, it's worth including test cases that include newlines too. Perhaps a multiline input and also one composed solely of newlines \$\endgroup\$ – trichoplax Jul 28 at 18:17
  • 1
    \$\begingroup\$ May input contains exclamation marks? \$\endgroup\$ – tsh Jul 29 at 5:01
  • \$\begingroup\$ @tsh Yes, I added a test case. Exclamation marks are printable ASCII characters. \$\endgroup\$ – A _ Jul 29 at 5:37
  • \$\begingroup\$ Oh no, I forgot to add an objective winning criterion! Does anyone have suggestions about the criterion?(I will go with code-golf temporarily.) \$\endgroup\$ – A _ Jul 29 at 7:14
  • 1
    \$\begingroup\$ I would indeed suggest code-golf. As for the test case of only newlines. Why are there seven newlines in the input, but only five exclamation marks in the output? I would expect eight exclamation marks instead. \$\endgroup\$ – Kevin Cruijssen Jul 29 at 8:52
  • \$\begingroup\$ There should only be 4 in the sample input. I seem to have problems with Markdown. \$\endgroup\$ – A _ Jul 29 at 8:59
  • 1
    \$\begingroup\$ @A__ Yeah, the markup can be a bit annoying at times. Using <pre><code>4 newlines</code></pre> makes it somewhat better, but not much. Maybe simply stating 4 newlines result in 5 newline-delimited exclamation marks is enough. Anyway, I've prepared two solutions for when it goes to main. \$\endgroup\$ – Kevin Cruijssen Jul 29 at 9:11
  • 1
    \$\begingroup\$ @KevinCruijssen I can not ask this question on main, as my question asking limit was reached. You may want to post this question yourself if you wish. \$\endgroup\$ – A _ Jul 29 at 9:31
  • 1
    \$\begingroup\$ Didn't even knew there was such a thing, but apparently there indeed is. Probably because some of your challenges were confusing at first so people down-voted/close-voted before it was fixed after 20+ edits. Let's leave it in the Sandbox for now. Not sure if your question ban could be lifted somehow. Also, if I post this challenge myself I can't really post my two answers, since it's usually best to wait a few days before answering your own challenges. ;) \$\endgroup\$ – Kevin Cruijssen Jul 29 at 9:42
  • 1
    \$\begingroup\$ I am puzzled as to why you're question-banned. Although you have some downvotes and deleted questions (not as much of an issue on our well moderated site), you have multiple questions with positive score. Seems the algorithm should change. \$\endgroup\$ – lirtosiast Jul 29 at 20:27
  • \$\begingroup\$ @KevinCruijssen Answering your own questions seems to be fine. There seems to be no problems arising when jimmy23013 answered their own question immediately after they asked it. \$\endgroup\$ – A _ Jul 30 at 0:04
  • 1
    \$\begingroup\$ @A__ That's a tip question. :) For an actual challenge it would be weird posting your own solution before giving other users with the same programming language a chance first. \$\endgroup\$ – Kevin Cruijssen Jul 30 at 7:24
0
\$\begingroup\$

Give me the jitters! / Add noise to data

When graphing data, it can often be helpful to display points as a scatterplot, but when duplicate data exist, you'll have multiple points graphed on top of one another. For fairness, we break ties at random with R's jitter function.

Inputs

  • x, a numeric (floating point) array. There will be at least 3 distinct values in the array.
  • factor, a numeric value
  • amount, a numeric value or some sort of non-numeric value (your choice). You may select your desired non-numeric sentinel value for amount.

Output

  • A single array y where:
    • y[i] = x[i] + a uniformly random number from -a to a

a is defined as follows:

  • Let z = max(x) - min(x)
  • If amount==0, a = factor * z/50
  • If amount is NULL or the , a = factor * d/5 where d = min(diff(sort(unique(x)))), i.e., the smallest difference between adjacent unique values.
  • Otherwise, a = amount.

Add test cases

Does this add anything beyond already existing challenges?

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

Output your place


Your challenge is simple. Output your program's place as an integer at the time of execution. The shortest program is first place, and the earlier submission wins a tie.

If your solution is tied with another in age as well as length, you may output either

All answers must begin with # [Language Name], [N] bytes alone on the first line.

You may access this page (URL). No URL shorteners are allowed. Standard IO and loophole rules hold.

As you may have noticed, this is , so the shortest answer (in bytes) wins. Happy golfing!

\$\endgroup\$
  • \$\begingroup\$ This will be very hard to test, no? So each program needs to find "its" post or at least have its own byte count and time stamp hard-coded? \$\endgroup\$ – Adám Jul 31 at 20:14
  • \$\begingroup\$ @Adám Correct. It'll be interesting to see how those two approaches fare, I hope. \$\endgroup\$ – Khuldraeseth na'Barya Jul 31 at 20:23
  • \$\begingroup\$ You might want to specify 1 indexing for clarity. \$\endgroup\$ – Sriotchilism O'Zaic Aug 1 at 14:03
  • \$\begingroup\$ @SriotchilismO'Zaic The shortest program is first place was meant to specify that. Too subtle? \$\endgroup\$ – Khuldraeseth na'Barya Aug 1 at 18:53
  • \$\begingroup\$ Ah I thought that was intended to say that it was code-golf. I think it is likely clear. \$\endgroup\$ – Sriotchilism O'Zaic Aug 1 at 18:54
  • 1
    \$\begingroup\$ 0 bytes, output is 0 indexed. or 0 bytes, outputs via exit code \$\endgroup\$ – Jo King Aug 2 at 4:13
  • \$\begingroup\$ @JoKing I thought of that. Some minutes searching TIO yielded nothing, unfortunately. \$\endgroup\$ – Khuldraeseth na'Barya Aug 2 at 4:14
  • 4
    \$\begingroup\$ From experience, questions like this need to be very explicit about what assumptions can be made about the context in which the answers are executed, because otherwise there will be debates on whether JS programs can execute in the console of a browser window which is currently open on the page. \$\endgroup\$ – Peter Taylor Aug 2 at 7:36
0
\$\begingroup\$

Buffer Evaluation

Given a printable ASCII string, but with leading spaces(0x20) and backspaces(0x08), return it "buffer-evaluated".

Input

For the inputted line, if you encounter a space, enter a space; otherwise, remove the rightmost character.

If you encounter a backspace when the buffer is empty, simply do nothing.

Output

After the inputted program, if the cursor is 0, output an optional trailing newline. If the cursor is not 0, output the string in the buffer and an optional trailing newline.

Example(s) and expected output

Rules

This is ; the shortest answer wins.


\$\endgroup\$
  • 1
    \$\begingroup\$ Please avoid adding unnecessary fluff like a cumbersome I/O format which just serves to make the challenge appear to be about layout when it is really just simple summing. \$\endgroup\$ – Adám Aug 9 at 6:06
  • 3
    \$\begingroup\$ This might be more interesting if there was no such thing as a negative buffer, and backspacing while at 0 did nothing, meaning it isn't just a simple sum of list anymore \$\endgroup\$ – Jo King Aug 9 at 6:09
  • 1
    \$\begingroup\$ @JoKing Good idea. Or maybe: Given a printable ASCII string, but with leading spaces and backspaces, return it "evaluated". E.g. "⌫⌫   ⌫hi" gives "  hi" \$\endgroup\$ – Adám Aug 9 at 6:16
  • \$\begingroup\$ Related \$\endgroup\$ – Adám Aug 9 at 6:39
  • \$\begingroup\$ Related, but not taking into account backspacing empty text. I don't like the special case of 0, since logically, the output should be an empty string, not a backspace \$\endgroup\$ – Jo King Aug 9 at 6:48
  • 1
    \$\begingroup\$ Regarding 0 → BS: Please avoid exceptional edge cases. \$\endgroup\$ – Adám Aug 9 at 7:08
  • \$\begingroup\$ Many languages will put a trailing line break after the output, further serving to indicate the the process has been completed. \$\endgroup\$ – Adám Aug 9 at 7:09
  • \$\begingroup\$ Your "Output " section seems to be a leftover from the previous version of the challenge: return it vs output how many \$\endgroup\$ – Adám Aug 9 at 7:11
0
\$\begingroup\$

Do X without Y

The goal is drawing an X on an empty 3x3 raster "canvas". You have to do so by drawing pixel by pixel, showing each intermediate step. But there should never be an Y visible along the way.

Details

  • You should start by outputting a 3x3 image of one background color. In each step one of the pixels must be changed to the foreground color.
  • You can use any two colors.
  • Instead of using pixels in an image, you can also use a string- (leading/trailing zeros/newlines are ok) or 2d-array/matrix representation.
  • An X is represented as follows:
o.o  (o = foreground, . = background)
.o.
o.o

while an y can be any of the following

o.o  o.o  ..o  o..  
.o.  .o.  .o.  .o.
o..  ..o  o.o  o.o

(title reference)

\$\endgroup\$
  • \$\begingroup\$ May we also toggle a foreground color back to a background color later on? I.e. would for example these steps be allowed (note the top-middle 'color'): (start:) ... ... ... > o.. ... ... > oo. ... ... > ooo ... ... > ooo .o. ... > ooo .o. o.. > ooo .o. o.o > (end/X:) o.o .o. o.o? Also, does the X have to be visible in the foregound color, or may it also be in the background color? I.e. would for example these steps be allowed: (start): ooo ooo ooo > o.o ooo ooo > o.o .oo ooo > o.o .o. ooo > (end/X:) o.o .o. o.o? \$\endgroup\$ – Kevin Cruijssen Aug 13 at 13:51
  • \$\begingroup\$ Remind me to upvote this question when it's posted; the title is just awesome \$\endgroup\$ – tjjfvi Aug 13 at 14:01
  • 1
    \$\begingroup\$ Wouldn't this work: 1.2 .5. 3.4 (... ... ... > o.. ... ... > o.o ... ... > o.o ... o.. > o.o ... o.o > o.o .o. o.o)? \$\endgroup\$ – tjjfvi Aug 13 at 14:03
  • 1
    \$\begingroup\$ -1. I don't think there's enough room for variance here. It basically reduces to a Kolmogorov complexity problem that is pretty simple in itself. \$\endgroup\$ – Beefster Aug 13 at 21:18
  • \$\begingroup\$ @tjjfvi Yes that would work. \$\endgroup\$ – flawr Aug 13 at 21:24
  • \$\begingroup\$ @Beefster I agree, as it is now it also felt a little bit too restricted. I honestly just wanted to come up with something silly to justify the title:) \$\endgroup\$ – flawr Aug 13 at 21:24
  • \$\begingroup\$ @KevinCruijssen That is an interesting extension. I think it would indeed make sense to abolish the idea of foreground/background and just have two colors, and letting people toggle back and forth as many times as they want. \$\endgroup\$ – flawr Aug 13 at 21:26
  • \$\begingroup\$ If the two things I asked in my comment aren't allowed, @tjjfvi approach is the only one possible (in any order of the corners of course) from what I can see, so maybe it's indeed good to allow both to have at least some variance in the challenge approaches. Although I guess most people would use either the one posted by tjjfvi being five steps or the second one I posted being four steps anyway. :) \$\endgroup\$ – Kevin Cruijssen Aug 14 at 6:17
  • \$\begingroup\$ Could also have the answers take input of the starting pixels and/or the canvas size. \$\endgroup\$ – tjjfvi Aug 14 at 12:09
  • \$\begingroup\$ idea: what if this were expanded to some sort of fractal/recursive version? You could specify an integer between, say, 0 and 9, and create X's out of X's recursively to that depth, but with the restriction that you can't ever create a Y out of any 5 evenly spaced pixels. \$\endgroup\$ – Beefster Aug 30 at 21:18
0
\$\begingroup\$

Crossing Sequences

Posted.

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

A triangle is worth a thousand lines

Vulkan is a relatively new cross-platform graphics API which is very powerful yet extremely verbose and detailed.

Arguably one of the most infamous saying on Vulkan, especially among beginners is, "The 1000 Lines journey". That is, getting a simple triangle to render on the screen takes a ton of code (~1k lines of C/C++).

It's time to break, nay, golf the stigma!

Challenge

Your challenge is writing a valid Vulkan-API based program which outputs a triangle to the screen. The windowing system is up to your choice as well as the colors/size of the triangle/screen itself.

The final script/compiled program should be able to be executed (preferably on a platform which does not require extra tools/hardware) and the output made visible in order to count as a valid solution.

Input

None. (Any if you require it, but it will also account into the score)

Output

A visible triangle on the screen. The following rules apply:

  1. The color of the triangle and the color of the background should be different.
  2. The size of the triangle should be noticeable. That is, any person with healthy eyesight should immediately be able to notice it.

Note: The final output triangle must be an actual call to drawing a 3 vertexed mesh and not simply points which render to some 4 pixels on screen.

Hardware constrains

Since the setup code differs greatly from GPU to GPU, you can assume that all the extensions are supported and that the GPU/driver is capable of executing a valid API call. Namely, input validations aren't mandatory, swapchain is present, queues are optimal, etc...

Scoring

Standard 1 (source code) byte = 1 point scoring, less is better. (The shaders source file sizes also counts towards the final score)

Note There are currently but a few available bindings for Vulkan which means that the language choice isn't as wide as other challenges. However, there is plenty to choose from with different paradigms, thus it shouldn't harm the creativity of the solutions :)

Helpful resources

\$\endgroup\$
  • 2
    \$\begingroup\$ Could you perhaps add a link to the Vulcan API in your challenge description? It's personally the first time I heard about it, and had to google a bit. From what I could see the Vulkan API can be used either in C or C++, with no other languages supported, is that correct? In that case this challenge could be tagged: [code-golf]; [c]; [c++]; [graphical-output]; [geometry]. \$\endgroup\$ – Kevin Cruijssen Aug 14 at 6:29
  • 1
    \$\begingroup\$ Sure! also, there are more than a few bindings for Vulkan already available, some even in "glofy" languages, such as lua and haskell: vinjn.com/awesome-vulkan/#bindings, I'll add some helpful links and directions in the challenge. \$\endgroup\$ – Elian Kamal Aug 14 at 11:01
  • 1
    \$\begingroup\$ "The size and color don't matter as long as they are different." I think I got your point, but could you rephrase it a bit? I think you mean that the color should be different from the screen's, but I'm not 100% sure, could be "from a run to another run, the triangle has to be different (random size and color)". Plus, if you take this sentence out of context, it has no sense, as seen at start of this comment :) \$\endgroup\$ – V. Courtois Aug 14 at 12:43
  • \$\begingroup\$ Yes I can see how it may seem unclear. What I meant was much more straightforward, "the background and the triangle color should be different" + The triangle itself should be visible too (A normal healthy human eye can see). The intent was clearing two loopholes: 1) Triangle and background are in the same color (Presenting a blank screen as an answer "It's a blue triangle on a blue background"). 2) Rendering a triangle which is too small to see without additional tools I'm not really sure how to formulate these to be honest.. \$\endgroup\$ – Elian Kamal Aug 14 at 14:37
0
\$\begingroup\$

Sandbox

So 2 months passed, and 2 months left. I simply didn't change it, and ask for your feedback. Everything is welcome. Like, improve my (poor) explanation, or correcting wrong grammar, or saying this propose is simply bad idea(then downvote and comment, please.), etc.

Does with length condition okay? Or I have to change it to ordinary with byte condition?

Make Korean Character Multi-style Ascii/Box Art

Note : I think I can't upload it on time, but if I can, I want to upload it to main in October 9th, Hangul Day.

About Hangul

As I'm Korean, I'm really proud of Korean character, Hangul(한글).

Hangul is artificial character made by King Sejong the great, 4th king of Joseon dynasty, at 1443.

Because today(hopefully today, October 9th) is Hangul day in Korea, I'll give you a challenge : Make Hangul ascii/box-styiled art.

List of characters

So, To make ascii art, you have to know every characters represent each syllables, right?

No. There are 11172 syllables in Korean character, so it's almost impossible to hardcode it. But, there are only 24 basic characters :

ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎㅏㅑㅓㅕㅗㅛㅜㅠㅡㅣ

And Korean character compose these to make that much syllables.

How to compose

24 basic characters can be separated into two part : consonant and vowel.

Leading 14 characters, ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎ, are consonants, and following 10 characters, ㅏㅑㅓㅕㅗㅛㅜㅠㅡㅣ are vowels.

There are roughly 3 part in Korean character : Initial consonant, Vowel, and Final consonant.

Initial consonant

Initial consonant (초성 in Korean) is simplest part. It is just consonant, only with ㄲㄸㅃㅆㅉ(double consonant). It placed in top-left position.

Vowel

Vowel (중성 or 모음 in Korean) is hardest part. Here is list of every vowel : ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ

ㅏㅐㅏㅒㅓㅔㅕㅖㅣ is on the right side of initial consonant, ㅗㅛㅜㅠㅡ is at the bottom, ㅘㅙㅚㅝㅞㅟㅢ is both. For example, 가, 고, 과.

Final consonant

Final consonant (종성 in Korean) is at the bottom-most side. Here is list of final consonant : ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ, and blank.

Here is example of some characters using final consonant : 각, 갌, 갏

How to decompose Unicode

See this webpage for help.

Quest

Input is like this format : (number) Korean char (number) Korean char ... Where (number) is optional. If number is given, change ascii(or unicode) art style to given number. 1 and 2 are ascii-art, and 3 is unicode box-art.

Seperate characters with 2 spaces. Note that not every character has same width.

If vowel is not ㅗㅛㅜㅠㅡ, following final consonant must indented with a space.

Default style is 1, so if first character is not number, style 1 is used.

This is example input : 1한2글3날 or 한3글날.

Here is list of Korean ascii art(style 1 and 2).

Here is list of Korean unicode box-art(style 3).

List of Ascii art

Style 1

ㄱ
___
   |
   |

ㄴ
|
|
|__

ㄷ
 ___
|
|___

ㄹ
___
 __|
|___

ㅁ
 __
|  |
|__|

ㅂ
|  |
|__|
|__|

ㅅ
 /\
|  |
|  |

ㅇ
 __
/  \
\__/

ㅈ
____
 /\
/  \

ㅊ
 __ 
____
/  \

ㅋ
___
___|
   |

ㅌ
 ___
|___
|___

ㅍ
____
 ||
_;;_

ㅎ
 __
____
 ()

ㄲ
_ _
 | |
 | |

ㄸ
 _ _
| |
|_|_

ㅃ
||||
[][]
""""

ㅆ
/|/|
||||
||||

ㅉ
____
/|/|
||||

ㅏ
    |
    |_
    |
    |

ㅐ
    | |
    |_|
    | |
    | |

ㅑ
    |
    |_
    |_
    |

ㅒ
    | |
    |_|
    |_|
    | |

ㅓ
     |
    _|
     |
     |

ㅔ
     ||
    _||
     ||
     ||

ㅕ
     |
    _|
    _|
     |

ㅖ
     ||
    _||
    _||
     ||

ㅗ



 |
_|__

ㅘ
    |
    |
    |_
 |  |
_|__|

ㅙ
    | |
    | |
    |_|
 |  | |
_|__| |

ㅚ
    |
    |
    |
 |  |
_|__|

ㅛ



 ||
_][_

ㅜ



____
 |

ㅝ
    |
    |
    |
____|
 |--|

ㅞ
    ||
    ||
    ||
____||
 |--||

ㅟ
    |
    |
    |
____|
 |  |

ㅠ



____
 ||

ㅡ



____

ㅢ
    |
    |
    |
    |
____|

ㅣ
    |
    |
    |
    |

ㄳ
_ /|
 |||
 |||

ㄵ
| __
| /|
|_||

ㄶ
| __
| __
|_()

ㄺ
_ _ 
 ] |
[_ |

ㄻ
_ ++
 ]||
[_""

ㄼ
_ ||
 ][]
[_""

ㄽ
_ /|
 ]||
[_||

ㄾ
_  _
 ]|_
[_|_

ㄿ
_ __
 ]][
[_""

ㅀ
_ __
 ]__
[_()

Style 2

ㄱ
---.
   :
   :

ㄴ
:
:
'---

ㄷ
.---
:
'---


ㄹ
---.
.--'
'---

ㅁ
.--.
:  :
'--'

ㅂ
:  :
:--:
'--'

ㅅ
 ,.
:  :
:  :

ㅇ
 ..
(  )
 ''

ㅈ
-.,-
 ;:
'  `

ㅊ
 -- 
-,.-
;  :

ㅋ
---.
---:
   :

ㅌ
.---
:---
'---

ㅍ
-..-
 ::
-''-

ㅎ
 --
----
 ()

ㄲ
-.-.
 : :
 : :

ㄸ
.-.-
: : 
'-'-

ㅃ
::::
[][]
''''

ㅆ
,:,:
::::
::::

ㅉ
----
,:,:
::::

ㅏ
    :
    :-
    :
    :

ㅐ
    : :
    :-:
    : :
    : :

ㅑ
    :
    :-
    :-
    :

ㅒ
    : :
    :-:
    :-:
    : :

ㅓ
     :
    -:
     :
     :

ㅔ
     ::
    -::
     ::
     ::

ㅕ
     :
    -:
    -:
     :

ㅖ
     ::
    -::
    -::
     ::

ㅗ


 :
-^--

ㅘ
    :
    :
    :-
 :  :
-^--:

ㅙ
    : :
    : :
    :-:
 :  : :
-^--: :

ㅚ
    :
    :
    :
 :  :
-^--:

ㅛ



 ::
-^^-

ㅜ



-v--
 :

ㅝ
    :
    :
    :
-v--:
 :--:

ㅞ
    ::
    ::
    ::
-v--::
 :--::

ㅟ
    :
    :
    :
-v--:
 :  :

ㅠ



-vv-
 ::

ㅡ



----

ㅢ
    :
    :
    :
    :
----:

ㅣ
    :
    :
    :
    :

ㄳ
-.,:
 :::
 :::

ㄵ
: --
: ,:
'-::

ㄶ
: --
: --
'-()

ㄺ
-.-.
.' :
'- :

ㄻ
-...
.'::
'-''

ㄼ
-.::
.'][
'-''

ㄽ
-.,:
.'::
'-::

ㄾ
-..-
.':-
'-'-

ㄿ
-...
.'][
'-''

ㅀ
-.--
.'--
'-()

Style 3

ㄱ
───┐
   │
   │

ㄴ
│
│
└──

ㄷ
┌───
│
└───

ㄹ
───┐
┌──┘
└───

ㅁ
┌──┐
│  │
└──┘

ㅂ
│  │
├──┤
└──┘

ㅅ
 ╱╲
│  │
│  │

ㅇ
╭──╮
│  │
╰──╯

ㅈ
────
 ╱╲
╱  ╲

ㅊ
 ── 
────
╱  ╲

ㅋ
───┐
───┤
   │

ㅌ
┌───
├───
└───

ㅍ
─┬┬─
 ││
─┴┴─

ㅎ
 ──
────
 ()

ㄲ
─┐─┐
 │ │
 │ │

ㄸ
┌─┌─
│ │
└─└─

ㅃ
││││
├┤├┤
└┘└┘

ㅆ
╱│╱│
││││
││││

ㅉ
────
╱│╱│
││││

ㅏ
    │
    ├─
    │
    │

ㅐ
    │ │
    ├─┤
    │ │
    │ │

ㅑ
    │
    ├─
    ├─
    │

ㅒ
    │ │
    ├─┤
    ├─┤
    │ │

ㅓ
     │
    ─┤
     │
     │

ㅔ
     ││
    ─┤│
     ││
     ││

ㅕ
     │
    ─┤
    ─┤
     │

ㅖ
     ││
    ─┤│
    ─┤│
     ││

ㅗ



 ╷
─┴──

ㅘ
    │
    │
    ├─
 ╷  │
─┴──│


ㅙ
    │ │
    │ │
    ├─┤
 ╷  │ │
─┴──│ │

ㅚ
    │
    │
    │
 ╷  │
─┴──│

ㅛ



 ╷╷
─┴┴─

ㅜ



─┬──
 ╵

ㅝ
    │
    │
    │
─┬──│
 ╵──┤

ㅞ
    ││
    ││
    ││
─┬──││
 ╵──┤│

ㅟ
    │
    │
    │
─┬──│
 ╵  │

ㅠ



─┬┬─
 ╵╵

ㅡ



────

ㅢ
    │
    │
    │
    │
────│

ㅣ
    │
    │
    │
    │

ㄳ
─┐╭╮
 │││
 │││

ㄵ
╷ ──
│ ╱│
└─╵╵

ㄶ
│ ──
│ ──
└─()

ㄺ
─┐─┐
┌┘ │
└─ ╵

ㄻ
─┐┌┐
┌┘││
└─└┘

ㄼ
─┐╷╷
┌┘├┤
└─└┘

ㄽ
─┐╭╮
┌┘││
└─╵╵

ㄾ
─┐┌─
┌┘├─
└─└─

ㄿ
─┐┬┬
┌┘││
└─┴┴

ㅀ
─┐──
┌┘──
└─()

Example input and output

1한2글3날

 __ |   ---.  │   │
____|_     :  │   ├─
 () |      :  └── │
    |   ----      │
 |      ---.   ───┐
 |      .--'   ┌──┘
 |__    '---   └───

뛟쀒3쫽

 _ _||  ||||||  ────│ │
| | ||  [][]||  ╱│╱││ │
|_|_||  """"||  ││││├─┤
____||  ____||   ╷  │ │
 |--||   |--||  ─┴──│ │
 _ __    _ __    ─┐─┐
  ]__     ]][    ┌┘ │
 [_()    [_""    └─ ╵

Scoring

This is , so shortest code with length wins.

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

Distant Programs

Create a program that, when run, prints "Do you still love me?" with or without a newline at the end.

Your score is the Levenshtein distance to the closest non-erroring program (the non-erroring program doesn't have to do anything, although it might), and you want the largest score. Ties are broken by whichever code is shorter, in bytes.

Your program can read it's own source code, through the filesystem or otherwise. If your program must have a specific name, the length of that name should be included in your byte count.

Notes:

  • Compiler warnings are not counted as errors for this challenge.
  • An erroring program can output, frobricate, do anything as long as it eventually errors.

Notes for the sandbox:

  • Is the specification clear?
  • Is it possible to create a solution that can simply be repeated to get any arbitrary score? If so it would pretty much ruin the challenge as it is, and I think it should be possible but I can't get it to work.
  • What tags would this use?
\$\endgroup\$
  • \$\begingroup\$ I think it should be possible to get arbitrary scores using quining techniques and cryptographic hash verification. \$\endgroup\$ – Peter Taylor Aug 20 at 15:41
  • 1
    \$\begingroup\$ In addition to what Peter said, I think there is a clarity problem in defining precisely what counts as an error. \$\endgroup\$ – FryAmTheEggman Aug 20 at 19:33
  • \$\begingroup\$ @FryAmTheEggman I was going top copy my definition of "error" from codegolf.stackexchange.com/questions/63433 but to my surprise there isn't one. Honestly I'm not sure how exactly to define "error". \$\endgroup\$ – Shelvacu Aug 23 at 23:03
0
\$\begingroup\$

Black And White Shirts 3

This is the third in a series. The first can be found here, and the second here. The premise is similar to the first two, but with some changes and a new goal.

Assume I have some number of black shirts and some number of white shirts, both at least 1. Both colors of shirt have a non-zero Vividness. All shirts of a given color start with the same Vividness.

Every day, I pick out a clean shirt to wear, and it becomes dirty. Once I run out of all clean black shirts or all clean white shirts, I wash all my dirty shirts of both colors and start over. Clean shirts do not get washed. Whenever a shirt gets washed, its color changes based on its Vividness and the Vividness and colors of the other shirts being washed, then its Vividness goes down by one to a minimum of 0. All things being equal, over time, all shirts will generally tend towards a shade of gray.

If a shirt is ever closer to the opposite color (eg. a black shirt looks light gray), it becomes a shirt of that color.

When picking which shirt to wear, I choose the shirt which is either closest to black or closest to white. If there is a tie, I choose the one with the highest Vividness.

Challenge:

Take in an arbitrarily long sequence of two indicators (eg. b b w w b w b b w b...) representing my choice of shirt to wear on that day. Continue execution until either my last black shirt or my last white shirt loses its last vividness. Once this occurs, stop consuming input and print out the colors of all shirts.

Inputs:

Number of black shirts, number of white shirts, Vividness of black shirts, Vividness of white shirts, and a sequence of shirt selections of arbitrary length at least long enough for one color of shirt to run out of Vividness (can be considered infinitely long). The selection can be represented by any two characters (eg. b, w).

Output:

Color of all shirts, sorted from darkest to lightest, as a percent of how close it is to white, rounded to the nearest whole percent. A completely black shirt is 0, and a completely white shirt is 100.

Color changing:

The color of a shirt tends towards the average of all shirts' colors in the wash. How close it gets depends on its own Vividness.

TODO: Determine if this rule is necessary (I don't think it is): If all shirts in the wash have 0 Vividness, none of them change color.

When washed, shirts are changed based on the following pseudocode algorithm (some of which may not be necessary for your simulation):

struct shirt {
    int vividness
    float color
}

func washShirts(shirt[] allDirtyShirts) {
    totalVividness = allDirtyShirts.sum(shirt => shirt.vividness)
    if (totalVividness == 0)
        return

    averageDirtyColor = allDirtyShirts.sum(shirt => shirt.color * shirt.vividness) / totalVividness

    for each shirt in allDirtyShirts
    {
        shirt.color = (shirt.color * shirt.vividness + averageDirtyColor) / (shirt.vividness + 1)
        if shirt.vividness > 0
            shirt.vividness--
        if shirt.isBlack && shirt.color > .5
            shirt.isBlack = false
        else if !shirt.isBlack && shirt.color < .5
            shirt.isBlack = true
    }
}

Make sure that all shirts base their calculation on the Vividness and color values of all other shirts before the change. Perform no rounding beyond normal floating point restraints within your language of choice (within reason) during any calculation. Only round the value during output. When rounding for output, choose any convenient rounding method among:

  • truncating (always round down)
  • rounding to the nearest integer
    • .5 rounds up
    • .5 rounds down
    • .5 rounds to the nearest even integer

Test cases:

Note: These test cases use rounding to the nearest even integer. Your output may vary in some cases.

1 2 1 1 w b
100 75 25

3 3 2 1 w b w b w w w w w w w w
71 71 71 14 14 0
#note that processing would stop after w b w b w. The remaining input would be ignored.

#todo: more test cases

General rules:

  • This is , so shortest answer in bytes wins.
  • Default I/O rules apply
\$\endgroup\$
0
\$\begingroup\$

Approaching the Graham's number

Write a program that could theoretically output an integer with the minimum absolute difference to the Graham's number. Your code is cracked if a robber writes a program to output the Graham's number exactly, in the same language, with the edit distance to your code under a specific limit.

Builtins for the Graham's number is disallowed.

Details to be added, if I think this idea actually works.


Problems:

How to set the limit?

  1. Fixed number of bytes.
  2. Fixed % of the code. Does the boilerplate count?
  3. Set by the cop. But how to fix the winning criterion?

Do the cops need to know a crack to make the submission valid?

\$\endgroup\$
  • \$\begingroup\$ What does "could theoretically output an integer with the minimum absolute difference..." mean? Would a program that outputs "Hello, World!" in a loop be valid, assuming enough time and radiation? Would a program that outputs all odd numbers be valid? Do we just have to output any number? \$\endgroup\$ – someone Sep 6 at 17:18
  • \$\begingroup\$ @someone "Output an integer" means to output a string matching /-?[0-9]+/ exactly, or any equivalents in other allowed formats. No hello world or multiple numbers. I'm not sure why you would think that. \$\endgroup\$ – jimmy23013 Sep 6 at 17:29
0
\$\begingroup\$

"Condense" String of Text

You will be given a string. You will be "condensing" it by combining the bits of characters into one.

Rules

  • The condensation works as follows:
    1. You are given a string with 8-bit characters, such as Hèl¹ò Wôrld, hex 48 e8 6c b9 f2 20 57 f4 72 6c 64
    2. Combines bits into 16-bit groups, from right to left. Above becomes hex 48 e86c b9f2 2057 f472 6c64, or H槲⁗汤.
  • You may assume that all characters in string range from 0x00 to 0xff.
  • Your resulting string would be encoded in UTF-16.
    • You may also assume that the resulting string won't contain characters from 0xd800 to 0xdfff, or the input containing any of ØÙÚÛÜÝÞß at even index in 0-index, or odd index in 1-index.
  • Standard loopholes apply.
  • This is code-golf so shortest code wins.

Examples

Input raw: abacaba
Input hex: 61 62 61 63 61 62 61
Outpt raw: a扡捡扡
Outpt hex: 61 6261 6361 6261
Input raw: Example.
Input hex: 45 78 61 6d 70 6c 65 2e
Outpt raw: 䕸慭灬攮
Outpt hex: 4578 616d 706c 652e
Input raw: ÿ!0ÿMÿEÿSÿSÿAÿGÿE0ÿCÿAÿN0ÿAÿPÿPÿEÿAÿR0ÿTÿOÿOÿ
Input hex: ff 21 30 00 ff 4d ff 45 ff 53 ff 53 ff 41 ff 47 ff 45 30 00 ff 43 ff 41 ff 4e 30 00 ff 41 ff 50 ff 50 ff 45 ff 41 ff 52 30 00 ff 54 ff 4f ff 4f ff 0e
Outpt raw: A message can appear too.
Outpt hex: ff21 3000 ff4d ff45 ff53 ff53 ff41 ff47 ff45 3000 ff43 ff41 ff4e 3000 ff41 ff50 ff50 ff45 ff41 ff52 3000 ff54 ff4f ff4f ff0e
Note that there are NULs in the input.
\$\endgroup\$
  • 1
    \$\begingroup\$ You might want to specify an encoding for the 16-bit encoding. For example, if you use UTF-16, then the values D800-DFFF are not valid characters \$\endgroup\$ – ar4093 Aug 23 at 18:21
  • \$\begingroup\$ This is essentially translation between encoding types, since the input bytes will be identical to the output bytes \$\endgroup\$ – Jo King Aug 25 at 12:14
0
\$\begingroup\$

Break it up and put it back together again

Note: This is , so read carefully and make sure your answer is valid before posting.

Write a program/function that takes a list of integers greater than 1 and returns a list of positive integers where each number from the original list has been split in two. For example:

[10,11,12] -> [5,5,4,7,6,6]

Each pair of numbers in the output add up to the corresponding number in the input. The algorithm used to split it up doesn't matter (for example a valid output could be [1,9,1,10,1,11]), as long as it is deterministic.

However, when fed its own byte values and the output is turned back into bytes, the resulting program should do the opposite, taking a list of integers and summing each pair. For example, if the program abcde splits each number into halves, with the leftover going to the second number:

"abcde" -> [97, 98, 99, 100, 101]
-> [48, 49, 49, 49, 49, 50, 50, 50, 50, 51] -> "0111122223"

The program 0111122223 should then be able to take the list [48, 49, 49, 49, 49, 50, 50, 50, 50, 51] and return the original [97, 98, 99, 100, 101]

Notes/Rules

  • Output must be deterministic
  • Output can't be a list of lists (no list of pairs)
  • The second program may assume that the length of the input is even (so you don't need to account for a leftover element)
  • Submissions can be functions, programs or different for either part
  • Remember, output must be a list of positive integers.
    • You won't get 1 in the input of the first program
  • The programs have to be in the same language
  • Input can be a string or list of characters instead
\$\endgroup\$
  • \$\begingroup\$ Knowing that low (<32) and high (>127) bytes in most languages are useless or cause errors, it will be difficult to use any lowercase letters in the second program, which might be a problem for case sensitive languages. Braces are nearly impossible without using the high bit, '{' and '}' are 123 and 125, and the maximum ascii value is 126. Not necessarily deal breakers, but important to know. \$\endgroup\$ – Hiatsu Aug 23 at 2:45
  • \$\begingroup\$ Can the two programs be in different languages? \$\endgroup\$ – Hiatsu Aug 23 at 21:05
  • \$\begingroup\$ @Hiatsu I knew I had forgotten to specify something. No, they can't \$\endgroup\$ – Jo King Aug 24 at 4:33
0
\$\begingroup\$

Golfed User-Pinging

In this task, given a user's display name(e.g. Display Name) from which the first space has been removed, use the API to find a user it could be and output their display name up to the first space. Both input and output must have an @ prefixed to them.

The input will not contain spaces in it, so you have to search for the user before doing this.

If the user does not exist, do anything else other than outputting the golfed user ping. (That includes outputting to stderr.)

Rules

  • This is a contest; the shortest answer wins.
  • No standard loopholes allowed. (In fact, hard-coding the answers will annoy other users, as you pinged all of them.)
  • The space (U+0020) is the word separator.
  • Input will not contain display names containing 2 or more spaces.
  • In addition to golfing the code, the answers also have to use as few calls as possible. (Due to the rate limiting of the API)
  • The input will always be case-insensitive and are restricted to printable ASCII.

    Examples

@Dennis -> @Dennis
@MartinEnder -> @Martin
@Cowsquack -> @Cows
@JB -> @J
@tsh -> @tsh
@cairdcoinheringaahing -> @caird


Sandbox

  • Is it a duplicate?
  • Do you understand everything here?
  • Any suggestions for test cases?
  • Most importantly, can you cheat over this challenge by using an algorithm not requiring network access?

\$\endgroup\$
  • 2
    \$\begingroup\$ Pings don't work like this. Maybe you can instead phrase the challenge as "given a CGCC comment mention (@username), reduce it to the first word of the CGCC username it refers to". Also, internet is a better tag than networking for here. Finally, what happens when the the ping/mention can refer to more than one user? \$\endgroup\$ – Erik the Outgolfer Aug 23 at 18:48
  • 2
    \$\begingroup\$ This is underspecified. It needs an unambiguous way of determining the word separation. \$\endgroup\$ – Peter Taylor Aug 24 at 6:19
  • 2
    \$\begingroup\$ 1. I overlooked that this was supposed to be a stack-exchange-api question. That should be made explicit. 2. Since it's an API question, it would be best to use the same terminology as the API: i.e. display name instead of username. 3. If space (U+0020) is the word separator, make that explicit. It seems the TL;DR would be "Given a user's display name from which the first space has been removed, use the API to find a user it could be and output their display name up to the first space. Both input and output must have an @ prefixed to them." \$\endgroup\$ – Peter Taylor Aug 24 at 7:20
  • 3
    \$\begingroup\$ 4. Making potentially 30+ calls to the API per input is going to make this hard to test without running foul of the rate limiting, so I would suggest explicitly requiring the answers to use as few calls as possible. 5. What about case? If the match should be case-insensitive, either the input should be restricted to ASCII or the way StackExchange handles case conversions should be explicitly documented. The former option seems preferable, because otherwise it randomly boosts languages with default behaviour which matches and penalises those which don't. \$\endgroup\$ – Peter Taylor Aug 24 at 7:23
0
\$\begingroup\$

Self-fibonaciing prophecy

Where L is the length in bytes of your source code
and n=(L+2)^2

Your program or function should output Fib(n)

Your program or function should take no input, and output according to the usual code golf rules

This seems like a very simple task, but the (L+2)^2 part is designed to prevent single digit outputs which could be hard coded in many languages, and ensure the required output will usually be longer than the source code, so it should produce some interesting mathematical answers

Question for meta - Is (L+2)^2 suitable for this?
Another possibility I have considered is (L^2)+8 which would grow a bit slower but still achieve the goal of preventing trivial solutions
Having a look at this again, I think the sequence still grows too quickly. Maybe n=ceil(L^1.5)+18 would be more reasonable

Another question for meta - Should I include a link to a source of Fibonaci numbers, or is it safe to assume readers know what this is and can find it for themselves?

\$\endgroup\$
  • 2
    \$\begingroup\$ It probably isn't exactly necessary to explain the Fibonacci sequence, but I think it would be better if you did. You should explicitly state what you consider to be valid initial points (i.e. is Fib(0), Fib(1) = 0, 1 acceptable? I'm not sure about the scaling sequence, but I do think your idea for preventing too many trivial answers is a good one. You might consider just doing L+100 since that should probably make hardcoding inefficient but make calculation much easier. \$\endgroup\$ – FryAmTheEggman Aug 27 at 14:54
  • 1
    \$\begingroup\$ The point of (L+2)^2 or whatever other function seems to be to push answers towards actually implementing a general-purpose Fibonacci function, but that makes the question a dupe of the general-purpose Fibonacci question. I don't see how this can be rescued: either it's a dupe, or it's possible to "cheat". \$\endgroup\$ – Peter Taylor Aug 27 at 19:36
  • 1
    \$\begingroup\$ @Peter Taylor Here Fib(n) is a number that depends only on the program length but not any other input. It is unnecessary to implement a general purpose Fibonoacci function at all. You can just print a Fibonoacci number and tune the length of the program to fit the requirement. \$\endgroup\$ – Joel Aug 28 at 1:14
  • \$\begingroup\$ @JoKing print(34) is 7 bytes, which would require to output a 9 digit number not a 2 digit number. If you simply change the 34 for the required 9 digit number, then your solution becomes 14 bytes, so would then require to output a 15 digit number rather than 9, and so on. The output is always longer than your source code, hence trival answers are by design, not possible \$\endgroup\$ – Darren H Aug 28 at 8:32
  • \$\begingroup\$ @FryAmTheEggman the L+100 idea seems promising, but I fear it would then open up to trival answers for high L, indeed JoKing's point would then run true for L>33. I feel the function needs some kind of exponent to eliminate that problem \$\endgroup\$ – Darren H Aug 28 at 8:38
  • \$\begingroup\$ Ah oops, I missed that part and thought it was just Fib(length). Still, it's then going to be either base compression for golfier languages, or just indexing into the fibonacci list at the correct index \$\endgroup\$ – Jo King Aug 28 at 9:24
  • \$\begingroup\$ @Joel, I said "push towards" not "absolutely require". The key points are: (1) if it's competitive to tweak an answer from the general-purpose Fibonacci question, this is a dupe; (2) if it isn't then setting n=(L+2)^2 would seem not to have done its job. \$\endgroup\$ – Peter Taylor Aug 28 at 9:46
  • \$\begingroup\$ @Peter Taylor I see your point. However, since the problem does not require to output the entire Fibonacci sequence, it is allowed to use any function to generate a single Fibonacci number that fits the requirement. There might be a non-trivial solution that is shorter than a general-purpose Fibonacci function implementation. \$\endgroup\$ – Joel Aug 28 at 13:10
  • \$\begingroup\$ I'm mostly curious about the calculation of n, I want to design it in such a way that it prevents trival answers, as my goal with this challenge is to see some interesting calculations. Trivial answers for very low L or very high L will be possible with a poorly chosen formula. This might even be a question for math.se \$\endgroup\$ – Darren H Aug 30 at 12:39
  • \$\begingroup\$ After some further research and experimentation, I'm considering using n=(L+2)*5 this is the slowest growing formula I have found so far that fits the requirements \$\endgroup\$ – Darren H Aug 30 at 12:52
0
\$\begingroup\$

Compare Multiratios

EDIT: No doesn't make any sense, I need to think about it again.

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

Smallest self-hosting golfing language

Implement a golfing language that is implemented in itself. Formally speaking: The original compiler O (an executable file assumed to be implemented in other language X), when given its own source code S (in golfing language G), must produce the identical executable file O. Your task is to create G by implementing O.

Language X might be an ELF binary, x86 assembly, Python, LLVM IR, etc.

Neither your language implementation S or executable file O may use functions that have the same functionality as exec or eval. That is, you may not use any built-in code evaluation of your compiler O. Standard Quine loopholes, such as reading your own file, downloading your file from the internet, and holding the program data in the filename, are not allowed.

The executable file O of the compiler must not be embedded in any shape or form in the source code S of the compiler. Additionally, the source code S of the compiler must be strictly shorter than the executable file O.

Your code must not be dependent on any external program or internet resource other than language X: if your language is dependent, include the size of the external dependencies in your submissions. Your program gets a standard POSIX system base for free, plus GCC 8 and LLVM 10: you do not have to include the size of this in your submission. For example, if you submitted a Bash Quine that just invoked the 05AB1E interpreter via the command line, you would have to include both the size of the the 05AB1E implementation, as well as the size of the Elixir implementation (since 05AB1E is implemented in Elixir and your base language X isn’t Elixir) in your bytecount.

In addition, standard golfing loopholes apply.

Requirements

Answer at least 10 other challenges on this website, beating at least 50% of the existing answers in byte size.

  • Only challenges that already have 4 answers are allowed
  • Your own other answers to the challenges do not count
  • Challenges newer than this post are allowed, as well as answering your own challenges; provided they already have 4 answers from other answerers
  • Link to your challenge answers for verification

Base language X restrictions

Language X must have an implementation, in other words we must be able to actually run your compiler O with source code S and get compiler O as output.

Language X must have already existed before this post was created.

You are encouraged to share the techniques of how you created your compiler and how you came up with your golfing language.

Scoring

$$S*0.98^{(n-10)}$$ where n is the number of challenges where you beat at least 50% of the other answers, not including your own.


Feedback

How can you prevent someone submit a zero bytes answer and claim: if source is empty, it output the interpreter, otherwise output compiled python code. – tsh Aug 24 at 4:42

\$\endgroup\$
  • 1
    \$\begingroup\$ I don't think your requirements are a good way to handle making people use a real language. It doesn't do much to prevent abuse and is extremely tedious to perform and to verify. I'm sorry I don't have an alternative, but I think that may be a red flag that this won't work very well on this site. \$\endgroup\$ – FryAmTheEggman Sep 3 at 3:49
  • \$\begingroup\$ Is there a reason languages created after this is posted are not eligible? \$\endgroup\$ – trichoplax Sep 3 at 11:42
  • \$\begingroup\$ It may be worth explicitly stating that lowest wins in the scoring section. \$\endgroup\$ – trichoplax Sep 3 at 11:43
0
\$\begingroup\$

DRAFT: Remove vertical comments

Vertical commnets...

        /> push back with    result.cows_used.push_back(possiblecow);
        the new cow added </ cows_used.push_back(result.cows_used);

Traditional comments...

        /* push back with */ result.cows_used.push_back(possiblecow);
     /* the new cow added */ cows_used.push_back(result.cows_used);


        result.cows_used.push_back(possiblecow);
        cows_used.push_back(result.cows_used);

Annotated, everything with . is considered a comment:

        />.................. result.cows_used.push_back(possiblecow);
        ..................</ cows_used.push_back(result.cows_used);

What is both between the start row of /= and the end row of =/ and between the start column of /= and the end column of =/ is considered a comment.

        /> push back with       result.cows_used.push_back(possiblecow);
           the new cow added </ cows_used.push_back(result.cows_used);

Todo

  • Add testcases
\$\endgroup\$
  • \$\begingroup\$ Can vertical comments be nested or overlapped? \$\endgroup\$ – Hiatsu Sep 4 at 18:03
  • \$\begingroup\$ Will this language have string literal? \$\endgroup\$ – tsh Sep 5 at 5:23
0
\$\begingroup\$

Sorted spiral matrix

Given a M x N matrix, your task is to sort the values in the matrix starting at the (0,0) position, and following the pattern downrightupleft.

                                                        enter image description here

Input

  • M and N (M, N ⩾ 1).
  • The M x N matrix with only integers values.
  • You can choose to ignore the M, N input (since it is given implicitly by the matrix).

Output

  • The M x N sorted spiral matrix.

Example

M = 4, N = 3 and matrix:

[2,8,3]
[1,5,5]
[5,7,6]
[8,3,6]

Should output the following matrix:

[1,7,6]
[2,8,6]
[3,8,5]
[3,5,5]

Test cases

[[2, 8, 3], [1, 5, 5], [5, 7, 6], [8, 3, 6]] --> [[1, 7, 6], [2, 8, 6], [3, 8, 5], [3, 5, 5]]

More tests will be added later.

This is so shortest answer in bytes wins!

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

Breaking the Wordbuilder (canned)

Dupe of Let's Play Countdown! ... oh well. Thanks for the feedback everyone.

\$\endgroup\$
  • \$\begingroup\$ Does the dictionary have to be encoded in submissions, or may they take it as input? \$\endgroup\$ – Unrelated String Aug 22 at 9:24
  • \$\begingroup\$ Take it as input. Assume unix-words is a local file. \$\endgroup\$ – roblogic Aug 22 at 9:26
  • 1
    \$\begingroup\$ similar question.. Solve an Anagram, this one is possibly a bit easier \$\endgroup\$ – roblogic Aug 22 at 15:35
  • \$\begingroup\$ can languages without file io take unix-words as input? \$\endgroup\$ – SuperStormer Aug 22 at 16:33
  • \$\begingroup\$ @SuperStormer, sure thing \$\endgroup\$ – roblogic Aug 22 at 16:44
  • \$\begingroup\$ So the two differences between this and that are that the input is always precisely five characters long and output words can leave out one or two of them. I'm not really sure if this is a duplicate, but it's close \$\endgroup\$ – Unrelated String Aug 22 at 18:23
  • 2
    \$\begingroup\$ The line about the standard loopholes seems to be a bit misleading - the standard loopholes do not ban built-ins that solve the problem. They primarily ban abusive an uninteresting answers like print("an anagram solver"). I'm not sure exactly what you want, but it certainly isn't to allow all loopholes. Unrelatedly, the other challenge included multi-word solutions, so I doubt that answers to either can be trivially used for the other without being highly uncompetitive. \$\endgroup\$ – FryAmTheEggman Aug 22 at 18:46
  • \$\begingroup\$ Thanks @FryAmTheEggman, restored the anti-loophole rule. \$\endgroup\$ – roblogic Aug 22 at 18:51
  • 1
    \$\begingroup\$ A closer previous question is Let's play countdown. IMO the change from 9 input letters to 5 is completely trivial, and the change in the filtering is still sufficiently trivial to count as a dupe. \$\endgroup\$ – Peter Taylor Aug 23 at 7:37
  • \$\begingroup\$ @Peter Taylor, you are correct! I'll take this down 😭 \$\endgroup\$ – roblogic Aug 27 at 3:29
0
\$\begingroup\$

I see your BIDMAS and raise you a BADMIS

Challenge

Given a set of numbers with operators between them: "5 + 4 * 9 / 3 - 8", return all the possible results of the expression for every permutation of the order of basic operations: [/, *, +, -].

Rules

  • Standard loopholes forbidden
  • I/O
    • Input must be ordered with infix operations, but however that is easiest (string or array)
    • Output must be all of the possible results of the expression, no specified format or order, no repeats
  • All of the inputs are valid (e.g. do not need to deal with "7 / 3 + *"
  • Operators are all left-associative so "20 / 4 / 2" = "(20 / 4) / 2"
  • This is Code Golf so fewest number of bytes wins

Test Cases (With explanation)

  • "2 + 3 * 4" = [14, 20]
    • 2 + (3 * 4) ⟶ 2 + (12) ⟶ 14
    • (2 + 3) * 4 ⟶ (5) * 4 ⟶ 20
  • "18 / 3 * 2 - 1" = [11, 6, 2, 6]
    • ((18 / 3) * 2) - 1 ⟶ ((6) * 2) - 1 ⟶ (12) - 1 ⟶ 11
    • ((18 / 3) * (2 - 1) ⟶ (6) * (1) ⟶ 6
    • (18 / (3 * 2)) - 1 ⟶ (18 / (6)) - 1 ⟶ (3) - 1 ⟶ 2
    • 18 / (3 * (2 - 1)) ⟶ 18 / (3 * (1)) ⟶ 6

Test Cases (Without explanation)

  • "45 / 8 + 19 / 45 * 3" = [5.765740740740741, 0.01234567901234568, 0.11111111111111113]
  • "2 + 6 * 7 * 2 + 6 / 4" = [154,113.5,88]
\$\endgroup\$
  • 1
    \$\begingroup\$ I'd recommend removing the bonus part, since people aren't going to do more than they have to, especially if it's code-golf (which I'm assuming this is, though you haven't specified it) \$\endgroup\$ – Jo King Sep 5 at 0:03
  • \$\begingroup\$ An I/O question: would providing 45 / 8 as 45.0 / 8.0 to the program be allowed? I suggest allowing it. This frees users working in languages which parse integers as integer types by default to work on the problem you ask, instead of an ancillary problem. \$\endgroup\$ – GammaFunction Sep 8 at 6:22
  • \$\begingroup\$ @GammaFunction Yes that would be fine \$\endgroup\$ – Freddie R Sep 8 at 22:02
0
\$\begingroup\$

The Rattlin' Bog

There's a relatively famous Irish Folk song called The Rattlin' Bog, a type of cumulative song.

Basically, this is a song that alternates between a chorus and an ever-expanding verse

The chorus is as follows:

Ho, ro, the rattlin' bog
The bog down in the valley-o
Ho, ro, the rattlin' bog
The bog down in the valley-o

Each verse starts with
And on that [x] there was a [y]
A rare [y], a rattlin' [y]

and ends with
In the bog down in the valley-o

Where x is the word from the previous round, and y is the word for the current round. In between these two is the cumulative part. It starts with:
The [z] in the bog

Each new round adds
The [y] in the [x] and
To its predecessor.

Challenge

Given a list of strings, character arrays, or whatever reasonable equivalent collection of string or your language equivalent thereof, Your job is to print the lyrics to the song, alternating between the chorus and each verse, starting and ending with the chorus. The chorus and verse must be separated by a pair of newlines.

For the sake of brevity, you may write the chorus once, preceded by "[Chorus]" then write "[Chorus]" in place. I'm also omitting any sort of final verse with unique text.

Example:

Input: [House, Roof, Nest] 
Output:
[Chorus] 
Ho, ro, the rattlin' bog 
The bog down in the valley-o 
Ho, ro, the rattlin' bog 
The bog down in the valley-o  

And on that bog there was a House
A rare House, a rattlin' House
The House in the bog
In the bog down in the valley-o

[Chorus]

And on that House there was a Roof
A rare Roof, a rattlin' Roof
The Roof in the House and the House in the bog
In the bog down in the valley-o

[Chorus]

And on that Roof there was a Nest
A rare Nest, a rattlin' Nest
The Nest in the Roof and the Roof in the House and the House in the bog
In the bog down in the valley-o

[Chorus]

\$\endgroup\$
  • \$\begingroup\$ I'm terrible at formatting, so if anyone wants to tell me the best formatting for this or edit and reformat it, that's fine. Of course, feedback is also appreciated to make this more readable or easier to understand. Also if/when I put it up on main golf, i'll add the standard disclaimers about abusing loopholes and least bytes wins, etc. \$\endgroup\$ – Andrew Baumher Sep 5 at 16:27
  • 4
    \$\begingroup\$ I'm not sure that adding input is enough to make a difference between this and something like There was an Old Lady or There's a hole in the bottom of the sea... \$\endgroup\$ – AdmBorkBork Sep 5 at 17:53
0
\$\begingroup\$

Is both your input and function/program correctly ordered?

Challenge:

Input: a string, consisting of only printable ASCII characters
Output: a truthy/falsey value whether its characters are in alphabetical order (based on their UTF-8 unicode values), from any starting point inside the string including wrap-around

For example: xyzabc would give a truthy result, because we could travel a→b→c→x→y→z, but xzy would give a falsey result, because all possible starting points (x→y→z; y→z→x; z→x→y) are not in the correct order.

This sounds pretty simple, right? But there is one catch, as this is a challenge: your program/function has to be in the correct order as well.

†: Based on the order of the characters in your own codepage. i.e. a program written in Jelly need to be (with the wraparound of course) in the order of its own codepage, instead of UTF-8 order.

Challenge rules:

  • The input can be in any reasonable format. Can be a string, read from STDIN, a list of characters, etc. (No, you are not allowed to take a list of unicode values - which would basically be an integer list - unless your language implicitly converts between characters and integers. So in Java a char[] is allowed (with String.toCharArray()), but a list of bytes or integers (i.e. String.getBytes()) is not.)
  • The input is guaranteed to be printable ASCII (range \$[32,126]\$ / [' ','~']).
  • If your program/function is written in a different codepage, it does not necessary have to hold a truthy value when used as input for itself. It does need to be in the correct order based on your codepage of course.
  • The input is guaranteed to be non-empty. An input of a single character will always result in truthy.

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (i.e. TIO).
  • Also, adding an explanation for your answer is highly recommended.

Test cases:

Truthy:

xyzabc

Falsey:

xzy

TODO: Will add some more test cases later on.


Sandbox questions:

  • Anything unclear?
  • Rules I should add / or other things I should keep in mind?
  • Suggested test cases?
  • Is this a duplicate? Or is there a related challenge asking this without the restricted-source to link when I post this to main?
  • Any tags I should add?
  • Better title suggestion?
\$\endgroup\$
0
\$\begingroup\$

Sliding window minimum

The task is, given a number array of length n and a positive integer k, to compute the smallest values in all its overlapping consecutive subarrays of length k in the order they occur.

The complexity of your program should be no more than linear with respect to n with a constant added.

Input

A positive integer array of length n and a positive integer k (k <= n)

Output

A positive integer array with n - k + 1 elements, where the element at position i equals the least number in the subarray starting at i and ending at i + k - 1 inclusive.

Examples

[1, 3, 5, 7], 2 -> [1, 3, 5]
[1, 3, 5, 3, 5, 1], 3 -> [1, 3, 3, 1] 

TODO

Sandbox stuff

  • Is it acceptable to combine code-golf with restricted-complexity?
  • Is the complexity restriction clear enough?
  • Is it a good idea to allow calculating the maximum instead of the mininum?
  • Is the grammar correct enough?
  • Has this been posted before?
  • Do any languages have built-ins for this?
\$\endgroup\$
  • \$\begingroup\$ Close to a dupe. This one adds the minimum operation; you don't need to modify the programs in that question too much in order to post submissions for this challenge. \$\endgroup\$ – A _ Sep 7 at 14:08
  • \$\begingroup\$ @A_ I'm perfectly certain it's not, that one doesn't have [restricted-complexity]. \$\endgroup\$ – someone Sep 7 at 14:12
  • \$\begingroup\$ This functionality is needed in statistical analysis so I think many statistics / data analysis oriented languages or libraries would have a built-in for it. For example, this is the built-in in the R language. \$\endgroup\$ – Joel Sep 7 at 15:24
  • \$\begingroup\$ Meanwhile, the complexity of the function depends also on k. So "linear with respect to n with a constant added" might not be accurate enough without mentioning k. It would be better to say sth. like "linear with respect to n for each fixed value of k". \$\endgroup\$ – Joel Sep 7 at 15:28
  • \$\begingroup\$ @Joel Are you sure? I think I can compute it with a deque in O(n + k), and since k <= n that is linear with respect to n. \$\endgroup\$ – someone Sep 7 at 15:31
  • \$\begingroup\$ A basic deque-based approach needs O(k) time to calculate or updating the minimum for each window in the worst case so the overall worse-case complexity would be O(n + k(n - k)) which is the same as O(n + kn). If you use a priority queue the complexity can be driven down to O(n+nlogk) or maybe O(n) only for some very advanced implementations. How do you implement that in O(n + k)? \$\endgroup\$ – Joel Sep 7 at 15:53
  • \$\begingroup\$ @Joel reference O(n) implementation by me \$\endgroup\$ – someone Sep 7 at 16:07
  • \$\begingroup\$ @someone OK. That algorithm is O(n). So you may emphasize in the description to say "The complexity of your program should be O(n), i.e. linear with respect to n for every possible k <= n", in case anyone wonders about whether an O(n + nlogk) implementation is accepted. \$\endgroup\$ – Joel Sep 7 at 16:39
  • \$\begingroup\$ @Joel I'd argue O(n log k) is not really linear with respect to n (since that equals O(n log n)) \$\endgroup\$ – someone Sep 8 at 6:04
  • \$\begingroup\$ @someone O(nlogk) is not linear with respect to n but it is also different from O(nlogn) because it really depends on the input k. If k has another constraint itself (e.g. an upper bound that is better than O(n)), O(nlogk) could be better than O(nlogn). That is why I suggested you clearly mention about the range of k in the complexity description to avoid any possible confusion, as I showed in my comment. \$\endgroup\$ – Joel Sep 8 at 6:26
0
\$\begingroup\$

Random point on a sphere

Posted here

\$\endgroup\$
  • \$\begingroup\$ Must we use a specific distribution (e.g. uniform or normal) or is the "bias" acceptable? \$\endgroup\$ – Erik the Outgolfer Aug 23 at 10:11
  • \$\begingroup\$ @EriktheOutgolfer My intention was to require a strictly uniform distribution. I do realize that it is unreasonable to verify this for each and every submission, so I have not made up my mind about that yet. Any suggestions? \$\endgroup\$ – Jitse Aug 23 at 10:18
  • \$\begingroup\$ I'm in favor of just using the community default for randomness, that is, if every possible output (up to precision limits) has a non-zero probability of being returned, the submission is valid. \$\endgroup\$ – Erik the Outgolfer Aug 23 at 10:24
  • \$\begingroup\$ @EriktheOutgolfer That sounds like a decent compromise. I'll update the challenge. \$\endgroup\$ – Jitse Aug 23 at 10:43
  • \$\begingroup\$ Hm... another thing I noticed is that you have 6 tags, you can't have more than 5. \$\endgroup\$ – Erik the Outgolfer Aug 23 at 11:13
  • \$\begingroup\$ @EriktheOutgolfer I was unaware of that. I'm removing number-theory, since it is the least fitting. \$\endgroup\$ – Jitse Aug 23 at 11:20
  • \$\begingroup\$ Also, thanks for your feedback! \$\endgroup\$ – Jitse Aug 23 at 11:20
  • 6
    \$\begingroup\$ Pick three uniform random numbers and normalise? I think it would be a more interesting question with the requirement that if the random number generation were substituted with true RNG from the reals then the distribution would be uniform. That opens up a variety of approaches. \$\endgroup\$ – Peter Taylor Aug 24 at 6:29
  • \$\begingroup\$ @PeterTaylor That was my original intention and I agree that it would definitely be more interesting. However, I thought it might be tricky to verify the uniformity of the distribution for each submission. Your reference could help with that, though. \$\endgroup\$ – Jitse Aug 24 at 9:52
  • \$\begingroup\$ I seem to remember a similar challrnge about uniformly generating random numbers that add up to the input, but I can't find it. Not that this is a duplicate, just related \$\endgroup\$ – Jo King Aug 25 at 12:17
  • \$\begingroup\$ The challenge as it stands is impossible. Since there are more real numbers than finite binary strings you cannot represent real numbers in the output of a program. It is going to be impossible to create a program that has a chance of outputting all the real numbers on the surface of a sphere. You likely need to restrict the output domain in some way. \$\endgroup\$ – Sriotchilism O'Zaic Aug 25 at 14:27
  • 1
    \$\begingroup\$ @JoKing perhaps this? \$\endgroup\$ – Giuseppe Aug 27 at 14:14
  • 1
    \$\begingroup\$ @PeterTaylor Since your comment has received quite some upvotes, I have reverted the challenge back to requiring a uniform distribution. I included some examples of how to achieve this. Do you think it is clear enough like this? \$\endgroup\$ – Jitse Aug 28 at 8:21
  • 1
    \$\begingroup\$ I think it's preferable to talk about being "theoretically uniform": to achieve actual uniformity "up to the precision limits of your language" would probably require using intermediate values of greater precision. Finding the right wording for questions which use floating point numbers is hard! \$\endgroup\$ – Peter Taylor Aug 28 at 8:30
  • 1
    \$\begingroup\$ In your second and third remarks, it would be good to point out that the random numbers in these invalid schemes are uniform. As shown in the fourth remark, both schemes are valid with specific non-uniform distributions. \$\endgroup\$ – Nitrodon Aug 29 at 21:28
0
\$\begingroup\$

Consequence Golf

As specified by this xkcd, Consequence Golf is a game involving golfing and bombs. The most obvious consequence of bombs: damage to the course.

A Consequence Golf course consists of the union of several circular regions. The tee is located at (0, 0). On each turn, you hit the ball bomb in a direction at some power. The bomb will travel in that direction for a distance equal to the power of the shot, unless it hits the edge of the course, in which case it will explode immediately. When a bomb explodes, it adds to the course a new circle centered on the point of contact with a radius equal to the remaining power. The next shot starts at the last location of the bomb.

Input

  • A list of circles, consisting of x/y coordinates and a radius for each circle, taken in any convenient format. If you must define a custom data type to store this information (e.g. struct c{float x,y,r};), you do not need to count that added boilerplate, nonproductive storage code in your byte count. Any code that does something besides specify storage must be counted.
  • A list of strokes, consisting of an angle in radians or degrees, and a power, again in any convenient format.

Output

  • The location of the bomb after the final stroke.

Additional Rules

  • The course will always contain at least one circle
  • The course will always contain the tee at (0, 0)
  • If there are zero strokes, you must return (0, 0)
  • The power of a stroke will never be zero
  • "Any convenient format" means a list of lists, list of C structs, a list for each input (x, y, radius, power, angle), or similar. You may not take information that is not as it is specified. For example, you may not take the circles as a series of equations.
  • This is consequence code golf, so shortest code in bytes wins.

Test cases

TBD...

Questions for META:

  • Is the description of how to play Consequence Golf clear enough?
  • Is the description of the input clear enough? This is my main concern.
  • Is allowing boilerplate storage code outside of the byte count an issue?
  • I am considering allowing fixed point approximations with at least 4 bits of precision for languages without floating point (and languages with, if it somehow makes things shorter). Would this cause any unintended issues?
\$\endgroup\$
  • \$\begingroup\$ The overview talks about the bomb hitting walls, but the input section doesn't include anything about the walls. \$\endgroup\$ – Peter Taylor Sep 9 at 8:27

You must log in to answer this question.

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