Skip to content

Commit

Permalink
Hash: [#23] Roach - 위장
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdgusya committed Jun 9, 2021
1 parent 2737a33 commit 0de0c8b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Hash/Default/roach/test_solution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'test/unit'

class TestCamouflage < Test::Unit::TestCase

def test_case_one
assert_equal(solution([["yellowhat", "headgear"], ["bluesunglasses", "eyewear"], ["green_turban", "headgear"]]), 5)
end

def test_case_two
assert_equal(solution([["crowmask", "face"], ["bluesunglasses", "face"], ["smoky_makeup", "face"]]), 3)
end

def solution(clothes)
answer = 0
type = {}

clothes.each_with_index do |array|
if type.key?(array[1].to_sym)
type[array[1].to_sym].push(array[0])
else
type.store(array[1].to_sym, [array[0]])
end
end

answer = 1

type.each do |key, value|
answer *= (value.length+1)
end

return answer-1
end

end

0 comments on commit 0de0c8b

Please sign in to comment.