Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

christmas tree

Name: Anonymous 2008-12-24 22:21

(define (christmasTree h)
    (define (foo k)
        (if (< k 1)
            "" (string-append " " (foo (- k 1)))))
    (define (bar k)
        (if (< k 1)
            "\n" (string-append "*" (bar (- k 1)))))
    (define (ct i)
        (if (= i (+ h 1))
            (string-append
                (foo (- h 1))
                (bar 1))
            (string-append
                (foo (- h i))
                (bar (- (* 2 i) 1))
                (ct (+ i 1)))))
    (display (ct 1)))


#;1> (christmasTree 10)
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *

Name: Anonymous 2008-12-25 20:47

import java.lang.*;

public class Kurisumasu {
    final int height;
   
    public Kurisumasu(int h)
    {
        height = h;
    }
   
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        final String nl = System.getProperty("line.separator", "\n");
        for(int i=1; i<height; i++)
        {
            for(int j=0; j<height-i; j++)
                sb.append(' ');
            for(int j=1; j<i*2; j++)
                sb.append('*');
            sb.append(nl);
        }
        for(int j=0; j<9; j++)
            sb.append(' ');
        sb.append('*');
        sb.append(nl);
        return sb.toString();
    }
   
    public static void main(String[] args)
    {
        final Kurisumasu k = new Kurisumasu(10);
        System.out.print(k);
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List