\$\begingroup\$

Score: 1320

I've plenty to do to improve this score... Oh well, at least I avoided repeated-language penalties. :-)

1. Python (21 chars)

def f(c,n):print(c*n)

The "obvious" solution.

2. ECMAScript 6 (47 chars)

f=(t,s,n)=>t.split(s).slice(0,n).join(s).length

Finds the index in a bit of an unconventional way, by counting the length of the substring before it.

3. J (12 chars)

f=:2 :'v^:u'

The built-in conjunction ^: raises a function to a power (i.e. repeats a function a given number of times). That is, f^:3 y = f (f (f y))) . However, it's overloaded to alos accept functions rather than integers, in which case it runs the function on the input to get the number of repetitions. Unfortunately we need to flip the operands for the task, otherwise we'd have the consise answer f=:^: .

4. C (95 chars)

#include <stdio.h> #include <stdlib.h> f(char*p){FILE*f=fopen(p,"a");for(int n=rand(),y=n*n;y--;y%n||putc(10,f))putc(rand()%94+32,f);}

This task leaves quite a bit of room for interpretation and abuse: is it okay to just output a random printable ASCII character and say it's a randomly-dimensioned rectangle with dimensions from the set {1}? Probably not. Anyway, I went with plain rand() but in reality you probably want to add %9 or something if you want to test it. On my linux box I didn't have to flush the file in order for it to be written (I guess it flushes automatically on program exit), but I'm pretty sure you have to flush it to be standards-compliant, so feel free to add fflush(f); to the count here.

5. Haskell (100 chars)

import Control.Arrow import Data.List import Data.Tuple import Control.Applicative h p c=head.filter(p c.snd).zip[1..] g c=swap.(id***fst.h(==)c).h elem c.lines f p c=g c<$>readFile p

I like the repeated pattern between finding the row and the column (abstracted via h ).

6. Lua (261 chars)

function f(s,m,y,...)if s and m then for i,v in pairs(m)do io.write(v,(" "):rep(#tostring(s[i])))end print()elseif s then r=unpack f(s,{"",f(trouse,r(s))})f({f(nil,r(s))},s)elseif y then return ("/%s%d\\"):format(m<y and"+"or"-",math.abs(m-y)),f(s,y,...)end end

Makes use of multiple return values and recursion to deal with computing the differences. It cost me a few characters to match the sample output exactly (adding the right amount of spaces everywhere).

7. Go (307 chars)

func f(p string)[]int{var l[]string g,_:=os.Open(p) H,M,s,m:=0,0,bufio.NewScanner(g),[][]int{{-1,-1,11},{-1,0,12},{-1,1,1},{0,-1,9},{0,1,3},{1,-1,7},{1,0,6},{1,1,5}} for s.Scan(){l=append(l,s.Text())} for _,a:=range m{if l[2+a[0]*2][2+a[1]*2]!=' '{M=a[2]} if l[2+a[0]][2+a[1]]!=' '&&(H==0||M!=a[2]){H=a[2]}} return[]int{H,M}}

Could probably be golfed a lot more; I barely know Go.

8. CoffeeScript (+ node.js) (223 chars)

f=(p)-> a=require('fs').readFileSync(p).toString().split "

" U=(i,j)->a[i]?[j]and a[i][j]==' ' for l,i in a for c,j in l m = "/":[i+1,j-1] "\\":[i+1,j+1] a:[i+1,j] return if U.apply(0,m[c]or m.a) 1

A bit of a cheap-shot since I already have JS. Oh well. Returns a falsy value (namely, undefined ) or a truthy value (namely, 1 ) to indicate the answer.

9. Bash (254 chars)

f(){ curl https://news.ycombinator.com/rss| awk -Ftitle '{OFS="h1\76

\74h1";ORS="";print substr(OFS,4);print$2,$4,$6,$8,$10,$12,$14,$16,$18,$20,$22,$24,$26,$28,$30,$32,$34,$36,$38,$40;print substr(OFS,0,3)}'| while read l;do echo ${l//$1/$2};done| tee $3 }