Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Histogram of characters used in Google Application Passwords
def histogram(message)
message.each_char.reduce(Hash.new(0)) { |h, k| h[k] += 1; h}
end
def graph_histogram(h)
h.to_a.
sort_by{|kv| kv[1]*-1}.
map{|a| "#{a[0]} |#{('+'*a[1])[0..120]}#{a[1].to_s}\n"}.
join
end
message = "bejkpcfcpofjctvlybwqvdpkwebavtbyxngwbrkobhrtribviwprprjpdootlzeykwypskoapaovadeenabiajviezaivmtyowwmmjkaqcretlgtlimiecizhempplsuhsjfwgsapyupyshyiduhcecnffzxvwidkufekanlarlroxqloemogsisdpsdvqpbvkefysmbnorzttjwhvxqchvjtvqzwcgilyclijgrttfcjhwjptnvnjoqrodvvibkiwmrddfxgolfnaijorrcvertiuyssxsuetdfbatrwwsazcstsjexttfigxvsdyzqjhpeynxbkaazpnekjemcngwtiazngnlaevvdehccbdzasqpmwncwspxktrbqdazecvpqyowjvaxlgpwzkkvnxthzdrdsdmdtzdeqffjznfxxbfjtewindravsxobrriyfxnorzfvovwkfxnrxrqcggdqpsgumzpi"
puts graph_histogram( histogram(message) )
@jonelf

This comment has been minimized.

Copy link
Owner Author

commented Sep 4, 2014

Outputs:

v |++++++++++++++++++++++++++26
e |++++++++++++++++++++++++24
r |++++++++++++++++++++++++24
t |++++++++++++++++++++++++24
p |+++++++++++++++++++++++23
w |++++++++++++++++++++++22
i |++++++++++++++++++++++22
d |++++++++++++++++++++++22
a |++++++++++++++++++++++22
s |+++++++++++++++++++++21
f |+++++++++++++++++++19
n |+++++++++++++++++++19
o |+++++++++++++++++++19
j |+++++++++++++++++++19
c |+++++++++++++++++++19
x |++++++++++++++++++18
z |++++++++++++++++++18
b |+++++++++++++++++17
k |++++++++++++++++16
y |+++++++++++++++15
g |++++++++++++++14
q |++++++++++++++14
l |+++++++++++++13
m |++++++++++++12
h |+++++++++++11
u |+++++++7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.