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 containingninstances ofc.Somewhere in the Rough (73)
f(t:string, s:string, n:integer) -> i
Whereiis the index of thenthinstance ofsint.Curry for Dinner (6235)
f(x:function, y: function) -> gWheregis a function that will cally,ntimes; wherenis the return value ofxSpew (92)
f(p:string)Writes to file atpand fills it with a randomly sized rectangle of random characters (ascii).Treasure Hunt (75)
f(p:string, c:char) -> (x, y)Reads file atpwhich contains a grid of symbols and returns thexandycoordinates 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 1Make 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 atpwhich 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:booleanWhere 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 ofstor, 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>...etcCatch:
- 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
Happy Gilmoore




Are languages without functions excluded from the challenge? Or can we also write STDIN to STDOUT programs instead of functions? – Martin Ender – 11 years ago
I'm closing this question because multi-part challenges with little interaction between subchallenges became off topic by community consensus.
– Dennis – 10 years agoI assume "angle braces" refers to what I call "brackets," right?
[]– apnorton – 12 years ago2@anorton
<&>– Dan Prince – 12 years ago@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 – 12 years ago
1An analog clock has 12 positions for each hand, but you only give us 8. How does that work? – Kevin – 12 years ago
@Kevin You don't have to account for the other positions. That diagram shows you all the possible configurations of either hand. – Dan Prince – 12 years ago
@anorton, just the function definition. – Dan Prince – 12 years ago
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 – 12 years ago1@anorton 1/5, 5/25, 7/35, 11/55 – Dan Prince – 12 years ago
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 – 12 years ago
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 – 12 years ago
@xem extensions should refer to
py,c,java, etc, which are the default file name extensions for Python, C, and Java (respectively). – apnorton – 12 years agoAs for the curry challenge, I take it
ywill take no arguments, but what shouldgreturn? – John Dvorak – 12 years ago1Continuing on Jan's comment: I assume we only have to provide
f, but notxory. Thus,gcould return anything. – apnorton – 12 years ago@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 – 12 years ago
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 – 12 years ago
What counts as a block in the Timber challenge? Each ASCII character is a separate block? Straight lines? – John Dvorak – 12 years ago
All non whitespace blocks are blocks (slashes are the only exception) – Dan Prince – 12 years ago
@xem updated the question. – Dan Prince – 12 years ago
Can we reorder the arguments? Namely, I'd like to get the arguments in Curry for Dinner in the opposite order. – John Dvorak – 12 years ago
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 – 12 years ago
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 – 12 years ago
@DanPrince 'not able to use angle braces', can we use the ascii values of said braces? (hole 9) – Tyzoid – 12 years ago
@Tyzoid Of course. – Dan Prince – 12 years ago
Is it okay to count JavaScript, TypeScript, CoffeeScript, ... as separate languages? (to avoid the penalty) – xem – 12 years ago
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 – 12 years ago
@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 – 12 years ago
@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 – 12 years ago
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 – 12 years ago
@Tyzoid my bad. Typo. – Dan Prince – 12 years ago
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 – 12 years ago
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 – 12 years agoTask 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 – 12 years ago
You've managed to not answer most of the questions. – Peter Taylor – 12 years ago
And everyone else has managed to do it without. This is a code golf. Use your imagination and sense of fun. – Dan Prince – 12 years ago
Unicycling Dwarf Magic: Does it have to be ONE word? Is that even possible? :) – Christian Palmstierna – 12 years ago
@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 – 12 years ago
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 – 12 years ago1Can 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 – 12 years ago
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 – 12 years ago