The main observation is that the card at index i (1 <= i <= N) ends up at index K * i % (N + 1) after 1 shuffle. So after x shuffles, the card will be at position K^x * i % (N + 1). We want to find the smallest x such that K^x * i = i for all i. In other words, we want K^x = 1. This is known as the multiplicative order of K mod (N + 1). Lagrange's theorem implies that this will be a factor of phi(N + 1) where phi is the Euler Totient function. So we can check all factors of phi(N + 1) and find the smallest one which works. See: http://en.wikipedia.org/wiki/Euler's_totient_function http://en.wikipedia.org/wiki/Lagrange's_theorem_(group_theory)
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
(ns demo.core | |
(:require [clojure.core.typed :as t])) | |
;; Map vs Vector AST representation | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; * Maps | |
(t/defalias M (t/U '{:op ':if :test M :then M :else M} | |
'{:op ':do :e1 M :e2 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
(defn seqable? [x] | |
(or (instance? clojure.lang.ISeq x) | |
(instance? clojure.lang.Seqable x) | |
(instance? Iterable x) | |
(instance? CharSequence x) | |
(instance? java.util.Map x) | |
(nil? x) | |
(.. x getClass isArray))) |
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
(defpackage #:dcpu-16 | |
(:use #:cl) | |
(:export | |
#:make-ram #:ram-read #:ram-write #:ram-size | |
#:execute #:debug | |
#:load-program #:assemble-program | |
#:set #:add #:sub #:mul | |
#:div #:mod #:shl #:shr | |
#:and #:bor #:xor #:ife | |
#:ifn #:ifg #:ifb #:jsr |
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
# List of all the valid pdf URLs ever posted to the #Clojure IRC channel. | |
# | |
# Many of them are interesting CS papers others are not that useful. What I've done: | |
# | |
# 1. crawled an IRC history archive for the channel | |
# 2. extract pdf list in a file with: grep -riIohE 'https?://[^[:space:]]+pdf' * > pdf-links.txt | |
# 3. remove dupes: cat pdf-links.txt | sort | uniq > pdf-links-uniq.txt | |
# 4. filter only HTTP 200: cat pdf-links-uniq.txt | xargs curl -o /dev/null --connect-timeout 2 --silent --head --write-out '%{http_code} %{url_effective}\n' | grep "^200" > valid-pdf-links.txt | |
# | |
# Now your choice to download them all or not. If you want, use: cat valid-pdf-links.txt | awk '{print $2}' | xargs wget |
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
#!/bin/bash | |
# author Ghadi Shayban <gshayban@gmail.com> | |
set -e | |
if [ -z ${1+x} ] | |
then | |
echo provide an asm git sha / ref | |
exit 1 | |
fi |
Find it here: https://github.com/bitemyapp/learnhaskell
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 classbytes (atom {})) | |
(defn bytes-of-forms [form] | |
(push-thread-bindings | |
{clojure.lang.Compiler/LOADER | |
(proxy [clojure.lang.DynamicClassLoader] [@clojure.lang.Compiler/LOADER] | |
(defineClass | |
([name bytes src] | |
(swap! classbytes assoc name bytes) |
It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
OlderNewer