This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package euler | |
object Euler8 extends App { | |
val digits = | |
"""73167176531330624919225119674426574742355349194934 | |
|96983520312774506326239578318016984801869478851843 | |
|85861560789112949495459501737958331952853208805511 | |
|12540698747158523863050715693290963295227443043557 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> (1 until 1000).filter{n => n % 5 == 0 || n % 3 == 0}.sum | |
res0: Int = 233168 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
NewerOlder