Skip to content

Instantly share code, notes, and snippets.

View cogas's full-sized avatar

cogas.iuk.uasanbon cogas

View GitHub Profile
@cogas
cogas / word_distribution.py
Created July 31, 2018 12:55
単語長分布ソースコード
# encoding: 'utf-8'
import random
import numpy as np
from datetime import datetime
from math import factorial, exp
SYL_MAX = 50
SAMPLING = 20
M = 0
@cogas
cogas / tokipona_and_pca.py
Created November 11, 2017 20:59
トキポナとPCA
import pandas as pd
import numpy as np
from sklearn.decomposition import PCA
PHONEME = "aeiouptksmnlwj"
def f(word):
v = [0] * len(PHONEME)
for i, p in enumerate(word):
v[PHONEME.index(p)] += i
@cogas
cogas / slicing.py
Created September 2, 2017 15:45
Pythonのスライシングが遅い話
# using:utf-8
import time
def test(n):
start = time.time()
xs = [None]*n
while xs:
xs = xs[1:]
end = time.time()
print("{}: {:.3f} sec".format(n, end-start))
@cogas
cogas / disjoint_set.py
Last active August 27, 2017 19:11
Aizu #2512222
# encoding: "utf-8"
from enum import Enum
class Unreachable(Exception):
pass
class Type(Enum):
VAL = 0
@cogas
cogas / purebtree.rs
Last active August 22, 2017 20:31
純粋な二分木
use std::rc::Rc;
use std::convert::From;
#[derive(Debug, Clone)]
pub enum PureBTree<T: Ord+Clone> {
Empty,
Node(T, Rc<PureBTree<T>>, Rc<PureBTree<T>>)
}
impl<T: Ord+Clone> From<T> for PureBTree<T> {
@cogas
cogas / btree.rs
Created August 22, 2017 19:49
BTreeを実装しようとした
fn main() {
let mut tree: BTree<i32> = BTree::Empty
.insert(10)
.insert(5)
.insert(15);
for i in 0..20 {
tree.insert_mut(i);
}
println!("{}", tree.search(&10));
@cogas
cogas / ehehe.rs
Last active August 18, 2017 15:41
Rust の vector memory allocation
fn main() {
let mut v: Vec<i32> = Vec::with_capacity(20);
println!("{} in {:?}", v.capacity(), v);
v.shrink_to_fit();
println!("{} in {:?}", v.capacity(), v);
v.push(0);
println!("{} in {:?}", v.capacity(), v);
v.shrink_to_fit();
println!("{} in {:?}", v.capacity(), v);
v.push(0);
use std::io;
fn main() {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
let mut word = String::new();
for c in buffer.trim().chars() {
if !['a', 'e', 'i', 'o', 'u'].contains(&c) {
word.push(c)
@cogas
cogas / blog.rs
Last active July 28, 2017 13:51
damepo.rs
// TRPL 17.3 Listing 17-18 のちょい下の3つの拡張問題の1つ目(Draft以外では投稿不能)を実装しようとしてのこれ
// https://doc.rust-lang.org/book/second-edition/ch17-03-oo-design-patterns.html
pub struct Post {
state: Option<Box<State>>,
content: String,
}
impl Post {
pub fn new() -> Post {
@cogas
cogas / piper.py
Created December 20, 2016 23:26
Piper - Pipe operation module
# coding=utf-8
class Piper:
def __init__(self, callable_obj):
self.__callable = callable_obj
def __call__(self, *args, **kwds):
return self.__callable(*args, **kwds)