-
-
Save jamiely/5513228 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = "If you are self-motivated, wow, this world is tailored for you. The boundaries are all gone. But if you're not self-motivated, this world will be a challenge because the walls, ceilings and floors that protected people are also disappearing. That is what I mean when I say \"it is a 401(k) world.\" Government will do less for you. Companies will do less for you. Unions can do less for you. There will be fewer limits, but also fewer guarantees. Your specific contribution will define your specific benefits much more. Just showing up will not cut it. - T. Friedman".downcase | |
pair = "ou" | |
third = "r" | |
pairs = (0..input.length-2).inject({}) do |h,i| | |
key, val = input[i,2], input[i + 2] | |
h[key] = {} unless h[key] | |
h[key][val] = (h[key][val] || 0) + 1 if val | |
h | |
end | |
p "Pairs:" | |
pairs.keys.sort.each { |k| p k } | |
prob = if pairs[pair][third] | |
( pairs[pair][third].to_f / pairs[pair].values.reduce(:+).to_f ) * 100 | |
else | |
0 | |
end | |
p "Probability:" | |
p "#{prob}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment