Skip to content

Instantly share code, notes, and snippets.

@simple
Created August 19, 2011 08:12
Show Gist options
  • Save simple/1156308 to your computer and use it in GitHub Desktop.
Save simple/1156308 to your computer and use it in GitHub Desktop.
Count 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
@happydeveloper
Copy link

Leo ju님처럼 저두 처음에 똑같은 결과값을 얻었는데~ 생각해보니 이 결과값이 틀린것 같더라구요~ 4가지 6가지 경우의 수를 가지고 실제로는 데이타를 넣어서 검증해보니 이식이 틀린것 같아요. 그래서 다시 생각한 다음에 짠 결과물이 아래와 같습니다.^^~ 제가 틀릴수도 있고요 ㅋㅋ 다음주 목요일날 답이 나오면 정확히 알수 있겠죠^^~

한국인 중 외향성인 E 사람은 41.32% 입니다.
한국인 중 내항성인 I 사람은 58.85% 입니다.
한국인 중 감각적인 S 사람은 74.5% 입니다.
한국인 중 직관적인 N 사람은 25.67% 입니다.
한국인 중 사고중인 T 사람은 63.25% 입니다.
한국인 중 감정적인 F 사람은 36.92% 입니다.
한국인 중 판단적인 J 사람은 62.62% 입니다.
한국인 중 인식적인 P 사람은 37.55% 입니다.

@simple
Copy link
Author

simple commented Aug 22, 2011

제가 문제를 잘못 이해했네요. MBTI의 4가지 판단 기준 별로 대응하는 두 성향을 비교하는 것이로군요. 조만간;; 업데이트 예정입니다. ㅎㅎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment