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
const log = console.log ; const assert = console.assert | |
//Object.prototype.trace = function(format) {format = format || (data => data); log(format(this)); return this} // prints something wrong | |
const trace = (data, format) => {format = format || (data => data); log(format(data)); return data} | |
const tracejs = (ms, data) => trace(data, data => [ms, data.json()]) | |
function range (len, begin) {begin = begin || 0 | |
return Array.apply(null, Array(len)).map((_, i) => {return begin+i;})} | |
//Array.prototype.fill = function(filler) {return this.map(_ => filler)} // startard func | |
Array.prototype.equals = function(that) {return this.every((my, i) => my == that[i] )} ; [1,2].equals([1,2]) | |
Array.prototype.sum = function() {return this.reduce((acc, el) => acc + el,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
package forcomp | |
object SicpAnagrams { | |
// Inplementing Odersky anagrams (FP Scala coursera) using SICP algorithm, http://mitpress.mit.edu/sicp/full-text/sicp/book/node16.html | |
// PART I: SICP count change algorithm | |
// Odersky recomends SICP book as the course resource material. Before taking the course, | |
// I studied it. Might be for this reason, I realized that the anagram assignment is the |
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
// task and parallel definition can be found at https://www.coursera.org/learn/parprog1/discussions/weeks/1/threads/2gsI2DHVEeaKAhJC1hWxEQ/replies/-avxXTIBEeabvwrOSKMg4w/comments/O5yTH3K6EeeM7BK4-ybiDA | |
/** Computes the blurred RGBA value of a single pixel of the input image. */ | |
def boxBlurKernel(src: Img, x: Int, y: Int, radius: Int): RGBA = { | |
val xMin = clamp(x-radius, 0, src.width-1) | |
val xMax = clamp(x+radius, 0, src.width-1) | |
val yMin = clamp(y-radius, 0, src.height-1) | |
val yMax = clamp(y+radius, 0, src.height-1) | |
var (i,j,n) = (xMin, yMin, 0.0) | |
var r,g,b,a = 0.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
import Vhdl._ | |
// TODO: CharLiteral -> Char, StringLiteral -> String to save memory | |
object AllTests extends App { | |
def recover[T](okMsg: String/*, shouldRecover: T => Boolean = _ => true*/): ParseResult[T] => ParseResult[_] = pr => pr match { | |
case f @ Failure(msg, rem) => Success(okMsg, rem) //if (shouldRecover(msg)) Success(okMsg, rem) else f | |
case e @ Error(msg, rem) => println("Recovering error " + msg); Success(okMsg, rem) //if (shouldRecover(msg)) Success(okMsg, rem) else f | |
case s @ Success(msg, rem) => Failure(s"we had to fail because $okMsg but succeeded with " + msg, rem); case a => a | |
} |
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.lang.reflect.{Method, InvocationHandler, Proxy} | |
import scala.language.reflectiveCalls, scala.language.postfixOps | |
import scala.collection.mutable, java.io._, Util._ | |
// I called this version "reduced" because proxies are not GC-ed when not referenced by user | |
// This makes a code a bit simpler and, probably, even faster if proxies are small indeed. | |
// The experiment | |
// timeit "scala -J-Xmx33m ProxyDemo + 16 100 > nul" | |
// however suggests that this implementation is slow as 144 sec vs 129 sec for managed proxies. |
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
# There were multiple goals: to implement AI for my game, to inject bugs ino VHDL and prove that sexual demorphims | |
# where boys have much higher mutation rate ' Сперматозоидов у мужчины за всю его жизнь вырабатывается гораздо больше, чем яйцеклеток у женщины. Это значит, что предшественники мужских половых клеток делятся гораздо интенсивнее и, следовательно, у них больше риск возникновения мутаций.' | |
#, is advantageous. | |
# Inspired by http://eli.thegreenplace.net/2010/01/28/generating-random-sentences-from-a-context-free-grammar | |
from collections import defaultdict | |
import random | |
def weighted_choice(weights): | |
rnd = random.random() * sum(weights) |
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
/** | |
* Assignment 4: Huffman coding | |
* | |
*/ | |
object Huffman1 { | |
abstract class CodeTree | |
case class Fork(left: CodeTree, right: CodeTree, chars: List[Char], weight: Int) extends CodeTree | |
case class Leaf(char: Char, weight: Int) extends CodeTree |
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
<script id="library" title="it must be a part of starndard javascript"> | |
const log = console.log ; const assert = console.assert | |
update = (o, mutator) => {mutator(o); return o} | |
trace = (value, format) => {format = format || (data => data) ; log(format(value)); return value}; | |
tracejs = (msg, data) => trace(data, data => [msg, data.json()]) | |
Object.prototype.trace = function(format) {trace(this, format)} | |
function range (len, begin) {begin = begin || 0 |
OlderNewer