Skip to content

Instantly share code, notes, and snippets.

@fjkz
fjkz / pentomino.py
Created August 14, 2022 04:09
pentomino solver
import string
from copy import deepcopy
from random import shuffle
PENTO = 5
_ = None
# O to Z
piece_labels = string.ascii_uppercase[-12:]
@fjkz
fjkz / minimal_wallet.py
Created August 13, 2022 04:47
minimal wallet problem -- how much we should pay for minimizing the number of coins in wallet
from copy import copy
coin_kind = [1, 5, 10, 50, 100, 500]
def minimal_coin_set(value):
# greedy algorithm
ret = {}
for coin in sorted(coin_kind, reverse=True):
ret[coin] = value // coin
value %= coin
@fjkz
fjkz / SshClient.java
Created February 23, 2020 04:15
Builder pattern
class SshClient {
SshClient(String user, String host, int port, int timeout) {
// ...
}
SshClient(String user, String host) {
this(user, host, 22, 60);
}
SshClient(String user, String host, int port) {
@fjkz
fjkz / gitdiff.py
Created October 8, 2016 04:26
Git interface to Python difflib module
#!/usr/bin/env python3
"""
Git interface to difflib.py
"""
import sys
import os
import time
import difflib
import re
@fjkz
fjkz / oxgame.py
Created May 29, 2016 13:48
A maru-batu game (tic tac toe) solver Raw
#!/usr/bin/env python3
from copy import deepcopy
from enum import Enum
from random import shuffle
class Simbol(Enum):
empty = 0
maru = 1
batu = 2
@fjkz
fjkz / kdv.py
Created May 11, 2016 10:26
KdV equation solver with pseudo-spectrum method
#!/usr/bin/env python3
"""
KdV equation solver
"""
from numpy import pi, cos, linspace, arange
from numpy.fft import rfft, irfft
# Constant in Zabusky & Kruskal (1965)
@fjkz
fjkz / create_rootfs.sh
Last active November 30, 2022 22:59
Create a rootfs environment for chroot building.
#!/bin/sh
#
# Create a rootfs environment for chroot building.
#
# Requires
# - OS installing CDROM at the current directory,
# - the root authority.
#
# mount install cd
@fjkz
fjkz / paxos.py
Created October 10, 2015 15:28
A simple Paxos implementation for study.
"""
A simple Paxos implementation for study.
"""
from collections import Counter
class Proposer:
def __init__(self, acceptors):
self.acceptors = acceptors
@fjkz
fjkz / settings.json
Last active October 6, 2015 02:13
A configuration of Visual Studio Code.
// Configurations of Visual Studio Code.
{
//-------- Editor configuration --------
// Controls the font family.
"editor.fontFamily": "源ノ角ゴシック Code JP",
// Controls the font size.
"editor.fontSize": 12,
@fjkz
fjkz / mandel.py
Created April 29, 2015 20:19
Mandelbrot set drawer
from sys import argv
from math import sqrt, pi, tan, atan2
def mandelbrot(r, i):
limit = 256
threshold = 1e10
zr = 0.0
zi = 0.0
for n in range(limit):