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
//! Chapter 1: Introduction to Algorithms. Binary Search. | |
// NB: input must be sorted | |
fn binary_search<T>(lst: &[T], item: &T) -> Option<usize> | |
where T: PartialEq + PartialOrd | |
{ | |
let mut low = 0; | |
let mut high = lst.len() - 1; | |
while low <= high { |
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
/** Python-style range function */ | |
function range(n) { | |
let arr = new Array(n); | |
let result = [...arr.keys()].map(m => Number(m)); | |
return result; | |
} |
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::f32; | |
#[derive(Debug, Clone, PartialEq, PartialOrd)] | |
pub struct Vector2D { | |
pub x: f32, | |
pub y: f32, | |
} | |
impl Default for Vector2D { | |
fn default() -> Self { |
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::io::{self, Write}; | |
fn prompt(input: &str) -> io::Result<String> { | |
let mut output = String::new(); | |
print!("{}", input); | |
io::stdout().flush()?; | |
io::stdin().read_line(&mut output)?; | |
Ok(output) | |
} |
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::marker::PhantomData; | |
use std::convert::From; | |
#[derive(Debug, Clone, Copy)] | |
struct H; | |
#[derive(Debug, Clone, Copy)] | |
struct L; | |
#[derive(Debug, Clone, Copy)] | |
struct Sec<S, A> { |
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::marker::PhantomData; | |
use std::convert::From; | |
// Define the empty temperature markers | |
#[derive(Debug, Copy, Clone)] struct C; | |
#[derive(Debug, Copy, Clone)] struct F; | |
// Temperature Struct with Phantom Data | |
#[derive(Debug, Copy, Clone)] | |
struct Temp<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
// | |
// i32_vec.c | |
// vector_idea | |
// | |
// Created by Nikolaj Lepka on 2018-09-19. | |
// Copyright © 2018 wausoft.eu. All rights reserved. | |
// | |
#include "i32_vec.h" | |
/** |
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; |
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
// Rudimentary implementation of the Collatz conjecture | |
fn next(input: u128) -> u128 { | |
if input % 2 == 0 { | |
input / 2 | |
} else { | |
input * 3 + 1 | |
} | |
} |