
-----------------------------------
limited_skillz
Mon Feb 23, 2004 12:05 am

help with bow-tie program
-----------------------------------
i was practicing some of the previous computing competitions and i am stumped by the first question in the 2001 one

For this question, you will write a program to print out a bow tie on the computer screen.

Your program should take as input the height H of the bow tie, where H is an odd positive integer greater than or equal to 5. A bow tie with H rows (and 2H columns) should then be printed using the pattern shown below. You may assume that all input data will be valid.

For this question you should read the input from the keyboard and print the output to the screen.

Sample Session: (User input is in italics.)

Enter height:
5
*-----------*  
***-----*** 
**********
***-----***
*-----------* 

Enter height:
7
*-----------------*
***----------*** 
*****---- *****
**************
*****---- *****
*** ---------***
*--------------- *

- = blank space

i cant even think up a way to do it for the other side, but i do have one side right

View.Set ("graphics:640;480,nocursor")
proc drawTie (h, x, y : int)
    if h > 0 then
        locatexy (x, y)
        for i : 1 .. 2 * h - 1
            put "*" ..
        end for
        drawTie (h div 2, x, y + 15)
        drawTie (h div 2, x, y - 15)
    end if
end drawTie

% main
var h : int
loop
    put "Height of bowtie (must be odd, positive integer greater or equal to 5): " ..
    get h
    exit when h >= 5 and h mod 2 not= 0
    cls
end loop
cls
drawTie (h , 250, 315)

-----------------------------------
Tony
Mon Feb 23, 2004 12:15 am


-----------------------------------
its very simple

var size:int
put "what size?"
get size

for i:1..floor(size/2)
put repeat("*",i),repeat(" ",size-i*2),repeat("*",i)
end for

put repeat("*",size)

for decreasing i : floor(size/2)..1
put repeat("*",i),repeat(" ",size-i*2),repeat("*",i)
end for


-----------------------------------
limited_skillz
Mon Feb 23, 2004 12:38 am


-----------------------------------
thanks a lot man,  i still dont understand lol, illl spend the next half hour figuring it out

my brain is just trying to act too complex, im here trying to use recursion and trying to find some sort of formula whether to print or not

i even tried to see if area was involved

man do i need to simplify things

-edit - oh i didnt know repeat existed, hm, this shouldnt have wasted so much of my time

-----------------------------------
Tony
Mon Feb 23, 2004 10:23 am


-----------------------------------
lol, recursion? you should know better then that, isn't this a J1 question? lol :lol:

-----------------------------------
Andy
Mon Feb 23, 2004 10:35 am


-----------------------------------
ya repeat is very helpful

-----------------------------------
naoki
Mon Feb 23, 2004 4:32 pm


-----------------------------------
way to spam dodge  :evil: 

anyways you could even shorten tony's code by doing a normal for loop, from 1 to H. I kept a counter which I set to 2 or -2. I change it to -2 when I'm unable to repeat any spaces (using a simple subtraction to figure out my spaces). When I can't output spaces, that means that my bowtie is shrinking and thus I change my counter.

The counter is added to my repeat function for the *'s before and after the spaces
