Skip to content

Instantly share code, notes, and snippets.

@mnzk
Last active June 4, 2016 21:42
Show Gist options
  • Save mnzk/5e046595299cd356dc4b9e20a5828653 to your computer and use it in GitHub Desktop.
Save mnzk/5e046595299cd356dc4b9e20a5828653 to your computer and use it in GitHub Desktop.
#lang racket
(require (only-in srfi/26 cute))
(define-syntax t>=
(syntax-rules ()
((_ x) x)
((_ x f g ...) (t>= (f x) g ...))))
(define (solve24 n)
(t>= "9876543210" string->list
permutations
(cute list-ref <> (sub1 n))
reverse list->string))
(define (solve24-seq n)
(t>= "0123456789" string->list
in-permutations
(cute sequence-ref <> (sub1 n))
reverse list->string))
(define N 1000000)
(time (solve24 N))
(time (solve24-seq N))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment