Skip to content

Commit

Permalink
[codejam - 2016-qualification] Add Racket solution for C.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeaumont committed May 12, 2020
1 parent 53115f1 commit 0940598
Show file tree
Hide file tree
Showing 8 changed files with 598 additions and 0 deletions.
4 changes: 4 additions & 0 deletions codejam/2016-qualification/c-1.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Case #1:
100111 3 2 5 2 7 2 3 2 11
100011 5 13 3 31 43 3 73 7 3
100001 3 2 5 2 7 2 3 2 11
2 changes: 2 additions & 0 deletions codejam/2016-qualification/c-1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
6 3
51 changes: 51 additions & 0 deletions codejam/2016-qualification/c-2.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Case #1:
1000000010110101 3 2 3 2 7 2 3 2 3
1000000010110011 47 2 3 2 11 2 204311 2 3
1000000010101001 3 5 13 3 5 43 3 73 7
1000000010100111 5 2 3 2 37 2 5 2 3
1000000010100011 3 1259 421 3 5 8893 3 67 17
1000000010011101 3 2 3 2 7 2 3 2 3
1000000010011011 11 2 3 2 13 2 47 2 3
1000000010011001 7 1667 179 13 5 11 23 7 311
1000000010010111 3 2 3 2 7 2 3 2 3
1000000010010001 3 2 5 2 7 2 3 2 7
1000000010001001 5 2 7 2 1933 2 29 2 157
1000000010000101 3 2 5 2 7 2 3 2 11
1000000010000011 167 2 11 2 58427 2 23 2 839
1000000001111111 3 2 5 2 7 2 3 2 7
1000000001111101 7 19 43 17 55987 23 7 7 31
1000000001111011 31 557 7 19 23 1129 7 5441 241
1000000001111001 3 2 3 2 7 2 3 2 3
1000000001110101 5 2 3 2 37 2 5 2 3
1000000001110011 3 2 3 2 7 2 3 2 3
1000000001101101 3 2 3 2 7 2 3 2 3
1000000001101011 5 2 3 2 37 2 5 2 3
1000000001100111 3 2 3 2 7 2 3 2 3
1000000001100011 23 19 11 105491 5 47 11117 1787 127
1000000001100001 3 2 5 2 7 2 3 2 11
1000000001011111 59 113 7 157 19 1399 7 43 107
1000000001011101 17 2 3 2 1297 2 11 2 3
1000000001011011 3 2 3 2 7 2 3 2 3
1000000001011001 11 5 281 101 5 67 5 13 19
1000000001010111 5 2 3 2 37 2 5 2 3
1000000001010101 3 7 13 3 5 17 3 53 7
1000000001001111 3 2 3 2 7 2 3 2 3
1000000001001001 3 2 5 2 7 2 3 2 7
1000000001000011 3 2 5 2 7 2 3 2 11
1000000000111101 3 2 3 2 7 2 3 2 3
1000000000111011 17 2 3 2 73 2 17 2 3
1000000000110111 3 2 3 2 7 2 3 2 3
1000000000110101 23 17 11 23 5 299699 43 239 59
1000000000110001 3 2 5 2 7 2 3 2 11
1000000000101111 5 2 3 2 37 2 5 2 3
1000000000101011 3 7 13 3 5 43 3 73 7
1000000000100101 3 2 5 2 7 2 3 2 7
1000000000011111 3 2 3 2 7 2 3 2 3
1000000000011011 5 1567 15559 6197 5 5 1031 7 83
1000000000011001 3 2 5 2 7 2 3 2 11
1000000000010011 3 2 5 2 7 2 3 2 7
1000000000001101 3 2 5 2 7 2 3 2 11
1000000000001001 73 5 3 19 19 3 5 19 3
1000000000000111 3 2 5 2 7 2 3 2 11
1000000000000101 13 11 3 4751 173 3 53 109 3
1000000000000001 3 2 5 2 7 2 3 2 7
2 changes: 2 additions & 0 deletions codejam/2016-qualification/c-2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
16 50
501 changes: 501 additions & 0 deletions codejam/2016-qualification/c-3.ans

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions codejam/2016-qualification/c-3.in.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
32 500
34 changes: 34 additions & 0 deletions codejam/2016-qualification/c.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env racket
;; https://codingcompetitions.withgoogle.com/codejam/round/0000000000201bee/0000000000201b6d
#lang racket
(require math/number-theory)

(define (process n j)
(define (collect i s)
(cons (format "~b" i)
(map (lambda (x)
(number->string (second (divisors (string->number s x)))))
(range 2 11))))
(define (no-primes? s)
(define (iter i)
(cond ([> i 10] #t)
([prime? (string->number s i)] #f)
(else (iter (+ i 1)))))
(iter 2))
(define (iter i k xs)
(if (= k j)
xs
(let ([s (format "~b" i)])
(if (no-primes? s)
(iter (+ i 2) (+ k 1) (cons (collect i s) xs))
(iter (+ i 2) k xs)))))
(iter (+ (expt 2 (- n 1)) 1) 0 '()))

(define (main n)
(define (iter i)
(when (<= i n)
(printf "Case #~a:\n" i)
(for-each (lambda (x) (printf "~a\n" (string-join x)))
(apply process (map string->number (string-split (read-line)))))))
(iter 1))
(main (string->number (read-line)))
2 changes: 2 additions & 0 deletions codejam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ There are solutions for the following [Google Code Jam](https://codejam.withgoog
([problem site](https://codingcompetitions.withgoogle.com/codejam/round/00000000002017f7/0000000000201878))
1. [2017 Qualification Round - A. Oversized Pancake Flipper](2017-qualification/a.py)
([problem site](https://codingcompetitions.withgoogle.com/codejam/round/00000000002017f7/0000000000201847))
1. [2016 Qualification Round - C. Coin Jam](2016-qualification/c.rkt)
([problem site](https://codingcompetitions.withgoogle.com/codejam/round/0000000000201bee/0000000000201b6d))
1. [2016 Qualification Round - B. Revenge of the Pancakes](2016-qualification/b.ml)
([problem site](https://codingcompetitions.withgoogle.com/codejam/round/0000000000201bee/0000000000201d17))
1. [2016 Qualification Round - A. Counting Sheep](2016-qualification/a.rkt)
Expand Down

0 comments on commit 0940598

Please sign in to comment.