Skip to content

Instantly share code, notes, and snippets.

View mjdominus's full-sized avatar

Mark Jason Dominus (陶敏修) mjdominus

View GitHub Profile
@mjdominus
mjdominus / toposort.py
Created May 10, 2019 20:21
Calculate topological sortings of a graph
#!/usr/bin/python3
class Graph():
def __init__(self, edge_list):
self.E = set(edge_list)
self.V = range(self._n_vertices())
def _n_vertices(self):
max = 0
for edge in self.E:
@mjdominus
mjdominus / dice
Created October 14, 2017 15:29
Perl program for comparing different combinations of dice
#!/usr/bin/perl
#
# 14 October 2017
# Author: Mark Jason Dominus
#
# This program is in the public domain.
# You may use, modify, copy, or distribute it
# in any way for any purpose, without restriction.
#
@mjdominus
mjdominus / 2-29.hs
Last active January 17, 2016 21:51
SICP exercise 2.29 in Haskell and Scheme
data Branch = Branch { branch_length :: Int, branch_structure :: Mobile } deriving Show
data Mobile = Weight Int | Mobile { left_branch :: Branch, right_branch :: Branch } deriving Show
total_branch_weight (Branch { branch_structure = str }) = total_weight str
total_weight (Weight wt) = wt
total_weight (Mobile lt rt) =
(total_branch_weight lt) + (total_branch_weight rt)
-- Verbose constructor syntax
#!/bin/bash
set -e
# Send a private message to someone on slack
# from the command line.
# Print a usage message and exit.
usage(){
local name=$(basename "$0")
import qualified Data.Map as Map
newtype NestedMap k = NestedMap (Map.Map k (NestedMap k))
instance (Show k) => Show (NestedMap k)
where
show (NestedMap m) =
if (Map.null m)
then "{}"
else listToString
(\e -> "{ " ++ e ++ ", ")
@mjdominus
mjdominus / 1729.txt
Created May 9, 2015 23:47
Sum of cubes in exactly two ways
1729: 1 12; 9 10
4104: 2 16; 9 15
13832: 2 24; 18 20
20683: 10 27; 19 24
32832: 4 32; 18 30
39312: 2 34; 15 33
40033: 9 34; 16 33
46683: 3 36; 27 30
64232: 17 39; 26 36
65728: 12 40; 31 33
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.13.0-32-generic (buildd@kissel) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 (Ubuntu 3.13.0-32.57-generic 3.13.11.4)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.13.0-32-generic.efi.signed root=UUID=955da1a0-707a-4705-be99-02b2551d91c8 ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] e820: BIOS-provided physical RAM map:
@mjdominus
mjdominus / gist:8699632
Last active August 29, 2015 13:55
Paragraph 56
56. Ford and Aboodowieh arrange for persons employed by MWDC, whose identity is known to Ford and Aboodowieh but not known to the
plaintiff, to facilitate the exposure of the plaintiff to Petros, and to facilitate the attack on the plaintiff on March 23, 2012,
and more particularly, to arrange for the plaintiff's detention in range 1B, and to ensure that there was no supervision or
surveillance of the area where the plaintiff was assaulted.
(A followup tweet adds “MWDC is Metro West Detention Centre”.)
starting
defined giant structure
Use of uninitialized value in concatenation (.) or string at (null) line 465.
Use of uninitialized value in concatenation (.) or string at (null) line 465.
YAML Error: Error in require YAML::Dumper - Can't find 'boot___B' symbol in /vol/home/mjd/.plenv/versions/5.18.2/lib/perl5/5.18.2/x86_64-linux/auto//B/B.so
at line .
BEGIN failed--compilation aborted at (null) line 28.
Compilation failed in require at (null) line 22.
BEGIN failed--compilation aborted at (null) line 22.
Compilation failed in require at (null) line 132.
@mjdominus
mjdominus / whichperm.pl
Created November 6, 2013 21:33
Permutation-generating program
#!/usr/bin/perl
use Test::More;
# Binomial coefficients
sub choose {
my ($n, $k) = @_;
return 0 if $k > $n;
my $r = 1;