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
#include <stdio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
#define LAMBDA(RETURN_TYPE, BODY) ({ RETURN_TYPE __fn__ BODY __fn__; }) | |
#define __NARG__(...) __NARG_I_(__VA_ARGS__,__RSEQ_N()) | |
#define __NARG_I_(...) __ARG_N(__VA_ARGS__) | |
#define __ARG_N( \ | |
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ |
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
#include <iostream> | |
#include <sstream> | |
#include <fstream> | |
static int board[9][9], moves[9][9]; | |
static bool solved = false; | |
static int get_candidates(int x, int y) { | |
int mask = 0; | |
for (int i = 0; i < 9; 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
var readline = require('readline'); | |
LOG = console.log.bind(console); | |
var NUMBER = /([0-9]+\.[0-9]*|\.[0-9]+|[0-9]+)(e[-+]?[0-9]+)?/; | |
function Operator(associativity, precidence) { | |
this.asso = associativity; | |
this.prec = precidence; | |
} |
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
from gmpy2 import mpz, get_context | |
# 19 loops maxes out 64-bit floating point number | |
# ~~ 2.718281828459045 == math.e ~~ | |
def E(prec=19): | |
num, den = 0, 1 | |
for i in range(1, prec): | |
# add fraction keeping GCD | |
# allows for greater precision | |
num = (num + 1) * 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
from math import factorial | |
from gmpy2 import mpz, mpq, get_context | |
def pi(iterations): | |
result = mpq() | |
for k in range(iterations): | |
num = mpz(factorial(6*k)*(13591409+545140134*k)) | |
den = mpz(factorial(3*k)*factorial(k)**3*(-640320)**(3*k)) | |
result += mpq(num, den) |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Monte Carlo Pi Approximation</title> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<style> | |
html, body { | |
font-family: Helvetica, 'Helvetica Neue', Neue, sans-serif, Arial; |
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
#include <array> | |
template <typename T, int L, int ...R> | |
struct MultiArray : public std::array<typename MultiArray<T, R...>::type, L> { | |
using type = std::array<typename MultiArray<T, R...>::type, L>; | |
MultiArray() : std::array<typename MultiArray<T, R...>::type, L>() {} | |
}; | |
template <typename T, int L> | |
struct MultiArray<T, L> : public std::array<T, L> { |
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 translate(text, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', 'https://www.google.com/async/translate?'); | |
var data = 'async=translate,sl:auto,tl:en,st:' + encodeURIComponent(text) + ',id:0,_id:tw-async-translate,_pms:s'; | |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8'); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
a = JSON.parse(xhr.responseText); | |
var doc = document.implementation.createHTMLDocument(); | |
doc.body.innerHTML = JSON.parse(xhr.responseText)[1][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
from threading import Thread | |
from queue import Queue | |
def threaded(fn): | |
def wrap(queue, *args, **kwargs): | |
queue.put(fn(*args, **kwargs)) | |
def call(*args, **kwargs): | |
queue = Queue() |
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.util.List; | |
import java.util.stream.Stream; | |
import java.util.stream.Collectors; | |
import java.util.function.Supplier; | |
import java.math.BigInteger; | |
class Fibonacci { | |
private static Stream<BigInteger> getGenerator() { | |
return Stream.generate(new Supplier<BigInteger>() { | |
private BigInteger a = BigInteger.ZERO; |