In the fourth chapter of “Programming Pearls”, Jon Bentley discusses program correctness and tells us that as part of some of his programming classes, he asks the attendees to implement the binary search algorithm. Although simple in appearance (“look at the middle element, if it’s the target terminate, if it’s smaller look in the upper half, otherwise look in the lower half”), it can be a surprisingly tricky algorithm to implement. He cites TAoCP Vol. 3 wherein Don Knuth mentions that although the first paper on binary
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
Seeded DCSS version 0.23.2 (console) character file. | |
Game seed: 18127138284784505733 | |
1676291 gotm the Invulnerable (level 27, 271/271 HPs) | |
Began as a Minotaur Gladiator on July 28, 2019. | |
Was a High Priest of Trog. | |
Escaped with the Orb | |
... and 3 runes on July 30, 2019! | |
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
fn deserialize_deals<'de, D>(de: D) -> ::std::result::Result<HashMap<u8, BTreeSet<String>>, D::Error> | |
where D: Deserializer<'de> | |
{ | |
struct DealsVisitor; | |
impl<'de> Visitor<'de> for DealsVisitor { | |
type Value = HashMap<u8, BTreeSet<String>>; | |
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
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 <err.h> | |
#include <inttypes.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/time.h> | |
#define CACHE_LINES 64 |
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
/* C code */ | |
int add(int x, int y) { | |
return x+y; | |
} | |
void caller() { | |
int a = add(3, 4); | |
} | |
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
iload_0 ; [a] | |
iconst_1 ; [a, 1] | |
ieq ; [a==1] | |
dup ; [a==1, a==1] | |
jmp_nonzero OR ; [a==1] | |
drop ; [] | |
iload_1 ; [b] | |
OR: | |
istore_2 ; [] | |
iload_2 ; [c] |
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
extern crate rayon; | |
use rayon::prelude::*; | |
use std::time::Instant; | |
fn collatz(mut x: u64) -> usize { | |
let mut steps = 0; | |
while x != 1 { | |
if x % 2 == 0 { | |
x /= 2; |
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
impl <'a> IntoIterator for &'a Bitmap { | |
type Item = u16; | |
type IntoIter = SharedBitmapIterator<'a>; | |
fn into_iter(self) -> Self::IntoIter { | |
return SharedBitmapIterator { offset: 0, bitmap: &self }; | |
} | |
} | |
impl IntoIterator for Bitmap { | |
type Item = u16; |
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::io; | |
use std::collections::HashMap; | |
use std::collections::VecDeque; | |
#[derive(Debug, PartialEq, Copy, Clone)] | |
enum Command { | |
Assign { bot: usize, value: usize }, | |
Give { | |
src: usize, // from which bot? | |
dst1: usize, // to which bot/bin? |
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
fn insertion_sort<T: PartialOrd>(xs: &mut Vec<T>) { | |
for i in 1..(xs.len() - 1) { | |
let mut j = i; | |
while j > 0 && xs[j-1] > xs[j] { | |
xs.swap(j, j-1); | |
j -= 1; | |
} | |
} | |
} |
NewerOlder