init
This commit is contained in:
39
util.lisp
Normal file
39
util.lisp
Normal file
@@ -0,0 +1,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))
|
||||
Reference in New Issue
Block a user