Another great Monday is upon us! Today's Problem of the Day comes from user D. Thanks for the submission!
For some input string, for example "Feel free to include attribution details such as a Twitter handle so you can get credit for submitting the problem.", determine the character frequencies and display a simple visualization:
................... e ............ t ............ i ........ r ...... o ...... a ...... l ..... n ..... u ..... s ..... c .... d .... b ... h ... f .. g .. m .. F . T . w . y . p . . .
Comments:
Emre Ozdemir - 10 years, 7 months ago
reply permalink
Pyro - 10 years, 7 months ago
My code in python. It's not really optimised but works well!
reply permalink
Pearce Keesling - 10 years, 7 months ago
Getting them to display in descending was a little ugly, but the output is quite elegant IMHO opinion. Alphabetical order was a side-effect :). Wrote this in C.
reply permalink
Tim - 10 years, 7 months ago
Happy to add another python submission to the pile. How does one enable pretty markup?
def counter(input_string): dictionary = {} for l in input_string: if l != " ": dictionary[l] = dictionary.get(l, 0) + 1 return dictionary
def graph(input_string): data = counter(input_string) tdata = data.items() tdata.sort(key=lambda tup: tup[1]) for tup in reversed(tdata): print tup[0], "."*tup[1]
graph("Feel free to include attribution details such as a Twitter handle so you can get credit for submitting the problem.")
reply permalink
Pyro - 10 years, 7 months ago
You have to put ``` before and after the code!
reply permalink
Tim - 10 years, 7 months ago
Thanks!
reply permalink
SithEngineer - 10 years, 7 months ago
a C# solution...
and test code...
reply permalink
Nick Krichevsky - 10 years, 7 months ago
Python Code!
reply permalink
Akshay Bist - 10 years, 7 months ago
My Python solution
reply permalink
rav - 10 years, 7 months ago
Python:
reply permalink
ujjl - 10 years, 7 months ago
Haskell solution
Output:
reply permalink
James - 10 years, 7 months ago
Python solution. Anyone give feedback?
reply permalink
Ben - 10 years, 7 months ago
A C# solution using LINQ:
reply permalink
Hueho - 10 years, 7 months ago
Reads the phrase from the standard input or loading any file passed to script as a argument
reply permalink
Anonymous - 10 years, 6 months ago
reply permalink