2014-04-01から1ヶ月間の記事一覧

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で処理時間測定

コード if __name__ == '__main__': time1 = time.clock() #計測したい関数 time2 = time.clock() time = time2*10000 - time1*10000 print time 参考にしたサイト pythonで開始から終了までの処理時間を計測して表示する--listen2the Silence Python - 時間…

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…