Created
October 30, 2019 11:16
-
-
Save youcune/330575403e7b081c7ec91dc36f0e1059 to your computer and use it in GitHub Desktop.
言語処理100本ノック2015
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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