Skip to content

Instantly share code, notes, and snippets.

@Glorp
Created July 31, 2014 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glorp/58a617d9e5f9eab24937 to your computer and use it in GitHub Desktop.
Save Glorp/58a617d9e5f9eab24937 to your computer and use it in GitHub Desktop.
#lang racket
(define (chars n)
(string->list (~a n #:min-width 6 #:pad-string "0")))
(define (char->str c)
(match c
[#\0 "((((((("]
[#\1 "(((((("]
[#\2 "((((("]
[#\3 "(((("]
[#\4 "((("]
[#\5 "(("]
[#\6 "("]
[#\8 ")"]
[#\9 "))"]
[_ "horses"]))
(define (read-string s)
(define in (open-input-string s))
(define (loop)
(unless (eof-object? (read in))
(loop)))
(loop))
(for/sum ([n (in-range 0 1000000)])
(with-handlers ([(λ (_) #t) (λ (_) 0)])
(read-string (list->string (sort (apply append (map string->list (map char->str (chars n))))
(λ (a b) (< (char->integer a) (char->integer b))))))
1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment