Skip to content

Instantly share code, notes, and snippets.

@dillmo
dillmo / FastExp.dfy
Last active January 11, 2022 06:32
Fast Natural Exponentiation in Dafny
method FastExp(a: int, n: nat) returns (z: int)
ensures z == Exp(a, n)
{
var b: int, i: nat;
z, b, i := 1, a, n;
while (i != 0)
invariant ExpInv(z, b, i, a, n)
decreases i
{
if i % 2 == 1 {
@dillmo
dillmo / treap_insertion.c
Created November 13, 2021 22:04
An implementation of treap insertion in ANSI C. Inserts 1 to 30 into a treap in order, then prints the treap in Graphviz's dot format.
#include <stdlib.h>
#include <stdio.h>
struct node {
struct node *parent;
struct node *left;
struct node *right;
int value;
int weight;
};
def soundex(name):
code = {
'b': '1',
'f': '1',
'p': '1',
'v': '1',
'c': '2',
'g': '2',
'j': '2',
'k': '2',
<?xml version="1.0" ?>
<enemy>
<behaviour>
<root x="110" y="40">
<normal>
<andblock>
<string id="Comment">Avoid Earthquake</string>
<normal>
<condition id="isOnGround">
<string id="condition" values="yesno">yes</string>
@dillmo
dillmo / out.txt
Created May 26, 2014 18:03
Introduction to C++ Tortoise and Hare Problem
BANG !!!
AND THEY'RE OFF !!!!!
H==T=================================================================
T = Tortoise
H = Hare
B = Both
=H==T================================================================
T = Tortoise
@dillmo
dillmo / project_2.cpp
Created May 13, 2014 23:40
Introduction to C++ Problem Set 6
/* Introduction to C++ Project 2 by Dillon Morse
* =============================================
*
* Description
* -----------
* Spec out how you will code and test the definition and use of a right
* triangle class.
* 1. Determine what your data will be.
* 2. Create prototypes of the following functions:
* - Constructor(s)
@dillmo
dillmo / solver.cpp
Created May 13, 2014 23:31
Linear Equation Solver
#include <iostream>
#include <regex>
#include <cstdlib>
using namespace std;
double* getInput();
bool undefined(double*);
double a(double*);
double c(double*, double);
@dillmo
dillmo / project.cpp
Created April 25, 2014 18:55
Introduction to C++ Homework Problem Set 5
/* Introduction to C++ Homework Problem Set 5 Project by Dillon Morse
* ------------------------------------------------------------------
* Create a sequential file that contains 34 rows and 34 columns. Fill the
* array with random numbers between -20 and 80. Your main code will ask the
* user to enter a number N between -20 and 80. Yoiu will open the file and
* search the two dimension array you read in for the number N. If found,
* display the number of times it was found. Next, pass your two dimension
* array to a functoin called diagonal. The function will ask the user if they
* want the sum of the main diagonal values to a function called diagonal. The
* function will ask the user if they want the sum of the main diagonal values
@dillmo
dillmo / test_2_lab.cpp
Created April 8, 2014 19:05
Introduction to C++ Test 2 Lab solution
/* Introduction to C++ Test 2 Lab solution by Dillon Morse
* -------------------------------------------------------
* a) Write a program that will create a file that will contain
* the data values:
* 4 -9 7
* 1 -1 8
* 7 4 5
* 9 0 -3
* when your program completes.
*
@dillmo
dillmo / dwarves_and_coins.cpp
Created April 4, 2014 14:39
Solution to the Dwarves and Coins problem
/* Dwarves and Coins Solution by Dillon Morse
* ------------------------------------------
* Several (M) dwarves have found a goblin's chest with N gold coins and have
* to divide them. Due to ancient rules governing the allocation of loot to
* pirates in order of seniority, the oldest dwarf should get one coin more
* than the next oldest dwarf, and so on, so that the youngest dwarf gets M-1
* fewer coins than the oldest dwarf. Additionally, no dwarf has to pitch in
* any coins (ie no negative coins to any dwarfs)
*
* Help the dwarves to divide the coins in this way, or tell them that this is