ilo.rkt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #lang racket/base
  2. (require srfi/26)
  3. (require racket/list)
  4. (require racket/function)
  5. (require racket/string)
  6. (random-seed 10)
  7. (define nimi-ale (read (open-input-file "nimi-ale.lisp")))
  8. ;; nimi li ken ijo li ken pali li ken ale.
  9. (define nimi-ijo
  10. (filter-map (lambda (sona-nimi)
  11. ;; sona-nimi li kulupu. ijo nanpa wan li nimi. ijo
  12. ;; nanpa tu en ijo nanpa mute li nimi pi nasin nimi
  13. ;; (adjective, noun, ijo ante)
  14. (and (findf (lambda (nasin-nimi)
  15. (findf
  16. (cut eq? <> nasin-nimi)
  17. '(adjective noun verb)))
  18. (cdr sona-nimi))
  19. ;; nimi ni li ken nasa lili tawa lipu
  20. ;; TODO: tenpo kama o lukin sin e ni
  21. (not (findf
  22. (cut eq? <> (car sona-nimi))
  23. '(meli mije unpa ijo pu mi sina ona ni)))
  24. (symbol->string (car sona-nimi))))
  25. nimi-ale))
  26. ;; lipu ale la nanpa pi mute lili o suli. mute li kama lon tenpo mute lon
  27. ;; lipu wan la jan li sona e suli ona. ni li ken wawa e nasin.
  28. ;; nasin ni li kute e kulupu nimi:
  29. ;; (list "a" "b" "c" "d")
  30. ;; li pana e kulupu pi tu nimi nanpa:
  31. ;; (list '("a" . 1) '("b" 1/2) '("c" 1/3))
  32. ;; nanpa li toki e ni: nimi seme li kama lon tenpo mute?
  33. (define (nanpa-ken kulupu)
  34. (for/list ([nimi (shuffle kulupu)]
  35. [nanpa (in-naturals 1)])
  36. (cons nimi (/ (expt nanpa 6/5)))))
  37. ;; nasin ni li kute e kulupu pi tu nimi nanpa (sama nasin nanpa-ken) li
  38. ;; pana e kulupu sama.
  39. ;;
  40. ;; ona li nasa lili e nanpa. tan ni la sike musi ante la nimi ante lili li
  41. ;; ken lon tenpo mute. ona li nasa pi lili taso; nimi suli tan kulupu nanpa
  42. ;; wan li ken awen suli lon kulupu nanpa tu.
  43. (define (o-nasa-e-kulupu-ken kulupu)
  44. (map (lambda (tu) (cons (car tu) (* (/ (random 51) 50) (cdr tu)))) kulupu))
  45. ;; o alasa e nimi wan tan kulupu pi ken nimi
  46. ;; ona li kute e kulupu (sama nasin nanpa-ken) li pana e nimi wan taso.
  47. (define (o-alasa kulupu-ken)
  48. ;; ijo nanpa x
  49. (define (ijo-nanpa kulupu-ken nanpa ijo)
  50. (cond
  51. [(null? kulupu-ken) ijo]
  52. [(< nanpa (cdar kulupu-ken)) (caar kulupu-ken)]
  53. [else (ijo-nanpa (cdr kulupu-ken)
  54. (- nanpa (cdar kulupu-ken))
  55. (caar kulupu-ken))]))
  56. (ijo-nanpa kulupu-ken (* (random) (apply + (map cdr kulupu-ken))) #f))
  57. ;; nasin ni li kute e kulupu nimi:
  58. ;; (list 'a 'b 'a 'a 'a 'c 'c)
  59. ;; li pana e kulupu pi tu nanpa nimi li toki e ni: mute seme la
  60. ;; nimi li lon kulupu?
  61. ;; (list '(4 . a) '(2 . c) '(1 . b))
  62. (define (o-nanpa-e-kulupu l)
  63. (map (lambda (kulupu) (cons (length kulupu) (car kulupu)))
  64. (sort (group-by identity l) > #:key length)))
  65. ;; tenpo mute la sike sin o nasa ala tawa sike ante. sike nanpa wan en
  66. ;; sike nanpa tu o ante suli ala. tenpo ona o sama lili.
  67. (define (suli-pi-sike-sin suli-pi-sike-ante)
  68. (let
  69. ([nanpa-ken
  70. (for/list
  71. ([nanpa (in-range 2 9)])
  72. (cons
  73. nanpa
  74. (* (/ nanpa)
  75. ;; nanpa ale li kama tan kulupu pi nanpa lili.
  76. ;; nanpa tu en nanpa tu li kama e nanpa tu tu.
  77. ;; nanpa tu en nanpa luka li kama e nanpa luka luka.
  78. ;;
  79. ;; nasin 'gcd' li toki e ni: kulupu pi nanpa nanpa wan en kulupu
  80. ;; pi nanpa nanpa tu la nanpa seme li lon kulupu tu? ijo mute li
  81. ;; lon kulupu tu la nanpa ni li pona tawa sike ante li sike lon
  82. ;; tenpo pi sama lili. nasin ni li mute e ken ona tan ni.
  83. (+ 4 (apply + (map (cut gcd <> nanpa) suli-pi-sike-ante))))))])
  84. (o-alasa nanpa-ken)))
  85. (define (pali-lili nimi-ken)
  86. (string-join
  87. (car
  88. (shuffle
  89. (list
  90. (list (o-alasa nimi-ken))
  91. (list (o-alasa nimi-ken)
  92. "li"
  93. (o-alasa nimi-ken))
  94. (list (o-alasa nimi-ken)
  95. "li"
  96. (o-alasa nimi-ken)
  97. "e"
  98. (o-alasa nimi-ken)))))
  99. " "))
  100. (define (sike-sin nimi-ken sike-ante)
  101. (let ([suli (suli-pi-sike-sin (map length sike-ante))]
  102. [nimi-ken (o-nasa-e-kulupu-ken nimi-ken)])
  103. (for/list ([nimi (in-range suli)])
  104. ;; TODO: ken la o ante e ni
  105. (pali-lili nimi-ken))))
  106. (define (sike-mute nimi-ken mute)
  107. (if (= mute 0)
  108. '()
  109. (let ([sike-ante (sike-mute nimi-ken (- mute 1))])
  110. (cons (sike-sin nimi-ken sike-ante)
  111. sike-ante))))
  112. (define toki-lawa
  113. #<<PINI
  114. \documentclass{article}
  115. \usepackage[T1]{fontenc}
  116. \usepackage{bookmark}
  117. \usepackage[utf8]{inputenc}
  118. \usepackage[margin=1in]{geometry}
  119. \usepackage{fourier}
  120. \usepackage{nanpa}
  121. \renewcommand\thepage{lawa}
  122. \usepackage{hyperref}
  123. \setcounter{secnumdepth}{0}
  124. \newcounter{nasin}
  125. \newcounter{sike}
  126. \begin{document}
  127. \thispagestyle{empty}
  128. \begin{titlepage}
  129. \vspace*{\fill}
  130. \renewcommand\thepage{open}
  131. \centering
  132. \pdfbookmark[0]{nasin musi sike}{nasin musi sike}
  133. {\Huge\textbf{nasin musi telo}\par}
  134. tan soweli nata
  135. \vspace*{1\baselineskip}
  136. \begin{minipage}[t]{0.45\linewidth}
  137. ni li nasin musi telo. wile la ona li ken
  138. nasin e musi sina. ona li tawa kalama musi,
  139. taso mute ante li ken. lipu mute mute li lon.
  140. ona la sike mute li lon. sina ken pali e ijo
  141. mute lon nasin mute. jan wan li ken musi. jan
  142. mute li ken musi. nasin mute pi lukin lipu li
  143. lon. jan ante li ken musi e sike ante. jan ale
  144. li ken musi e sike wan. jan wan li ken kalama e
  145. sike ante lon tenpo ante. jan wan li ken kalama e
  146. sike ale lon tenpo wan. nasin ante li ken lon li
  147. pona. nasin ale li pona tawa lipu ni. ona li lawa
  148. ala e musi sina. lipu li nasin taso e ona. sina ken pali
  149. e wile sina.
  150. \centering
  151. o musi pona!
  152. \end{minipage}
  153. \vspace*{\fill}
  154. \end{titlepage}
  155. \setcounter{page}{1}
  156. \renewcommand\thepage{nanpa \nanpasuli{page}}
  157. PINI
  158. )
  159. (define toki-noka
  160. #<<PINI
  161. \end{document}
  162. PINI
  163. )
  164. (define (sitelen-sike sike)
  165. (string-append
  166. "\\begin{minipage}[t][10\\baselineskip]{0.30\\linewidth}\n"
  167. "\\begin{center}\n"
  168. "\\stepcounter{sike}\\textbf{sike nanpa \\nanpasuli{sike}}\n\n"
  169. (string-join sike "\n\n")
  170. "\\end{center}\\end{minipage}\\hfill\n"))
  171. (define (lipu-wan)
  172. (string-append
  173. "\\newpage{}\\begin{center}\n"
  174. "\\thispagestyle{empty}\n"
  175. "\\stepcounter{nasin}\n"
  176. "\\setcounter{sike}{0}\n"
  177. "\\section{\\Huge nanpa \\nanpasuli{nasin}}"
  178. "\\vspace*{\\fill}"
  179. (string-join
  180. (let ([nanpa-ken (nanpa-ken nimi-ijo)])
  181. (map (cut apply string-append <>)
  182. (list
  183. (map sitelen-sike (sike-mute nanpa-ken 1))
  184. (map sitelen-sike (sike-mute nanpa-ken 3))
  185. (map sitelen-sike (sike-mute nanpa-ken 3)))))
  186. "\n")
  187. "\n"
  188. "\\vspace*{\\fill}"
  189. "\\end{center}"))
  190. (displayln toki-lawa)
  191. (for ([i (in-range 500)])
  192. (displayln (lipu-wan)))
  193. (displayln toki-noka)