# Omnimaga

## Calculator Community => Contests => Community Contests => Topic started by: pimathbrainiac on June 01, 2015, 08:27:41 am

Title: [ENDED] Code Golf - The Reboot #1
Post by: pimathbrainiac on June 01, 2015, 08:27:41 am
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 (http://codegolf.stackexchange.com/questions/50980/character-counts-in-source-code) challenge, but with a critical twist).

Challenge #1: Counting Code
Write 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.

The hypothetical program
Code: [Select]
`{omnimaga};` should produce one of the following outputs:
Code: [Select]
`; 1a 2g 1i 1m 2n 1o 1{ 1} 1`or
Code: [Select]
`{ 1o 1m 2n 1i 1a 2g 1} 1; 1`
Good luck, and make each character count.

Ranking
1) @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 Ranking
1) 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
Code: [Select]
`history 1|grep -o .|sort|uniq -c|rev`
Juju/Bash
Code: [Select]
`grep -o . a|sort|uniq -c|awk '{print \$2,\$1}'`
Code: [Select]
`sed 's/\(.\)/\1\'\$'\n/g' \$0|sort|uniq -c|rev|sed '1d'`
Tie for Python:
Cumred_Snektron/Python
Code: [Select]
`d=open("c").read()for c in list(set(d)):   print c, d.count(c)`Ikj/Python
Code: [Select]
`f=open('a').read()for i in sorted(set(f)):print(i,f.count(i))`
Sorunome/PHP
Code: [Select]
`<?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.
Code: [Select]
`FNS{Ks'Gs[Nd/KN`
That's it! I'll post another one later today!
Title: Re: Code Golf - The Reboot #1
Post by: Sorunome on June 01, 2015, 08:31:12 am
How is the input read in? Just declaring a variable? File input?
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 01, 2015, 08:32:06 am
The input is the source code of the program, so there is no typed/formatted input this time.
Title: Re: Code Golf - The Reboot #1
Post by: Sorunome on June 01, 2015, 09:02:54 am
108 bytes in PHP, let's see if i can get that smaller!
EDIT: 106 bytes!
EDIT2: more like 88 bytes :3
Title: Re: Code Golf - The Reboot #1
Post by: Ivoah on June 01, 2015, 10:15:36 am
Done in python with 87 bytes
:P Sorunome

EDIT: 81 77 bytes
Title: Re: Code Golf - The Reboot #1
Post by: Sorunome on June 01, 2015, 10:16:21 am
well PHP needs a two-byte header "<?" :P
edit: 73 bytes ^.^
Title: Re: Code Golf - The Reboot #1
Post by: Juju on June 01, 2015, 12:33:28 pm
Sounds fun, I'll check this out.

EDIT: 85 bytes!
Title: Re: Code Golf - The Reboot #1
Post by: c4ooo on June 01, 2015, 03:36:53 pm
I was just about to start this  :P but o well we all sorta "restarted" this on irc. Can I do reboot #2?  :3
Title: Re: Code Golf - The Reboot #1
Post by: lkj on June 01, 2015, 04:09:12 pm
62 bytes in Python  :)
Title: Re: Code Golf - The Reboot #1
Post by: Juju on June 01, 2015, 04:42:47 pm
I was just about to start this  :P but o well we all sorta "restarted" this on irc. Can I do reboot #2?  :3
That's an idea, different hosts for each week? Can I do #3?
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 01, 2015, 06:03:45 pm
I was just about to start this  :P but o well we all sorta "restarted" this on irc. Can I do reboot #2?  :3
That's an idea, different hosts for each week? Can I do #3?
As the guy where the idea came from in the first, place, go right ahead. That'd certainly reduce the workload between the hosts, making sure they get a break from hosting. ;)
Title: Re: Code Golf - The Reboot #1
Post by: Adriweb on June 01, 2015, 08:08:02 pm
53 in (ba)sh (using standard commands)

(and a bit less if I want to lose some portability, but oh well)

Edit : heh, Levak improved mine and got 36.
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 03, 2015, 10:15:07 am
I have to say, the results are very good so far. All of these but 2 are sub-100. I'm proud of the coders. :)
Title: Re: Code Golf - The Reboot #1
Post by: Sorunome on June 03, 2015, 10:15:57 am
If you could read a file in brainfuck i'd attempt it :P
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 03, 2015, 10:20:11 am
Just a heads-up. I will not be the only one posting Code Golf topics on Omni. When you submit in the future, please submit to whoever posted the code golf or myself (if they don't have an account on the site you have an account on)
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 07, 2015, 12:33:15 pm
As a heads-up, guys, today is the last day of the challenge. Make it count!
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 08, 2015, 07:01:41 am
The contest is closed, and the OP will be updated in a few minutes! Thanks everyone!
Title: Re: Code Golf - The Reboot #1
Post by: Sorunome on June 08, 2015, 08:03:12 am
Will be there any chance to see the other source codes which aren't in the first post? I am interested in muessigb's php sollution
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 08, 2015, 08:25:18 am
To keep the OP uncluttered, no, but PM me and I'll give you the requested solution.
Title: Re: Code Golf - The Reboot #1
Post by: Ivoah on June 08, 2015, 08:26:02 am
To keep the OP uncluttered, no, but PM me and I'll give you the requested solution.

Maybe you could just link to a pastebin with all the entries in it
Title: Re: Code Golf - The Reboot #1
Post by: Adriweb on June 08, 2015, 09:58:58 am
Ah if I knew about grep -o ... :P
ggwp
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 08, 2015, 10:26:47 am
To keep the OP uncluttered, no, but PM me and I'll give you the requested solution.
Actually, what I did was put the code in a table, with [ spoiler ] tags with the code inside. For example, taken at random from a pre existing contest:

Java
 Rank User Size Date Code 1 3298 189 8/29/2014 12:16:14 PM Spoiler For Spoiler: class G{public static void main(String[]s){String o="";int p=0;for(char c:"code".toCharArray()){p=s[0].toLowerCase().indexOf(c,p);if(p<0){o="0";break;}o=o+(p+1)+"\n";}System.out.print(o);}} 2 pimathbrainiac 268 8/25/2014 6:57:57 PM Spoiler For Spoiler: import java.util.Arrays;public class C7{public static void main(String[] args){String s=Arrays.toString(args);int a,b,c,d;a=s.indexOf('c')-1;b=s.indexOf('o')-1;if(b>a){c=s.indexOf('d')-1;if(c>b){d=s.indexOf('e')-1;if(d>c){System.out.print(a+"\n"+b+"\n"+c+"\n"+d);}}}}}

Maybe you should do that.
Title: Re: Code Golf - The Reboot #1
Post by: Juju on June 08, 2015, 01:25:32 pm
Yep, what @JWinslow23 said.