Skip to content

Instantly share code, notes, and snippets.

@genos
genos / x.py
Created October 2, 2013 19:13
A Python file to play with a special continued fraction. If you don't have a Python interpreter, try running it in an online one (copy and paste the code), like: http://repl.it/ http://codepad.org/ http://labs.codecademy.com/
def x(k):
"""Numerically investigate the continued fraction x =
1 + 1
________________
1 + 1
__________
1 + 1
_____
...
We won't be able to go out to infinity, so we'll use a counter to take only
#!/usr/local/bin/sbcl --script
;;;; craps.lisp
;;;;
;;;; My submission to http://programmingpraxis.com/2011/11/04/craps/
;;;; Simulates games of Craps, outputs statistics; REQUIRES SBCL (*posix-argv*)
;;;; GRE, 11/4/11
(defun two-dice ()
"The sum of rolling two dice"
(+ (1+ (random 6)) (1+ (random 6))))
@genos
genos / shamir_threshold_2.c
Created October 25, 2011 17:52
Shamir Threshold: C (version 2)
/* shamir_threshold_scheme.c
*
* My C implementation of Shamir's (k, n) Theshold scheme.
* Uses a single flag as opposed to an array; idea from Razvan's great implementation.
* GRE, 6/23/11
*/
#include <stdio.h>
#include <stdlib.h>
#define uint unsigned int
@genos
genos / shamir_threshold.c
Created October 25, 2011 17:51
Shamir Threshold: C (version 1)
/* shamir_threshold_scheme.c
*
* My C implementation of Shamir's (k, n) Theshold scheme.
* GRE, 6/23/11
*/
#include <stdio.h>
#include <stdlib.h>
#define uint unsigned int
#define ulong unsigned long
@genos
genos / shamir_threshold.lisp
Created October 25, 2011 17:47
Shamir Threshold: Common Lisp
;;; shamir_threshold_scheme.lisp
;;;
;;; Implements Adi Shamir's (k, n) threshold secret sharing scheme.
;;; GRE, 6/17/11
(defun prod (nums)
"Product of nums"
(reduce #'* nums :initial-value 1))
@genos
genos / shamir_threshold.hs
Created October 25, 2011 17:46
Shamir Threshold: Haskell
{- shamir_threshold_scheme.hs
-
- My Haskell implementation of Shamir's (k, n) Threshold scheme.
- GRE, 6/23/11
-}
import Data.Bits (shiftR, testBit)
import Data.List (foldl', nub)
import Random (mkStdGen, randomRs)
@genos
genos / obfuscated_collatz.c
Created September 8, 2011 19:47
Obfuscated C code to play with the Collatz Conjecture
main(int c,char **v){int n=atoi(v[1]);while(n-1){n=n&1?3*n+1:n/2;printf("%d\n",n);}}