[Question]
  [
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
 
 
---
 This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic).
Closed 4 years ago.
[Improve this question](/posts/19163/edit) 
# 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](https://codegolf.stackexchange.com/q/16707/3808) and [Text Mechanic](http://textmechanic.com/)
# Holes
1. ## 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`
2. ## 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"`
3. ## War of tabs vs spaces
Take a string `s`, a number `n`, and a boolean `b` (specified however you want) as input.  
If `b` is true, output `s` with every tab converted to `n` spaces.  
Else, output the `s` with every `n` 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)
4. ## Pillars of golf
Take a string `s`, a number `n`, and another number `m` as input.  
Output `s` in columns of `n` lines each and `m` 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...
```
5. ## Friendly letters
Take a string `s` and a number `n` as input.  
Output the most common group of `n` letters in `s`.  
If there is a tie, output any or all of them.  
Example: `f("abcdeabcfghiabc", 3)` => `"abc"`
6. ## Scrambled ~~eggs~~ letters for breakfast
Take a string as input.  
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"`
7. ## 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"`
8. ## 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`, and `foo* 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>"`
9. ## Only the best characters
Take a string `s`, number `n`, and string `r` as input.  
Output the `n`th character of each word in `s`. (0-indexed, words are space-separated).  
If the length of the word is less than `n`, use `r` 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.
# Good luck!
  
[Answer]
# Score: 382 \* 1.12 = 462
Languages prone to change.
## 1. APL, ~~8~~ 4
Thanks @marinus for shaving 4 chars off.
```
f←⍴~
```
Called with the strings as the left and right arguments, eg.
```
      'foobarbaz' f 'ao'
5
```
## 2. Ruby, ~~35~~ 31
Thanks @DoorknobofSnow for shaving 4 chars off.
```
f=->s,r{s.gsub(/(?<=^)/,r+' ')}
```
## 3. Python, 48
```
f=lambda s,n,b:s.replace(*['\t',' '*n][::2*b-1])
```
## 4. GolfScript, 20
```
{@//zip{' '*}%n*}:f;
```
Assumes that the arguments are on the stack. [Test online](http://golfscript.apphb.com/?c=e0AvL3ppcHsnICcqfSVuKn06ZjsKInRoaXMgaXMgc29tZSBwbGFjZWhvbGRlciB0ZXh0LCBmb28gYmFyIGJhei4uLiIgMyA1IGY%3D)
## 5. J, 50
```
f=:({~[:(i.>./)+/"1@=@(}.~0-1{$))@|:@([$~],1+[:$[)
```
Called with the string as the left argument and the number as the right, eg.
```
   'abcdeabcfghiabc' f 3
abc
```
## 6. Ruby, 61
```
f=->s{s.gsub(/(?<!^| )[^ ]+(?!$| )/){[*$&.chars].shuffle*''}}
```
## 7. GolfScript, ~~39~~ ~~35~~ 34
```
{[.10,' '*-{{}/]' '*}{~]''+}if}:f;
```
Again, assumes the argument is on the stack. [Test online](http://golfscript.apphb.com/?c=e1suMTAsJyAnKi17e30vXScgJyp9e35dJycrfWlmfTpmOwpbIkFTQ0lJZnkgY2hhbGxlbmdlIiAiNjUgODMgNjcgNzMgNzMgMTAyIDEyMSAzMiA5OSAxMDQgOTcgMTA4IDEwOCAxMDEgMTEwIDEwMyAxMDEiXXtmIHB1dHN9Lw%3D%3D)
## 8. Perl, 98
```
sub f{$_=@_[0];s!\*\*(.+?)\*\*!<b>$1</b>!g;s!\*(.+?)\*!<i>$1</i>!g;s!`(.+?)`!<code>$1</code>!g;$_}
```
## 9. Haskell, 36
```
f s n r=[(x++cycle r)!!n|x<-words s]
```
[Answer]
## Python - 697 × 1.19 ≈ 1644
Gee, I sure love lambdas.
**Note**: 3 and 5 were shamelessly copied from [Volatility's answer](/a/19168/14202), as I couldn't find a better alternative. Also, this was done *just for fun*.
```
f=lambda a,b:sum([x not in b for x in a])        # 1, 41 chars
f=lambda a,b:b+' '+a.replace('\n','\n'+b+' ')    # 2, 43 chars
f=lambda s,n,b:s.replace(*['\t',' '*n][::b*2-1]) # 3, 47 chars
f=lambda s,n,m:'\n'.join([' '.join([s[x:x+m]for x in range(y*m,len(s),m*n)])for y in range(n)])
                                                 # 4, 94 chars
f=lambda s,n:max([s[x:x+n]for x in range(len(s)+1-n)],key=s.count)
                                                 # 5, 66 chars
import random;f=lambda s:' '.join([''.join(sorted(y,key=lambda*x:random.random()))for y in s.split()])
                                                 # 6, 102 chars
f=lambda s:s.replace(' ','').isdigit()and ''.join(map(chr,map(int,s.split())))or ' '.join(map(str,map(ord,s)))
                                                 # 7, 110 chars
import re;f=lambda s:re.sub('`(.*?)`','<code>\\1</code>',re.sub(r'\*(.*?)\*','<i>\\1</i>',re.sub(r'\*\*(.*?)\*\*','<b>\\1</b>',s)))
                                                 # 8, 128 chars
f=lambda s,n,r:''.join([len(x)>n and x[n]or r for x in s.split()])
                                                 # 9, 66 chars
```
**EDIT**: Thanks to Volatility for the tips.
[Answer]
# Score 513 \* 1.15 = 826
Took quite a beating by the same-language penalty. Solved most of these in Ruby just to finish them as fast as I could. Might change some languages later. Added a small recap/explanation on each answer.
# 1: Python (46)
```
f=lambda a,b:len([x for x in a if not x in b])
```
First, shorter answer in **Ruby 2.0 (30)** that gives more penalty and higher overall score:
```
p (gets.chars-gets.chars).size
```
# 2: Ruby 1.9+ (37)
Returns each line of `s` prefixed with `t`:
```
f=->s,t{s.split(?\n).map{|x|t+x}*?\n}
```
# 3: Ruby 1.9+ (48)
Returns `s` with tabs replaced by `n` spaces or vice versa, depending on `b`:
```
f=->s,n,b{r=[" "*n,?\t];b||r.reverse!;s.gsub *r}
```
# 4: Ruby 1.9+ (95)
Somebody shoot me.
```
f=->s,n,m{[*s.chars.each_slice(m).map{|w|w*''}.each_slice(s.size/m/n)].transpose.map{|w|w*' '}}
```
# 5: Ruby 1.9+ (58)
Returns most common run of `n` characters in `s`:
```
f=->s,n{(a=s.chars.each_slice(n)).max_by{|v|a.count v}*''}
```
# 6: J (47)
Scrambles the text somehow; Shamelessly stolen verbatim from [marinus](https://codegolf.stackexchange.com/a/9263/4372):
```
''[1!:2&4('\w(\w+)\w';,1)({~?~@#)rxapply 1!:1[3
```
# 7: Ruby (57+1)
Prints input ASCIIfied or de-ASCIIfied. Run with the `-p` switch.
```
~/\d/?gsub(/\d+\s*/){$&.to_i.chr}:gsub(/./){"#{$&.ord} "}
```
# 8: Sed (87)
Prints input converted from (mini)markdown to HTML:
```
s:\*\*([^*]+)\*\*:<b>\1</b>:g;
s:\*([^*]+)\*:<i>\1</i>:g;
s:`([^`]+)`:<code>\1</code>:g
```
# 9 Ruby 1.9+ (37)
Returns a string of the `n`th characters of each first word in `s`, or `r`:
```
f=->s,n,r{s.split.map{|w|w[n]||r}*''}
```
[Answer]
Work in progress
## 1. Java - 66
```
int f(String s,String b){for(char c:b)s=s.replace(b,"");return s;}
```
## 2. Java - 64
```
String f(String i,String r){return i.replaceAll("(?m)^",r+" ");}
```
## 3. Python - 58
```
def f(s,n,b):t=" "*n;a=t,'\t';print s.replace(a[b],a[b^1])
```
## 4. Python - 84
```
def f(s,n,m):
 a=['']*n;c=0
 while s:a[c%n]+=s[:m]+" ";s=s[m:];c+=1
 for i in a:print i
```
## 5.
## 6.
## 7. Befunge 98 - 9
```
&,5j3.~@#
```
## 8.
## 9.
]