Search for '{{search_term}}'

Exercise: count digits

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

Exercise: count digits in a file

Given a file like this, that has rows of numbers in it without anything, but a single space in between the numbers. Our task is to count how many times each digit appears.

examples/data/count_digits.txt

23 34 9512341
3 34 2452345 5353 67 22
42136357013412
42 5 65 64 

Our expected output looks like this:

0 1
1 5
2 9
3 11
4 9
5 8
6 4
7 2
8 0
9 1

Tools for Perl 5

Tools for Ruby

Solutions

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus