summaryrefslogtreecommitdiff
path: root/util.lisp
blob: 4180bd7e5724e18e1f1deb50f8f33f844edd6d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(in-package :japonca)

(defun ağırlıklı-rastgele (options weights &optional length)
  ;; (declare (type simple-array options) (type simple-array weights))
  (let ((len (or length (length weights))))
    (loop :with rand := (* (random 1.0) (aref weights (- len 1)))
          :for i :from 0 :below (length weights)
          :when (> (aref weights i) rand)
          :do (return (aref options i)))))

(defun ağırlık-ata (weights &optional length)
  (let ((len (or length (length weights))))
    (loop :for i :from 1 :below len
          :do (incf (aref weights i)
                    (aref weights (- i 1))))
    weights))

(defun dosya-metni-oku (dosya)
  (let* ((uzunluk 0)
         (metin
           (with-output-to-string (out)
             (with-open-file (in dosya :external-format :utf-8)
               (loop :with buffer := (make-array 8192 :element-type 'character)
                     :for n := (read-sequence buffer in)
                     :while (< 0 n)
                     :do (incf uzunluk n)
                         (write-sequence buffer out :start 0 :end n))))))
    (values metin uzunluk)))



;; (defun random-test (options weigths)
;;   (let ((opts options)
;; 		(weights (set-weights-array weigths))
;; 		(times (make-array 3 :initial-element 0)))
;; 	(loop :for i :from 0 :below 1000
;; 		  :for choice := (weighted-random opts weights)
;; 		  :do (incf (aref times choice)))
;; 	times))