Skip to content

Instantly share code, notes, and snippets.

@fakefarm
Created December 11, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakefarm/9b6afecd39754e640476624760e02928 to your computer and use it in GitHub Desktop.
Save fakefarm/9b6afecd39754e640476624760e02928 to your computer and use it in GitHub Desktop.
class SockMerchant
attr_reader :pile
def initialize(socks: , pile:)
@socks = socks
@pile = pile
end
def match
last = nil;
pile.sort.inject(0) do |memo, color|
if color == last
memo += 1
last = nil
else
last = color
end
memo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment