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
/* | |
* Author: Abhinav Sarkar <[email protected]> | |
* License: MPL 1.1 | |
* | |
* Provides an ubiquity command: "lyrics", to find the lyrics for a song. | |
* Usage: Type the song in the form "Song <by> Artist". Provides suggestions as you type. | |
* Uses lyricwiki.org API for fetching lyrics and last.fm webservices API for | |
* providing suggestions. | |
*/ |
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 net.abhinavsarkar.util; | |
/** | |
* A (infinite) Fibonacci number generator. | |
* | |
* @author Abhinav Sarkar | |
*/ | |
public class Fibonacci extends Generator<Integer> { | |
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 net.abhinavsarkar.util; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.net.URLStreamHandler; |
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
import Stream.cons | |
import java.io.{BufferedWriter, PrintWriter} | |
import Console.{readInt, readLine} | |
import Math.{sqrt, ceil} | |
import scala.collection.mutable.{HashMap => MHashMap} | |
/* | |
My solution to SPOJ problem PRIME1 (https://www.spoj.pl/problems/PRIME1/) in Scala. | |
Unfortunately it takes more time than expected and hence fails in SPOJ submission. | |
*/ |
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
import annotation.tailrec | |
import collection.immutable.List | |
import collection.immutable.Stream.{Empty,Cons} | |
object EvaluatedStream { | |
def evaluatedItems[T](stream: => Stream[T]): List[T] = { | |
@tailrec | |
def inner(s: => Stream[T], acc: List[T]): List[T] = s match { | |
case Empty => acc |
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
import collection.immutable.HashMap | |
import Stream.cons | |
import java.io.{BufferedWriter, PrintWriter} | |
import Console.{readInt, readLine} | |
import Math.{sqrt, ceil} | |
import concurrent.ops.future | |
import concurrent.FutureTaskRunner | |
import actors.scheduler.ExecutorScheduler | |
import java.util.concurrent.Executors.newFixedThreadPool | |
import java.util.concurrent.CountDownLatch |
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
import java.util.concurrent.atomic.AtomicLong | |
import java.util.concurrent.locks.ReentrantLock | |
import collection.immutable.HashMap | |
import Stream.cons | |
import java.io.{BufferedWriter, PrintWriter} | |
import Console.{readInt, readLine} | |
import Math.{sqrt, ceil} | |
import actors.Actor | |
import collection.mutable.ListBuffer |
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
/* Solution to SPOJ problem "Complete the Sequence!" | |
* (https://www.spoj.pl/problems/CMPLS/) in Scala. Written in Scala 2.8. | |
*/ | |
object SpojCmpls { | |
def main(args: Array[String]) { | |
val noOfTestCases: Int = readInt | |
1 to noOfTestCases foreach { i => | |
val input = readLine.trim.split(" ").map { _ toInt } | |
val s = input(0) |
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
(defn capitalize [#^String s] | |
"capitalizes String s" | |
(if (and s (not (zero? (count s)))) | |
(apply str (conj (rest s) (Character/toUpperCase (.charAt s 0)))) | |
s)) | |
(defn trim [s] | |
"trims leading and trailing whitespace in the String s" | |
(let [trim-leading | |
(fn [s] |
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
(ns net.abhinavsarkar | |
(:use | |
[clojure.contrib.math :only (sqrt ceil)] | |
[clojure.contrib.import-static])) | |
(import-static java.lang.Integer parseInt) | |
(declare primes) | |
(defn- divisible? [x y] (zero? (mod x y))) |
OlderNewer