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::iter::iterate; | |
use std::num::Float; | |
use std::sync::Future; | |
fn main() { | |
if let Some(n) = read_uint(1) { | |
let sum_of_primes = { | |
let block_size = if n > 999 { n / 20 } else { n }; | |
let mut futures = Vec::new(); |
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
extern crate chrono; | |
pub mod expiring_cache { | |
use chrono::{DateTime, Duration, UTC}; | |
use std::collections::HashMap; | |
use std::collections::hash_map::Entry::{Occupied, Vacant}; | |
use std::hash::Hash; | |
pub struct ExpiringCache<Key, Value> where Key: Eq + Hash { | |
expiry: Duration, // cache endurance |
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
#![feature(unboxed_closures)] | |
use Bounce::{Process, Result}; | |
fn main() { | |
let x: int = from_str(std::os::args()[1].as_slice()).unwrap(); | |
let result = Process(box move || is_even(x)).execute(); | |
println!("{}", if result { "even" } else { "odd" }); | |
} |
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
#![feature(unboxed_closures)] | |
fn main() { | |
let x = from_str::<int>(std::os::args()[1].as_slice()).unwrap(); | |
let n = Bounce::Incomplete(x).execute(|n| { | |
match n { | |
n if n < 1 => Bounce::Fault("Value out of range."), | |
1i => Bounce::Complete(n), | |
n => Bounce::Incomplete(n - 1i), | |
} |
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
fn main() { | |
let (cnt, sum) = sieve(1000000).iter() | |
.fold((0u, 0u), |a, b| { | |
let (cnt, sum) = a; | |
(cnt + 1, sum + *b) | |
}); | |
println!("{}", sum as f32 / cnt as f32); | |
} |
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::iter::Unfold; | |
fn main() { | |
let fib_seq = Unfold::new((0i64, 1i64), |state| { | |
// closures pretty much always borrow, so *dereference | |
// to get value instead of pointer | |
let (x, y) = *state; | |
let result = Some(x); | |
// again, set *value, not reference |
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
#![feature(phase)] | |
#[phase(plugin)] | |
extern crate regex_macros; | |
extern crate regex; | |
use regex::Regex; | |
use std::ascii::AsciiExt; | |
use std::collections::{HashMap}; | |
use std::collections::hash_map::Entry::{Vacant, Occupied}; | |
use std::io::{BufferedReader, File}; |
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
#![feature(phase)] | |
#[phase(plugin)] | |
extern crate regex_macros; | |
extern crate regex; | |
use regex::Regex; | |
use std::ascii::AsciiExt; | |
use std::collections::HashSet; | |
use std::io::{BufferedReader, File}; | |
use std::io::fs::PathExtensions; |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Security.Cryptography; | |
namespace Dice | |
{ | |
class Program | |
{ | |
static void Main(string[] args) |
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
namespace EasyChallenge188_Dates | |
{ | |
class Program | |
{ |