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 random | |
# Make this higher when you want better graphs | |
iters = 100 | |
def trunc(x): | |
return x % (2**64) | |
def test_row(f, swaps): | |
seen = set() |
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 trait InternalIterator { | |
type Item; | |
fn each<F>(&mut self, mut f: F) -> bool | |
where F: FnMut(Self::Item) -> bool; | |
} | |
impl<I> InternalIterator for I | |
where I: Iterator, | |
{ | |
type Item = I::Item; |
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
time: 0.594; rss: 322MB parsing | |
time: 0.000; rss: 322MB recursion limit | |
time: 0.000; rss: 322MB crate injection | |
time: 0.000; rss: 322MB plugin loading | |
time: 0.000; rss: 322MB plugin registration | |
time: 0.295; rss: 349MB expansion | |
time: 0.000; rss: 349MB maybe building test harness | |
time: 0.012; rss: 349MB maybe creating a macro crate | |
time: 0.000; rss: 349MB checking for inline asm in case the target doesn't support it | |
time: 0.023; rss: 349MB complete gated feature checking |
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 random | |
hero_hp = random.randint(500, 1000) | |
minotaur_hp = random.randint(1000, 2000) | |
damage_base = 100 | |
heal_base = 50 | |
while True: | |
print("Hero HP: {}".format(hero_hp)) |
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
/** | |
* This code uses std.experimental.ndslice to take the mean of the columns in | |
* a 2d 100x1000 array and creates a benchmark of that code. | |
* | |
* My mean running time is about 1.2 ms. | |
* | |
* If we compare this code to the Numpy equivalent, | |
* | |
* import numpy | |
* data = numpy.arange(100000, dtype="int32").reshape((100, 1000)) |
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(test)] | |
extern crate test; | |
use std::f64; | |
pub fn parse_builtin(string: &str) -> Option<f64> { | |
string.parse().ok() | |
} |
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 const WIDTH: usize = 7; | |
pub const HEIGHT: usize = 6; | |
pub const MAX_DEPTH: i32 = 7; | |
pub const ORANGE_WINS: i32 = 1000000; | |
pub const YELLOW_WINS: i32 = -ORANGE_WINS; | |
// Couldn't resist changing the type of this | |
pub type Board = [[i8; WIDTH]; HEIGHT]; | |
pub fn other_color(color:i8) -> i8 { |
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
def fibonacci(n): | |
if n == 0: | |
return 0 | |
elif n == 1: | |
return 1 | |
else: | |
return fibonacci(n - 1) + fibonacci(n - 2) | |
def fibonacci(n): | |
if n == 0: |
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
require 'prime' | |
class Integer | |
# Make a lazy enumerator of the lower half of factors of self | |
def half_factors | |
(1..Math.sqrt(self) + 1).lazy.select { |n| (self % n).zero? } | |
end | |
end | |
puts "Started at #{Time.now}." |
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
#include "benchmark/benchmark.h" | |
#include <algorithm> | |
class X { | |
private: | |
std::size_t size; | |
int *data; | |
public: |