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
# initial value of sum := 0 | |
sumItUp := method(reduce(sum, nextList, sum + nextList reduce(+), 0)) | |
testList := list(list(1,2,34,5,3),list(1,23,412,32), list(2,3,4)) | |
testList sumItUp |
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
fibRecursive := method(num, | |
if(num<=2, 1, fibRecursive(num-1) + fibRecursive(num-2),0) | |
) | |
Range 1 to(10) foreach(v, fibRecursive(v) println) |
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
Number $ ::= Number getSlot("/") # saving the original operator as it's a CFunction | |
OperatorTable addOperator("$",2) # adding it to the OperatorTable, so we can use it in the new definition of / | |
Number / := method( b, if (b == 0, 0, self$b)) # redefining the Number / slot |
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 org.lscc.minfinder; | |
import org.lscc.parallelpatterns.divideandconquer.DivideAndConquer; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
public class MinValueFinder extends DivideAndConquer<MinValueFinderProblem, 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 org.lscc.minfinder; | |
public class MinValueFinder { | |
private Function<Integer, Integer> f; | |
public MinValueFinder(Function<Integer, Integer> function) { | |
this.f = function; | |
} |
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 org.lscc.minfinder; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.concurrent.*; | |
public class MinValueFinder { | |
private Function<Integer, Integer> f; | |
private ExecutorService executorService = Executors.newCachedThreadPool(); |
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 org.lscc.minfinder; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.concurrent.*; | |
public class MinValueFinder { | |
private Function<Integer, Integer> f; |
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 com.balopat.qc; | |
import org.scalatest.FlatSpec | |
import org.scalatest.matchers.ShouldMatchers | |
import ComplexNumberRectangular._ | |
class ComplexNumberSpec extends FlatSpec with ShouldMatchers { | |
"A Complex Number" should | |
"add to another Complex Number by components" in { |
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 com.balopat.qc | |
case class ComplexNumberRectangular(im: Int, r: Int) { | |
def i() = this | |
def +(b: ComplexNumberRectangular) = ComplexNumberRectangular(im + b.im, r + b.r) | |
def +(b: Int) = ComplexNumberRectangular(im, r + b) |
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 com.balopat.timeinjection | |
import java.util.Date | |
class Wall { | |
var messages = List[Message]() | |
def message(message: String) { | |
messages ::= Message(message, new Date()) // hardcoded dependency on time!!! | |
} |
OlderNewer