Skip to content

Latest commit

Β 

History

History

histogram-h2

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 

This Kata is a variation of Histogram - H1

Background

A 6-sided die is rolled a number of times and the results are plotted as percentages in a character-based horizontal histogram.

Example:

6|β–ˆβ–ˆ 5%
5|
4|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 15%
3|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 70%
2|β–ˆ 3%
1|β–ˆβ–ˆβ–ˆ 7%

Task

You will be passed the dice value frequencies, and your task is to write the code to return a string representing a histogram, so that when it is printed it has the same format as the example.

Notes

  • There are no trailing spaces on the lines
  • All lines (including the last) end with a newline \n
  • The percentage is displayed beside each bar except where it is 0%
  • The total number of rolls varies, but won't exceed 10,000
  • The bar lengths are scaled so that 100% = 50 x bar characters
  • The bar character is β–ˆ, which is the Unicode U+2588 char
  • When calculating percentages and bar lengths always floor/truncate to the nearest integer