Skip to content

Instantly share code, notes, and snippets.

@sheremetyev
sheremetyev / jupyter.ipynb
Last active June 16, 2019 18:59
jupyter.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sheremetyev
sheremetyev / matching.js
Created February 22, 2011 14:38
Matching problem in JavaScript
// Problem from Concurrent Programming course exercises
// Two kinds of processes Man and Woman pair off with the help of a Matcher
function random(max) {
return Math.floor(Math.random()*max);
}
function Man(name) {
setTimeout(function run() {
matcher.Man(name, function(pair) {
@sheremetyev
sheremetyev / philosophers.js
Created February 20, 2011 23:34
Dining Philosophers in JavaScript
// Dining Philosophers problem
function Phil(me, left, right) {
var run = function() {
sequential([
500, // pause
function() { console.log(me + ' sits'); },
left, // channel
function() { console.log(me + ' picked left fork'); },
500,
@sheremetyev
sheremetyev / hamming.js
Created February 20, 2011 23:33
Hamming sequence in JavaScript
// Hamming sequence http://oeis.org/A051037
// multipliers for subsequences and corresponding next element
var index = [ { mul: 2, next: 0 }, { mul: 3, next: 0 }, { mul: 5, next: 0 } ];
var queue = [];
function next() {
// special case for the seed of the sequence
if (queue.length == 0) {
@sheremetyev
sheremetyev / parallel.go
Created February 14, 2011 00:40
Parallel execution in Go
package main
import fmt "fmt"
import runtime "runtime"
func parallel(f ... func()) {
c := make(chan int, len(f))
for i := 0; i < len(f); i++ {
f := f[i]
go func() {