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
| import java.util.Collections; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.function.LongPredicate; | |
| import java.util.function.LongSupplier; | |
| import java.util.stream.LongStream; | |
| /** | |
| * Primes generator. | |
| */ |
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
| datatype 'a stream = Empty | Cons of 'a * (unit -> 'a stream) | |
| fun from n = Cons(n, fn () => from(n +1)) | |
| val naturals = from(1) | |
| fun filter f xs = | |
| case xs of | |
| Empty => Empty | |
| | Cons(h,t) => if f(h) | |
| then Cons(h, fn () => filter f (t())) |
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
| public static <T> Stream<T> concatenate(Stream<T>... streams) { | |
| return Stream.of(streams).reduce(Stream.empty(), Stream::concat); | |
| } | |
| public static void main(String[] args) { | |
| Stream<? extends CharSequence> res = concatenate( | |
| Stream.of("One"), | |
| Stream.of(new StringBuffer("Two")), | |
| Stream.of(new StringBuilder("Three")) |
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
| [ | |
| { "keys": ["home"], "command": "move_to", "args": {"to": "bol"} }, | |
| { "keys": ["end"], "command": "move_to", "args": {"to": "eol"} }, | |
| { "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} }, | |
| { "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } }, | |
| { "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof"} }, | |
| { "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof"} }, | |
| { "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true} }, | |
| { "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} }, | |
| ] |
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
| (function(){ | |
| var index = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', | |
| 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', | |
| '0','1','2','3','4','5','6','7','8','9','+','/','=']; | |
| var octets = ["","0","00","000","0000","00000","000000","0000000"]; | |
| var sixths = ["","00000","0000","000","00","0"]; | |
| var paddings = [[],[],[64,64],[],[64]]; |
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
| function brainfuck(code,input){ | |
| var pc = 0; | |
| var sysout = []; | |
| var sysin = input.split('').reverse(); | |
| var ptr = 0; | |
| var data = [0]; | |
| var size = code.length; | |
| var program = code.split('') | |
| var loops = []; |
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
| var interpret = (function(){ | |
| var stack = []; | |
| var sysout = []; | |
| var dir = '>' | |
| var strmode = false; | |
| var skipmode = false; | |
| var pc = {row:0,col:0}; | |
| var program = []; |
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
| function pascal(depth){ | |
| var value = function(col,row){ return (col===1 || row===1 || col===row) ? 1 : value(col-1, row-1) + value(col, row-1); } | |
| return Array.apply(null, {length: depth}) | |
| .map(function(u,row,self){ return Array.apply(null,{length:row+1}).map(function(u,col,self){ return value(col+1,row+1)}); }); | |
| } |
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
| function Value(value){ | |
| this.value = value || 0; | |
| } | |
| Value.prototype.eval = function(){ return this; }; | |
| Value.prototype.valueOf = function(){ return this.value.valueOf(); }; | |
| Value.prototype.toString = function(){ return this.value.toString(); }; | |
| var createOperator = function(){ | |
| function reduce(oper){ |
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
| asDecimal = function(){ | |
| var romans = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000 }; | |
| return function(roman){ | |
| return roman.split('').map(function(r){ return romans[r];}) | |
| .reduce(function(res,n,i,digits){ | |
| var prev = i > 0 ? digits[i-1] : 0; | |
| return prev < n ? res + n - 2 * prev : res + n; | |
| },0); | |
| }; | |
| }(); |