Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View eduardoleon's full-sized avatar

eduardoleon

View GitHub Profile
#include <stdio.h>
struct node {
int value;
struct node *next;
};
void uniquify_head(struct node *head)
{
struct node *node = head;
@eduardoleon
eduardoleon / .Renviron
Created August 10, 2019 18:27
R dotfiles
R_LIBS=~/programs/rpkg
@eduardoleon
eduardoleon / tree.sml
Created April 22, 2019 03:17
Reversing binary trees.
signature TREE =
sig
type 'a tree
type 'a many
datatype 'a split = Pure of 'a | Many of 'a tree many
val pure : 'a -> 'a tree
val many : 'a tree many -> 'a tree
val rev : 'a tree -> 'a tree
<stevie> Hi, I am having trouble with this statistics problem:
http://dpaste.com/267R2R4 - Would anyone be able to help push me in
the right direction? [18:37]
<indomitable> stevie, I'm going to recommend reading two chapters in secondary
school statistics [18:38]
<indomitable> This is basic stuff
<unyu> indomitable: All the more reason for you to help him. Do you want to be
asked hard questions?
<unyu> stevie: Let's work with one bolt at a time, and only then figure out
how to combine the information from all 25 bolts. [18:44]
@eduardoleon
eduardoleon / iso.sml
Last active February 17, 2019 23:02
Binary trees are isomorphic to forests of rose trees
datatype bin = Leaf | Node of bin * bin
datatype rose = T of rose list
fun forth Leaf = nil
| forth (Node (a, b)) = T (forth a) :: forth b
fun back nil = Leaf
| back (T a :: b) = Node (back a, back b)
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
@eduardoleon
eduardoleon / reader-writer.pml
Last active November 26, 2018 15:06
Readers-Writers solution, writers have preference
#define NRDRS 5
#define NWRTS 2
#define MAXRDRS 100
#define MAXRDRQ 20
#define MAXWRRQ 20
chan readrequest = [MAXRDRQ] of { chan }
chan writerequest = [MAXWRRQ] of { chan }
chan finished = [MAXRDRQ+MAXWRRQ] of { mtype }
@eduardoleon
eduardoleon / santa.pml
Last active October 14, 2018 15:07
Santa Claus problem (TLBoS, 5.5.2)
#include "semaphore.hdr"
#define NR 9
#define NE 3
#define TE 10
Semaphore ss, rs, es1, es2, mut
byte rc = NR, ec = NE
proctype Reindeer(byte id) {
@eduardoleon
eduardoleon / dancers.pml
Last active October 7, 2018 16:10
Dancers (TLBoS, 3.8)
#define pairs 5
#include "semaphore.h"
mtype = { male, female }
Semaphore mutex, convo1, convo2
Semaphore queue[3]
byte count[3]
inline male_dance() {
@eduardoleon
eduardoleon / bridge.pml
Created September 1, 2018 04:26
Promela model for the problem about people crossing a bridge or a river or whatever
mtype = { left, right }
inline shift(source, target) {
/* select who goes */
if
:: side[0] == source -> pick = 0
:: side[1] == source -> pick = 1
:: side[2] == source -> pick = 2
:: side[3] == source -> pick = 3
fi