Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View gnuvince's full-sized avatar

Vincent Foley gnuvince

View GitHub Profile
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!
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 {
@gnuvince
gnuvince / sob.c
Last active December 29, 2018 16:17
#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
/* C code */
int add(int x, int y) {
return x+y;
}
void caller() {
int a = add(3, 4);
}
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]
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;
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;
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?
@gnuvince
gnuvince / binsearch.org
Last active April 13, 2024 17:45
Literate programming in Org-mode + Rust: binary search

Introduction

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

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;
}
}
}