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

Pages: 1-4041-8081-

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-24 22:32

>>> xmas = lambda m, c: (('*' * c).center(m)) + '\n' + xmas(m, c + 2) if c < m else '*'.center(m)
>>> tree = lambda n: xmas(n * 2, 1)
>>> print tree(10)
         *         
        ***        
       *****       
      *******      
     *********     
    ***********    
   *************   
  ***************  
 ***************** 
*******************
         *

Name: Anonymous 2008-12-24 22:40

christmasTree h = ct 1
              where ct i | i==(h+1) = foo (h-1) ++ bar 1
                         |otherwise = foo (h-i) ++ bar (2*i-1) ++ ct (i+1)
                    foo k | k>0 = " " ++ foo (k-1)
                    foo _ = ""
                    bar k | k>0 = "*" ++ bar (k-1)
                    bar _ = "\n"

main = putStr (christmasTree 10)



$ runhugs christmas.hs
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *

Name: Anonymous 2008-12-24 23:18

>>3-san, it's much nicer if you translate it into more idiomatic Haskell.

christmasTree h = ct h ++ replicate (h-1) ' ' ++ "*" where
    ct 0 = ""
    ct i = ct (i - 1) ++ replicate (h - i) ' ' ++ replicate (2*i-1) '*' ++ "\n"

main = putStr $ christmasTree 10

Name: Anonymous 2008-12-24 23:25

>>4
main = putStrLn "         *\n        ***\n       *****\n      *******\n     *********\n    ***********\n   *************\n  ***************\n *****************\n*******************\n         *"

Name: Anonymous 2008-12-24 23:26

(h-1)
(h - i)
apparently idiomatic haskell makes inconsistent use of whitespace.

Name: Anonymous 2008-12-24 23:28

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *
         "GRUNNUR"
         ;

Name: Anonymous 2008-12-24 23:35

sub christmas_tree($){
 return join"\n",(map{(' 'x($_[0]-$_)).('*'x($_*2-1}1..$_[0]),' 'x($_[0]-1).'*','';
}

print christmas_tree(10);

Name: Anonymous 2008-12-24 23:55

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *christmas_tree(int n){
 char *ret = calloc(1, n * 15 + n / 2 + 1);
 char *cur = ret;
 for(int i = 0; i < n; ++i){
  memset(cur, ' ', n - i - 1);
  cur += n - i - 1;
  memset(cur, '*', i * 2 + 1);
  cur += i * 2 + 1;
  *(cur++) = '\n';
 }
 memset(cur, ' ', n - 1);
 cur += n - 1;
 *cur = '*';
 return ret;
}

int main(void){
 puts(christmas_tree(10));
 return 0;
}

Name: Anonymous 2008-12-25 0:15

>>5

christmasTree i | i==10 = "         *\n        ***\n       *****\n      *******\n     *********\n    ***********\n   *************\n  ***************\n *****************\n*******************\n         *\n"
                | i==9 = "        *\n       ***\n      *****\n     *******\n    *********\n   ***********\n  *************\n ***************\n*****************\n        *\n"
                | i==8 = "       *\n      ***\n     *****\n    *******\n   *********\n  ***********\n *************\n***************\n       *\n"
                | i==7 = "      *\n     ***\n    *****\n   *******\n  *********\n ***********\n*************\n      *\n"
                | i==6 = "     *\n    ***\n   *****\n  *******\n *********\n***********\n     *\n"
                | i==5 = "    *\n   ***\n  *****\n *******\n*********\n    *\n"
                | i==4 = "   *\n  ***\n *****\n*******\n   *\n"
                | i==3 = "  *\n ***\n*****\n  *\n"
                | i==2 = " *\n***\n *\n"
                | otherwise = error "No."

Name: Anonymous 2008-12-25 0:20

>>7
lol\'d

Name: Anonymous 2008-12-25 4:07

>>11
Since it's Christmas, I'll tell you as a free public service; you ought to get that Alzheimer's looked at.

Name: Anonymous 2008-12-25 11:44

Did you mean: Alzheimer\'s

Name: Anonymous 2008-12-25 11:51

>>7
I shat myself

Name: Anonymous 2008-12-25 12:33

>>4
christmasTree h = putStr $ unlines $ take (h + 1) $ cycle $ take h
                         $ iterate ((++ "**") . tail) $ replicate h ' ' ++ "*"

Name: Anonymous 2008-12-25 13:20

aaaaaaaaaaaaaaaaaaaa $ aaaaaaaaaaaa
ccccccccc aaaaaaaaaa c naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
cccccccc aaaaaaaaaa ccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
ccccccc aaaaaaaaaa ccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
cccccc aaaaaaaaaa ccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
ccccc aaaaaaaaaa ccccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
cccc aaaaaaaaaa ccccccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
ccc aaaaaaaaaa ccccccccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
cc aaaaaaaaaa ccccccccccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
c aaaaaaaaaa ccccccccccccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
 aaaaaaaaaa ccccccccccccccccccc naaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaa
ccccccccc aaaaaaaaaa c

Name: Anonymous 2008-12-25 16:01

>>1
(define (christmas-tree h)
  (define (line n)
    (display (make-string (- h n) #\ ))
    (display (make-string (+ (* 2 n) 1) #\*))
    (newline))
  (do ((i 0 (+ i 1))) ((= i h))
    (line i))
  (line 0))


>>15
I lol'd.

Name: Anonymous 2008-12-25 16:08

(define kikes (lambda (n) (display (string-append (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append "|  " (f (- x 1))))))) (+ (* n 2) 1)) "\n" (f (- x 1))))))) n) (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append (string-append (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append "|  " (f (- x 1)))))))(- x 1)) (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append "---" (f (- x 1))))))) (- n (- x 1))) "|" (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append "---" (f (- x 1))))))) (- n (- x 1))) "  " (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "" (string-append "|  " (f (- x 1)))))))(- x 1)) "\n") (f (- x 1))))))) n) (((lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))) (lambda (f) (lambda (x) (if (< x 1) "|\n" (string-append "   " (f (- x 1))))))) n)))))

#;1> (kikes 4)
|  |  |  |  |  |  |  |  |
|  |  |  |  |  |  |  |  |
|  |  |  |  |  |  |  |  |
|  |  |  |  |  |  |  |  |
|  |  |  ---|---  |  |  |
|  |  ------|------  |  |
|  ---------|---------  |
------------|------------
            |

Name: Anonymous 2008-12-25 16:20

>>18
JEWS

Name: Anonymous 2008-12-25 16:37

>>18
LISP

Name: Anonymous 2008-12-25 17:17

Not this shit again. This thread stops here.

Name: Anonymous 2008-12-25 17:22

>>21
At least it isn't a ``Compiling Python code with a Ruby compiler`` thread.

Name: Anonymous 2008-12-25 17:28

import Control.Monad.Instances

kikes n = putStr $ unlines $ (++ [replicate (n * 3) ' ' ++ "|"])
                 $ (zipWith (flip (++) . ('|':)) =<< map reverse) $ map (concat . take n)
                 $ take (n * 2) $ iterate ((++ ["---"]) . tail) $ replicate (n * 2 - 1) "|  "

Name: Anonymous 2008-12-25 17:33

>>22 clearly knoweth not the correct usage of ``faggote quotes''.

Name: Anonymous 2008-12-25 18:42

>>24
I'm pretty sure that was supposed to be two pairs of empty shell backticks.

Name: Anonymous 2008-12-25 19:00

>>7
This filled me with the true "GRUNNUR" spirit. Thanks, you guys.

Name: Anonymous 2008-12-25 20:11

>>9
Now try again without leaking memory.

>>2
Not forceful enough.

Name: Anonymous 2008-12-25 20:17

¤ø„¸¸„ø¤º°¨``°º¤ø„¸ „ø¤º°¨
¨°º¤ø„¸♫ Wu-Tang ♫ „ø¤º°¨ copy
¸„ø¤º°¨♪ Forever for ♫ ``°º¤ø„¸ and paste
¨°º¤ø„¸♫ LIFE ♪„ø¤º°¨ „ø¤º°¨°º¤ø„¸if you agree fuck lil wayne

Name: Anonymous 2008-12-25 20:19

>>9
>calloc(1, n * 15 + n / 2 + 1);
wat

Name: Anonymous 2008-12-25 20:29

>>27
get a real operating system.

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);
    }
}

Name: Anonymous 2008-12-25 21:30


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M(v,s,c) (v)=malloc((s)); memset((v),(c),(s))
int main(int argc, char **argv) {
  int i,n;
  char *sp,*st;
  if(!argv[1])
    return 1;
  n = atoi(argv[1]);
  M(sp,n,' ');
  M(st,2*(n+2),'*');
  st[0]=0;
  for(i=0;i<n;i++) {
    sp[n-i-1]=0;
    printf("%s%s",sp,st);
    sp[n-i-1]=' ';
    st[i]='*';
    st[i+1]=0;
    printf("%s\n",st);
  }
  sp[n-1]=0;
  printf("%s*\n",sp);
  return 0;
}

Name: Anonymous 2008-12-25 21:36

>>31
ENTERPRISE QUALITY

However, Use of the default package is discouraged.

Name: Anonymous 2008-12-25 21:47

>>9
This segfaults for n=1000

Name: Anonymous 2008-12-25 22:16

>>32
fails for n<0

Name: Anonymous 2008-12-25 22:29

>>7
Is that BBCODE?

Name: Anonymous 2008-12-26 11:20

>>35
user error

Name: Anonymous 2008-12-26 15:25

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char ** argv) {
   int i, h = atoi(argv[1] ? argv[1] : (exit(1), NULL));
   char * str = malloc(h > 0 ? h * 3 : (exit(0), 0));
   memset(str, ' ', h - 1);
   memset(str + h - 1, '*', h * 2);
   for(i = 0; i <= h; i++) {
      fwrite(str + i % h, 1, h + i % h, stdout);
      puts("");
   }
   return free(str), 0;
}

Name: Anonymous 2008-12-26 17:10

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char ** argv) {
   int i, h = atoi(argv[1] ? argv[1] : (exit(1), NULL));
   char * str = malloc(h > 0 ? h : (exit(0), 0));
   memset(str, '*', h);
   for(i = 0; i <= h; i++)
      printf("%*s%s\n", h, str + h - 1 - i % h, str + h - i % h) ;
   return free(str), 0;
}

Name: Anonymous 2008-12-26 18:15

[code]                                                 *[code]

Name: Anonymous 2008-12-26 18:16

                                                ***

Name: Anonymous 2008-12-26 18:16

                                               *****

Name: Anonymous 2008-12-26 18:16

                                              *******

Name: Anonymous 2008-12-26 18:16

                                             *********

Name: Anonymous 2008-12-26 18:16

                                            ***********

Name: Anonymous 2008-12-26 18:17

                                           *************

Name: Anonymous 2008-12-26 18:17

                                          ***************

Name: Anonymous 2008-12-26 18:17

                                         *****************

Name: Anonymous 2008-12-26 18:17

                                        *******************

Name: Anonymous 2008-12-26 18:17

                                       *********************

Name: Anonymous 2008-12-26 18:17

                                      ***********************

Name: Anonymous 2008-12-26 18:18

                                     *************************

Name: Anonymous 2008-12-26 18:18

                                    ***************************

Name: Anonymous 2008-12-26 18:18

                                   *****************************

Name: Anonymous 2008-12-26 18:18

                                  *******************************

Name: Anonymous 2008-12-26 18:18

                                 *********************************

Name: Anonymous 2008-12-26 18:18

                                ***********************************

Name: Anonymous 2008-12-26 18:19

                               *************************************

Name: Anonymous 2008-12-26 18:19

                              ***************************************

Name: Anonymous 2008-12-26 18:19

                             *****************************************

Name: Anonymous 2008-12-26 18:19

                            *******************************************

Name: Anonymous 2008-12-26 18:19

                           *********************************************

Name: Anonymous 2008-12-26 18:19

                          ***********************************************

Name: Anonymous 2008-12-26 18:20

                         *************************************************

Name: Anonymous 2008-12-26 18:20

                        ***************************************************

Name: Anonymous 2008-12-26 18:20

                       *****************************************************

Name: Anonymous 2008-12-26 18:20

                      *******************************************************

Name: Anonymous 2008-12-26 18:20

                     *********************************************************

Name: Anonymous 2008-12-26 18:20

                    ***********************************************************

Name: Anonymous 2008-12-26 18:21

                   *************************************************************

Name: Anonymous 2008-12-26 18:21

                  ***************************************************************

Name: Anonymous 2008-12-26 18:21

                 *****************************************************************

Name: Anonymous 2008-12-26 18:22

                *******************************************************************

Name: Anonymous 2008-12-26 18:23

LISP

Name: Anonymous 2008-12-27 18:27

> let n = 10 in mapM_ (putStrLn . liftM2 (++) (flip replicate ' ' . (`div`2) . (n*2-)) (flip replicate '*')) $ filter odd [1..n*2] ++ [1]
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *

Name: Anonymous 2008-12-27 18:44

>>75
Enjoy your O(h^2) runtime.

Name: Anonymous 2008-12-27 19:16

>>2
Two functions and a conditional? Really?
>>> tree = lambda k: '\n'.join(('*' * n).center(2 * k) for n in range(1, 2 * k, 2) + [1])

Name: Anonymous 2008-12-27 19:56

>>75
>>15 is still superior.

Name: I CAN DO FUNCTIONAL TOO 2008-12-27 19:58

#include <iostream>
#include <string>

template < size_t n, size_t n1 >
struct _xmastree {
    static const std::string val;
};

template < size_t n, size_t n1 >
const std::string _xmastree< n, n1 >::val =
    _xmastree< n, n1 - 1 >::val +
    std::string( "\n" ) +
    std::string( n - n1, ' ' ) +
    std::string( n1 * 2 + 1, '*' );

template < size_t n >
struct _xmastree< n, 0 > {
    static const std::string val;
};

template < size_t n >
const std::string _xmastree< n, 0 >::val =
    std::string( n, ' ' ) +
    std::string( "*" );

template < size_t n >
struct xmastree {
    static const std::string val;
};

template < size_t n >
const std::string xmastree< n >::val =
    _xmastree< n, n >::val +
    std::string( "\n" ) +
    std::string( n, ' ' ) +
    std::string( 1, '*' );

template <>
const std::string xmastree< 0 >::val = "\"GRUNNER\"";

int main( int argc, char *argv[] ) {
    std::cout << xmastree<10>::val << std::endl;
    return 0;
}

Name: Anonymous 2008-12-27 20:24

>>76
along with my job

Name: Anonymous 2008-12-27 20:32


#!/bin/bash
[ -z "$1" ] && exit
l='*'
s='                                                                           '
for i in $(seq 1 $1)
do
  echo -n "$(echo "$s" | cut -b$i-$1)"
  echo "$l"
  l=$(echo "$l" | sed 's/^/*/' | sed 's/$/*/')
done
echo "$(echo "$s" | cut -b-$1)*"

Name: Anonymous 2008-12-27 20:53

>>81
#!/bin/sh

n=$(($1+0))
stars='*'

for i in $(seq 1 $n); do
 printf "%$(($n+$i-1))s\n" "$stars"
 stars="**$stars"
done

printf "%${n}s\n" '*'

Name: Anonymous 2008-12-27 20:54

>>80
lol\'d

Name: Anonymous 2008-12-27 20:56


#include <stdio.h>
#define a(e) for(s=0;s<(e);s++)
#define x(a) putchar((a)^040);
#define f x(n);x(040|n)
int main(int argc, char **argv) {
int s,l=1,n=10;for(;l<=n;l++){a(n-l)x(0);
a(((l-1)<<1)+1)f;}a(n)x(0);f;return 0;}

Name: Anonymous 2008-12-27 21:21

>>84
#include <stdio.h>
#define a(e,i) for((i)=1;(i)<=(e);++(i))
#define x(a) putchar((a)^040)
#define f x(n);x(040|n)
int main(void){int i,j,n=10;a(n,i){a(n-i,j)x(0);
a(((i-1)<<1)+1,j)f;}a(n-1,i)x(0);f;return 0;}

Name: Anonymous 2008-12-27 21:59

>>> tree = lambda k: '\n'.join(' '*(k-n-1)+'*'*2*n+'*' for n in map(k.__rmod__,range(k+1))

Name: Anonymous 2008-12-27 22:10

lol iteration

Name: Anonymous 2009-03-06 17:47


             ▲
            ▲ ▲
           ▲ ▲ ▲
          ▲ ▲ ▲ ▲
         ▲ ▲ ▲ ▲ ▲
        ▲ ▲ ▲ ▲ ▲ ▲
       ▲ ▲ ▲ ▲ ▲ ▲ ▲
      ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
     ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
    ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
   ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
  ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
 ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
 ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
  ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
   ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
    ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
     ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
      ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
       ▼ ▼ ▼ ▼ ▼ ▼ ▼
        ▼ ▼ ▼ ▼ ▼ ▼
         ▼ ▼ ▼ ▼ ▼
          ▼ ▼ ▼ ▼
           ▼ ▼ ▼
            ▼ ▼
             ▼

Name: Anonymous 2009-03-06 20:35

>>89
phail

Name: Anonymous 2009-03-06 21:12

>>89
A yellow rupee? For me?

Name: Anonymous 2009-03-06 21:57


#!/usr/bin/ruby
puts Array.new(11){|e|(e>9&&e=0;'*'*e*2)+'*'}.map!{|e|e.center(19)}

Name: Anonymous 2009-03-06 22:01

"GRUNNA"

Name: Anonymous 2009-03-06 22:06

"GRANDMA"


am i doint rite

Name: Anonymous 2009-03-06 22:08

"GRANDMASTER"

Name: Anonymous 2009-03-06 23:06

>>7 still makes me feel warm and fuzzy when I look at it.

Name: Anonymous 2009-03-07 0:48

>>92
lel wot

Name: Anonymous 2009-03-07 6:24

>>97
lel its ruby

Name: Anonymous 2009-08-16 22:59

Lain.

Name: Anonymous 2011-02-03 8:31


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