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 | |
import numpy as np | |
import pygame | |
from abc import ABC, abstractmethod | |
class Color: | |
GREEN = (34, 139, 34) | |
WHITE = (255, 255, 255) | |
BLACK = (0, 0, 0) |
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 | |
import sys | |
import argparse | |
TRANS = { | |
# op: (nest, python_code) | |
'>': (0, 'index += 1'), | |
'<': (0, 'index -= 1'), | |
'+': (0, 'memory[index] = (memory[index] + 1) & 0xff'), | |
'-': (0, 'memory[index] = (memory[index] - 1) & 0xff'), |
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 itertools import permutations | |
def exp(a, b, *c): | |
if c: | |
for op in '+-*/': | |
yield from exp(f'({a}{op}{b})', *c) | |
yield from exp(f'({b}{op}{a})', *c) | |
for i in range(1, len(c) + 1): | |
yield from exp(*c[:i], f'({a}{op}{b})', *c[i:]) | |
yield from exp(*c[:i], f'({b}{op}{a})', *c[i:]) |
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
def two_digit_sieve(digits: tuple[int], numbers: list[int], i: int = 0) -> bool: | |
""" | |
1桁数列digitsのi番目から順に1桁または2桁の数を作ってnumbersに追加し、digits | |
をすべて使って数の重複がないnumbersが完成したらTrue、失敗したらFalseを返す | |
""" | |
if i == len(digits): | |
return True # 完成 | |
if (i + 1 < len(digits) and digits[i] != 0 and | |
(number := digits[i]*10 + digits[i+1]) not in numbers): | |
numbers.append(number) # 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
### tic-tac-toe game | |
from tkinter import * | |
from tkinter.messagebox import * | |
class Board: | |
def __init__(self, size=3): | |
self.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 | |
class Answer: | |
"""出題者""" | |
def __init__(self, digits: int) -> None: | |
"""digits桁の重複しない数を作って隠し持つ""" | |
self._number = ''.join(map(str, random.sample(range(0, 10), digits))) |
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
public class ParkingSimulator { | |
public static void main(String[] args) { | |
Parking parking = new Parking("駅前駐車場", 2); | |
Car car1 = new Car("品川33 あ 1234"); | |
Car car2 = new Car("横浜555 い 5678"); | |
Car car3 = new Car("多摩345 う 9012"); | |
car1.park(parking); | |
car2.park(parking); | |
car3.park(parking); |
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
def signed(value, bits=8): | |
return (value & ((sign := (1 << (bits - 1))) - 1)) - (value & sign) | |
print(signed(0x7f)) # 127 | |
print(signed(0x80)) # -128 | |
print(signed(0x81)) # -127 | |
print(signed(0x7fff)) # -1 | |
print(signed(0x7fff, 16)) # 32767 | |
print(signed(0x8000, 16)) # -32768 | |
print(signed(0x8001, 16)) # -32767 |
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 java.util.HashMap; | |
import java.util.Map; | |
class Digit { // 1桁数字 | |
static final Map<Integer, Integer> next = new HashMap<>() {{ | |
put(0, 1); | |
put(1, 2); | |
put(2, 3); | |
put(3, 4); | |
put(4, 5); |
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 | |
from datetime import datetime, timedelta, timezone | |
# サイズ設定 | |
SEG_WIDTH = 12 # このサイズを変更するだけで全体サイズが連動して変更される | |
SEG_HEIGHT = SEG_WIDTH * 4 | |
COLON_SIZE = SEG_WIDTH * 5 // 3 | |
CANVAS_WIDTH_NUMBER = SEG_WIDTH * 5 | |
CANVAS_WIDTH_COLON = CANVAS_WIDTH_NUMBER // 2 | |
CANVAS_HEIGHT = CANVAS_WIDTH_NUMBER * 2 - SEG_WIDTH |
NewerOlder