Hello ladies and gents, welcome to Code Golf! As you probably noticed, I am not JWinslow23 because my name is pimathbrainiac. For those of you who don't know what Code Golf is, I'll tell you. You must write a program in
any programming language and make the source as few bytes as possible. There are some rules that you must follow each week.
All programs and source files must be submitted to me via PM by midnight Sunday. Winners will be announced Saturday afternoon, and new challenges appear on Monday.
The program outputs must follow the proper formatting as stated in the week's challenge.
All of your source must be in a single source file. Using certain command-line options to compile code not in your source file is cheating.
Esolangs are okay, but the source must be text.
No drag-and-drop languages, since those can't be counted the same way.
Without further ado: This weeks challenge! (inspired by
this challenge, but with a critical twist).
Challenge #1: Counting CodeWrite a program that counts the number of occurrences of each unique character in your code and outputs a list of the number of occurrences of each unique character.
No extra white space, with the exception of an optional newline at the end of the program.
The characters listed must be in one of two orders. Either the order of character values in the character encoding used by your language (probably ASCII), or the order the characters appear in your source.
Your program
must read its source file.
The hypothetical program
{omnimaga};
should produce one of the following outputs:
; 1
a 2
g 1
i 1
m 2
n 1
o 1
{ 1
} 1
or
{ 1
o 1
m 2
n 1
i 1
a 2
g 1
} 1
; 1
Good luck, and make each character
count.
Ranking1)
@Levak - 36 Bytes (Bash)
2)
@Juju - 44 Bytes (Bash)
3)
@Adriweb - 53 Bytes (Bash)
4) Cumred_Snektron - 62 Bytes (Python)
4) @Ikj - 62 Bytes (Python)
6)
@Sorunome - 73 Bytes (PHP)
7)
@Ivoah - 77 Bytes (Python)
8 ) DarkestEx/muessigb - 78 Bytes (PHP)
9)
@Juju - 84 Bytes (Ruby)
10)
@Juju - 86 Bytes (Python2)
11) DarkestEx/muessigb - 126 Bytes (html/JavaScript)
12)
@Scipi - 157 Bytes (C++)
Language Ranking1) Bash - 36 Bytes
2) Python - 62 Bytes
3) PHP - 73 Bytes
4) Ruby - 84 Bytes
5) html/JS - 126 Bytes
6) C++ - 157 Bytes
Here we go, top three entries and top entry in the top three languages:
Levak/Bash
history 1|grep -o .|sort|uniq -c|rev
Juju/Bash
grep -o . a|sort|uniq -c|awk '{print $2,$1}'
Adriweb/Bash
sed 's/\(.\)/\1\'$'\n/g' $0|sort|uniq -c|rev|sed '1d'
Tie for Python:
Cumred_Snektron/Python
d=open("c").read()
for c in list(set(d)): print c, d.count(c)
Ikj/Python
f=open('a').read()
for i in sorted(set(f)):print(i,f.count(i))
Sorunome/PHP
<?foreach(count_chars(@file(b)[0])as$i=>$n)if($n>0)echo chr($i)." $n\n";
Congrats guys!
Now, we had someone among us who requested not to be listed as a competitor, but his code was the smallest. At 15 Bytes in Pyth, Runer112 had the smallest valid solution, but is not in the competitive group, so the standings above are it.
FNS{Ks'Gs[Nd/KN
That's it! I'll post another one later today!