CheckIO

Pythonで Letter Queue

コード # coding:utf-8 def letter_queue(c): r = [] for i in c: s = i.split() if len(s) == 2 and s[0] == "PUSH": r.extend(s[1]) if len(s) == 1 and r != []: r = r[1:] if r == []: return "" else: return "".join(r) if __name__ == '__main__': le…

PythonでSimple Areas

コード import math def simple_areas(*args): m = args if len(args) == 1: r = m[0] / 2.0 print round(r * r * math.pi,2) elif len(args) == 2: print m[0] * m[1] elif len(args) == 3: if m[0] == m[1] == m[2]: m = sorted(m) print round(m[0] * m[1…

PythonでMorse Clock

コード def checkio(time_string): s = time_string.encode("utf-8").split(":") b = "" for i in s: i = i.zfill(2) li = list(i) if b == "": b = b + format(int(li[0]),"b").zfill(2) + " " else: b = b + format(int(li[0]),"b").zfill(3) + " " b = b …

PythonでVerify anagrams

コード def verify_anagrams(first_word, second_word): f = first_word.encode("utf-8") s = second_word.encode("utf-8") f = f.lower().translate(None, ' ') s = s.lower().translate(None, ' ') f = sorted(f) s = sorted(s) if s == f: print "yes" el…

PythonでTransposed Matrix

コード def checkio(data): print zip(*data) 一言 ZIP

PythonでRoman numerals

コード def checkio(data): n4 = [0,1000,2000,3000] r4 = ["","M","MM","MMM"] n3 = [0,100,200,300,400,500,600,700,800,900] r3 = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"] n2 = [0,10,20,30,40,50,60,70,80,90] r2 = ["","X","XX","XXX","X…

PythonでFind Sequence

コード import math def check_hc(matrix,option): if option == 1: matrix = zip(*matrix) s = [x for i in matrix for x in i] for i in range(len(s)-3): if s[i] == s[i+1] == s[i+2] == s[i+3]: return 1 else: return 0 def check_Diagonal(matrix,opt…

PythonでStriped Words

コード2 http://www.checkio.org/mission/striped-words/publications/RRRQ/python-3/first/ からの引用。 すげー綺麗なコードで感動した。 VOWELS = "AEIOUY" CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ" PUNCTUATION = ",.!?" def checkio(text): text = text.u…

PythonでBrackets

#coding utf-8 import string def checkio(expression): s = expression s = s.encode("utf-8") s = s.translate(string.maketrans("",""),"+-*/0123456789") if s == "": return True t = 0 while t < len(expression): s = s.replace("()","").replace("{}…

PythonでNumber Factory

コード def checkio(number): n = prime_decomposition(number) n = check_prime(n) if n != 0: n = rounding_numbers(n) n = "".join(map(str,n)) print int(n) def check_prime(number): if len(number) == 1 or max(number) > 10: return 0 else: return …

PythonでThe Hamming Distance

コード def checkio(n, m): num3 = format(n ^ m,"b").count("1") print num3 if __name__ == '__main__': checkio(117, 17) checkio(1, 2) checkio(16, 15) 参考にしたサイト ハミング距離 - Wikipedia ビット演算子 - 数値 - Python入門 pythonでn進数への…

PythonでXs and Os Referee

コード def checkio(game_result): magic_square = [8,1,6,3,5,7,4,9,2] x = [0,0,0,0,0,0,0,0,0] o = [0,0,0,0,0,0,0,0,0] s = "".join(game_result) for i in magic_square: if s[magic_square.index(i)] == "X": x[magic_square.index(i)] = i elif s[mag…

PythonでThe Most Wanted Letter

コード3 def checkio(text): s = text.lower() print max("abcdefghijklmnopqrstuvwxyz", key=s.count) コード2 import string def checkio(text): s = text.lower() return max(string.ascii_lowercase, key=s.count) 一言 max()を忘れていた、公式ドキュ…

PythonでHousePassword

コード3 def checkio(psswd): if (len(psswd) >= 10) and (not psswd.islower()) and (not psswd.isupper()) and (not psswd.isalpha()) and (not psswd.isdigit()): return True #処理時間:0.125s コード2 def checkio(psswd): return ( (len(psswd) >= …

PythonでMedian

コード def checkio(data): if len(data) >= 1000000: return "Long" else: d = len(data) li = sorted(data) if (d + 1) % 2 == 0: print li[(((d + 1) / 2) - 1)] else: n = (d + 1) // 2 print ( li[(n - 1)] + li[n] ) / 2.0 checkio([1,2,3,4,5,6,7,8,9…

PythonでNon Unique Elements

コード def checkio(data): c = [] for i in data: if data.count(i) >= 2: c.append(i) print c 参考にしたサイト python count 要素の確認(in演算子, indexメソッド, countメソッド) - リスト - Python入門

PythonでThe Absolute Sorting

コード def checkio(numbers_array): print sorted(numbers_array, key=abs) 参考にしたサイト 「python abs」 abs関数 「python タプル 比較関数」 「Pythonのmax, min関数について」 アは max()にkey=absが使えるなら、sorted()でもkey=absが使えるんじゃ…

PythonでThe Common Words

コード2 def checkio(first,second): f = set(first.split(",")) s = set(second.split(",")) common = f.intersection(s) print ",".join(sorted(common)) コード1 def checkio(first,second): f=first.split(",") s=second.split(",") n=[] for i in f: fo…

PythonでNumber Base

コード def checkio(str_number, radix): try: return int(str_number,radix) except ValueError: return -1 参考にしたサイト 検索語「python 基数変換」サイト「174:2進、8進、10進、16進の各表現を相互に変換」 検索語「python ValueError」 サイト「8. …

PythonでBinary count

コード def checkio(number): print bin(number).count("1") 参考にしたサイト python bin bin(x) SubLimetext3 Non-ASCII character pythonで「SyntaxError: Non-ASCII character」のエラーが出た場合の対処方法 python count 要素の確認(in演算子, indexメ…

PythonでThe End of other

コード def checkio(words_set): words = list(words_set) if len(words) != 1: for i in words: for j in words: if i != j and i.endswith(j): return True return False else: return False 参考にしたサイト python 文字列関数 文字列処理メソッドのまと…

PyhtonでDigits Multiplication

コード def checkio(number): x = 1 for i in list(str(number)): if i != str(0): x = int(i) * int(x) return x 参考にしたサイト python int split split 1234 into ('1', '2', '3', '4')

PythonでThe Most Numbers

コード def checkio(*args): if len(args) > 0: return max(args) - min(args) else : return 0

PythonでThree words

コード def checkio(words): check = 0 for i in words.split(): if i.isalpha(): check = check + 1 if check == 3: return True else: check = 0 return False 参考にしたサイト for文 http://www.pythonweb.jp/tutorial/for/index3.html

PythonでEven the last

コード def checkio(array): if array != []: return sum(array[0::2]) * array[-1] else: return 0 参考にしたサイト 配列の最後尾の要素を指定 Python でリストの要素を指定 – car, cdr に相当するもの 配列内の偶数 Pythonのリストの偶数と奇数の取り出し…

PythonでFizz Buzz

コード def checkio(number): if number % 15 == 0: return 'Fizz Buzz' elif number % 3 == 0: return 'Fizz' elif number % 5 == 0: return 'Buzz' else: return str(number) 参考にしたサイト

はじめに

CheckIO 読書漬けでたまりにたまったRSSを消化している最中に、CheckIOというpython学習プラットフォームを見つけた。 さっそく会員登録を済ませた。 ひまな時間や脳みその別の部分を使いたくなった時にちょくちょく問題をといて遊んでいる。 CheckIO Lv.2 L…