Skip to content

Instantly share code, notes, and snippets.

@johnta0
Created June 25, 2018 02:50
Show Gist options
  • Save johnta0/85bd8c1809d249e0e5280dbbf908f6b3 to your computer and use it in GitHub Desktop.
Save johnta0/85bd8c1809d249e0e5280dbbf908f6b3 to your computer and use it in GitHub Desktop.
殆どが「暇」で構成される文字列から、1つの「蝦」を見つけ出すためのRuby script
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
str = '暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇蝦暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇暇'
arr = str.split(/\s*/)
arr.each_with_index do |hima, index|
if arr[index] != arr[index - 1]
puts "#{index + 1}番目が#{hima}です"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment