Skip to content

Instantly share code, notes, and snippets.

@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
// 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)
}
#!/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" +
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 =
object Euler18 extends App {
val s =
"""|75
|95 64
|17 47 82
|18 35 87 10
|20 04 82 47 65
|19 01 23 75 03 34
|88 02 77 73 07 63 67
scala> (1 until 1000).filter{n => n % 5 == 0 || n % 3 == 0}.sum
res0: Int = 233168
@dholbrook
dholbrook / Euler54.scala
Created November 29, 2012 04:31
euler 54
package euler
import scala.annotation.tailrec
object Euler54 extends App {
sealed abstract class CardRank extends Ordered[CardRank] {
import CardRank._
private def toInt(r: CardRank): Int = r match {