We'll be counting stars

GolfScript, 30 characters

.{.'
 '?)\42if}%.{@'*'/,(}2*]`

Takes the input from stdin. Example (test online):

> |  v  |
> * * * *
>  * * *

["*  *  *\n* * * *\n * * *\n" 7 10]

Python - 58 66 characters

Sooo... my first Code Golf attempt...

Code:

import re;p=re.sub(r'\S','*',i);print[p,i.count('*'),p.count('*')]

Output:

['*  *  *\n* * * *\n * * *', 7, 10]

Variables:

  • i - input string
  • p - pattern
  • o - output - removed

Dependencies:

Python re module

Full code:

import re
i = '|  v  |\n* * * *\n * * *'    
p = re.sub(r'\S','*', i)
print [p, i.count('*'), p.count('*')]

Edits:

  • Added import re to solution
  • Replaced o= with print
  • r'[/\S/g]' was changed to r'\S' (thanks @14mRh4X0r)

Ruby 2.0, 53 characters

p [r=gets($n).gsub(/\S/,?*),$_.count(?*),r.count(?*)]

Not sure on the exact input/output formats required. This takes input on STDIN and formats the output like so:

Input:

|  v  |
* * * *
 * * *

Output:

["*  *  *\n* * * *\n * * *", 7, 10]

Tags:

Code Golf