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
-- Json parser written in haskell | |
-- Credit: https://www.youtube.com/watch?v=N9RUqGYuGfw | |
{-# Language OverloadedStrings #-} | |
{-# LANGUAGE ViewPatterns #-} | |
module Parser ( | |
JValue(..) | |
,parseJson | |
,ParseResult | |
,Parse |
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
def ?(r: Int, ops: Seq[Char], nums: Seq[Int]):Int=if(ops.isEmpty)r else ?(ops.head match{case '+' => r+nums.head; case '-' => r-nums.head}, ops.tail, nums.tail); (1 to 9).map{i=>"123456789".grouped(i).toList}.map{_.map{_.toInt}}match{ case l => l.zip((1 to l.length).permutations.toList.map{_.map{i => if(i%2 == 0) '+' else '-'})}.map{x=> (?(0, x._1, x._2), x)}}.filter(_ != 100) |
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
class A{ | |
public: | |
A():v(0){} | |
A* incr(){ | |
v++; | |
return this; | |
} | |
private: | |
int v; | |
}; |
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
def I(s): | |
val = 0 | |
for i in range(len(s)): | |
digit = ord(s[len(s) - i - 1]) | |
val <<= 8 | |
val |= digit | |
return val | |
def Sn(i, length): | |
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
//g++ db.cpp -o db.exe 2>&1 | more | |
#include<algorithm> | |
#include <string> | |
#include <vector> | |
#include<iostream> | |
#include <typeinfo> | |
#include <map> | |
using namespace std; |
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
//simple algorithm to calculate entropy of a file in Scala | |
package zw.trevor.disorder | |
class Entropy(bytes: Seq[Byte]){ | |
val max_bytes = 256 | |
def log2(n: Double) = math.log(n)/math.log(2) | |
lazy val token_freqs = { | |
var freqs: Array[Int] = (0 until max_bytes).map{x=>0}.toArray | |
bytes.map{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
//Lucky numbers challenge | |
//http://codegolf.stackexchange.com/questions/94695/unlucky-numbers | |
case class LuckyNumbers(val n: Double, seq: Seq[Double] ) | |
case class Test(val m: Int, val n: Int, val expected: Double) | |
object LuckyNumbers{ | |
def natural_numbers(max: Double) = { | |
def next(n: Double, seq: Seq[Double]): Seq[Double] = if(n >= max) seq ++ Seq(n) else next(n+1, seq ++ Seq(n) ) | |
next(1, Seq()) | |
} |
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
//http://codegolf.stackexchange.com/questions/94679/find-the-odd-one-out-in-a-sequence | |
import math._ | |
object OddOneOut{ | |
case class Test(val l: Seq[Double],val expected: Double){ | |
def apply( _l: Seq[Double], _e: Double ) = new Test( _l, _e ) | |
} | |
def log2(x: Double) = math.log(x)/math.log(2) |
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
//Simple DNA encoder | |
//http://codegolf.stackexchange.com/questions/91645/dna-encode-a-string/91850 | |
import java.io.{ByteArrayOutputStream, ByteArrayInputStream} | |
import java.util.Base64 | |
import java.util.zip.{GZIPOutputStream, GZIPInputStream} | |
import scala.util.Try | |
object Nucleotide{ | |
abstract class Nucleotide(val symbol: String){ |
NewerOlder