Created
August 19, 2011 08:12
-
-
Save simple/1156308 to your computer and use it in GitHub Desktop.
Count Characters
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
#!/usr/bin/env ruby | |
def serialize_types(types, ratios) | |
serialized = "" | |
types.each_with_index do | type, i | | |
occurrences = (ratios[i] * 100).to_i | |
serialized += type * occurrences | |
end | |
serialized | |
end | |
def compare_characters(a, b, serialized) | |
a_count = serialized.scan(a).size | |
b_count = serialized.scan(b).size | |
total_count = a_count + b_count | |
puts "#{a}: #{a_count.to_f / total_count * 100}, #{b}: #{b_count.to_f / total_count * 100}" | |
end | |
def count_temperaments(serialized) | |
temp = {} | |
temp["NT"] = serialized.scan("NT").size | |
temp["NF"] = serialized.scan("NF").size | |
temp["SP"] = serialized.scan(/S.P/).size | |
temp["SJ"] = serialized.scan(/S.J/).size | |
temp | |
end | |
types = [ | |
"ISTJ", "ISFJ", "INFJ", "INTJ", | |
"ISTP", "ISFP", "INFP", "INTP", | |
"ESTP", "ESFP", "ENFP", "ENTP", | |
"ESTJ", "ESFJ", "ENFJ", "ENTJ" | |
] | |
ratios = [ | |
21.5, 8.18, 2.4, 5.47, | |
7.83, 6.5, 3.67, 3.3, | |
5.33, 5.37, 3.37, 2.18, | |
14.2, 5.59, 1.84, 3.44 | |
] | |
serialized = serialize_types(types, ratios) | |
[["I", "E"], ["S", "N"], ["F", "T"], ["J", "P"]].each do |a, b| | |
compare_characters(a, b, serialized) | |
end | |
temperaments = count_temperaments(serialized) | |
total = serialized.length / 4 | |
temperaments.each do |temp, count| | |
puts "#{temp}: #{count.to_f / total * 100}" | |
end | |
__END__ | |
Result: | |
I: 58.7501247878606, E: 41.2498752121394 | |
S: 74.3735649396027, N: 25.6264350603973 | |
F: 36.8573425177199, T: 63.1426574822801 | |
J: 62.5137266646701, P: 37.4862733353299 | |
SJ: 49.3860437256664 | |
NF: 11.2608565438754 | |
NT: 14.3655785165219 | |
SP: 24.9875212139363 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
제가 문제를 잘못 이해했네요. MBTI의 4가지 판단 기준 별로 대응하는 두 성향을 비교하는 것이로군요. 조만간;; 업데이트 예정입니다. ㅎㅎ