Skip to content

Instantly share code, notes, and snippets.

Avatar

Taro Kuriyama tkuriyama

View GitHub Profile
View tic_tac_toe.py
# Helpers
def transpose(lst):
"""Transpose list of lists, returning list of lists."""
return [list(row) for row in zip(*lst)]
def diagonals(lst):
"""Return both diagonals of given square list of lists."""
rev_lst = [row[::-1] for row in lst]
@tkuriyama
tkuriyama / mini_regex.hs
Created Feb 16, 2020
Implementing find for a regex subset
View mini_regex.hs
-- Regex subset: https://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
-- Find the left-most occurence of pattern that matches regex
import Data.List(tails)
type Regex = String
type Match = String
find :: Regex -> String -> Match
find r s = unwrap $ mapUntil "" (findWord r) (tails $ wrap s)
View useful_pandas_snippets.md

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@tkuriyama
tkuriyama / .vimrc
Last active May 23, 2017
vim config
View .vimrc
""" Plugins https://github.com/tpope/vim-pathogen
execute pathogen#infect()
""" General UI
" line numbers
set number
" Turn on the WiLd menu
@tkuriyama
tkuriyama / fording_puzzle_v3.py
Last active Jun 18, 2016
River Fording Puzzle v3
View fording_puzzle_v3.py
"""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 Jun 18, 2016
River Fording Puzzle v2
View fording_puzzle_v2.py
"""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_v1.py
Created Jun 18, 2016
River Fording Puzzle v1
View fording_puzzle_v1.py
"""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 / lex_perm.py
Last active Dec 23, 2015
Find lexicographical predecessor or successor (permutation)
View lex_perm.py
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 / fold_syntax_tests
Last active Sep 27, 2015
Testing GitHub syntax highlighting in F#
View fold_syntax_tests
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 / weighted_draw.py
Last active Sep 19, 2015
Probability-weighted drawing.
View weighted_draw.py
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
You can’t perform that action at this time.