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

Pages: 1-

Post your Sierpinksi

Name: Anonymous 2011-01-17 17:40

Write a program to print k-th iteration (where k is given as an argument) of the Sierpinski triangle on standard output in your language of choice, then post it in this thread. Convoluted solutions more than welcome.

Name: Anonymous 2011-01-17 17:44

gtfo

Name: Anonymous 2011-01-17 17:44

In this thread, we post screwed up triforce code.

Name: Anonymous 2011-01-17 17:47

inb4 perl code golf

Name: Anonymous 2011-01-17 17:52

[/code]import System
import Data.List
import Control.Monad

a >< b = zipWith (++) a b

sierpinski triangleChar spaceChar depth =
   intercalate "\n" $ recursion depth ++ [[]]
   where
      recursion depth
         | depth  < 1 = error "Depth must be greater than zero"
         | depth == 1 = [[triangleChar]]
         | otherwise = sideSpace >< recurse  >< sideSpace ++
                       recurse   >< midSpace >< recurse
         where
            nextDepth = depth - 1
            recurse = recursion nextDepth

            spaceSize = 2 ^ (nextDepth - 1)
            midSpace = replicate spaceSize [spaceChar]
            sideSpace = replicate spaceSize $ replicate spaceSize spaceChar

main =
   do [triangleChar: spaceChar: [], depth] <- getArgs
      putStr $ sierpinski triangleChar spaceChar (read depth :: Int)[/code]

Name: Anonymous 2011-01-17 17:52

import System
import Data.List
import Control.Monad

a >< b = zipWith (++) a b

sierpinski triangleChar spaceChar depth =
   intercalate "\n" $ recursion depth ++ [[]]
   where
      recursion depth
         | depth  < 1 = error "Depth must be greater than zero"
         | depth == 1 = [[triangleChar]]
         | otherwise = sideSpace >< recurse  >< sideSpace ++
                       recurse   >< midSpace >< recurse
         where
            nextDepth = depth - 1
            recurse = recursion nextDepth

            spaceSize = 2 ^ (nextDepth - 1)
            midSpace = replicate spaceSize [spaceChar]
            sideSpace = replicate spaceSize $ replicate spaceSize spaceChar

main =
   do [triangleChar: spaceChar: [], depth] <- getArgs
      putStr $ sierpinski triangleChar spaceChar (read depth :: Int)

Name: Anonymous 2011-01-17 20:27

FUCK YOU FUNCTIONAL MONAD FAGS... REAL MEAN USE C AND DONT USE RECURSION LOL. CRUMBLE AT MY ENTERPRISE GRADE SOLUTION


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define I (strlen(i))

int main(int argc, char **argv) {
    int k,p,g;
    char *i,**f;
    argv[1] ? k = 1<<atoi(argv[1]) : exit(1);
    i = malloc(k+1);
    memset(i,32,k);
    f = malloc((k>>1)*sizeof(i));
    for(p=0;p<k;p+=2) {
        f[p>>1] = malloc(k-p);
        memset(f[p>>1],32,k-p);
    }
    for(i=i+k;I!=k;--i) {
        if(*i)
            printf("%s%s",i,i);
        for(g=p=0;(I<(k>>1)) && (p<(k-(I<<1)));p++) {
            f[I][p] = (!I || ((p+I)&I)>(I-1))? '#' : '.';
            printf("%C ",f[I][p]);
            g++;
        }
        for(p=I-1;p>=0 && I<=(k>>1);p--) {
            printf("%C ",f[p][g+((I-p)-1)]);
        }
        g = 0;
        for(p=(k-I)-1;p>=0 && I>(k>>1);p--) {
            printf("%C ",f[p][g++]);
        }
        printf("\n");
    }
    return 0;
}

Name: Anonymous 2011-01-17 20:31

this thread still blows

also OP shouldn't try to frame this as an assignment when all he really wants to do is show off some code he's written.

also all code in this thread is ugly and tl;dr.

Name: Anonymous 2011-01-17 21:13

#!/usr/bin/perl

@s="*"; $d=shift || 6;
for $l (0..$d-2) {
    push @s, map {sprintf "%-*s%s", 2**$l, $_, $_} @s;
}
print "$_\n" for @s;

Name: Anonymous 2011-01-17 23:13

Easy version:

#include <stdio.h>

int main(int argc, char *argv[])
{
    int x, y, n;

    n = (argv[1] ? 1 << atoi(argv[1]) : 64);

    for (x = 0; x < n; x++) {
        for (y = 0; y < n; y++) {
            putchar(x & y ? ' ' : '#');
        }
        putchar('\n');
    }

    return 0;
}

Name: Anonymous 2011-01-18 6:58

>>8
U mad?

Name: Anonymous 2011-01-18 7:01

>>10
disqualified. failed to include <stdlib.h>"

Name: Anonymous 2011-01-18 13:22

bump

Name: Anonymous 2011-01-18 15:13

CA method:
lsh x = tail x ++ [head x]
rsh x = [last x] ++ init x
disp True  = '#'
disp False = ' '

sierpFirst s =
  map (disp . (== s)) [1..s*2]

nextSierp row =
  map disp $ zipWith (/=) (rsh row) (lsh row)

sierpinski iters =
  let size = 2 ^ iters
  in take size $ iterate nextSierp $ sierpFirst size

main = do
  putStrLn "Iterations:"
  n <- getLine
  mapM_ putStrLn $ sierpinski (read n)

Name: Anonymous 2011-01-18 16:20

mov ax h13 | int h10 | mov bp sp
mov w[bp,0] h6480 | mov w[bp,2] h80 | mov w[bp,4] hc700 | mov w[bp,6] hc7ff | mov w[bp,8] h0
mov ax ha000 | mov es ax
mov dx ds | xor ax ax | mov ds ax | mov al [h41a | mov ah [h41c | mov ds dx | cmp ah al | jne h18e
mov bx [bp,8] | inc bx | cmp bx -1 | jne h143 | xor bx bx | mov [bp,8] bx | mov dx [bx | and dx 3 | cmp dl 0 | je h125
mov bx dx | shl bx | add bx bp
mov ch 0 | mov ah 0 | mov al [bx | mov cl [bp | add cx ax | shr cx | mov [bp cl
mov di cx
mov ch 0 | mov ah 0 | mov al [bx,1 | mov cl [bp,1 | add cx ax | shr cx | mov [bp,1 cl
mov ax h140 | mul cx | add di ax
mov ax ds | mov cx ha000 | mov ds cx | mov bx di | mov [bx 15 | mov ds ax
jmp h125 | mov ax 3 | int h10 | ret

Name: Anonymous 2011-01-19 4:51

mov ax h13 | int h10 | mov bp sp

And not a single comma was pressed that day? WTF is wrong with you, dude?

Name: Anonymous 2011-01-19 5:16

>>16
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Name: Anonymous 2011-01-19 5:46

>>17
Please immediately return the superfluous commas! Some people suffer because of the comma shortage! (see >>15)

Name: Anonymous 2011-01-19 7:26

>>18
in china we have many comma and we horde them so west will run out of comma, and then we can sell comma to west at high price!

Name: Anonymous 2011-01-19 8:32

>>19
too bad korea have many comma factory and can corner comma market

can't beat korea

Name: Anonymous 2011-01-19 8:37

This is almost as intense as the semicolon deficiency, late last year.

Name: LISPPER 2011-01-19 9:01

>>21
I can give you all the semicolons you want, but please give me some parentheses!

Name: TBL Berners-Lee 2011-01-19 9:44

>>22
All I can give you are some angle brackets. You'll have to make do with them.

Name: SGML Guy 2011-01-19 11:23

>>23
Oh, I'll make do all right. I'll make do.

Name: Anonymous 2011-01-19 13:14

$ make do

Name: Anonymous 2011-01-19 13:52

>>25
0]=> make do
make: *** No rule to make target `do'.  Stop.
2]=>

Name: Anonymous 2011-01-19 17:19

>>24
Do they even make you anymore?

Name: Anonymous 2011-02-04 13:30


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