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
# run: coffee --nodejs --harmony-generators .\main.coffee <number> | |
# ref: https://en.wikipedia.org/wiki/Integer_factorization | |
primes = (max) -> | |
c = (true for [0..max]) | |
i = 1 | |
while i < max | |
# skip to next prime | |
i = i + 1 | |
while not c[i] |
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
[<StructuredFormatDisplay("C v:{v} c:{c} r:{r}")>] | |
type Cell = { v: int Set; c : int; r : int; b : int } with | |
static member create i v = | |
let (c,r) = (i%9,i/9) | |
let b = r/3*3 + c/3 | |
match v with | |
| 0 -> { v=Set.ofSeq [1..9]; c=c; r=r; b=b } | |
| v -> { v=Set.singleton v; c=c; r=r; b=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
data BTree a = Node Int a [(BTree a)] deriving Show | |
data BHeap a = Heap [BTree a] deriving Show | |
empty :: BHeap a | |
empty = Heap [] | |
link :: Ord a => BTree a -> BTree a -> BTree a | |
link t1@(Node r x1 c1) t2@(Node _ x2 c2) = | |
if x1 < x2 then |
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
using System; | |
using System.Linq; | |
using System.Collections.Immutable; | |
using System.Diagnostics; | |
using System.Collections.Generic; | |
namespace ConsoleApplication | |
{ | |
public static class MoreLinq | |
{ |
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 Data.List | |
solve xs t = nub $ map sort $ solve' xs [] t | |
where | |
solve' _ solution 0 = [solution] | |
solve' [] _ _ = [] | |
solve' (x:xs) solution t = solve' xs (x:solution) (t-x) ++ solve' xs solution t | |
test = solve [1,3,3,3,9] 10 | |
--[[3,3,3,1],[9,1]] |
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
[string]$doc = @" | |
{ | |
"parameters" : { | |
"valuename": { | |
"value": "123" | |
} | |
} | |
} | |
"@ |
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
$doc = Get-Content .\mapping.txt -raw | |
$json = $doc.ToLower() | ConvertFrom-Json | |
function calc-num-properties($o) | |
{ | |
$count = 0 | |
if ($o) | |
{ |
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
var JSONPath = require('JSONPath'); | |
const doc = require('./mapping.json'); | |
const mappings = JSONPath({json: doc, path: "$['serilog-2017.05'].mappings.*", resultType: "all" }); | |
function countProps(obj) { | |
var result = 0; | |
if (obj) { | |
Object.getOwnPropertyNames(obj).forEach(function(p) { | |
result += 1 + countProps(obj[p].properties); |
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
function mbind | |
{ | |
param( | |
[parameter(valuefrompipeline=$true)]$Ma, | |
[parameter(position=0)][scriptblock]$fMb | |
) | |
process | |
{ | |
if ($Ma) { |
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
function Merge($x, $y) | |
{ | |
$y.GetEnumerator() | % { $x[$_.Name] = $_.Value } | |
return $x | |
} | |
function Get-Settings | |
{ | |
[CmdletBinding()] |