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 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
Code:
{omnimaga};
should produce one of the following outputs:

Code:
; 1
a 2
g 1
i 1
m 2
n 1
o 1
{ 1
} 1

or

Code:
{ 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

Code:
history 1|grep -o .|sort|uniq -c|rev


Juju/Bash

Code:
grep -o . a|sort|uniq -c|awk '{print $2,$1}'


Adriweb/Bash

Code:
sed 's/\(.\)/\1\'$'\n/g' $0|sort|uniq -c|rev|sed '1d'


Tie for Python:
Cumred_Snektron/Python

Code:
d=open("c").read()
for c in list(set(d)):   print c, d.count(c)

Ikj/Python

Code:
f=open('a').read()
for i in sorted(set(f)):print(i,f.count(i))


Sorunome/PHP

Code:
<?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:
FNS{Ks'Gs[Nd/KN


That's it! I'll post another one later today!
Wait, so it doesn't matter how inefficient the program is, either in time or memory space, just how large the source code is? I guess that's fair...

Python, assuming that the input is stdin.

Code:
import sys
a=sys.stdin.read()
print [(c, list(a).count(c)) for c in sorted(set(list(a)))]
This is 79 characters without the import line, if that's how this game works.
A couple questions on the rules. First, does the import line count in the source code size?

Secondly, I am doing it in Haskell, so do I have to give you something that compiles to an executable, or can I give you source without a main function that you can run in ghci like this:


Code:

> :l main
> c "{omnimaga};"
{ 1
o 1
m 2
n 1
i 1
a 2
g 1
} 1
; 1
KermMartian wrote:
Wait, so it doesn't matter how inefficient the program is, either in time or memory space, just how large the source code is? I guess that's fair...

Python, assuming that the input is stdin.

Code:
import sys
a=sys.stdin.read()
print [(c, list(a).count(c)) for c in sorted(set(list(a)))]
This is 79 characters without the import line, if that's how this game works.


That is how it works, but import lines do count. Also next time, please PM me the source so people don't end up cheating off yours. I'll post the winning sources at the end of each iteration.

Also: The input is the source file itself, not stdin, so that is almost right, but not quite.

flyingfisch wrote:
A couple questions on the rules. First, does the import line count in the source code size?

Secondly, I am doing it in Haskell, so do I have to give you something that compiles to an executable, or can I give you source without a main function that you can run in ghci like this:

The import line does count in source code size. The program must be compiled to an executable in this particular case. Sorry.
Oh, this is an actual contest? I assumed that we just posted in the topic until someone reached the smallest possible size. Thanks for clarifying on the rules.
Well, it's a weekly contest, so nothing huge with prizes or anything, but yes, this is an actual contest.
KermMartian wrote:
Oh, this is an actual contest? I assumed that we just posted in the topic until someone reached the smallest possible size. Thanks for clarifying on the rules.


Something like that could be fun too.
KermMartian wrote:
Oh, this is an actual contest? I assumed that we just posted in the topic until someone reached the smallest possible size. Thanks for clarifying on the rules.

Yeah, and my Code Golf contests over on Omni (remember those?) were the inspiration. Same idea, but better and with more variety of puns Razz
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 )
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/
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.
My explained submission for Contest #2 has been posted on the contest thread at https://www.omnimaga.org/community-contests/code-golf-the-reboot-2/, and an explanation for my Contest #3 submission is at http://codegolf.stackexchange.com/a/51975/39328. I have reproduced both of the programs here.

Contest 2: Move a pixel about the screen using either WASD or arrow keys (27 bytes, winning entry)

Code:
While 1
Ans-iPart(i^int(48ln(getKey-1
Pxl-On(real(Ans),imag(Ans
End


Contest 3: Implement Conway's Game of Life on the graphscreen (87 bytes, lost to Runer112's 79-byte Axe entry)

Code:
0
While 1
For(X,0,93
Ans/7+49seq(pxl-Test(Y,X+1),Y,0,62
For(Y,1,61
If 2rand>isClockOn=pxl-Test(Y,X)+int(3fPart(3cosh(fPart(6-1iPart(sum(Ans,Y,Y+2
Pxl-Change(Y,X
End
End
ClockOff
End


So far Contest 4 is interesting; I'm not sure which of a few approaches I should take.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement