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 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) |
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 | |
import random | |
HANDS = ROCK, SCISSORS, PAPER = "グー", "チョキ", "パー" | |
WIN, LOSE, DRAW = "勝ち", "負け", "引き分け" | |
class Player: | |
STRONGER_THAN = {ROCK: PAPER, SCISSORS: ROCK, PAPER: SCISSORS} |
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
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): |
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 | |
class Card: | |
RANKS = "A23456789TJQK" | |
def __init__(self, rank): | |
self.rank = rank if rank != "T" else "10" | |
self.number = Card.RANKS.index(rank) + 1 |
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
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() |
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 sys | |
import random | |
def show_maze(maze): | |
print() | |
for row in maze: | |
print(' ', *row, sep='') | |
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 |
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
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): |