Created
July 29, 2014 18:51
-
-
Save akovalenko/ea8033d65e9948f94e6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar *ru-vowels* "аоуыэяёюие") | |
(defun vowelp (character) (position character *ru-vowels*)) | |
(defun move-vowels (n &optional (input *standard-input*) (output *standard-output*)) | |
(let ((vowels 0)) | |
(loop | |
(let ((character (read-char input nil :eof))) | |
(when (eq :eof character) | |
(return)) | |
(if (alpha-char-p character) | |
(when (vowelp character) | |
(incf vowels)) | |
(unless (< vowels n) | |
(unread-char character input) | |
(return))) | |
(write-char character output))))) | |
(defun format-cake (string &optional (output *standard-output*)) | |
(with-input-from-string (input string) | |
(dolist (n '(9 8 9 8)) | |
(move-vowels n input output) | |
(terpri output)))) | |
#| Test: | |
(with-output-to-string (*standard-output*) | |
(format-cake "не пил не ел не спал однажды и невозможно похудел но не однажды а всё время такой олег олег олег и так")) | |
==> "не пил не ел не спал однажды | |
и невозможно похудел | |
но не однажды а всё время | |
такой олег олег олег | |
" | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment