65
27
The 9 Hole Challenge
- 9 code golfing challenges of varying difficulty.
- Penalties for using the same language more than once.
The question will be updated with pars, hole champions and trophy winners.
This comes from a competition I have with some friends, it's not the usual format, but I hope some of you will appreciate the different spin on it. Challenges, rules and trophies below.
Holes
Greenway (24)
f(c:string, n:integer)
Prints a line containingn
instances ofc
.Somewhere in the Rough (73)
f(t:string, s:string, n:integer) -> i
Wherei
is the index of thenth
instance ofs
int
.Curry for Dinner (6235)
f(x:function, y: function) -> g
Whereg
is a function that will cally
,n
times; wheren
is the return value ofx
Spew (92)
f(p:string)
Writes to file atp
and fills it with a randomly sized rectangle of random characters (ascii).Treasure Hunt (75)
f(p:string, c:char) -> (x, y)
Reads file atp
which contains a grid of symbols and returns thex
andy
coordinates of the first instance of that symbol within the grid, assume it exists.Bridge on the River Kwai (179)
f(l:list[int])
Prints difference bridges diagram forl
. E.g for[1,7,3,17,1]
/+6\ /-4\ /+14\ /-16\ 1 7 3 17 1
Make sure that the spaces are created according to the size of the number above. For a 3 digit long number, you are going to need 4 spaces between the digits on the line below.
Catch: Somewhere, your code must spell trousers (Must have at least 1 non-alphanumeric delimiters. E.g.
tr(ou,se)(rs)
Time Flies When You're Playing Golf (1157)
f(p:string) -> [h, m]
Reads file atp
which contains an ASCII representation of an analogue clock, where the hour hand is represented with one lines, and the minutes by two. Output a list containing two elements: the hours and minutes shown on the clock. If only one hand is visible, assume both point to that position.Here are all the possible combinations for a hand.
\ | / \|/ --o-- /|\ / | \
These positions, respectively are (12, 1, 3, 5, 6, 7, 9, 11). Assume that the other characters within the clock face are spaces.
Timber! ()
f(p:string) -> b:boolean
Where p is the path to a file with an ascii building in. Blocks with white space underneath them will fall. (Except from slashes, which stay in place if there is a stable block in the opposite direction to the way they face). If the building is structurally integral return true, otherwise return false. All non whitespace blocks are counted as being solid and other than slashes, they all fall.Structurally safe
____ |/\| | |
Not Safe
|__ | |
Safe version
|__ \\| |
Slacker News (218)
f(s:string, r:string, p:string)
Gets the titles of the top 20 stories on Hacker News and changes all instances ofs
tor
, then writes the new titles to a html file atp
, where each title is contained within a h1 element.The outputted file should something like this
<h1>Some title</h1></h1>Some other title</h1>...etc
Catch:
- You may not use the HN api.
- You may not use Regex.
- You may not use angle braces anywhere in your code.
Scoring
- Character count is the length of the function that will compile & run correctly. However you still need to submit the full code, including imports.
- +10% for every repeated language in your submission. (E.g. If you use Ruby for 3 solutions, then your final score will be multiplied by 1.2). Different versions of the same language count still count as the same language.
- Par will be average score for each hole.
- Submit your solutions in one answer.
- Your overall score is your character count + your language penalty, then round it up.
Trophies
- Gold Jacket - (@Sprigyig - 1290) Lowest overall score
- Shooter - (@Sprigyig - 9) Most languages used
- Bunker - Most above par score on any hole
- Snakes on a Plane - (@AsksAnyway - 1727) Highest python character submission in a single solution
- Good Parts - (@AsksAnyway - 255) Highest JS character count in a single solution
- Shakey Steve - Shortest solution that uses interfaces
- You're Not From Round Here - Shortest unique language solution that's language has the shortest wikipedia page.
- Happy Gilmoore - (@AsksAnyway - 31) Shortest solution that has the word 'alligator' in the code.
- Unicycling Dwarf Magic - The default extensions of your 9 submission source files are a perfect anagram of a word in the Oxford Dictionary.
You are only eligible for a trophy once you have completed all 9 holes
Submissions
- @Sprigyig 1290
- @Firefly 1320
- @grc 1395
- @Trevor M 1465
- @C Gearhart 1654
- @Guy Sirton 1719
- @AsksAnyway 4651
Are languages without functions excluded from the challenge? Or can we also write STDIN to STDOUT programs instead of functions? – Martin Ender – 2015-01-31T16:10:37.900
I'm closing this question because multi-part challenges with little interaction between subchallenges became off topic by community consensus.
– Dennis – 2016-04-22T22:44:16.457I assume "angle braces" refers to what I call "brackets," right?
[]
– apnorton – 2013-12-29T20:14:28.4102@anorton
<
&>
– Dan Prince – 2013-12-29T20:15:21.743@DanPrince Ah! Glad I asked. :) One other question: must the file contain a test case (e.g. actually calling the function f), or just the definition of the function itself? – apnorton – 2013-12-29T20:16:54.577
1An analog clock has 12 positions for each hand, but you only give us 8. How does that work? – Kevin – 2013-12-29T20:17:13.057
@Kevin You don't have to account for the other positions. That diagram shows you all the possible configurations of either hand. – Dan Prince – 2013-12-29T20:29:48.293
@anorton, just the function definition. – Dan Prince – 2013-12-29T20:33:22.653
1@DanPrince Do you want the
/
position to refer to 1 o'clock or 2 o'clock? (and similarly for all the rest of the diagonals) – apnorton – 2013-12-29T20:33:24.3131@anorton 1/5, 5/25, 7/35, 11/55 – Dan Prince – 2013-12-29T20:38:34.897
This challenge is awesome x 9. However I think it's too bad that there are penalties for using many times the same language. Can you please precise what you mean in the trophies "Snakes on a Plane", "Good Parts" (do we need to write a lot of code to win those?) and "Unicycling Dwarf Magic" (what are extensions?). Thanks – xem – 2013-12-29T20:50:15.053
The 10% penalty applies to the entire score, or only to those submissions that use that language? Also, are these additive (100, 110, 120...), or multiplicative (100, 110, 121...)? Can you show a narrated example? – John Dvorak – 2013-12-29T20:50:54.213
@xem extensions should refer to
py
,c
,java
, etc, which are the default file name extensions for Python, C, and Java (respectively). – apnorton – 2013-12-29T20:51:29.413As for the curry challenge, I take it
y
will take no arguments, but what shouldg
return? – John Dvorak – 2013-12-29T20:55:47.6771Continuing on Jan's comment: I assume we only have to provide
f
, but notx
ory
. Thus,g
could return anything. – apnorton – 2013-12-29T20:57:03.043@xem, the you'll end up with a bad score if you write too much code, so the idea is to write an optimally bad amount of code, and still do well on the other challenges.
JanDvorak there is a 10% penalty for each time you use a language beyond the first time. E.g. if you use golfscript 3 times, then you'll get a 20% multiplier on your overall score. – Dan Prince – 2013-12-29T21:00:52.513
So if I make my 9 short functions in JS, I'll have a 190% penalty but I'll be running for the "good parts" trophy? What does "highest" mean in this trophy definition? Does it refer to the number of characters or the number of functions? – xem – 2013-12-29T21:02:41.510
What counts as a block in the Timber challenge? Each ASCII character is a separate block? Straight lines? – John Dvorak – 2013-12-29T21:04:32.900
All non whitespace blocks are blocks (slashes are the only exception) – Dan Prince – 2013-12-29T21:05:08.640
@xem updated the question. – Dan Prince – 2013-12-29T21:06:24.223
Can we reorder the arguments? Namely, I'd like to get the arguments in Curry for Dinner in the opposite order. – John Dvorak – 2013-12-29T21:12:13.163
Think of it almost as a booby prize. The more trophies you get, the better right? But it's hard to get the JS/Python trophies and also get low character counts, so you'd have to write an 'optimally bad amount of code' – Dan Prince – 2013-12-29T21:12:50.393
1@JanDvorak, Sorry, but people have already started. I'm happy to clarify on rules/edge-cases, but not change the actual puzzles. – Dan Prince – 2013-12-29T21:14:28.323
@DanPrince 'not able to use angle braces', can we use the ascii values of said braces? (hole 9) – Tyzoid – 2013-12-29T21:23:12.740
@Tyzoid Of course. – Dan Prince – 2013-12-29T21:23:42.930
Is it okay to count JavaScript, TypeScript, CoffeeScript, ... as separate languages? (to avoid the penalty) – xem – 2013-12-29T22:00:44.427
2Will different versions or flavours of a language be considered "different" for scoring purposes? e.g. Python 2 vs Python 3? Visual Basic vs VB.Net vs VBScript? How about supersets or near-supersets like C vs C++? Sorry for the pedantry, but this is code-golf! :-) – Darren Stone – 2013-12-30T00:14:32.050
@xem You can use one compile-to variant of another language. E.g. JS + Coffee won't get you a penalty, but JS+Coffee+Livescript will. – Dan Prince – 2013-12-30T04:45:08.067
@DarrenStone versions don't. See above comment for flavours. I'd count the VB variants as the same, but C and C++ as different. – Dan Prince – 2013-12-30T04:48:03.427
1@DanPrince are the hands on you clock backwards? The minute hand is generally the larger of the two. (my implementation is trivially changed by this, but I'd like to get it right) – Tyzoid – 2013-12-30T06:06:14.040
@Tyzoid my bad. Typo. – Dan Prince – 2013-12-30T06:36:57.890
Task 4: define "grid", constraints on random range. Task 5: define "grid", what about multiple occurrences of the symbol? Task 6: are we required to reverse engineer this format? How flexible is it (with respect to signs, slashes, padding, etc)? Task 7: what does it mean to "output a list"? Return it? Print it? What assumptions can be made about the padding in the input file? – Peter Taylor – 2013-12-30T13:55:37.937
Task 8: what is the "root" of a slash? Which positions touch it? Task 9: What is "Hacker News"? What is the ordering on its stories? Must the output file be valid? If so, to which standard? Does "each title is contained within a h1 element" mean
<h1>Title 1Title 2...Title 20</h1>
? – Peter Taylor – 2013-12-30T13:57:29.913Task 4: Rectangular data structure with a random height and width. Task 5: Any occurrence. Task 6: No you aren't. Look at the example diagram and extrapolate. Task 7: Return it. Task 8: Look at the example diagrams, the root is bottom. E.g. a \ attaches this way ->, whereas a / attaches this way <-. Task 9: Google it. No, but it must be able to display in a popular browser. No, it means each element in it's own h1 tag. – Dan Prince – 2013-12-30T14:05:05.993
You've managed to not answer most of the questions. – Peter Taylor – 2013-12-30T16:04:12.907
And everyone else has managed to do it without. This is a code golf. Use your imagination and sense of fun. – Dan Prince – 2013-12-30T16:32:45.227
Unicycling Dwarf Magic: Does it have to be ONE word? Is that even possible? :) – Christian Palmstierna – 2013-12-30T19:21:30.497
@CPX Seven source code extensions is possible, at least: hs lua b s el om py => blasphemously. If one allows .ii ("gcc pre-processed C++ source code") it's possible with 9. You don't happen to have a good list of programming language file extensions around, do you? – FireFly – 2013-12-30T20:19:04.833
Ok, it's definitely possible. I'll attempt a solution, but it'll take a while since I'll have to learn & find implementations for some... interesting languages. Here's a useful tip: the E programming language gets you a much-needed vowel.
– FireFly – 2013-12-30T21:21:26.6901Can you clarify what you mean by "you only need to submit the function"? Can we exclude imports/includes from the character count? What about code outside the function, or even separate functions? – grc – 2013-12-31T01:54:00.443
This is OT to me as both not a good fit for the SE model (out-of-band trophies, multiple mostly independent sub-answers per answer) and likely to generate copypaste-debate as the per-language and per-task shortest converge. – J B – 2013-12-31T12:43:56.610