CodeWalrus

Development => Calculators => Calculator News, Coding, Help & Talk => Topic started by: pimathbrainiac on June 01, 2015, 12:46:43 pm

Title: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 01, 2015, 12:46:43 pm
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 Sunday 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.
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.

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
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!
Title: Re: Code Golf - The Reboot #1
Post by: Snektron on June 01, 2015, 01:47:25 pm
Awesome! This is such a cool thing! I will be participating for sure! :D
Also how about code from system libraries?
Also what about making a custom programming language? :trollface:

also: i'm at 91 bytes already :P
EDIT: 62 now.
Title: Re: Code Golf - The Reboot #1
Post by: Unicorn on June 01, 2015, 04:17:01 pm
Wait wat? No scratch? But But so much...


:trollface:
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 01, 2015, 05:00:55 pm
Ha ha! Excellent job with the challenge idea, it's sure to be interesting. This is exactly how I imagined a reincarnation of the contest. :)

And nice job with the pun, by the way. I was worried you were trying to byte off more than you could chew. At first I didn't notice the pun, I think my brain's getting number by the minute...but brilliant wordsmithing nonetheless. :P
Title: Re: Code Golf - The Reboot #1
Post by: Scipi on June 01, 2015, 06:38:56 pm
I've got it down to 168 bytes in C++. Don't think there's much the language will let me do to reduce it further, though. :/ Damn strict typing.
Title: Re: Code Golf - The Reboot #1
Post by: DarkestEx on June 01, 2015, 06:39:50 pm
I am at 79 bytes right now.
Title: Re: Code Golf - The Reboot #1
Post by: Juju on June 01, 2015, 06:42:40 pm
I'm down to 116 85 bytes in Ruby now.
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 01, 2015, 07:11:14 pm
Also, please remember to PM me with your source to be added to the list. Otherwise, you don't get counted.
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 01, 2015, 07:21:32 pm
Question, since the next Code Golf contests will be Omni-exclusive, will members of other forums be required to create an Omni account and be disallowed to post about their entry elsewhere? Because in 2011 United-TI did a joint contest with Revsoft and MaxCoderz where contestants were not allowed to cross-post their work on any forum other than United-TI, and this backfired with zero entry.
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 01, 2015, 07:25:38 pm
People will be allowed to post about their entry elsewhere and can PM me from any site for entry, but the topics for each week and the official discussion/q&a will only be on Omni so contestants at least have to check the omni subforum (https://www.omnimaga.org/community-contests/) where I'm posting the topics on Monday at least.
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 01, 2015, 07:40:28 pm
Aah nice to see there's a community contest sub-forum :D. I hope that since you will be busy this Summer that you will still have time to create new contests every week, though, especially considering you can usually barely even find time to do project periodical anymore >.<

Good luck! And good luck to participants too. Code Golf was one of the longest running TI community contest actually.
Title: Re: Code Golf - The Reboot #1
Post by: alexgt on June 01, 2015, 08:39:10 pm
What about the name? In Ti-Basic and HP PPL the name counts towards the total bytes used :-\
Title: Re: Code Golf - The Reboot #1
Post by: DarkestEx on June 01, 2015, 08:41:36 pm
I got it to 126 chars in JS
Title: Re: Code Golf - The Reboot #1
Post by: Scipi on June 01, 2015, 08:46:07 pm
I've brought it down to 157 bytes in C/C++
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 01, 2015, 09:07:56 pm
Another issue is that on-calc TI-Z80 BASIC uses tokens, so Output( is actually 1 byte instead of 7.
Title: Re: Code Golf - The Reboot #1
Post by: Snektron on June 01, 2015, 09:09:30 pm
Can you even read files with TI-Basic? well maybe with some libs but still
Title: Re: Code Golf - The Reboot #1
Post by: alexgt on June 01, 2015, 09:13:15 pm
Quote from: DJ Omnimaga on June 01, 2015, 09:07:56 pm
Another issue is that on-calc TI-Z80 BASIC uses tokens, so Output( is actually 1 byte instead of 7.

Yeah, different languages have different strengths.

I don't think I will do this one because I only know 3 languages Axe, Ti-Basic, and HP PPL :-\

EDIT:
Quote from: Cumred_Snektron on June 01, 2015, 09:09:30 pm
Can you even read files with TI-Basic? well maybe with some libs but still

I don't think so :(, still I never want to code with it again :P
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 03, 2015, 02:16:11 pm
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 03, 2015, 02:20:58 pm
I also wanna become a host. I'll have way more free time now :3=
Title: Re: Code Golf - The Reboot #1
Post by: Unicorn on June 03, 2015, 02:27:17 pm
O.O @alexgt how could you? TI BASIC is best! <3
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 03, 2015, 02:30:19 pm
Try to make Supersonic Ball with scrolling in Basic, though. :P

Anyway glad that this contests have more authors now. I was a bit worried about the workload that pimath would have if he had worked on this alone.
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 03, 2015, 02:34:47 pm
Quote from: DJ Omnimaga on June 03, 2015, 02:30:19 pm
Try to make Supersonic Ball with scrolling in Basic, though. :P

Anyway glad that this contests have more authors now. I was a bit worried about the workload that pimath would have if he had worked on this alone.

Workload was part of why I quit :P
Title: Re: Code Golf - The Reboot #1
Post by: DarkestEx on June 03, 2015, 02:39:03 pm
Quote from: JWinslow23 on June 03, 2015, 02:20:58 pm
I also wanna become a host. I'll have way more free time now :3=

Yeah, I'd love to become a host aswell :)
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 03, 2015, 02:40:01 pm
Quote from: JWinslow23 on June 03, 2015, 02:34:47 pm
Quote from: DJ Omnimaga on June 03, 2015, 02:30:19 pm
Try to make Supersonic Ball with scrolling in Basic, though. :P

Anyway glad that this contests have more authors now. I was a bit worried about the workload that pimath would have if he had worked on this alone.

Workload was part of why I quit :P
Don't you mean spending way too much time on Twitter and Vine? :trollface:
Title: Re: Code Golf - The Reboot #1
Post by: JWinslow23 on June 03, 2015, 02:46:28 pm
Quote from: DJ Omnimaga on June 03, 2015, 02:40:01 pm
Quote from: JWinslow23 on June 03, 2015, 02:34:47 pm
Quote from: DJ Omnimaga on June 03, 2015, 02:30:19 pm
Try to make Supersonic Ball with scrolling in Basic, though. :P

Anyway glad that this contests have more authors now. I was a bit worried about the workload that pimath would have if he had worked on this alone.

Workload was part of why I quit :P
Don't you mean spending way too much time on Twitter and Vine? :trollface:

Dude. No. I don't even do that anymore. :P
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 05, 2015, 11:46:11 pm
Okay, so there's a discussion/information/rules topic on Omni for this now: https://www.omnimaga.org/community-contests/code-golf-the-informationdiscussionplanning-thread/
Title: Re: Code Golf - The Reboot #1
Post by: pimathbrainiac on June 08, 2015, 11:15:51 am
Final standings are up! Thanks for playing! Don't forget to check https://www.omnimaga.org/community-contests/ later today for the new challenge, and remember, you don't have to be a member of Omni or even log in over there to play.
Title: Re: Code Golf - The Reboot #1
Post by: Snektron on June 08, 2015, 03:44:49 pm
I actually could lose another byte, theres a spae between ',' and 'c.dount(d)' <_<
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 08, 2015, 04:10:24 pm
Comgrats to winners. :D Also pimath DarkestEx is benedikt_muessig on Omni. Cumred is Kryzrox but then it might lead to confusion if you replace his name.
Title: Re: Code Golf - The Reboot #1
Post by: Snektron on June 08, 2015, 04:24:11 pm
Kzyrox* it's my gaming name thingly. Noone can ever pronounce it right <_<
Title: Re: Code Golf - The Reboot #1
Post by: Ivoah on June 08, 2015, 04:32:17 pm
@Cumred_Snektron you could have reduced your program by 2 bytes if you removed some whitespace
Title: Re: Code Golf - The Reboot #1
Post by: Scipi on June 08, 2015, 09:09:01 pm
Thought I PMed an updated version of my entry that brought it down to 131 bytes. <_< Oh, well it doesn't really affect my placement :P

Here's my entry, if anyone's curious.

#include<set>
int main(){int a[256]{},i;auto f=fopen("m","r");while(i=~getc(f))a[~i]++;for(int x:a)x?printf("%c %d\n",i,x):0,++i;}
Title: Re: Code Golf - The Reboot #1
Post by: DJ Omnimaga on June 08, 2015, 10:32:24 pm
Quote from: Cumred_Snektron on June 08, 2015, 04:24:11 pm
Kzyrox* it's my gaming name thingly. Noone can ever pronounce it right <_<
It is quite hard to spell properly too :P