2020-11-24.rkt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. (+ 9 (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[utf8]{inputenc}
  117. \usepackage[margin=1in]{geometry}
  118. \usepackage{fourier}
  119. \usepackage{nanpa}
  120. \pagenumbering{gobble}
  121. \setcounter{secnumdepth}{0}
  122. \newcounter{nasin}
  123. \newcounter{sike}
  124. \begin{document}
  125. PINI
  126. )
  127. (define toki-noka
  128. #<<PINI
  129. \end{document}
  130. PINI
  131. )
  132. (define (sitelen-sike sike)
  133. (string-append
  134. "\\begin{minipage}[t][10\\baselineskip]{0.30\\linewidth}\n"
  135. "\\begin{center}\n"
  136. "\\stepcounter{sike}\\textbf{sike nanpa \\nanpasuli{sike}}\n\n"
  137. (string-join sike "\n\n")
  138. "\\end{center}\\end{minipage}\\hfill\n"))
  139. (define (lipu-wan)
  140. (string-append
  141. "\\newpage{}\\begin{center}\n"
  142. "\\stepcounter{nasin}\n"
  143. "\\setcounter{sike}{0}\n"
  144. "\\section{\\Huge nanpa \\nanpasuli{nasin}}\n"
  145. "\\vspace*{\\fill}"
  146. (string-join
  147. (let ([nanpa-ken (nanpa-ken nimi-ijo)])
  148. (map (cut apply string-append <>)
  149. (list
  150. (map sitelen-sike (sike-mute nanpa-ken 1))
  151. (map sitelen-sike (sike-mute nanpa-ken 3))
  152. (map sitelen-sike (sike-mute nanpa-ken 3)))))
  153. "\n")
  154. "\n"
  155. "\\vspace*{\\fill}"
  156. "\\end{center}"))
  157. ;; (for-each (lambda (x) (newline) (for-each displayln x)) (sike-mute (nanpa-ken nimi-ijo) 5))
  158. (displayln toki-lawa)
  159. (for ([i (in-range 500)])
  160. (displayln (lipu-wan)))
  161. (displayln toki-noka)