This commit is contained in:
riton
2025-02-11 23:03:13 +03:00
commit d683a2e52f
9 changed files with 694 additions and 0 deletions

39
util.lisp Normal file
View File

@@ -0,0 +1,39 @@
(in-package :japonca)
(defun ı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 ı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))