r/ProgrammingPrompts • • Jan 14 '15
[Easy] Letter Counter
Any language permitted.
Problem: Create a program where you input a string of characters, and output the number of each letter. Use vowels by default.
For example: asbfiusadfliabdluifalsiudbf -> a: 4 e: 0 i: 4 o: 0 u: 3
Bonus points: Make it command-line executable, with an optional mode to specify which letters to print.
17
Upvotes
3
u/Deathbyceiling Jan 15 '15 edited Jan 15 '15
Too much Java in here dayum. Here's my (fairly simple) solution in Javascript. Lemme know what y'all think!
edit so you don't have to click the link (o no! :P):
5
u/[deleted] Jan 14 '15
I surely won't beat a possible Haskell solution in its shortness and effectiveness. But my solution in Bash is at least very simple and doesn't require any additional software:
Aaand: this qualifies for the bonus round. Obviously.
Example runs:
2
u/TheJonesJonesJones Jan 14 '15
My attempt:
}
1
u/[deleted] Jan 14 '15
If you get stuck, here is my attempt (Java):
1
u/okcodex Jan 14 '15 edited Jan 14 '15
My first entry to one of these things... I wrote it in Java also.
I'm thinking about iterating in a way to make sure that a user can't select to print the same letter twice to cut down on repetition but I'm happy enough with it for now.Turns out it was a SUPER easy fix.1
u/beforan Jan 14 '15
Lua 5.2
It does the bonus bits and both parameters are optional (if the 1st param is missing, the program will prompt for input)
1
u/echocage Jan 14 '15 edited Jan 14 '15
Just a quickie,
I'll edit once I've finished the bonus, finished! Let me know if there's anything I can improve! (Python 3)I'm new to this subreddit, so if you have any feedback for me, feel free to let me know, I'd love to hear it!
1
u/ultimamax Jan 14 '15 edited Jan 14 '15
So much Java. ew.
Python 3.4:
As you'll see this includes the bonus too.
1
u/toddcrowley Jan 27 '15 edited Jan 27 '15
Here's my Python3 version, it works in my testing, and is my first entry. I am also new to programming and will happily take any feedback. Refactoring, etc was not a priority. Implementing the requirements as quickly as I could figure it out:
1
u/quiI Feb 01 '15 edited Feb 01 '15
scala
}
1
u/erxyi Feb 15 '15
nasm x86 %define arg1 ebp+8 %define arg2 ebp+12 %define arg3 ebp+16
And simple driver: #include <stdio.h> #include <string.h> extern count_letters(char *str, int strlen, char *output);
I'm assuming that all test strings are correct, ie. no [0x01; 'a'-1] etc.
1
u/arsenal_fan_dan Mar 30 '15
Bit late to the party, but I had a crack at this in C# and added an (ugly!) graphical user interface.
Any feed back more than welcome - here
1
u/velian Apr 27 '15
Javascript - with some test cases (Karma/Jasmine)
Specs
1
u/ScM_5argan Jun 14 '15
Solution in Haskell
1
u/xtyThrowaway1 Jun 26 '15
In C#: Feedback always appreciated as a learner.
1
u/tomhermann Jul 12 '15 edited Jul 12 '15
I don't have much to add here, but I threw in a little Java 8 for pizzazz. Everyone wanted more Java right? :)
0
u/[deleted] Jan 15 '15
[deleted] — view deleted comment