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
| public class AreYouDone { | |
| private boolean done = false; | |
| public void done() { | |
| done = true; | |
| } | |
| public boolean isDone() { | |
| return done; | |
| } |
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
| // better use of lazy eval with Stream. | |
| // please refer to http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Stream for details | |
| lazy val fib: Stream[Int] = Stream.cons(0, Stream.cons(1, fib.zip(fib.tail).map(p => p._1 + p._2))) | |
| implicit def iterableWithSum(it: Iterable[Int]) = new { def sum = it.foldLeft(0)(_ + _) } | |
| fib.filter( _ % 2 == 0).takeWhile(_ < 4000000).sum | |
| /* | |
| The following implementation provides a more "cost effective" implementation due to the fact that |
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
| /** | |
| * | |
| * @author Lim, Teck Hooi | |
| * | |
| * <br/><br/>30/01/2013 10:19 AM | |
| * | |
| */ | |
| object MapReduce { | |
| def mapReduce(f : Int => Int, combine : (Int, Int) => Int, zero : Int)(a:Int, b: Int) : Int = |
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
| def minmax(values : Array[Int]) : (Int, Int) = { | |
| def minmax_(values : Array[Int], n : (Int, Int)) : (Int, Int)= { | |
| if (values.isEmpty) n | |
| else { | |
| values.head match { | |
| case x if x < n._1 => minmax_(values.tail, (x, n._2)) | |
| case x if x > n._2 => minmax_(values.tail, (n._1, x)) | |
| case _ => minmax_(values.tail, n) | |
| } | |
| } |
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 org.thlim; | |
| import java.math.BigDecimal; | |
| /** | |
| * | |
| * | |
| * @author Lim, Teck Hooi | |
| * | |
| */ |
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 akka.actor._ | |
| import akka.pattern.ask | |
| import akka.util.Timeout | |
| import scala.concurrent.forkjoin.ForkJoinPool | |
| import scala.concurrent.{Future, ExecutionContext, Await} | |
| import scala.concurrent.duration._ | |
| import scala.util.Random | |
| /** | |
| * |
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 com.hp.hpls.monsoon.servicecat.service.impl; | |
| import java.math.BigInteger; | |
| /** | |
| * | |
| * @author Lim, Teck Hooi | |
| * | |
| * | |
| */ |
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 org.teckhooi; | |
| import java.util.*; | |
| /** | |
| * @author Lim, Teck Hooi | |
| */ | |
| public class Permutations { | |
| public static void main(String[] args) { | |
| List<Integer> series = Arrays.asList(new Integer[] {1, 0, 0, 5, 2, 0, 3, 0, 0}); |
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 org.teckhooi.generics; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| /** | |
| * java -ea to enable assert otherwise AssertionError will not be thrown with | |
| * false assertion. | |
| * | |
| * To compile, |
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 java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.Random; | |
| import java.util.concurrent.Callable; | |
| import java.util.concurrent.ExecutorService; | |
| import java.util.concurrent.Executors; | |
| import java.util.concurrent.Future; | |
| /** | |
| * |
OlderNewer