Last active
December 14, 2015 08:49
-
-
Save codepony/5060893 to your computer and use it in GitHub Desktop.
CommonLisp "rows" done for a task @ prooops #coders
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
; Simple print-rows for prooops #coders | |
; Print * (+1 for every row) and in the middle print as may stars as there are rows. (rows marks the middle) | |
#| | |
Example: | |
rows = 5 | |
* | |
** | |
*** | |
**** | |
********* (9*) | |
**** | |
*** | |
** | |
* | |
|# | |
; Easiest way without loop: | |
(defparameter *rows* 0) | |
; 1) Write function, which only prints as many * as you wish (returns #\newline at the end) | |
(defun aster (cur num) | |
(if (> num cur) | |
(progn | |
(princ #\*) | |
(aster (1+ cur) num)) | |
(princ #\Newline))) | |
; 2) Write function, which knows in which row we are and how many we need. | |
(defun linenumber (row) | |
(if (> *rows* row) | |
(progn | |
(aster 0 row) | |
(linenumber (1+ row)) | |
)) | |
(if (= *rows* row) | |
(progn | |
(aster 0 (1+ (* 2 (1- *rows*)))) | |
(linenumber (1+ row)) | |
)) | |
(if (< *rows* row) | |
(if (<= row (1+ (* 2 (1- *rows*)))) | |
(progn | |
(aster 0 (- *rows* (- row *rows*))) | |
(linenumber (1+ row)) | |
) | |
(print_rows) | |
) | |
) | |
) | |
(defun print_rows () | |
(format t "~% How many rows?~%") | |
(setf *rows* (parse-integer (read-line) :junk-allowed t)) | |
(format t "rows:~a" *rows*) | |
(linenumber 0) | |
) | |
(print_rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment