Skip to content

Instantly share code, notes, and snippets.

View shiracamus's full-sized avatar

@shiracamus shiracamus

View GitHub Profile
import random
from itertools import count
class Card:
SUITS = "♣♦♥♠"
RANKS = "A23456789TJQK"
def __init__(self, suit, rank=""):
self.suit = suit
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]
#!/usr/bin/env python3.6
#-*- coding:utf-8 -*-
import sys
import random
from itertools import product
"""
開発するブラックジャックのルール
・初期カードは52枚。
#!/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.
@shiracamus
shiracamus / fizzbuzz.py
Last active April 13, 2018 00:31
fizzbuzz veriation
print(*map(lambda x:"Fizz"*(x%3<1)+"Buzz"*(x%5<1)or x,range(1,101)))
> インタフェースとは後から使うものを先に簡単に作っておいて、それを後でimplementで呼び出して使うものだと自分は認識しました。
API はご存知ですか? Application Programming Interface.
プログラムの仕様。プログラム同士を接続するための仕様。
使う人も作る人もインタフェースに合わせて作る。
クラスが違ってもインタフェースが同じなら接続して使える。
プログラムを作る前にまずインタフェースを定義しましょう。
ハードウェアも同じインタフェース同士なら接続できます。
USB、LAN、RS232C、HDMI、etc.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
import matplotlib.pyplot as plt
NUM_TRIAL = 500 # 試行回数
ODDS = 2 # オッズ
START_MONEY = 100 # 初期資金
START_BET = 1 # 最初のベット額
import time
from itertools import count
def make_gunegune(size):
size = (size + 1) | 1
gunegune = [['-'] * size for y in range(size)]
number = count(1)
for z in range(1, size, 2):
for x in range(1, z, +1): gunegune[z][x] = next(number)
for y in range(z, 0, -1): gunegune[y][z] = next(number)
def number2yx(number):
b = int((number - 1) ** 0.5)
start = b ** 2 + 1
a = min(number - start, start + b * 2 - number)
return (a, b) if (b % 2 == 1) ^ (a == number - start) else (b, a)
def yx2number(y, x):
if y < 0 or x < 0: return '-'
a, b = sorted((y, x))
start = b ** 2 + 1
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <random>
#include <vector>
class Maze {
int start_x,
start_y;