fork download
  1. (defparameter +alpha-chars+
  2. "ABCDEFGHIJKLMNOPQRSTUVWXIZabcdefghijklmnopqrstuvwxiz")
  3.  
  4. (defun odai-pt11-206 (s s-repeat fn &optional (preserve-newlines-p t))
  5. (let ((s (format nil "~v@{~A~:*~}" s-repeat s))
  6. (result '()))
  7. (do* ((n 1 (1+ n))
  8. (col 1 (if (char= chr #\Newline) 1 (1+ col)))
  9. (chr #1=(and (< (1- n) (length s))
  10. (char s (1- n)))
  11. #1#))
  12. ((null chr) (concatenate 'string (nreverse result)))
  13. (let ((x (funcall fn n col chr)))
  14. (push (cond ((and (char= chr #\Newline)
  15. preserve-newlines-p)
  16. #\Newline)
  17. ((zerop (mod x 3))
  18. (char +alpha-chars+
  19. (random (1- (length +alpha-chars+)))))
  20. ((evenp x)
  21. (char-downcase chr))
  22. (t
  23. (char-upcase chr)))
  24. result)))))
  25.  
  26. (progn
  27. (format t "~
  28. 206: ID:hUDFoTxj 2018/05/02(水) 05:46:42.10 <sage>
  29. お題:Hello, World!を10回出力してください。
  30. ただし、偶数文字を小文字、奇数文字を大文字にすること。
  31. さらに3の倍数の文字をランダムな英字にすること。
  32. ")
  33. (format t "~%;; 文字コード~%~A~&"
  34. (odai-pt11-206 (format nil "Hello, World!~%") 10
  35. (lambda (n col ch) (declare (ignorable n col ch))
  36. (char-code ch))
  37. nil))
  38. (format t "~%;; 通算 n 文字目~%~A~&"
  39. (odai-pt11-206 (format nil "Hello, World!~%") 10
  40. (lambda (n col ch) (declare (ignorable n col ch)) n)
  41. nil))
  42. (format t "~%;; 各行 n 文字目~%~A~&"
  43. (odai-pt11-206 (format nil "Hello, World!~%") 10
  44. (lambda (n col ch) (declare (ignorable n col ch)) col)
  45. nil)))
  46.  
Success #stdin #stdout 0.01s 25288KB
stdin
Standard input is empty
stdout
206: ID:hUDFoTxj 2018/05/02(水) 05:46:42.10 <sage>
    お題:Hello, World!を10回出力してください。
    ただし、偶数文字を小文字、奇数文字を大文字にすること。
    さらに3の倍数の文字をランダムな英字にすること。

;; 文字コード
cEusf, Fhrjdl
EEafQ, nkZhdR
qESIZ, ccNxdu
HEptr, IMPAdF
MEtmb, GCNudu
iELSn, ZCwwdC
kEkJZ, JahHdu
BEIUo, mDrMdS
JEOIL, qIHodw
ZERqs, nQFQdW

;; 通算 n 文字目
HehlOU wIrLo!
DeLSO,jwOFLdj
HjLlJ, nOrBd!WHePlOh wqrLu!
beLKO,CwOELdt
HmLlq, KOrkd!vHeKlOD warLV!
neLcO,hwOqLdK
HdLlF, fOrnd!XHePlOf wKrLW!

;; 各行 n 文字目
HeolOC wxrLQ!
HeAlOE wBrLj!
HeTlOf wdrLe!
HeQlOe wCrLw!
HemlOB wLrLw!
HeklOZ wirLO!
HeZlOj wXrLH!
HeNlOW wtrLI!
HeVlOw wfrLh!
HeIlOC whrLE!