Skip to content

Instantly share code, notes, and snippets.

View henninglive's full-sized avatar

Henning Ottesen henninglive

  • Mo i Rana, Norway
View GitHub Profile
@henninglive
henninglive / isqrt.rs
Created April 21, 2018 18:07
Integer Square Root
/// Integer Square Root
///
/// `n` is the positive integer for which the return value is the greatest
/// integer less than or equal to the square root of n.
pub fn isqrt(mut n: usize) -> usize {
let mut res = 0;
let mut b = 1 << ((::std::mem::size_of::<usize>() * 8) - 2);
while b > n {
b >>= 2
@henninglive
henninglive / ksubset.rs
Created April 29, 2017 18:00
k-element subsets of an n-element set using bijection
// k-element subsets of an n-element set.
// Implemented using the Bijection Rule. The Bijection Rule
// lets us find subsets of an equivalent bit set and map
// those subsets to our original set to get our subsets.
fn ksubset<T: Clone>(set: &[T], k: usize) -> Vec<Vec<T>> {
assert!(set.len() < std::mem::size_of::<usize>() * 8);
assert!(k <= set.len());
let mut subsets = Vec::new();
@henninglive
henninglive / tmux_local_install.sh
Created March 29, 2017 12:30 — forked from ryin/tmux_local_install.sh
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=1.8

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: