Click on a position on the image panel, then click the Zoom In button
This will not work in Safari
// problem 1 var one = (3 until 1000 by 3 sum) + (5 until 1000 by 5 sum) - (15 until 1000 by 15 sum) // or better yet var two = (3 until 1000 filter (x => x % 3 == 0 || x % 5 == 0) sum)
val limit = 4000000 val fibs: Stream[Int] = 1 #:: fibs.scanLeft(1)(_ + _) val result = fibs takeWhile(_ <= limit) filter(_ % 2 == 0) sum
var maxPalindrom = (for ( i <- (100 until 999 reverse); j <- (100 until 999 reverse) if (i * j).toString() == (i * j).toString().reverse ) yield (i * j)) max
val l = 20 val d = 2 to l var result = l while(d.takeWhile(result % _ == 0).length != d.length) { result += l } println(result)
val sosq = 1 to limit map(x => x * x) sum val temp = 1 to limit sum val sqos = temp * temp val result = sqos - sosq println(result)
import java.awt.image.BufferedImage import java.awt.Color import java.awt.Dimension import java.awt.Graphics2D import scala.swing.MainFrame import scala.swing.Panel import scala.swing.SimpleSwingApplication object Mandelbrot extends SimpleSwingApplication { val ER = 4.0 // escape radius val maxIter = 50000 // max iteration val N = 1000 // image dimension def top = new MainFrame { title = "Mandelbrot Set" contents = new Panel { override protected def paintComponent(g: Graphics2D) = { super.paintComponent(g) var start = System.currentTimeMillis() g setColor Color.BLACK var image = new BufferedImage(N, N, BufferedImage.TYPE_INT_RGB) var m = new Mandelbrot(N, ER, maxIter, 1) for { i <- 0 until N j <- 0 until N } image.setRGB(i, j, m.pms(i * N + j)) g.drawImage(image, 0, 0, null) println(System.currentTimeMillis() - start) } } size = new Dimension(N, N) } } class Mandelbrot(n: Int, er: Double, maxIter: Int, zoom: Int) { val pms = (0 to n * n).map { (x => computeColor(x / n, x % n)) } // work gets done here def computeColor(x: Int, y: Int): Int = { var (i, zx, zy) = (0, 0.0, 0.0) val cx = -2.5 + x * (er / n) / zoom val cy = 2 - y * (er / n) / zoom while (zx * zx + zy * zy < er && i < maxIter) { val temp = zx * zx - zy * zy + cx zy = 2 * zx * zy + cy; zx = temp; i = i + 1; } if (i == maxIter) Color.BLACK.getRGB() else (Color.getHSBColor(i / 20.0F, 1F, 1F)).getRGB() } }
// Before val pms = (0 to n * n).map { (x => computeColor(x / n, x % n)) } // work gets done here // After val pms = (0 to n * n).par.map { (x => computeColor(x / n, x % n)) } // work gets done here // notice the extra method call par after the list
// Scala interpreter // So start with case 4, all the way up to case 1000 // Count any case that has either 8 or 3 as remainder when divided by 9 scala> 4 to 1000 count {x => (x % 9 == 8) || (x % 9 == 3)}