This file contains hidden or 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 Control.Monad.State.Strict | |
import System.Random | |
main = do | |
print "hello world" | |
print $ evalState (genPrimes 100) [2] | |
isPrime :: Int -> [Int] -> Bool | |
isPrime n primes = all (\p -> mod n p /= 0) primes |
This file contains hidden or 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
template<typename T> | |
std::vector<T> thread_map(int thread_num, std::vector<T> origin_arg, std::function<T(T)> func) { | |
std::vector<std::thread> threads_; | |
std::vector<T> output_(origin_arg.size()); | |
for(int i = 0; i < thread_num; ++i){ | |
auto runner = [i, func, origin_arg, thread_num, &output_]() { | |
int array_size = origin_arg.size(); | |
int start = (array_size + thread_num - 1) / thread_num * i; | |
int end = std::min((array_size + thread_num - 1) / thread_num * (i + 1), array_size); | |
for(int j = start; j < end; ++j) { |
This file contains hidden or 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 regex::Regex; | |
use std::cell::RefCell; | |
use std::rc::Rc; | |
fn main() { | |
println!("{:?}", Parser::new("(+ 1234 1)").token_tree); | |
} | |
#[derive(Clone, Debug)] | |
enum Token { |
This file contains hidden or 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::{self, Read}; | |
use std::rc::Rc; | |
use std::cell::RefCell; | |
fn main() -> io::Result<()>{ | |
let mut buffer = String::new(); | |
let stdin = io::stdin(); | |
let mut handle = stdin.lock(); | |
handle.read_to_string(&mut buffer)?; | |
let tokens = str2token(buffer); |
This file contains hidden or 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
pub const TEST: u64 = 100; |
This file contains hidden or 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::cell::RefCell; | |
struct BinTree { | |
value: u64, | |
left: Option<Rc<RefCell<BinTree>>>, | |
right: Option<Rc<RefCell<BinTree>>>, | |
} | |
impl BinTree { |
This file contains hidden or 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::cell::RefCell; | |
use std::fmt::{ self, Display }; | |
enum MyNumber { | |
One(Rc<RefCell<MyNumber>>), | |
Zero, | |
} | |
impl MyNumber { |
This file contains hidden or 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::sync::{ Arc, Mutex }; | |
#[derive(Debug)] | |
struct BinTree { | |
left: Option<Arc<Mutex<BinTree>>>, | |
right: Option<Arc<Mutex<BinTree>>>, | |
value: u64, | |
} | |
impl BinTree { |
This file contains hidden or 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::cell::RefCell; | |
use std::rc::Rc; | |
use std::collections::LinkedList; | |
#[derive(Debug, Clone)] | |
struct VueGraph { | |
parent: Vec<Rc<RefCell<VueGraph>>>, | |
name: String, | |
children: Vec<Rc<RefCell<VueGraph>>>, | |
} |
This file contains hidden or 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 java.io.*; | |
import java.util.Random; | |
import java.util.Date; | |
import java.util.StringTokenizer; | |
class Species { | |
protected double max; // 最大適応度 | |
protected double mean; // 平均適応度 | |
protected double [] pi; // 適応度 |