-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from cdlab-sit/higurashi-takuto
Higurashi takuto
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# "paraparaparadise"と"paragraph"に含まれる文字bi-gramの集合を,それぞれ, XとYとして求め,XとYの和集合,積集合,差集合を求めよ.さらに,'se'というbi-gramがXおよびYに含まれるかどうかを調べよ. | ||
|
||
|
||
def n_gram(sequence, n): | ||
return [sequence[i:i+n] for i in range(len(sequence)-n+1)] | ||
|
||
|
||
string = ['paraparaparadise', 'paragraph'] | ||
|
||
# 普通に1個ずつ書いた方がわかりやすそう。set(n_gram('paraparaparadise', 2)) | ||
X, Y = map(set, map(n_gram, string, [2, 2])) | ||
union = X | Y | ||
intersection = X & Y | ||
difference = X - Y | ||
is_include_x = 'se' in X | ||
is_include_y = 'se' in Y | ||
|
||
print(X, Y, union, intersection, difference, is_include_x, is_include_y) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 引数x, y, zを受け取り「x時のyはz」という文字列を返す関数を実装せよ.さらに,x=12, y="気温", z=22.4として,実行結果を確認せよ. | ||
|
||
|
||
def template(x, y, z): | ||
# f-stringsはPython3.6からの機能なので注意 | ||
return f'{x}時の{y}は{z}' | ||
|
||
|
||
x = 12 | ||
y = '気温' | ||
z = 22.4 | ||
|
||
print(template(x, y, z)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 与えられた文字列の各文字を,以下の仕様で変換する関数cipherを実装せよ. | ||
# 英小文字ならば(219 - 文字コード)の文字に置換 | ||
# その他の文字はそのまま出力 | ||
# この関数を用い,英語のメッセージを暗号化・復号化せよ. | ||
|
||
|
||
def cipher(string): | ||
return ''.join([chr(219-ord(char)) if char.islower() else char | ||
for char in string]) | ||
|
||
|
||
# 2回通すと復元される。入力の文字コードをnとすると | ||
# 入力: n | ||
# 1回目: 219 - n | ||
# 2回目: 219 - (219 - n) = n | ||
string = input() | ||
ciphered = cipher(string) | ||
decrypted = cipher(ciphered) | ||
|
||
print(string, ciphered, decrypted) |
This file contains 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