fork download
  1. (defun string-replace-all (string substring replacement)
  2. (let ((s string)
  3. (x substring)
  4. (x-len (length substring)))
  5. (loop for pos1 = 0 then (+ pos2 x-len)
  6. for pos2 = (search x s :start2 pos1)
  7. while pos2
  8. append (list (subseq s pos1 pos2)
  9. replacement)
  10. into result
  11. finally (return (format nil "~{~A~}~A"
  12. result (subseq s pos1))))))
  13.  
  14. (defun max-length (sequence)
  15. (apply #'max (map 'list (lambda (x) (length x)) sequence)))
  16.  
  17. (defun odai-pt13-681 (n &key (justify :center)
  18. (dot "::")
  19. (dot-display-width (length (string dot)))
  20. &aux (placeholder (make-string dot-display-width
  21. :initial-element #\*)))
  22. (labels ((r (n lines)
  23. (if (= n 0)
  24. lines
  25. (r (1- n)
  26. (append (mapcar (lambda (line)
  27. (format nil "~@?"
  28. (ecase justify
  29. (:center "~v:@<~A~>")
  30. (:left "~v@<~A~>")
  31. (:right "~v:<~A~>"))
  32. (+ (max-length lines)
  33. (length line))
  34. line))
  35. lines)
  36. (mapcar (lambda (line)
  37. (format nil "~A~A" line line))
  38. lines))))))
  39. (format nil "~{~A~%~}"
  40. (mapcar (lambda (s) (string-replace-all s placeholder dot))
  41. (r n (list placeholder))))))
  42.  
  43. (loop for n from 0 upto 5
  44. do (format t "~%n=~D~%~A~%"
  45. n (odai-pt13-681 n :dot #\木 :dot-display-width 2)))
  46.  
  47. (loop for justify in '(:left :center :right)
  48. do (format t "~A~%" (odai-pt13-681 4 :dot "##" :justify justify)))
  49.  
Success #stdin #stdout 0s 203840KB
stdin
Standard input is empty
stdout
n=0
木


n=1
 木 
木木


n=2
   木   
  木木  
 木  木 
木木木木


n=3
       木       
      木木      
     木  木     
    木木木木    
   木      木   
  木木    木木  
 木  木  木  木 
木木木木木木木木


n=4
               木               
              木木              
             木  木             
            木木木木            
           木      木           
          木木    木木          
         木  木  木  木         
        木木木木木木木木        
       木              木       
      木木            木木      
     木  木          木  木     
    木木木木        木木木木    
   木      木      木      木   
  木木    木木    木木    木木  
 木  木  木  木  木  木  木  木 
木木木木木木木木木木木木木木木木


n=5
                               木                               
                              木木                              
                             木  木                             
                            木木木木                            
                           木      木                           
                          木木    木木                          
                         木  木  木  木                         
                        木木木木木木木木                        
                       木              木                       
                      木木            木木                      
                     木  木          木  木                     
                    木木木木        木木木木                    
                   木      木      木      木                   
                  木木    木木    木木    木木                  
                 木  木  木  木  木  木  木  木                 
                木木木木木木木木木木木木木木木木                
               木                              木               
              木木                            木木              
             木  木                          木  木             
            木木木木                        木木木木            
           木      木                      木      木           
          木木    木木                    木木    木木          
         木  木  木  木                  木  木  木  木         
        木木木木木木木木                木木木木木木木木        
       木              木              木              木       
      木木            木木            木木            木木      
     木  木          木  木          木  木          木  木     
    木木木木        木木木木        木木木木        木木木木    
   木      木      木      木      木      木      木      木   
  木木    木木    木木    木木    木木    木木    木木    木木  
 木  木  木  木  木  木  木  木  木  木  木  木  木  木  木  木 
木木木木木木木木木木木木木木木木木木木木木木木木木木木木木木木木

##                              
####                            
##  ##                          
########                        
##      ##                      
####    ####                    
##  ##  ##  ##                  
################                
##              ##              
####            ####            
##  ##          ##  ##          
########        ########        
##      ##      ##      ##      
####    ####    ####    ####    
##  ##  ##  ##  ##  ##  ##  ##  
################################

               ##               
              ####              
             ##  ##             
            ########            
           ##      ##           
          ####    ####          
         ##  ##  ##  ##         
        ################        
       ##              ##       
      ####            ####      
     ##  ##          ##  ##     
    ########        ########    
   ##      ##      ##      ##   
  ####    ####    ####    ####  
 ##  ##  ##  ##  ##  ##  ##  ## 
################################

                              ##
                            ####
                          ##  ##
                        ########
                      ##      ##
                    ####    ####
                  ##  ##  ##  ##
                ################
              ##              ##
            ####            ####
          ##  ##          ##  ##
        ########        ########
      ##      ##      ##      ##
    ####    ####    ####    ####
  ##  ##  ##  ##  ##  ##  ##  ##
################################