Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
class DiningPhilosophers {
public static void main(String[] args) {
Fork[] forks = new Fork[5];
for (int i=0; i<forks.length; i++) {
forks[i] = new Fork();
}
Philosopher p1 = new Philosopher(1,forks[0],forks[1]);
Philosopher p2 = new Philosopher(2,forks[1],forks[2]);
Philosopher p3 = new Philosopher(3,forks[2],forks[3]);
; don't show the tool bar, should use keyboard anyway
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
; auctex stuff for latex editing
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
; auto-fill (linewrap) on by default
(setq-default auto-fill-function 'do-auto-fill)
<?php
//based on http://lists.w3.org/Archives/Public/www-validator/2007Jul/0208.html
$mime = 'text/html'; //fallback
// set xhtml mimetype if browser claims it accepts it:
if(!empty($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')) {
$mime = 'application/xhtml+xml';
}
// or if it is the validator:
if (stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") OR stristr($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") OR
stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")) {
(* church booleans *)
fun True x y = x;
fun False x y = y;
(*conditionals*)
fun If b x y = b x y;
fun Or b1 b2 x y = b1 x (b2 x y);
fun Xor b1 b2 x y = b1 (b2 y x) (b2 x y);
fun And b1 b2 x y = b1 (b2 x y) y;
fun Nand b1 b2 x y = b1 (b2 y x) x;
#!/usr/bin/python3
def generate_solutions(letters, digits):
if len(letters) == 6:
if is_solution(letters):
print("solution",letters)
return
else:
for i in digits:
remaining_digits = digits[:]
(* write an ML function such that Move(3,"A","B","C") solves the hanoi puzzle*)
load "Int";
fun Move(1,start,other,finish) = ["move 1 from " ^ start ^ " to " ^ finish]
| Move (x,start,other,finish) =
Move(x-1,start,finish,other)@
["move " ^ (Int.toString x) ^ " from " ^ start ^ " to " ^ finish]@
Move(x-1,other,start,finish);
P01 (*) Find the last box of a list.
Example:
* (my-last '(a b c d))
(D)
P02 (*) Find the last but one box of a list.
Example:
* (my-but-last '(a b c d))
(C D)
@Wilfred
Wilfred / Hangman.py
Created June 9, 2009 21:54
Text mode hangman game
#!/usr/bin/python3
# Hangman game
# Copyright (c) 2009, Wilfred Hughes
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
#include <stdio.h>
int main(void) {
int i, total=0;
for (i=0; i<1000; i++) {
if (i % 3 == 0 || i % 5 == 0) {
total += i;
}
}
printf("Total is %d\n",total);