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(box_patterns)] | |
use std::fmt; | |
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone)] | |
enum Tree<T: fmt::Display> { | |
Leaf, | |
Node { data: T, left: Box<Tree<T>>, right: Box<Tree<T>> }, | |
} | |
impl<T: fmt::Display> fmt::Display for Tree<T> { |
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
// modulo operation that behaves correctly with negative numbers | |
function mod(n, m) { | |
return ((n % m) + m) % m; | |
} | |
// converts a character to its digit representation | |
// same as indexOf, but more succinct | |
function toDigit(char, alphabet) { | |
return alphabet.indexOf(char) | |
} |
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
cleanup() { | |
count=0 | |
filename=$1 | |
for file in $(find .); do | |
if [ -f $file ] && [[ $file =~ $filename || $file == $filename ]]; then | |
let "count++" | |
fi | |
done |
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
show() { | |
for file in $(find .); do | |
if [[ $file =~ $1 || $file == $1 ]]; then | |
echo $file | |
fi | |
done | |
} |
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.Trans.State | |
data Expression = Var Char | |
| Const Int | |
| Expression :+: Expression | |
| Int :*: Expression | |
deriving (Eq, Ord, Show) | |
type Context = State (Maybe Expression) |
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
Array.prototype.pick = function(index) { | |
let element = this.splice(index, 1) | |
if (element == null || element.length == 0) { | |
return undefined | |
} | |
return element[0] | |
} |
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
macro_rules! cond { | |
($($e:expr => $body:expr),+, _ => $default:expr) => ( | |
$(if $e { $body } else)+ { $default } | |
); | |
($e:expr => $body:expr) => ( if $e { $body }) | |
} | |
fn main() { | |
let age = 25; |
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
// Rudimentary implementation of the Collatz conjecture | |
fn next(input: u128) -> u128 { | |
if input % 2 == 0 { | |
input / 2 | |
} else { | |
input * 3 + 1 | |
} | |
} |
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 rand; | |
use rand::Rng; | |
use std::env; | |
const MAX_DAYS: usize = 365; | |
/// Creates an array with `count` number of birthdays in it represented by numbers | |
/// if more than one birthday occurs on the same day, then that day's entry will be > 1 | |
fn paradox(count: u16) -> [u16; MAX_DAYS] { | |
let mut arr = [0; MAX_DAYS]; |
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
html { | |
font-family: "Arial Narrow", sans-serif | |
} | |
div { | |
font-size: 200%; | |
padding: 50px; | |
background-color: black; | |
color: white; | |
height: 1000px; |