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
# Flip a fair coin 100 times--it gives a sequence of heads (H) and tails (T). | |
# For each HH in the sequence of flips, Alice gets a point; for each HT, | |
# Bob does, so e.g. for the sequence THHHT Alice gets 2 points and Bob | |
# gets 1 point. Who is most likely to win? | |
# -- https://twitter.com/littmath/status/1769044719034647001 | |
# Based on https://gist.github.com/llllvvuu/02e08ee87b2191c0f3f504072be73a0f#file-hh_vs_ht-c, | |
# a _very_ clever algorithm by L (llllvvuu). See https://twitter.com/llllvvuu/status/1770557954372382765 | |
# I implemented this to try to understand llllvvuu's algorithm and as a bonus to benefit from | |
# Python's bignum support. |
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
<html> | |
<style> | |
dl.definitions, dl.definitions dt, dl.definitions dd { | |
display: block; | |
} | |
dl.definitions dt { | |
float: left; | |
clear: right; | |
margin-inline-end: 2ch; | |
} |
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 <tuple> | |
namespace detail { | |
template <size_t... N> struct Indices { }; | |
template <typename T, size_t I> | |
inline void print_tuple(std::ostream &out, const T &tup, Indices<0, I>) { } | |
template <typename T, size_t N, size_t 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
/* | |
* LinkedList.h | |
*/ | |
#include <assert.h> | |
template <class C, int N=0> | |
class Linked | |
{ | |
Linked* m_next; |
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
// | |
// Copyright (c) 2015 Stan Switzer. | |
// | |
#ifndef llsort_llsort_h | |
#define llsort_llsort_h | |
#include <vector> | |
#include <functional> |
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 Msort (msortBy, msort) where | |
msortBy :: (a -> a -> Ordering) -> [a] -> [a] | |
msortBy orderOp = | |
foldr merge [] . foldr mergeStack [] . runs | |
where | |
-- mergeStack :: [a] -> [[a]] -> [[a]] | |
-- mergeStack "k" [ "" "ij" "" "abcdefgh" ] = [ "k" "ij" "" "abcdefgh" ] | |
-- mergeStack "l" [ "k" "ij" "" "abcdefgh" ] = [ "" "" "ijkl" "abcdefgh" ] | |
mergeStack x ([]:s) = x: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
a="console.log(\"a=\"+JSON.stringify(a)+\";\"+a)";console.log("a="+JSON.stringify(a)+";"+a) |
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 hanoiGenerator(n, a="left", b="center", c="right"): | |
if n > 0: | |
for i in hanoiGenerator(n-1, a, c, b): | |
yield i | |
yield (a, c) | |
for i in hanoiGenerator(n-1, b, a, c): | |
yield i | |
def test_hanoiGenerator(): | |
for (fm, to) in hanoiGenerator(3): |