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
// #![allow(dead_code)] | |
// #![allow(unused_variables)] | |
// #![allow(unused_mut)] | |
#![feature(question_mark)] | |
use std::sync::Mutex; | |
use std::sync::Arc; | |
use std::collections::VecDeque; | |
use std::thread; | |
use std::ops::Deref; |
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
--let attempt2bitmap (x,y,n) = ((9*x+n)*9^4, (9*y+n)*9^2, 9*x+y) | |
--let allAttempts = [bit row .|. bit col .|. bit pos | x <- [0..8], y <- [0..8], n <- [0..8], let (row, col, pos) = attempt2bitmap (x,y,n)] :: [Integer] | |
--let attempt2bitmap x y n = bit (9*x + n) .|. bit (9*y + n + 9^2) .|. bit (9*boxOf x y + n + n^4) .|. bit (9*x + y + 9^6) :: Integer | |
let attempt2bitnr x y n = [9*x + n, 9*y + n, 9*boxOf x y + n, 9*x + y] :: [Int] | |
let attempt2bitmap x y n = sum [ bit $ a + 9^2*i | (i,a) <- zip [0..] $ attempt2bitnr x y n] :: Integer | |
let matrix2bitmaps rows = [ attempt2bitmap x y (n-1) | (x, row) <- zip [0..] rows, (y, n) <- zip [0..] row, n /= 0] | |
let mapMatIdx f rows = [ f x y (n-1) | (x, row) <- zip [0..] rows, (y, n) <- zip [0..] row, n /= 0] | |
let matrix2tuples = mapMatIdx (,,) |
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
//#![allow(dead_code)] | |
use std::iter::FromIterator; | |
// Example of linked lists -- Comes from stackoverflow | |
enum List { Nil, Cons{value: i32, next: Box<List>}} | |
fn main() { | |
let v = vec![1, 5, 3, 8, 12, 56, 1230, 2, 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
#![allow(dead_code, unused_variables)] | |
struct PrimeList { | |
primes: Vec<i64>, | |
} | |
/// Basically the same as | |
/// self.primes.iter().cloned().chain(self) on a PrimeList | |
struct PrimeIter<'a> { | |
primes: &'a mut PrimeList, |
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
#[derive(Debug)] | |
struct Parent { | |
count: u8, | |
} | |
#[derive(Debug)] | |
struct Child<'a> { | |
parent: &'a Parent, | |
} |
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
#![feature(trace_macros)] | |
trace_macros!(true); | |
/// Piano numbers | |
#[derive(Debug, Clone, Copy)] | |
struct S<T>(T); | |
trait ToInt { | |
fn to_int(self) -> i32; | |
} |
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
// Project Euler Problem 36: Double-base palindromes | |
fn binary(n: i32) -> String { | |
format!("{:b}", n) | |
} | |
fn decimal(n: i32) -> String { | |
n.to_string() | |
} | |
fn is_palindrome(s: String) -> bool { |
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::sync::Once; | |
pub struct Lazy<T: Sync>(pub *const T, pub Once); | |
impl<T: Sync> Lazy<T> { | |
#[inline(always)] | |
pub fn get<F>(&'static mut self, f: F) -> &T | |
where F: FnOnce() -> T | |
{ | |
unsafe { |
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
#![feature(trace_macros)] | |
trace_macros!(true); | |
macro_rules! wrap { | |
($n:expr) => (wrap!(S($n))) | |
} | |
macro_rules! wrap_nocrash { | |
($($n:tt)*) => (wrap_nocrash!(S($($n)*))) | |
} |
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
#![feature(trace_macros)] | |
trace_macros!(true); | |
macro_rules! wrap { | |
($n:expr) => (wrap!(S($n))) | |
} | |
macro_rules! wrap_nocrash { | |
($($n:tt)*) => (wrap_nocrash!(S($($n)*))) | |
} |