Skip to content

Instantly share code, notes, and snippets.

View shiracamus's full-sized avatar

@shiracamus shiracamus

View GitHub Profile
import time
class Hanoi:
def __init__(self, n):
self.n = n
self.tower = list(range(1, n+1))[::-1], [], []
def solve(self):
yield from self.move(self.n, 0, 1, 2)
import tkinter as tk
import random
HANDS = ROCK, SCISSORS, PAPER = "グー", "チョキ", "パー"
WIN, LOSE, DRAW = "勝ち", "負け", "引き分け"
class Player:
STRONGER_THAN = {ROCK: PAPER, SCISSORS: ROCK, PAPER: SCISSORS}
from pprint import pprint
def sign(i):
return (+1, -1)[i & 1]
def cof(matrix, y, x):
return [[value for c, value in enumerate(row) if x != c]
for r, row in enumerate(matrix) if y != r]
def det(matrix):
import random
class Card:
RANKS = "A23456789TJQK"
def __init__(self, rank):
self.rank = rank if rank != "T" else "10"
self.number = Card.RANKS.index(rank) + 1
from ipaddress import IPv4Address, IPv4Network, AddressValueError
def read_lines(filename):
try:
with open(filename) as f:
return f.read().splitlines()
except IOError:
print(f"Error: {filename}が開けない")
exit()
import sys
import random
def show_maze(maze):
print()
for row in maze:
print(' ', *row, sep='')
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
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
//
// 昔懐かし、CBM-3032のようなキャラクタゲームを
// ncurseswで実現。
// Raging robots.
//
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
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):