Skip to content

Instantly share code, notes, and snippets.

@dholbrook
dholbrook / Tree.scala
Created June 21, 2012 17:59
Scala binary tree
/**
* D Holbrook
*
* Code Club: PO1
*
* (*) Define a binary tree data structure and related fundamental operations.
*
* Use whichever language features are the best fit (this will depend on the language you have selected). The following operations should be supported:
*
* Constructors
@dholbrook
dholbrook / SleepingBarber.scala
Created October 12, 2011 03:03
Sleeping Barber Problem, Akka actor implementation
import java.lang.Thread
import scala.collection.mutable.Queue
import akka.actor.Uuid
import akka.actor.scala2ActorRef
import akka.actor.Actor
import akka.event.EventHandler
/*
* Sleeping Barber Code Club Problem
* See (http://en.wikipedia.org/wiki/Sleeping_barber_problem)
@dholbrook
dholbrook / Euler Problem 5
Created May 18, 2017 17:42 — forked from anonymous/playground.rs
Rust code shared from the playground
extern crate num_integer;
use num_integer::Integer;
// run at http://play.integer32.com/?gist=6e4b93f907407f67704430e60f771e1f&version=undefined
fn main() {
let e5 = euler5();
assert_eq!(e5, 232792560);
println!("Euler5 {}", e5);
}
@dholbrook
dholbrook / .bash_profile
Created January 21, 2017 18:24
.bash_profile
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\n\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
alias ls='ls -GFh'
package euler
object Euler8 extends App {
val digits =
"""73167176531330624919225119674426574742355349194934
|96983520312774506326239578318016984801869478851843
|85861560789112949495459501737958331952853208805511
|12540698747158523863050715693290963295227443043557
package euler
object Euler21 extends App {
def properDivisors(n: Int): Seq[Int] =
(1 to n / 2).filter(n % _ == 0)
val dn = for {n <- 0 until 10000} yield properDivisors(n).sum
private def isAmicable(n: Int, i: Int): Boolean =
// Fibonacci from http://rustbyexample.com/trait/iter.html
struct Fibonacci {
curr: u32,
next: u32,
}
impl Iterator for Fibonacci {
type Item = u32;
fn next(&mut self) -> Option<u32> {
fn euler1() -> u32 {
// using fold() instead of sum() because of iter_arith stability
// "use of unstable library feature 'iter_arith': bounds recently changed (see issue #27739)"
(1..1000)
.filter(|n| n % 5 == 0 || n % 3 == 0)
.fold(0, |acc, n| acc + n)
}
@dholbrook
dholbrook / sudoku.scala
Created September 4, 2012 15:38
brute force Sudoku solver
/**
* D Holbrook
*
* Code Club: Sudoku solver
*
* Brute force solver
*/
object Sudoku extends App {
val valid = Range(1, 10)
#!/usr/bin/env node
const s = "75\n" +
"95 64\n" +
"17 47 82\n" +
"18 35 87 10\n" +
"20 04 82 47 65\n" +
"19 01 23 75 03 34\n" +
"88 02 77 73 07 63 67\n" +
"99 65 04 28 06 16 70 92\n" +