Skip to content

Instantly share code, notes, and snippets.

@oddlyfunctional
Last active February 2, 2016 14:57
Show Gist options
  • Save oddlyfunctional/b22cb558c021bec5f0dc to your computer and use it in GitHub Desktop.
Save oddlyfunctional/b22cb558c021bec5f0dc to your computer and use it in GitHub Desktop.
#!/bin/ruby
# https://www.hackerrank.com/contests/worldcodesprint/challenges/save-our-ship
S = gets.strip
wrong_letters = 0
SOS = "SOS"
S.each_char.each_slice(3) do |sos|
wrong_letters += sos.each_with_index.select { |char, i| char != SOS[i] }.length
end
puts wrong_letters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment