@@ 1,16 1,18 @@
#lang racket/base
-(require racket/port)
+(require math/matrix)
(require racket/contract)
+(require racket/list)
(require racket/math)
+(require racket/port)
-(require readline/readline)
+(require (only-in openssl/sha1 hex-string->bytes))
+(require binaryio)
(require crypto)
+(require json)
(require net/http-client)
(require net/uri-codec)
-(require json)
-(require binaryio)
+(require readline/readline)
(require simple-http)
-(require (only-in openssl/sha1 hex-string->bytes))
(define num-bytes (/ 1024 8))
@@ 118,21 120,33 @@
(natural->hex-string point))))))))))))))
(newline)
- (display "summing sums...")
- (define sum
- (foldl + 0
- (map
- hex-string->natural
- (hash-values
- (json-response-body
- (let loop ([wait 0])
- (sleep wait)
- (with-handlers ([exn:fail:network:http:error?
- (λ (exn)
- (break-enabled #t)
- (display ".")
- (flush-output)
- (loop 3))])
- (get bulletin "/sums"))))))))
+ (display "finding constant...")
+ (define constant
+ (let ([k (length peer-inputs)]
+ [sums (for/hash ([(k v)
+ (in-hash
+ (json-response-body
+ (let loop ([wait 0])
+ (sleep wait)
+ (with-handlers ([exn:fail:network:http:error?
+ (λ (exn)
+ (break-enabled #t)
+ (display ".")
+ (flush-output)
+ (loop 3))])
+ (get bulletin "/sums")))))])
+ (values (hex-string->natural (symbol->string k))
+ (hex-string->natural v)))])
+ (matrix-ref
+ (matrix-solve
+ ; M
+ (for*/matrix k k ([x peer-inputs]
+ [p (range k)])
+ (expt x p))
+ ; B
+ (for*/matrix k 1 ([x peer-inputs])
+ (hash-ref sums x)))
+ 0 0)))
(newline)
- (displayln (format "sum: ~a" sum)))
+
+ (displayln (format "Result: ~a" constant)))