This file contains hidden or 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/python | |
| from math import floor, sqrt | |
| from random import randint | |
| import sys | |
| # given floats x and y, generate noise values from -1.0 to 1.0. | |
| # | |
| # coordinate. | |
| # based on code at: |
This file contains hidden or 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 spire.example | |
| import Predef.{any2stringadd => _, _} | |
| import spire.algebra._ | |
| import spire.implicits._ | |
| import spire.syntax._ | |
| import scala.reflect.ClassTag | |
| import scala.annotation.tailrec |
This file contains hidden or 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
| <html> | |
| <audio id="music" style="height:30px;width:300px" src="inevitable.mp3" loop="true" autoplay="true" controls="controls"> | |
| no audio | |
| </audio> | |
| </html> |
This file contains hidden or 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 spire.example | |
| import spire.implicits._ | |
| import spire.math._ | |
| import spire.syntax._ | |
| import scala.annotation.tailrec | |
| object MandelbrotDemo { | |
| /** |
This file contains hidden or 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
| import scala.annotation.tailrec | |
| object SnapToReal { | |
| def apply(n: Double, limit: Int = 10, thresh: Double = 0.00000000001): (Double, Int, Int) = { | |
| @tailrec | |
| def outer(i: Int, ex: Int, div: Int): (Double, Int, Int) = { | |
| if (i >= limit) { | |
| (n, 1, 1) | |
| } else if (div < 1) { | |
| outer(i + 1, 1, i + 1) |
This file contains hidden or 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
| d_m@vein ~ $ scala | |
| Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> val f0 = () => 999 | |
| f0: () => Int = <function0> | |
| scala> val f1 = (n: Int) => n + 123 | |
| f1: Int => Int = <function1> |
This file contains hidden or 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 angles | |
| import spire.algebra._ | |
| import scala.math.Pi | |
| object Angle { | |
| def apply(n: Double): Angle = | |
| if (n < 0.0) new Angle(n % 360.0 + 360.0) else new Angle(n % 360.0) | |
| def fromRadians(n: Double): Angle = | |
| Angle(n * 360.0 / (2.0 * Pi)) |
This file contains hidden or 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
| // fizzbuzz in 116 chars | |
| (1 to 100)map{n=>val v=Seq(3->"fizz",5->"buzz").collect{case(m,s)if n%m==0=>s}.mkString;if(v=="")n.toString else v} | |
| // less cryptic version | |
| val mods = Seq(3 -> "fizz", 5 -> "buzz") | |
| (1 to 100).map { n => | |
| val words = mods.collect { | |
| case (m, s) if n % m == 0 => s | |
| } | |
| val v = words.mkString() |
This file contains hidden or 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 spire.examples | |
| import spire.algebra._ | |
| import spire.math.{Natural, UInt} | |
| import scala.collection.mutable | |
| object SetUtil { | |
| def powerStream[A](members: Stream[A]): Stream[Set[A]] = { | |
| val done = Stream.empty[Set[A]] |
This file contains hidden or 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
| [info] benchmark us linear runtime | |
| [info] example 47.3 = | |
| [info] integers 89.2 == | |
| [info] jp10 180.6 ==== | |
| [info] jp100 1089.3 ========================= | |
| [info] jp50 585.0 ============= | |
| [info] numbers 363.8 ======== | |
| [info] twitter1 15.4 = | |
| [info] twitter10 96.8 == | |
| [info] twitter100 936.2 ===================== |