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
// https://twitter.com/e869120/status/1741475801026204116# | |
(* | |
(20 + (((23 + 12) - 31) * ((20 * (24 + 1)) + 1))) | |
(((20 * 23) + (((12 + 31) - 20) * 24)) * (1 + 1)) | |
*) | |
let rec gcd a (b: int) = if b = 0 then a else gcd b (a % 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
let fizz = | |
Seq.initInfinite (fun i -> if (i+1) % 3 = 0 then "Fizz" else "") | |
let buzz = | |
Seq.initInfinite (fun i -> if (i+1) % 5 = 0 then "Buzz" else "") | |
let fizzbuzz = | |
Seq.mapi2 (fun i f b -> match f + b with "" -> string (i + 1) | x -> x) fizz buzz | |
fizzbuzz | |
|> Seq.take 100 | |
|> Seq.iter (printfn "%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
module type OrderedType = sig | |
type t | |
val compare : t -> t -> int | |
end | |
module type S = | |
sig | |
type elt | |
type t | |
val empty: t |
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
open System | |
let memo_rec f = | |
let m = ref Map.empty in | |
let rec g x = | |
match Map.tryFind x !m with | |
| Some ans -> ans | |
| None -> | |
let y = f g x in | |
m := Map.add x y !m |
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 <vector> | |
#include <cmath> | |
using namespace std; | |
vector<int> primes(int n) | |
{ | |
vector<bool> table(n + 1, true); | |
table[0] = table[1] = false; | |
int mid = (int)floor(sqrt(n)); | |
for (int i = 2; i <= mid; 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
module Heap = | |
type tree<'T> = Node of 'T * tree<'T> * tree<'T> | |
| Leaf | |
type t<'T> = { root : tree<'T> | |
cmp : 'T -> 'T -> bool | |
} | |
let create cmp = | |
{root=Leaf; cmp=cmp} | |
let rec meld cmp a 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
// sample of has_mem_xxx. | |
// this can be compiled with MS VC2012. | |
#include <iostream> | |
#include <utility> | |
#include <type_traits> | |
template< typename T > | |
struct has_mem_xxx { | |
template< typename U > static std::true_type check( decltype( std::declval<U>().xxx )* ); |
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://www.prefield.com/algorithm/container/fenwick_tree.html | |
// add(k, a) == v[k] = v[k] + a | |
// sum(i, j) == v[i] + ... + v[j] (両端を含む) | |
type FenwickTree(N : int) = | |
let zero = LanguagePrimitives.GenericZero | |
let x = Array.create N zero | |
member me.sum i j = | |
if i = 0 then | |
let rec loop acc k = | |
if k >= 0 then loop (acc + x.[k]) ((k &&& (k+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
--- ocaml-4.02.1/asmrun/signals_osdep.h 2014-09-29 04:46:24.000000000 +0900 | |
+++ ocaml-4.02.1_fix/asmrun/signals_osdep.h 2014-10-05 15:22:24.000000000 +0900 | |
@@ -163,14 +172,24 @@ | |
#elif defined(TARGET_i386) && defined(SYS_bsd_elf) | |
- #define DECLARE_SIGNAL_HANDLER(name) \ | |
- static void name(int sig, siginfo_t * info, struct sigcontext * context) | |
+ #if defined (__NetBSD__) | |
+ #include <ucontext.h> |
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
(* Groovy: | |
/** | |
* Hindley-Milner type inference | |
* Ported to Groovy from Scala by Example Chapter 16 code. | |
* (http://www.scala-lang.org/docu/files/ScalaByExample.pdf) | |
* refered also | |
* https://github.com/namin/spots/blob/master/hindleyMilner/typeInference.scala | |
* Japanese page of 'Scala by Example': | |
* http://www29.atwiki.jp/tmiya/pages/78.html | |
*/ *) |
NewerOlder