Skip to content

Instantly share code, notes, and snippets.

@tkuriyama
tkuriyama / railroad_puzzle.py
Last active August 29, 2015 14:27
Solver for "Passengers in a Railroad Compartment" puzzle.
"""Passengers in a Railroad Compartment
Six passengers sharing a train compartment are from Moscow, Leningrad, Tula,
Kiev, Kharkov, and Odessa.
1. A and the man from Moscow are physicians
2. E and the Leningrader are teachers.
3. The man from Tula and C are engineers.
4. B and F are WWII veterans, but the man from Tula has never served in the
armed forces.
@tkuriyama
tkuriyama / jumping_checkers.py
Created August 16, 2015 17:22
Solver for "Jumping Checkers" puzzle.
"""Solver for "Jumping Checkers" problem.
Place 3 white checkers in squares 1, 2, and 3 of the figure, and 3 black ones
on swuares 5, 6, 7. Shift the white checkers to the squares occupied by the
black ones, and vice versa.
Board |0|0|0| |1|1|1|
Square # 1 2 3 4 5 6 7
You may move a checker forward to an adjacent unoccupied square, if any.
@tkuriyama
tkuriyama / blacksmith.py
Last active September 19, 2015 03:20
Solver for "Blacksmith Khecho's Ingenuity"
"""Blacksmith Khecho's Ingenuity
[...]
Khecho, calmly looking around, climbed the steps to the tower's upper
part and glanced out the window. He realized it would be impossible to
jump out and survive. But he saw a rope, forgotten by the masons, hanging
near the window. The rope was thrown over a rusty tackle fastned to the
tower wall above the window. Empty baskets were tied to each end of the
rope. Those baskets had been used by the masons to lift bricks and lower
@tkuriyama
tkuriyama / weighted_draw.py
Last active September 19, 2015 15:33
Probability-weighted drawing.
from __future__ import division
import random
def weighted_draw(items, target):
"""Draw item from iterable based on probability distribution of items.
Args
items: tuple of (item: float of probability) pairs where the.
sum probability has been normalized to 1
target: float, random number between 0 and 1 used to determine
the item to draw from items
@tkuriyama
tkuriyama / fold_syntax_tests
Last active September 27, 2015 15:17
Testing GitHub syntax highlighting in F#
let product = List.fold (*) 1
let product = List.fold (fun acc x -> acc * x) 1
let fold1 f items =
List.fold f (List.head items) (List.tail items)
@tkuriyama
tkuriyama / lex_perm.py
Last active December 23, 2015 17:14
Find lexicographical predecessor or successor (permutation)
import sys
### Test
def test_predecessor():
"""Basic unit tests for find_predecessor."""
assert main('1432', 0) == '1423'
assert main('04123', 0) == '03421'
assert main('315426', 0) == '315264'
assert main('315246', 0) == '314652'
@tkuriyama
tkuriyama / fording_puzzle_v1.py
Created June 18, 2016 01:16
River Fording Puzzle v1
"""River Fording Puzzle.
3 girls, each with her father, go for a stroll. They come to a small river.
One boat, able to carry 2 persons at a time, is at their disposal.
Crossing would be simple for everyone except the girls. None is willing to be
in the boat or ashore with 1 or 2 strange fathers, unless her own father is
present too. How do they all get across?
"""
@tkuriyama
tkuriyama / fording_puzzle_v2.py
Created June 18, 2016 01:16
River Fording Puzzle v2
"""River Fording Puzzle.
3 girls, each with her father, go for a stroll. They come to a small river.
One boat, able to carry 2 persons at a time, is at their disposal.
Crossing would be simple for everyone except the girls. None is willing to be
in the boat or ashore with 1 or 2 strange fathers, unless her own father is
present too. How do they all get across?
"""
@tkuriyama
tkuriyama / fording_puzzle_v3.py
Last active June 18, 2016 01:17
River Fording Puzzle v3
"""River Fording Puzzle.
3 girls, each with her father, go for a stroll. They come to a small river.
One boat, able to carry 2 persons at a time, is at their disposal.
Crossing would be simple for everyone except the girls. None is willing to be
in the boat or ashore with 1 or 2 strange fathers, unless her own father is
present too. How do they all get across?
"""
@tkuriyama
tkuriyama / .vimrc
Last active May 23, 2017 08:19
vim config
""" Plugins https://github.com/tpope/vim-pathogen
execute pathogen#infect()
""" General UI
" line numbers
set number
" Turn on the WiLd menu