This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: "utf-8" | |
from enum import Enum | |
class Unreachable(Exception): | |
pass | |
class Type(Enum): | |
VAL = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
class Piper: | |
def __init__(self, callable_obj): | |
self.__callable = callable_obj | |
def __call__(self, *args, **kwds): | |
return self.__callable(*args, **kwds) |
NewerOlder