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
//forked from https://gist.github.com/jkdeveyra/4030815 | |
def sentenceAnagrams(sentence: Sentence): List[Sentence] = { | |
def subSentence(occ: Occurrences): List[Sentence] = { | |
if (occ.isEmpty) List(List()) | |
else | |
for { | |
x <- combinations(occ) | |
y <- dictionaryByOccurrences.getOrElse(x, List()) |
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
// Inspired by Oderski's anagram and the idea that SICP count change algorithm can be used | |
// for anagram lookup and more efficiently than odersky wanted. Anagrams are however permu | |
// tated "changes" and, thus, we need an algorithm for permutation. There is none in stack | |
// overflow, at least I could not find out whether scala and other programmers provide per | |
// mutations with replacements or not whereas anagrams requre special kind of permutations | |
// It should be that "aab", "aba" and "baa" would be permutations. Note multiplicity 2 of | |
// 'a'. With replacements produces aaa since a is not exhausted by two repetitions wheras | |
// without repetitions cannot produce sequences longer than 2 since picked two items we a | |
// re out of items in the dictionary. If we put two a items in the dictionary, with/wo rep | |
// etitions will produce idential sequences, aab and aab can be produced two times. |
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
object GenericChange { | |
// Part I: generic coin change algorithm | |
// SICP count change algorithm, http://mitpress.mit.edu/sicp/full-text/sicp/book/node16.html | |
def coin_change(sum: Int, coins: List[Int]): Int = { | |
if (sum == 0) 1 else | |
if (coins.isEmpty || sum < 0) 0 else | |
coin_change(sum - coins.head, coins) + coin_change(sum, coins.tail) |
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 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 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
/** | |
* 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 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 Args (val args: Array[String]) extends Enumeration { | |
class OptVal extends Val { | |
override def toString = "-" + super.toString | |
} | |
val nopar, silent, reportSamples = new OptVal() { // boolean options | |
def apply(): Boolean = args.contains(toString) | |
} | |
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
// Rumor says that they must match. They do indeed (I believe less than 1% mistmach is because | |
// tables are not 100% complete rather than invalid input data) | |
import math.pow | |
object student_vs_anova { | |
def log(msg: String) { | |
//println(msg) | |
} //> log: (msg: String)Unit | |
def fTest(alpha: Double, var1: Double, freedoms1: Int, var2: Double, freedoms2: 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
// Indeterministic chooses all possible states, maintaining probabilities | |
// Probabilistic chooses one of possible states on every transition. | |
object Probabilistic { | |
class Machine[T : Ordering] (transitions: Map[T, Set[T]]) { // TODO: probabilistic transitions | |
def step(history: List[T]) = { | |
val p2 = transitions(history.head) | |
val picked = (Math.random() * p2.size).toInt | |
p2.toList(picked) :: history |
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
# 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 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
File deletion does not have immediate effect at least process image file, at least when | |
process was killed ungracefully prematurely. I have to retry the delete in my app. | |
Also, EVEN IF FILE DELETED, IT IS REPORTED EXISTING and complire cannot reporduce the | |
file. I have to retry the compilation also. | |
object prog_gen extends App { | |
import scala.sys.process._, scala.concurrent._, ExecutionContext.Implicits.global, Paths.get | |
implicit def toPath(filename: String) = get(filename) |
OlderNewer