{"size": 1433, "ext": "rktl", "max_stars_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/common/typed/nqueens.rktl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/common/typed/nqueens.rktl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/common/typed/nqueens.rktl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 32.5681818182, "max_line_length": 76, "alphanum_fraction": 0.505931612}
;;; NQUEENS -- Compute number of solutions to 8-queens problem.
;; 2006/08 -- renamed `try' to `try-it' to avoid Bigloo collision (mflatt)
;; 2010/04 -- got rid of the one-armed id (stamourv)
;; 2010/05 -- ported to typed Scheme (stamourv)

(define trace? #f)

(: nqueens (Integer -> Integer))
(define (nqueens n)

  (: one-to (Integer -> (Listof Integer)))
  (define (one-to n)
    (let: loop : (Listof Integer)
          ((i : Integer n) (l : (Listof Integer) '()))
          (if (= i 0) l (loop (- i 1) (cons i l)))))

  (: try-it ((Listof Integer) (Listof Integer) (Listof Integer) -> Integer))
  (define (try-it x y z)
    (if (null? x)
        (if (null? y)
            (begin (if trace? (begin (write z) (newline)) #t) 1)
            0)
        (+ (if (ok? (car x) 1 z)
               (try-it (append (cdr x) y) '() (cons (car x) z))
               0)
           (try-it (cdr x) (cons (car x) y) z))))

  (: ok? (Integer Integer (Listof Integer) -> Boolean))
  (define (ok? row dist placed)
    (if (null? placed)
        #t
        (and (not (= (car placed) (+ row dist)))
             (not (= (car placed) (- row dist)))
             (ok? row (+ dist 1) (cdr placed)))))

  (try-it (one-to n) '() '()))

(let ((input (with-input-from-file "input.txt" read)))
  (time
   (let: loop : Integer ((n : Integer 10000) (v : Integer 0))
         (if (zero? n)
             v
             (loop (- n 1) (nqueens (if input 8 0)))))))
