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
class HashTable { | |
private int capacity | |
private LinkedList<Node>[] buckets | |
HashTable() { | |
this(10) | |
} | |
HashTable(capacity) { |
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
class MaxTriangleWeight { | |
static def main(args) { | |
println(new MaxTriangleWeight().getTriangle(args[0]).maxWeight) | |
} | |
private def getTriangle(fileName) { | |
def reader = new BufferedReader(new FileReader(fileName)) | |
def triangle = new Triangle(reader.readLine()) | |
def row | |
while ((row = reader.readLine()) != null) { |
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 jj.async | |
import scala.concurrent.{ ExecutionContext, Future, Await } | |
import java.util.concurrent.Executors.newCachedThreadPool | |
import rx.lang.scala.Observable | |
import jj.async.Helpers._ | |
import scala.concurrent.duration._ | |
import jj.async.Enriched._ | |
/* Problem: How to optimize multi-process records asynchronously in chunks. |
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 jj.async | |
import scala.concurrent.{ ExecutionContext, Future } | |
import java.util.concurrent.Executors.newCachedThreadPool | |
import rx.lang.scala.Observable | |
import ExecutionContext.Implicits.global | |
import jj.async.helpers._ | |
/* Problem: How to multi-process records asynchronously in chunks. | |
Processing steps: |
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 util.Random.nextInt | |
/** | |
Dice | |
Write a program that simulates throwing two six-sided dice 200 times, and creates a histogram of the results, like this: | |
2: XXXX | |
3: XXXXXXXXXX | |
4: XXXXXXXXXXXXXXXXXXXXXX | |
5: XXXXXXXXXXXXXXXXXXXXX |
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.util.Random.nextInt | |
/** | |
Simulate throwing two six-sided dice 200 times and create a histogram of the results like this: | |
2: XXXX | |
3: XXXXXXXXXX | |
4: XXXXXXXXXXXXXXXXXXXXXX | |
5: XXXXXXXXXXXXXXXXXXXXX | |
6: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
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 jj.musicshareroomapp.msr | |
import scala.concurrent | |
import concurrent.{ Future, Promise, ExecutionContext } | |
import ExecutionContext.Implicits.global | |
import Future.firstCompletedOf | |
import concurrent.duration._ | |
import scala.util.{ Success, Failure } | |
import scala.collection | |
import collection.parallel |
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 median(data): | |
return sorted(data)[len(data)/2] |
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 mode(data): | |
def loop(i, counts, c_max): | |
max_val = c_max[0] | |
if (i < 0): | |
return max_val | |
else: | |
c_val = data[i] | |
new_count = counts.get(c_val, 0) + 1 | |
counts[c_val] = new_count | |
max_dup = c_max[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
def variance(data): | |
n = len(data) | |
sums = reduce(lambda acc, x: (acc[0] + x, acc[1] + x**2), data, (0, 0)) | |
return sums[1] / n - sums[0]**2 / n**2 |
OlderNewer