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
> インタフェースとは後から使うものを先に簡単に作っておいて、それを後でimplementで呼び出して使うものだと自分は認識しました。 | |
API はご存知ですか? Application Programming Interface. | |
プログラムの仕様。プログラム同士を接続するための仕様。 | |
使う人も作る人もインタフェースに合わせて作る。 | |
クラスが違ってもインタフェースが同じなら接続して使える。 | |
プログラムを作る前にまずインタフェースを定義しましょう。 | |
ハードウェアも同じインタフェース同士なら接続できます。 | |
USB、LAN、RS232C、HDMI、etc. |
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
print(*map(lambda x:"Fizz"*(x%3<1)+"Buzz"*(x%5<1)or x,range(1,101))) |
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
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
def flatten(data, depth=-1): | |
""" | |
flatten(data) -> list | |
flatten(data, depth) -> list | |
Return flatted data of list or tupple as list. |
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
#!/usr/bin/env python3.6 | |
#-*- coding:utf-8 -*- | |
import sys | |
import random | |
from itertools import product | |
""" | |
開発するブラックジャックのルール | |
・初期カードは52枚。 |
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
import random | |
SIZE = 4 | |
DIGITS = 4 | |
class Game: | |
def __init__(self, board=None, verbose=True): | |
self.board = [row[:] for row in board or [[0] * SIZE] * SIZE] |
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
import random | |
from itertools import count | |
class Card: | |
SUITS = "♣♦♥♠" | |
RANKS = "A23456789TJQK" | |
def __init__(self, suit, rank=""): | |
self.suit = suit |
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
class Pipe: | |
def __init__(self, func, *args, **kwargs): | |
self.func, self.args, self.kwargs = func, args, kwargs | |
def __call__(self, *args, **kwargs): | |
return Pipe(self.func, *self.args, *args, **self.kwargs, **kwargs) | |
def __or__(self, pipe): | |
if not isinstance(pipe, Pipe): |
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
// | |
// 昔懐かし、CBM-3032のようなキャラクタゲームを | |
// ncurseswで実現。 | |
// Raging robots. | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#include <time.h> |
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
import tkinter as tk | |
class Shape: | |
def __init__(self, x, y, width, height, center=False): | |
if center: | |
x -= width // 2 | |
y -= height // 2 | |
self.x1 = x |
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
import tkinter as tk | |
class Shape: | |
def __init__(self, x, y, width, height, center=False): | |
if center: | |
x -= width // 2 | |
y -= height // 2 | |
self.x1 = x |