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
; http://projecteuler.net/problem=14 | |
(define (eu14 m) | |
(let ((memo (make-vector m #f)) | |
(best-l 0) | |
(best-i 0)) | |
(define (up n a) | |
(cond | |
((= n 1) a) | |
((and (< n m) (vector-ref memo n)) => (lambda (x) (+ a x))) |
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 rand::rng; | |
fn main() { | |
let mut count : u64 = 0; | |
let rng = rand::seeded_rng(~[17]); | |
loop { | |
let r = rng.gen_f64(); | |
if r > 1.0f64 { | |
io::println(#fmt("%s > 1.0 (after %? tries)", | |
float::to_str_exact(r as float, 16), count)); |
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
enum pc = u32; | |
struct state<S: copy> { | |
let state: S; | |
let pc: pc; | |
let idx: uint; | |
} | |
trait success<S: copy, R> { | |
fn succeed(state: &S) -> R; |
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 vec::*; | |
fn truncate<T>(&v: ~[const T], newlen: uint) { | |
let oldlen = len(v); | |
assert(newlen <= oldlen); | |
unsafe { | |
for uint::range(newlen, oldlen) |i| { | |
let _dropped <- *ptr::mut_addr_of(v[i]); | |
} | |
unsafe::set_len(v, newlen); |
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 core::cmp::{Eq,Ord}; | |
mod exhibitA { | |
fn unique<T: copy Eq>(&v: ~[mut T]) { | |
let mut i_dst = 0, i_src = 1; | |
let ln = v.len(); | |
if ln < 1 { return; } | |
while i_src < ln { | |
if !v[i_src].eq(v[i_dst]) { | |
i_dst += 1; |
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 to_bytes::{IterBytes,iter_le_bytes_2,iter_be_bytes_2}; | |
enum thing = uint; | |
impl thing : IterBytes { | |
fn iter_le_bytes(f: to_bytes::Cb) { (*self).iter_le_bytes(f) } | |
fn iter_be_bytes(f: to_bytes::Cb) { (*self).iter_be_bytes(f) } | |
} | |
enum stuff1 = ~[thing]; | |
impl stuff1 : IterBytes { |
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
stuff = e13 | |
e0 = ∅ | |
e1 = ε | |
e2 = !e0 | |
e3 = '/' | |
e4 = '*' | |
e5 = e3 + e4 | |
e6 = e4 + e3 | |
e7 = e3 + e2 | |
e8 = e4 + e7 |
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 foo<T>(&dst: @const T, &src: @const T) { | |
dst = src; | |
} | |
fn main() | |
{ | |
let mut r_imm = @0; | |
let mut r_mut = @mut 0; | |
foo(r_imm, r_mut); | |
io::println(fmt!("r_imm = %?", r_imm)); |
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 v : ~[[i8 * 0]] = ~[]; | |
io::println(fmt!("%?", v.len())); | |
} |
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
pub struct SetupRequest { | |
byte_order: u8, | |
protocol_major_version: u16, | |
protocol_minor_version: u16, | |
authorization_protocol_name: ~[u8], | |
authorization_protocol_data: ~[u8], | |
} | |
struct_io!{ | |
SetupRequest; | |
copy byte_order; |
OlderNewer