Skip to content

Instantly share code, notes, and snippets.

@youcune
Created October 30, 2019 11:16
Show Gist options
  • Save youcune/330575403e7b081c7ec91dc36f0e1059 to your computer and use it in GitHub Desktop.
Save youcune/330575403e7b081c7ec91dc36f0e1059 to your computer and use it in GitHub Desktop.
言語処理100本ノック2015
require 'set'
def bigram(str)
size = str.size
Set.new.tap do |result|
0.upto(size-2) do |i|
result << str[i, 2]
end
end
end
puts bigram('paraparaparadise')
puts bigram('paragraph')
puts bigram('paraparaparadise') + bigram('paragraph')
puts bigram('paraparaparadise') & bigram('paragraph')
puts bigram('paraparaparadise') - bigram('paragraph')
require 'pathname'
path = Pathname('hightemp.txt')
path.readlines.map { |line| line.split(/\t/, 2).first }.uniq.display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment