from functools import reduce
def fun(M, *args):
rfun = lambda x, y: x + y
return reduce(rfun, args) <= M
# or return sum(args) <= M
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
| from bisect import bisect | |
| from sys import stdin | |
| # utility function | |
| identity = I = lambda x: x | |
| consistent = K = lambda x: lambda y: x | |
| # 辞書(d)を受取り,bisectを用いてvalue(v)に最も近いkeyを探し,そのkeyに対応するvalueを返す関数 | |
| bisect_pick = lambda d, v: list(d.values())[bisect(list(d.keys()), v) - 1] | |
| # sepで区切り,fnで加工して結合する関数 | |
| join = lambda sep="\n", fn=str: lambda values: sep.join(map(fn, values)) |
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
| # https://paiza.jp/poh/hatsukoi/challenge/hatsukoi_clothes6 | |
| # アイドルの下積み時代に苦労はつきもの…。節約のために、まずは光熱費を見直しましょう。 冷蔵庫の電気代は意外と見落としがちな家計の負担となっています。実際いくら使っているのか気になったあなたは試しに冷蔵庫の使用状況を観察しながら電気代を概算してみることにしました。あなたは冷蔵庫の電気代は以下のように発生すると考えました。 | |
| # | |
| # ・冷蔵庫内の温度が設定温度より高いとき冷蔵庫は 1 時間で 1 度温度を下げる「冷却」を行い、これには 1 時間あたり 2 円かかる。 | |
| # ・冷蔵庫内の温度が設定温度に等しいとき冷蔵庫は温度を等しく保つ「保温」を行い、これには 1 時間あたり 1 円かかる。 | |
| # | |
| # またものの出し入れの際に次のように冷蔵庫内の温度が変化すると考えました。 | |
| # | |
| # ・ ものを取り出すと冷蔵庫内の温度は外気に触れることでその瞬間に 3 度上がる | |
| # ・ ものを新たに入れると冷蔵庫内の温度は外気と温かいものに触れることでその瞬間に 5 度上がる |
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
| def pos_neg(a, b, negative=False): | |
| both_neg = lambda a,b: a < 0 and b < 0 | |
| pos_neg = lambda a,b: a < 0 < b | |
| return both_neg(a,b) if negative else pos_neg(a, b) or pos_neg(b, a) |
IP アドレス(Internet Protocol Address)は、IP ネットワーク上の情報機器を識別するために指定するネットワーク層における識別用の番号であり,version 4 では 32bit, version 6 では 128bit のアドレス空間が付与されている。 IPv4 では,32bit を 8bit(1 オクテット)ごとに区切った 10 進数で表す。
アドレス空間 0 - 4294967295 python3 -c "print(2 ** 32)"
| 2 進数 | 10 進数 | 16 進数 |
|---|---|---|
| 00000000000000000000000000000000 | 0.0.0.0 | 0.0.0.0 |
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
| # 1 ビット変換関数 | |
| to_bit = lambda c: '1' if c.isupper() else '0' | |
| apply = lambda fun, text : map(fun, text) | |
| to_matrix = lambda array: [array[i: i+ 8] for i in range(0, len(array), 8)] | |
| to_byte = lambda matrix: [''.join(array) for array in matrix] | |
| to_char = lambda byte: chr(int(byte, 2)) | |
| result = apply(to_char, ) | |
| text = 'tIvolFLgqDzvIUnifAwfnenAtJskbNBMpAAEIxUXpeFPJbnepKPWBcmBkAIzGAShjJdxkoynfXBDehUtiDVTLjeFaUnRQJCEjREfNWRwqRaGkAaHlKVrOOoGjpUJfBSygOLotGcJuMrHomUbpCJZGNaX' |
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
| const fn = value => { | |
| return value | |
| } | |
| // main function | |
| ;((stdin, stdout) => { | |
| // input | |
| const value = stdin('/etc/passwd').readStream() | |
| // call function | |
| const result = fn(value) |
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
| const identity = v => v | |
| const join = (sep = '\n') => array => array.join(sep) | |
| const split = (sep = ' ') => string => string.split(sep) | |
| const seq = (size, start) => [...Array(size)].map((_, i) => i + start) | |
| const inputs = (file = '/dev/stdin') => { | |
| const stream = require('fs').readFileSync(file, 'utf-8').trim() | |
| const toArray = sep => fn => iter => Array.from(split(sep)(iter), fn) | |
| return { | |
| readCols: (fn = identity) => toArray(' ')(fn)(stream), | |
| readRows: (fn = identity) => toArray('\n')(fn)(stream), |
NewerOlder