Skip to content

Instantly share code, notes, and snippets.

View neilmayhew's full-sized avatar

Neil Mayhew neilmayhew

View GitHub Profile
@neilmayhew
neilmayhew / Queens.hs
Last active August 29, 2015 14:07
Calculate solutions to the 8 queens on a 5x5 board problem
{-# LANGUAGE TupleSections #-}
import Control.Arrow (first, second)
import Control.Monad (forM_)
import Data.List (intersperse, intersect, (\\))
import System.IO (hFlush, stdout)
-- Generate the list of possible choices of n items from a list
-- Each choice is a pair of the chosen and not-chosen items
choices 0 xs = [([], xs)]
@neilmayhew
neilmayhew / Queens.out
Created October 17, 2014 22:14
Output from Queens.hs
W W - - -
- - - B B
- - - - B
W - - - -
- - B B -
W - - W -
W - - - -
- - - - B
- B - - B
@neilmayhew
neilmayhew / HighProduct.cs
Last active August 29, 2015 14:20
An example of using C# and LINQ to program in a functional style
// Use the digits 0-9 (once each) to create two numbers by concatenation. (e.g. 152 and 3476980).
// What's the highest product you can achieve when these two numbers are multiplied together?
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
namespace HighProduct
{
@neilmayhew
neilmayhew / MergeSort.fs
Created May 8, 2015 18:24
MergeSort algorithm in F#
let mergeSort xs =
let wrap x = [x]
let rec merge = function
| x::xs, y::ys -> if x < y then x :: merge (xs, y::ys) else y :: merge (x::xs, ys)
| l, [] -> l
| [], m -> m
let rec mergePairs = function
| (l::m::ns) -> merge (l, m) :: mergePairs ns
| ls -> ls
let rec mergeAll = function
@neilmayhew
neilmayhew / FactorTree.fs
Created June 5, 2015 04:44
Print trees of factors of integers
// Display trees of factors of integers
// Tree type
type 'a Tree =
| Branch of 'a * 'a Tree * 'a Tree
| Leaf of 'a
// Computation of Trees of factors
@neilmayhew
neilmayhew / 85restrict-applications
Last active December 2, 2015 17:02
Restrict applications in a desktop session
#!/bin/sh
# This file is sourced by Xsession(5), not executed.
# Conditionally restrict the set of applications visible to the user
if [ -e ~/.config/restrict-applications.conf -a -n "$XDG_DATA_DIRS" ]
then
XDG_DATA_DIRS=$(restrict-applications)
fi
@neilmayhew
neilmayhew / .gitignore
Last active March 10, 2016 17:03
A script for testing delays on ssh connections
*.log
@neilmayhew
neilmayhew / readfile.cc
Created February 17, 2017 17:07
Read a file into a vector using C++11
#include <cstring> // For strerror
#include <list>
#include <memory>
#include <vector>
#include <stdexcept>
#include <unistd.h> // For read
std::vector<unsigned char> readfile(int fd)
{
struct Chunk
@neilmayhew
neilmayhew / names.in
Last active December 8, 2017 04:19
DuplicityAnalyzer test input and output
./duplicity-inc.20170401T165721Z.to.20170402T145302Z.vol1.difftar.gpg
./duplicity-full.20170331T220513Z.vol1.difftar.gpg
./duplicity-full.20170331T220513Z.vol2.difftar.gpg
./duplicity-full.20170331T220513Z.vol3.difftar.gpg
./duplicity-full.20170331T220513Z.vol4.difftar.gpg
./duplicity-full.20170331T220513Z.vol5.difftar.gpg
./duplicity-full.20170331T220513Z.vol6.difftar.gpg
./duplicity-full.20170331T220513Z.vol7.difftar.gpg
./duplicity-full.20170331T220513Z.vol8.difftar.gpg
./duplicity-full.20170331T220513Z.vol9.difftar.gpg

Keybase proof

I hereby claim:

  • I am neilmayhew on github.
  • I am neil_mayhew (https://keybase.io/neil_mayhew) on keybase.
  • I have a public key ASAuEc7S-F-BkzOBsWRe9AsYaOUOMw9X81JWkCF4ZA3GTwo

To claim this, I am signing this object: