26
4
9-hole mini-golf: Description
- 9 (mostly fairly easy) code golfing challenges of varying difficulty
- Penalties for using the same language more than once
- All challenges about a specific theme (this theme: Text Manipulation)
- Input and output can be anywhere reasonable (i.e. STDIN and STDOUT, reading from/writing to a file, function argument and return value, etc.) but must NOT be hardcoded into the program
- Heavily inspired by 9 Hole Challenge and Text Mechanic
Holes
Code-golf bag
Take two strings as input.
Output the first string's character count, while ignoring any occurence of any character in the second string.
Example:f("foobarbaz", "ao")
=>5
A pre-text for golfing
Take two strings as input.
Output the first string, with every line prefixed with the second.
Example:f("foo\nbar\nbaz", "a")
=>"a foo\na bar\na baz"
War of tabs vs spaces
Take a strings
, a numbern
, and a booleanb
(specified however you want) as input.
Ifb
is true, outputs
with every tab converted ton
spaces.
Else, output thes
with everyn
spaces converted to tabs.
Example:f("if (x) {\n\tdoStuff();\n}", 4, true)
=>"if (x) {\n[sp][sp][sp][sp]doStuff();\n}"
([sp]
means space)Pillars of golf
Take a string
s
, a numbern
, and another numberm
as input.
Outputs
in columns ofn
lines each andm
characters per column.
Also have padding of one space between the columns.
Example:f("this is some placeholder text, foo bar baz...", 3, 5)
=>this aceho foo is so lder bar b me pl text, az...
Friendly letters
Take a strings
and a numbern
as input.
Output the most common group ofn
letters ins
.
If there is a tie, output any or all of them.
Example:f("abcdeabcfghiabc", 3)
=>"abc"
Scrambled
Take a string as input.eggsletters for breakfast
Output the string with all of its words scrambled (letter order randomized) except their first and last letters.
For simplicity, assume that the input will be a list of "word"s, space separated (i.e. in@$&_():;" foo bar
,@$&_():;"
is considered a "word.")
Example:f("this is a sentence that will be scrambled")
=>"tihs is a stcneene that wlil be sclamrbed"
ASCIIfy
Take a string as input.
If the string only contains numbers and spaces, then replace the numbers with their respective ASCII characters (removing the spaces).
Else, do the reverse (characters to numbers).
Example:f("ASCIIfy challenge")
=>"65 83 67 73 73 102 121 32 99 104 97 108 108 101 110 103 101"
Example 2:f("65 83 67 73 73 102 121 32 99 104 97 108 108 101 110 103 101")
=>"ASCIIfy challenge"
Mini-mini-markdown transformation
Take a string as input.
Output the string converted with mini-markdown, as used in comments on Stack Exchange.
This is an even mini-er version: you only need to handle**bold**
,*italics*
, and`code`
.
You need not handle invalid nesting, like**foo *bar** baz*
. Also assume that when you see a delimiter (*
or`
), it will always mean to format (i.e.te**st**ing
=>te<b>st</b>ing
, andfoo* bar *baz
=>foo<i> bar </i>baz
).
Example:f("**foo** *bar **baz*** `qux`")
=>"<b>foo</b> <i>bar <b>baz</b></i> <code>qux</code>"
Only the best characters
Take a strings
, numbern
, and stringr
as input.
Output then
th character of each word ins
. (0-indexed, words are space-separated).
If the length of the word is less thann
, user
for that word instead.
Example:f("this is a test sentence foo bar baz", 2, "-")
=>"i--snorz"
Scoring
Your score is the sum of the character counts of your programs. For every repeated language, multiply by 110%. For example, if you have three Ruby solutions, and the total character count of all of your solutions is 1000, your score is 1000 * 1.1 * 1.1 = 1210. Round down if you have a non-integer score.
1
Challenge 8 touches on one of the least well specified aspects of Markdown, and the one which is hardest to do really well. It needs a clear explanation of how to handle ambiguities and a good test suite. See Emphasis.text from the mdtest suite.
– Peter Taylor – 2014-01-22T22:59:57.013@PeterTaylor Well,
_
doesn't matter since I specified not to include it. I've edited to clarify some of the others. – Doorknob – 2014-01-22T23:04:58.720What about
**foo***bar**baz*
? – Peter Taylor – 2014-01-22T23:12:12.890@PeterTaylor That would be
<b>foo</b><i>bar</i><i>baz</i>
, as per "Also assume that when you see a delimiter (*
or ```), it will always mean to format" – Doorknob – 2014-01-22T23:14:50.6231
Challenge 6 is identical to this one.
– daniero – 2014-01-23T02:34:26.437@danerio Darn it! But in mine you don't have to keep the positions of the non-word characters, so it's slightly different. :-P I'll try to make it a little more different... – Doorknob – 2014-01-23T02:37:24.910
:P Also, in challenge 4, the example would suggest that you mean "
m
characters per column"..? – daniero – 2014-01-23T02:56:25.970@daniero Yep, fixed. And sorry about the typo of your username in my last comment, just noticed that also :-P – Doorknob – 2014-01-23T02:57:48.960
In challenge 8, can we assume that the
<foo>
s always appear at the beginning of a word and that the</foo>
s always appear at the end? – Justin – 2014-01-23T06:11:01.637Considering that this is the second question of the kind, is a new tag appropriate? (maybe something like [tag:multi-challenge]) – Justin – 2014-01-23T07:27:02.657
@Quincunx "Also assume that when you see a delimiter (
*
or\``), it will always mean to format (i.e.
testing=>
te<b>st</b>ing`," – Doorknob – 2014-01-23T12:49:42.563*foo**bar**baz*
:<i>foo<b>bar</b>baz</i>
or<i>foo</i><i>bar</i><i>baz</i>
? – Peter Taylor – 2014-01-23T18:01:46.960@Peter You don't have to handle edge-cases like that. – Doorknob – 2014-01-23T18:03:17.943
4
I'm voting to close this question as off-topic because it's a multi-part challenge with insufficient interaction between the parts
– pppery – 2019-11-09T01:54:52.320