From 6a805f28f2d1aaa8255e87312599b1e549da949b Mon Sep 17 00:00:00 2001 From: higurashi-takuto Date: Thu, 21 Feb 2019 22:21:15 +0900 Subject: [PATCH 1/4] =?UTF-8?q?map=E3=81=A8set=E3=81=A7=E3=81=84=E3=81=84?= =?UTF-8?q?=E6=84=9F=E3=81=98=E3=81=AB=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- higurashi-takuto/06.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/higurashi-takuto/06.py b/higurashi-takuto/06.py index e69de29..51605c3 100644 --- a/higurashi-takuto/06.py +++ b/higurashi-takuto/06.py @@ -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) From 93eddc20c088fa58813515bc66200321af1a7b86 Mon Sep 17 00:00:00 2001 From: higurashi-takuto Date: Thu, 21 Feb 2019 22:27:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?f-strings=E3=81=A7=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- higurashi-takuto/07.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/higurashi-takuto/07.py b/higurashi-takuto/07.py index e69de29..f00acef 100644 --- a/higurashi-takuto/07.py +++ b/higurashi-takuto/07.py @@ -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)) From 049d10252b9a95383f7fd98045f80b41d613176d Mon Sep 17 00:00:00 2001 From: higurashi-takuto Date: Thu, 21 Feb 2019 22:45:36 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E5=86=85?= =?UTF-8?q?=E8=A1=A8=E8=A1=A8=E8=A8=98=E3=81=A7=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- higurashi-takuto/08.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/higurashi-takuto/08.py b/higurashi-takuto/08.py index e69de29..9d8e839 100644 --- a/higurashi-takuto/08.py +++ b/higurashi-takuto/08.py @@ -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) From 01adb5d9fde4eed72cf6cda958f320bdeecda9d3 Mon Sep 17 00:00:00 2001 From: higurashi-takuto Date: Fri, 22 Feb 2019 20:00:42 +0900 Subject: [PATCH 4/4] =?UTF-8?q?OS=E3=81=AE=E3=83=90=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E6=83=85=E5=A0=B1=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- higurashi-takuto/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/higurashi-takuto/README.md b/higurashi-takuto/README.md index a76689e..f03f55d 100644 --- a/higurashi-takuto/README.md +++ b/higurashi-takuto/README.md @@ -1,7 +1,7 @@ # higurashi-takuto ## 開発環境 - 言語: Python 3.7.2 -- OS: macOS Mojave(10.14.2) +- OS: macOS Mojave ## ファイル生成 各番号のファイルを生成するコマンドです。適宜拡張子などを変えてご利用ください。