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 apply_instruction(program: &mut Vec<u32>, ip: usize) { | |
let instruction = program[ip]; | |
let verb = program[ip+1] as usize; | |
let noun = program[ip+2] as usize; | |
let target = program[ip+3] as usize; | |
program[target] = match instruction { | |
1 => program[verb] + program[noun], | |
2 => program[verb] * program[noun], | |
_ => unimplemented!("Unknown instruction: {}", instruction), |
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::ops::AddAssign; | |
use std::collections::HashMap; | |
use std::collections::HashSet; | |
type Segment = (char, u32); | |
#[derive(PartialEq, Eq, Hash, Copy, Clone)] | |
struct Point { | |
x: i32, | |
y: i32 |
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::fs::File; | |
use std::io::{prelude::*, BufReader}; | |
use std::cmp::max; | |
fn fuel_for_mass(mass: i32) -> i32 { | |
let mut fuel = mass; | |
fuel = fuel / 3; // assume round down | |
fuel -= 2; | |
//println!("mass: {} requires: {}", mass, max(fuel, 0)); | |
max(fuel, 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
# pip install python-constraint | |
from constraint import Problem, AllDifferentConstraint, ExactSumConstraint | |
DIGITS = range(1, 10) | |
COLS = "ABCDEFGHI" | |
ROWS = "123456789" | |
COL_GRP = ["ABC", "DEF", "GHI"] | |
ROW_GRP = ["123", "456", "789"] | |
CELLS = [] | |
for cg in COL_GRP: |
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Copyright (C) Metaswitch Networks. | |
"""Picks two 5 letter words at random from a dictionary, | |
finds a route between the words by only changing one letter at a time""" | |
import random | |
import heapq | |
import time |
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
""" | |
profit.py | |
Pair-wise comparison and adjustment of profit share contribution ratios. | |
""" | |
from pprint import pprint | |
import random | |
# Seed this with numbers that are approximately sensible... |
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
""" | |
Map the next 1000 weeks to quarters in a sensible way so that | |
most quarters are 13 weeks long... and occasionally we introduce | |
a 14 week quater, so as to maximise the amount of working days that | |
fall in their correct quarter | |
""" | |
from datetime import date, timedelta | |
from collections import defaultdict | |
import networkx as nx |
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
""" | |
csv_entropy.py | |
Author: MBJ (2017) | |
Purpose: Command line utility to assess the most "Informative" columns in a CSV file. | |
Detail: | |
* Reads the contents of a CSV file | |
- Assumes header row is at the top |
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 json | |
from pprint import pprint | |
from elasticsearch import Elasticsearch # pip install elasticsearch | |
host = 'corpus.metaswitch.com' | |
es = Elasticsearch(hosts=[host]) | |
query = { | |
"_source": ["html", "id", "subject", "breadcrumbs.title", "replyCount" ], | |
"size" : 100, |
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
# https://pypi.python.org/pypi/python-dateutil/2.5.3 | |
# https://dateutil.readthedocs.io/en/stable/ | |
from dateutil import parser # pip install python-dateutil | |
if __name__ == '__main__': | |
try: | |
a = parser.parse("18 Aug 2001") | |
print a | |
b = parser.parse("2016-04-05 12:33:55") | |
print b |
NewerOlder