Skip to content

Instantly share code, notes, and snippets.

View bgnori's full-sized avatar

Noriyuki Hosaka bgnori

  • Itabashi, Tokyo, Japan
View GitHub Profile
#!/bin/python
import math
def smartsub(N, k):
if k == 0:
return 1
""" k > 1 """
d, m = divmod(N, 10**k)
{
init: function(elevators, floors) {
var A = elevators[0];
A.on("idle", function() {
A.goToFloor(0);
});
A.on("floor_button_pressed", function(floorNum) {
if (A.currentFloor < floorNum) {
A.goingUpIndicator(true)
package main
import (
"crypto/rand"
"encoding/base64"
"encoding/binary"
"fmt"
"github.com/seehuhn/mt19937"
)
package main
import (
"crypto/rand"
"encoding/base64"
"fmt"
)
func main() {
#/usr/bin/python
# coding: utf-8
from sqlalchemy.engine import create_engine
from sqlalchemy.engine import create_engine
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy.sql.expression import and_
from sqlalchemy.schema import Column
from sqlalchemy.dialects.postgresql import DATE, VARCHAR, DOUBLE_PRECISION, BIGINT, INTEGER, NUMERIC
from sqlalchemy.dialects.postgresql import TIMESTAMP
nori@Nagato:~/.go/src/github.com/bgnori/npoker$ /usr/local/go/bin/go run main.go
18.849115秒
3 players, 1000000 trials
player 0 has J♠,J♣, won 0.189, won eq of 186.78.
player 1 has A♠,A♥, won 0.714, won eq of 708.11.
player 2 has K♦,A♦, won 0.111, won eq of 105.10.
nori@Nagato:~/.go/src/github.com/bgnori/npoker$ /usr/local/go/bin/go run main.go
49.913845秒
package main
import (
"encoding/json"
"fmt"
"os"
)
type LINEContent struct {
ToType int `json:"toType"`
@bgnori
bgnori / trello.py
Last active December 30, 2015 10:49
simple validation.
#!/usr/bin/python
import re
import requests
import json
source = "https://trello.com/docs/api/index.html"
pattern = re.compile(
r" (?P<method>[A-Z]+) /(?P<version>\d+)/boards/\[board_id\]/?(?P<entity>[^/]*)/?(?P<params>.*)")
@bgnori
bgnori / monadstudy.py
Last active December 29, 2015 01:49
itertoolsとcollections, functoolsの勉強が必要. 無限リストの扱いの都合上、pythonのlistをそのまま使うことはできない.
#!/usr/bin/python
# -*- coding=utf8 -*-
"""
kana notation: usint | for bind of monad, flatMap in Scala.
see http://labs.timedia.co.jp/2011/05/monad-in-python.html
need monad law test
a. Associativity
(m flatMap f) flatMap g == m flatMap (f flatMap g)
@bgnori
bgnori / gist:6460186
Created September 6, 2013 06:21
coursesera stack sequence solver
source = list(range(10))
stack = []
expected = [6, 5, 4, 3, 2, 1, 0, 7, 8, 9]
while expected:
while not stack or stack[0] != expected[0]:
stack.insert(0, source.pop(0))
print("push", stack[0])