48

This is inspired by/taken from this thread: http://www.allegro.cc/forums/thread/603383

The Problem

Assume the user gives you a numeric input ranging from 1 to 7. Input should be taken from the console, arguments are less desirable.

When the input is 1, print the following:

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

Values greater than one should generate multiples of the pattern, ending with the one above, but stacked symmetrically. For example, 3 should print the following:

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

Bonus points if you print the reverse as well.

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

Can we try and keep it to one answer per language, that we all improve on?

rekire
  • 47,260
  • 30
  • 167
  • 264
Grant Paul
  • 5,852
  • 2
  • 33
  • 36

23 Answers23

38

Assembler, 165 bytes assembled

Build Instructions

  1. Download A86 from here
  2. Add a reference to the A86 executable into your DOS search path
  3. Paste the code below into a text file (example: triforce.asm)
  4. Invoke the assembler: a86 triforce.asm
  5. This will create a .COM file called triforce.com
  6. Type triforce to run

This was developed using the standard WinXP DOS box (Start->Programs->Accessories->Command Prompt). It should work with other DOS emulators.

Assemble using A86 and requires WinXP DOS box to run the .COM file it produces. Press 'q' to exit, keys 1-7 to draw the output.

  l20:mov ah,7
      int 21h
      cmp al,'q'
      je ret
      sub al,'0'
      cmp al,1
      jb l20
      cmp al,7
      ja l20
      mov [l0-1],al
      mov byte ptr [l7+2],6
      jmp $+2
      mov ah,2
      mov ch,0
      mov bh,3
   l0:mov bl,1
   l1:mov dh,0
   l3:cmp dh,ch
      je l2
      mov dl,32
      int 21h
      inc dh
      jmp l3
      ret
   l2:mov dh,bh
   l6:mov cl,12
   l5:mov dl,42
      cmp cl,bl
      ja l4
      mov dl,32
      cmp dh,1
      je l21
   l4:int 21h
      dec cl
      jnz l5
  l21:dec dh
      jnz l6
      mov dl,10
      int 21h
      mov dl,13
      int 21h
  l10:inc ch
   l9:add bl,2
   l7:cmp ch,6
      jne l1
  l13:add byte ptr [l7+2],6
  l11:dec bh
  l12:cmp bh,0
      jne l0
      xor byte ptr [l0+1],10
      xor byte ptr [l9+1],40
      xor byte ptr [l10+1],8
      xor byte ptr [l13+1],40
      sub byte ptr [l7+2],12
      mov dh,[l0-1]
      inc dh
      xor [l12+2],dh
      xor byte ptr [l11+1],8
      xor byte ptr [l1+1],1
      inc bh
      cmp byte ptr [l0+1],11
      je l0
      jmp l20

It uses lots of self-modifying code to do the triforce and its mirror, it even modifies the self-modifying code.

Skizz
  • 69,698
  • 10
  • 71
  • 108
  • 10
    I could post a Base64 encoded chunk of machine code if you want ;) – Skizz Mar 09 '10 at 14:02
  • 3
    Skizz, isn't the language called Assembly and not Assembler? – b.roth Mar 09 '10 at 14:29
  • 3
    @Bruno: I don't think it's really a language as such. The text is just a list of machine code mnemonics that an assembler converts to machine code. Although this is often referred to as assembly language, there is no standard way of describing it, even on a single CPU it can be written in several forms. For example, Intel specifies mnemonics as `op dest,src` whereas a gcc listing has `op src,dest`. Wikipedia has a section on the terminology: http://en.wikipedia.org/wiki/Assembly_language#Related_terminology. It says that calling it assembler is a synonym for assembly but can lead to confusion. – Skizz Mar 09 '10 at 15:34
  • http://pastebin.com/vnust9Qt 141 byte entry based on Skizz entry using int 0x29 and argument (1-9) from the commandline (and changed two inc dl to inc dx to save two bytes). – Jonas Engström Mar 10 '10 at 07:47
  • I'd love it if someone could tell us how to compile and launch this thing. Impressed! – Agnel Kurian Mar 10 '10 at 10:29
  • @Agnel: I've added build instructions. – Skizz Mar 10 '10 at 11:19
  • @Skizz, My screen's "melt"ing out here! Great stuff!! – Agnel Kurian Mar 10 '10 at 14:07
  • 1
    I love how this person has written self-modifying assembly code and self-modifying self-modifying code and there are still some people who want to nit-pick about "assembly" vs. "assembler." From where I'm bowing, it's all the same. This person has done something pretty amazing to me! – Dinah Mar 10 '10 at 20:36
  • 1
    very clever! although even if we count the output size, the other examples are shorter (43 chars = 43 bytes < 165 bytes) – Claudiu Mar 11 '10 at 22:40
  • 2
    IMHO, the key in code golf is how to complete a task with minimum code, that YOU write. So count the code you wrote, and not the compiled one. Or write already compiled code. – Kamarey Mar 11 '10 at 23:17
  • 4
    @Kamarey: No, I think there's more to code golf than that. Language comparisons for one. Show off your skill at programming (could you show me a programmer who doesn't?). Clever implementations. etc. Would the person who wrote the python interpreter have to include that code if they posted a python version? I could create a new languauge, triforce for example, that has a single letter command which implements a solution to this problem - should I include the language code or could I claim a result of 1 char (golfscript anyone?) On this site, I think size is less important. But what do I know? – Skizz Mar 12 '10 at 09:37
  • 1
    @Skizz, Whatever gave you the idea that code golf is not just about size? Code golf is *exactly* about shortest code. It's this simple: Each character corresponds to a golf stroke. You don't win golf by doing fancy shots do you? – John La Rooy Mar 17 '10 at 20:47
  • 1
    @gnibbler: On this site, if it was just about size, we'd all be writing these things using golfscript. It might be about size, but it's also about different languages and how much they can be abused to get the smallest code, and about finding clever solutions. It is interesting to see code reduced in size for each langauge as each language requires a different approach. – Skizz Mar 18 '10 at 09:27
  • 1
    @Skizz, See here for a discussion of what code-golf is on this site. http://meta.stackexchange.com/questions/20736/what-is-code-golf-on-stack-overflow Generally people upvote answers that they like or are cool, but the OP accepts the shortest answer. – John La Rooy Mar 19 '10 at 08:16
23

GolfScript - 43 chars

~:!6*,{:^' '
 *'*'12*' '
  ^6%.+)*+
   -12>!^
    6/-*
     n}
     /

~:!6*,{:^' '*'*'12*' '^6%.+)*+-12>!^6/-*n}/

48 Chars for the bonus

~:!6*,.-1%+{
 :^' '*'*'12
  *' '^6%.+
   )*+-12>
    !^6/-
     *n}
      /

~:!6*,.-1%+{:^' '*'*'12*' '^6%.+)*+-12>!^6/-*n}/
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
17

Python - 77 Chars

n=input()
for k in range(6*n):print' '*k+('*'*12+' '*(k%6*2+1))[-12:]*(n-k/6)

n=input()
for k in range(6*n):j=1+k%6*2;print' '*k+('*'*(12-j)+' '*j)*(n-k/6)

89 Chars for the bonus

n=input();R=range(6*n)
for k in R+R[::-1]:print' '*k+('*'*11+' '*11)[k%6*2:][:12]*(n-k/6)

114 Chars Version just using string replacements

u,v=' *';s=(v*11+u)*input()
while s.strip():print s;s=u+s.replace(*((v*2+u,u*3),(v*1+u*10,v*11))[' * 'in s])[:-2]

Unk Chars all in one statement, should work w/ 2.x and 3.x. The enumerate() is to allow the single input() to work for both places you need to use it.

print ('\n'.join('\n'.join(((' '*(6*n))+' '.join(('%s%s%s'%(' '*(5-x),'*'*(2*x+1),' '*(5-x)) for m in range(i + 1)))) for x in range(5,-1,-1)) for n, i in enumerate(range(int(input())-1,-1,-1))))

Yet Another Method

def f(n): print '\n'.join(' '*6*(n-r)+(' '*(5-l)+'*'*(l*2+1)+' '*(5-l)+' ')*r for r in xrange(1, n+1) for l in xrange(6))
f(input())
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • Unk Chars won't work in 3.x because in 3.x `print` is a function ;) – kennytm Mar 09 '10 at 11:08
  • Unk Chars should be fixed now for both 2.x and 3.x – Noctis Skytower Mar 09 '10 at 13:02
  • x=xrange; ... x(6) should shorten the Yet another Method – Hamish Grubijan Mar 09 '10 at 17:03
  • For someone that is trying to learn python (and programming in general), where would I be able to find an explanation of how one arrives to this answer?. I think what I'm trying to ask, is, having read the question, I currently have no clue how where I would start implementing a solution to it. Any pointers? Cheers. – prevailrob Apr 01 '10 at 12:15
13

Ruby - 74 Chars

(6*n=gets.to_i).times{|k|puts' '*k+('*'*(11-(j=k%6*2))+' '*(j+1))*(n-k/6)}
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
12

COBOL - 385 Chars

$ cobc -free -x triforce.cob && echo 7| ./triforce

PROGRAM-ID.P.DATA DIVISION.WORKING-STORAGE SECTION.
1 N PIC 9.
1 M PIC 99.
1 value '0100***********'.
2 I PIC 99.
2 K PIC 99.
2 V PIC X(22). 
2 W PIC X(99).
PROCEDURE DIVISION.ACCEPT N
COMPUTE M=N*6
PERFORM M TIMES
DISPLAY W(1:K)NO ADVANCING
PERFORM N TIMES
DISPLAY V(I:12)NO ADVANCING
END-PERFORM
DISPLAY ''
ADD 2 TO I
IF I = 13 MOVE 1 TO I ADD -1 TO N END-IF
ADD 1 TO K
END-PERFORM.

K could be returned to outside the group level. An initial value of zero for a numeric with no VALUE clause is compiler-implementation dependent, as is an initial value of space for an alpha-numeric field (W has been cured of this, at no extra character cost). Moving K back would save two characters. -free is compiler-dependant as well, so I'm probably being over-picky.

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
9

sed, 117 chars

s/$/76543210/
s/(.).*\1//
s/./*********** /gp
:
s/\*(\**)\*/ \1 /gp
t
:c
s/\* {11}\*/ ************/
tc
s/\*  /   /p
t

Usage: $ echo 7 | sed -rf this.sed

First attempt; improvements could probably be made...

KirarinSnow
  • 1,062
  • 2
  • 9
  • 22
7

Ruby 1.9 - 84 characters :

v=gets.to_i
v.times{|x|6.times{|i|puts' '*6*x+(' '*i+'*'*(11-2*i)+' '*i+' ')*(v-x)}}
Gdeglin
  • 12,432
  • 5
  • 49
  • 65
7

Perl - 72 chars

die map$"x$_.("*"x(12-($l=1+$_%6*2)).$"x$l)x($n-int$_/6).$/,0..6*($n=<>)

78 chars

map{$l=$_%6*2;print$"x$_,("*"x(11-$l).$"x$l.$")x($n-int$_/6),$/}0..6*($n=<>)-1

87 chars

$n=<>;map{$i=int$_/6;$l=$_%6*2;print$"x$_,("*"x(11-$l).$"x$l.$")x($n-$i),$/}(0..6*$n-1)

97 chars

$n=<>;map{$i=int$_/6;$l=$_%6;print$"x(6*$i),($"x$l."*"x(11-2*$l).$"x$l.$")x($n-$i),$/}(0..6*$n-1)

108 chars

$n=<>;map{$i=int$_/6;$l=$_%6;print ""." "x(6*$i),(" "x$l."*"x(11-2*$l)." "x$l." ")x($n-$i),"\n";}(0..6*$n-1)
mob
  • 117,087
  • 18
  • 149
  • 283
Dustin Howett
  • 1,635
  • 11
  • 13
6

Powershell, 78 characters

0..(6*($n=read-host)-1)|%{" "*$_+("*"*(12-($k=1+$_%6*2))+" "*$k)*(.4+$n-$_/6)}

Bonus, 92 characters

$a=0..(6*($n=read-host)-1)|%{" "*$_+("*"*(12-($k=1+$_%6*2))+" "*$k)*(.4+$n-$_/6)}
$a
$a|sort

The output is stored in an array of strings, $a, and the reverse is created by sorting the array. We could, of course, just reverse the array, but it would be more characters to type :)

Danko Durbić
  • 7,077
  • 5
  • 34
  • 39
5

Haskell - 131 138 142 143 Chars

(⊗)=replicate
z o=[concat$(6*n+m)⊗' ':(o-n)⊗((11-m-m)⊗'*'++(1+m+m)⊗' ')|n<-[0..o-1],m<-[0..5]]
main=getLine>>=mapM_ putStrLn.z.read

This one is longer (146 148 chars) at present, but an interesting, alternate line of attack:

(⊗)=replicate
a↑b|a>b=' ';_↑_='*'
z o=[map(k↑)$concat$(6*n)⊗' ':(o-n)⊗"abcdefedcba "|n<-[0..o-1],k<-"abcdef"]
main=getLine>>=mapM_ putStrLn.z.read
MtnViewMark
  • 5,120
  • 2
  • 20
  • 29
5

FORTRAN - 97 Chars

Got rid of the #define and saved 8 bytes thanks to implict loops!

$ f95 triforce.f95  -o triforce && echo 7 | ./triforce

READ*,N
DO K=0,N*6
M=2*MOD(K,6)
PRINT*,(' ',I=1,K),(('*',I=M,10),(' ',I=0,M),J=K/6+1,N)
ENDDO
END

125 bytes for the bonus

READ*,N
DO L=1,N*12
K=L+5
If(L>N*6)K=N*12-L+6
M=2*MOD(K,6)
PRINT"(99A)",(32,I=7,K),((42,I=M,10),(32,I=0,M),J=K/6,N)
ENDDO
END

FORTRAN - 108 Chars

#define R REPEAT
READ*,N
DO I=0,6*N
J=MOD(I,6)*2
PRINT*,R(' ',I)//R(R('*',11-J)//R(' ',J+1),N-I/6)
ENDDO
END
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
4

JavaScript 1.8 - SpiderMonkey - 118 chars

N=readline()
function f(n,c)n>0?(c||' ')+f(n-1,c):''
for(i=0;i<N*6;i++)print(f(i)+f(N-i/6,f(11-(z=i%6*2),'*')+f(z+1)))

w/ bonus - 151 chars

N=readline()
function f(n,c)n>0?(c||' ')+f(n-1,c):''
function l(i)print(f(i)+f(N-i/6,f(11-(z=i%6*2),'*')+f(z+1)))
for(i=0;i<N*6;i++)l(i)
for(;i--;)l(i)

Usage: js thisfile.js

JavaScript - In Browser - 154 characters

N=prompt()
function f(n,c){return n>0?(c||' ')+f(n-1,c):''}
s='<pre>'
for(i=0;i<N*6;i++)s+=f(i)+f(N-i/6,f(11-(z=i%6*2),'*')+f(z+1))+'\n'
document.write(s)

The non-obfuscated version (before optimizations by gnarf):

var N = prompt();
var S = ' ';

function fill(c, n) {
    for (ret=''; n--;)
        ret += c;
    return ret;
}

var str = '<pre>';

for (i=0; i<N*6; i++) {
    str += fill(S, i);
    for (j=0; j<N-i/6; j++)
        str += fill('*', 11-i%6*2) + fill(S, i%6*2+1);
    str += '\n';
}

document.write(str);

Here's a different algorithm that uses replace() to go from one line to the next of each line of a triangle row:

161 characters

N=readline()
function f(n,c){return n>0?(c||' ')+f(n-1,c):''}l=0
for(i=N;i>0;){r=f(i--,f(11,'*')+' ');for(j=6;j--;){print(f(l++)+r)
r=r.replace(/\*\* /g,'   ')}}
gnarf
  • 105,192
  • 25
  • 127
  • 161
Joey Adams
  • 41,996
  • 18
  • 86
  • 115
  • Functions must have braces, at least in the Spidermonkey 'js' commandline programs packaged in the latest Fedora and Ubuntu releases. I recommend the person who removed the braces indicate what versions of Spidermonkey this works in. – Joey Adams Mar 10 '10 at 02:58
  • 1
    JavaScript-C 1.8.0 ... Works fine from the `spidermonkey-bin` debian package.. Functions don't need braces or "return" for single line functions since JavaScript 1.8.0 - See http://stackoverflow.com/questions/2350718 – gnarf Mar 10 '10 at 09:57
4

F#, 184 181 167 151 147 143 142 133 chars

let N,r=int(stdin.ReadLine()),String.replicate
for l in[0..N*6-1]do printfn"%s%s"(r l" ")(r(N-l/6)((r(11-l%6*2)"*")+(r(l%6*2+1)" ")))

Bonus, 215 212 198 166 162 158 157 148 chars

let N,r=int(stdin.ReadLine()),String.replicate
for l in[0..N*6-1]@[N*6-1..-1..0]do printfn"%s%s"(r l" ")(r(N-l/6)((r(11-l%6*2)"*")+(r(l%6*2+1)" ")))
Danko Durbić
  • 7,077
  • 5
  • 34
  • 39
m0sa
  • 10,712
  • 4
  • 44
  • 91
  • 1
    You can improve this by 17 characters. "Int32.Parse" can be just "int". Then get rid of "open System" and just do System.Console. Get rid of needless space after "concat". Get rid of needless parens (left paren after semicolon, left paren after z=). – Brian Mar 11 '10 at 05:55
  • 1
    Also, you can save a character with `let z=(l%6)*2+1`, and `r(12-z)"*"` and `r z" "`. – Danko Durbić Mar 11 '10 at 16:03
  • Int32 cannot be replaced with just int.. That's why I need the open System. – m0sa Mar 11 '10 at 18:40
  • @m0sa: `int` is a function; see: http://msdn.microsoft.com/en-us/library/ee370576(v=VS.100).aspx . I've updated your answer; hope you don't mind :) – Danko Durbić Mar 11 '10 at 21:49
  • It turns out we save 4 more chracters if we remove the whole `let z=...` thing and just use the expression directly :) – Danko Durbić Mar 11 '10 at 22:31
  • ...and 4 more if we assign `N` and `r` as a tuple. – Danko Durbić Mar 11 '10 at 23:11
  • @danko Well, this is (was) actually the first "program" I've written in F#. So thank you for your comments, I've learned a lot from them :) – m0sa Mar 11 '10 at 23:30
  • with the removal of let z in the for loop you can also remove the newline after for ... do! – m0sa Mar 11 '10 at 23:35
  • Excellent! I've just found out you can use `stdin` instead of `System.Console`. -9 chars! – Danko Durbić Mar 12 '10 at 13:16
4

C - 120 Chars

main(w,i,x,y){w=getchar()%8*12;for(i=0;i<w*w/2;)y=i/w,x=i++%w,putchar(x>w-2?10:x<y|w-x-1<y|(x-y)%12>=11-2*(y%6)?32:42);}

Note that this solution prints some trailing spaces (which is okay, right?). It also relies on relational operators having higher precedence than bitwise OR, saving two characters.

124 Chars

main(n,i,k){n=getchar()&7;for(k=0;k<6*n;k++,putchar(10))for(i=-k-1;++i<12*n-2*k-1;putchar(32+10*(i>=0&&(11-i%12>2*k%12))));}
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
3

C - 177 183 Chars

#define P(I,C)for(m=0;m<I;m++)putchar(C)
main(t,c,r,o,m){scanf("%d",&t);for(c=t;c>0;c--)for(r=6;r>0;r--){P((t-c)*6+6-r,32);for(o=0;o<c;o++){P(r*2-1,42);P(13-r*2,32);}puts("");}}

C - 222 243 Chars (With Bonus Points)

#define P(I,C)for(m=0;m<I;m++)putchar(C)
main(t,c,r,o,m){scanf("%d",&t);for(c=t-1;-c<2+t;c-=1+!c)for(r=c<0?1:6;c<0?r<7:r>0;r+=c<0?1:-1){P((t-abs(c+1))*6+6-r,32);for(o=0;o<abs(c+1);o++){P(r*2-1,42);P(13-r*2,32);}puts("");}}

This is my first Code Golf submission as well!

Community
  • 1
  • 1
Adam Maras
  • 26,269
  • 6
  • 65
  • 91
2

dc 105 chars

123 129 132 139 141

[rdPr1-d0<P]sP?sn
0sk[1lk6%2*+sj32lkd0<Plnlk6/-si
[[*]12lj-d0<P32ljd0<Pli1-dsi0<I]dsIx
10Plk1+dskln6*>K]dsKx
Carlos Gutiérrez
  • 13,972
  • 5
  • 37
  • 47
2

Written in C

Bonus points (492 chars):

p(char *t, int c, int s){int i=0;for(;i<s;i++)printf("      ");for(i=0;i<c;i++)printf("%s",t);printf("\n");}main(int a, char **v){int i=0;int k;int c=atoi(v[1]);for(;i<c;i++){p("*********** ",c-i,i);p(" *********  ",c-i,i);p("  *******   ",c-i,i);p("   *****    ",c-i,i);p("    ***     ",c-i,i);p("     *      ",c-i,i);}for(i=0;i<c;i++){k=c-i-1;p("     *      ",1+i,k);p("    ***     ",1+i,k);p("   *****    ",1+i,k);p("  *******   ",1+i,k);p(" *********  ",1+i,k);p("*********** ",i+1,k);}}

Without bonus points (322 chars):

p(char *t, int c, int s){int i=0;for(;i<s;i++)printf("      ");for(i=0;i<c;i++)printf("%s",t);printf("\n");}main(int a, char **v){int i=0;int k;int c=atoi(v[1]);for(;i<c;i++){p("*********** ",c-i,i);p(" *********  ",c-i,i);p("  *******   ",c-i,i);p("   *****    ",c-i,i);p("    ***     ",c-i,i);p("     *      ",c-i,i);}}

First time posting, too!

2

Lua, 121 chars

R,N,S=string.rep,io.read'*n',' 'for i=0,N-1 do for j=0,5 do X=R(S,j)print(R(S,6*i)..R(X..R('*',11-2*j)..X..S,N-i))end end

123

R,N,S=string.rep,io.read'*n',' 'for i=0,N-1 do for j=0,5 do print(R(S,6*i)..R(R(S,j)..R('*',11-2*j)..R(S,j)..S,N-i))end end
DerKuchen
  • 1,840
  • 1
  • 15
  • 15
2

PHP, 153

<?php $i=fgets(STDIN);function r($n,$c=' '){return$n>0?$c.r($n-1,$c):'';}for($l=0;$l<$i*6;){$z=$l%6*2;echo r($l).r($i-$l++/6,r(11-$z,'*').r($z+1))."\n";}

with Bonus, 210

<?php $i=fgets(STDIN);function r($n,$c=' '){return$n>0?$c.r($n-1,$c):'';}$o=array();for($l=0;$l<$i*6;){$z=$l%6*2;$o[]=r($l).r($i-$l++/6,r(11-$z,'*').r($z+1));}print join("\n",array_merge($o,array_reverse($o)));
Kevin Vaughan
  • 14,320
  • 4
  • 29
  • 22
2

Mathematica, 46 characters

The answer prints sideways.

TableForm@{Table["*",{l,#},{l},{j,6},{2j-1}]}&
Community
  • 1
  • 1
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
1

HyperTalk - 272 chars

function triforce n
    put"******" into a
    put n*6 into h
    repeat with y=0 to h-1
        put"   " after s
        put char 1 to y of s after t
        repeat n-y div 6
            get y mod 6*2
            put char 1 to 11-it of (a&a)&&char 1 to it of s after t
        end repeat
        put return after t
    end repeat
    return t
end triforce

Indentation is neither needed nor counted (HyperCard automatically adds it).

Miscellanea:

Since there is no notion of console or way to access console arguments in HyperCard 2.2 (that I know of), a function is given instead. It can be invoked with:

on mouseUp
    ask "Triforce: "
    put triforce(it) into card field 1
end mouseUp

To use this, a card field would be created and set to a fixed-width font. Using HyperCard's answer command would display a dialog with the text, but it doesn't work because:

  • The answer dialog font (Chicago) is not fixed-width.
  • The answer command refuses to display long text (even triforce(2) is too long).
Community
  • 1
  • 1
Joey Adams
  • 41,996
  • 18
  • 86
  • 115
0

Common Lisp, 150 characters:

(defun f(n o)(unless(= n 0)(dotimes(x 6)(format t"~v@{~a~:*~}~-1:*~v@{~?~2:*~}~%"
 o" "n"~11@: "(list(- 11(* 2 x))#\*)))(f(1- n)(+ 6 o))))
Svante
  • 50,694
  • 11
  • 78
  • 122
0

77 char alternative python solution based on gnibbler's:

n=input()
k=0
exec"print' '*k+('*'*12+' '*(k%6*2+1))[-12:]*(n-k/6);k+=1;"*6*n

Amazingly the bonus came out exactly the same also (101 chars, oh well)

n=input()
l=1
k=0
s="print' '*k+('*'*12+' '*(k%6*2+1))[-12:]*(n-k/6);k+=l;"*6*n
exec s+'l=-1;k-=1;'+s
pat
  • 301
  • 3
  • 7