' STAR_6.bas Mar. 29/97 hh ' May 20/97 Changed g>d to i>b to confirm to new basic solution standard. ' No change in running time and # of solutions. ' Mar. 29/96 searchs for all solutions for 6-pointed star. ' adapted from STAR_9_C.bas. Saves (appends) output to STAR_6.dat. ' check each line for O.K. before proceeding further. ' g > d to prevent horizontal reflections ' A is smallest point. This prevents rotations and vertical reflections. DEFINT A-Z CONST false = 0, true = NOT false DIM used(1 TO 12) ' look at numbers 1 to 12 & keep track ' store the number in location corresponding to letter COMMON SHARED used(), index, nflag DECLARE SUB clearused () ' cleared the array at & above the current position DECLARE SUB usedtest (number) ' tests if the integer has already been used nflag = false ' usedtest() returns true for nflag if number not used index = 1 ' this is the current position & indicates so in used array counter = 0 ' count the solutions sum = 26 ' this is the magic constant for a 6-point star CLS PRINT "May/97 STAR_6 hh" PRINT : PRINT "This program finds all combinations of the numbers from 1 to 12 that form " PRINT "BASIC solutions for the magic six pointed star. " PRINT "The solutions are arranged so the top point has the lowest point value " PRINT "and the adjacent right valley value is lower then the left valley." PRINT "The output is also being saved in STAR_6.dat. " PRINT "Place these numbers at defined locations i.e.line by line in order." PRINT "** Press 'esc' to end program **" PRINT : INPUT "Do you wish a hardcopy list (Y/y, anything else is no)"; response\$ IF response\$ = "Y" OR response\$ = "y" THEN pflag = true IF pflag THEN LPRINT "May/97 STAR_6 hh" LPRINT : LPRINT "This program finds all combinations of the numbers from 1 to 12 that form a" LPRINT "magic six pointed star ." LPRINT "The solutions are arranged so the top point has the lowest point value " LPRINT "and the adjacent right valley value is lower then the left valley." LPRINT : LPRINT " a b c d e f g h i j k l counter" LineNum = 7 END IF OPEN "Star_6.dat" FOR OUTPUT AS #1 ' open to start a NEW file CLOSE #1 startDate\$ = DATE\$: startTime\$ = TIME\$ ' save date & time FOR a = 1 TO 7 ' always the lowest point value ' ' at least 1 point must be 7 or less used(1) = a ' show this number used FOR b = 1 TO 12: used(2) = b ' position 2 nflag = false: index = 2 ' nflag will be true when an unused # is found clearused ' clear from this posit. up (to free up unused #'s DO UNTIL nflag = true usedtest (b) ' is this number used? IF NOT nflag THEN b = b + 1 ' yes, so get next number IF b > 12 THEN b = 1: EXIT FOR LOOP FOR c = 1 TO 12 ' position 3 nflag = false: index = 3 ' nflag will be true when an unused # is found clearused ' clear from this posit. up (to free up unused #'s DO UNTIL nflag = true usedtest (c) ' is this number used? IF NOT nflag THEN c = c + 1 ' yes, so get next number IF c > 12 THEN c = 1: EXIT FOR LOOP FOR d = a + 1 TO 12 ' pos. 4 - all points > A prevents rotations nflag = false: index = 4 clearused DO UNTIL nflag = true firstline: usedtest (d) ' loop until 1st line is O.K. IF NOT nflag THEN d = d + 1 IF d > 12 THEN d = a + 1: EXIT FOR IF a + b + c + d <> 26 THEN ' make first line correct before proceeding d = d + 1 IF d > 12 THEN d = a + 1: EXIT FOR ' i.e. go back for next c GOTO firstline END IF LOOP FOR e = 1 TO 12 ' position 5 nflag = false: index = 5 clearused DO UNTIL nflag = true usedtest (e) IF NOT nflag THEN e = e + 1 IF e > 12 THEN e = 1: EXIT FOR ' i.e. go back for next d LOOP FOR f = 1 TO 12 ' position 6 nflag = false: index = 6 ' nflag will be true when an unused # is found clearused ' clear from this posit. up (to free up unused #'s DO UNTIL nflag = true usedtest (f) ' is this number used? IF NOT nflag THEN f = f + 1 ' yes, so get next number IF f > 12 THEN f = 1: EXIT FOR ' i.e. go back for next e LOOP FOR g = a + 1 TO 12 ' pos. 7 - g > d prevents horizontal reflections nflag = false: index = 7 clearused DO UNTIL nflag = true secondline: usedtest (g) ' loop until 2nd line is O.K. IF NOT nflag THEN g = g + 1 IF g > 12 THEN g = a + 1: EXIT FOR ' i.e. go back for next f IF d + e + f + g <> 26 THEN ' make second line correct before proceeding g = g + 1 IF g > 12 THEN g = a + 1: EXIT FOR ' i.e. go back for next f GOTO secondline ' loop to make 2nd line correct END IF LOOP FOR h = 1 TO 12 ' position 8 nflag = false: index = 8 clearused DO UNTIL nflag = true usedtest (h) IF NOT nflag THEN h = h + 1 IF h > 12 THEN h = 1: EXIT FOR ' i.e. go back for next g LOOP FOR i = b + 1 TO 12 ' position 9 - last empty position in 3rd line nflag = false: index = 9 ' nflag will be true when an unused # is found clearused ' clear from this posit. up (to free up unused #'s DO UNTIL nflag = true thirdline: usedtest (i) ' is this number used? IF NOT nflag THEN i = i + 1 ' yes, so get next number IF i > 12 THEN i = b + 1: EXIT FOR IF g + h + i + a <> 26 THEN ' make third line correct before proceeding i = i + 1 IF i > 12 THEN i = b + 1: EXIT FOR ' i.e. go back for next i GOTO thirdline ' loop until line 3 is correct END IF LOOP FOR j = a + 1 TO 12 ' position 10 - point nflag = false: index = 10 clearused DO UNTIL nflag = true usedtest (j) IF NOT nflag THEN j = j + 1 IF j > 12 THEN j = a + 1: EXIT FOR ' i.e. go back for next i LOOP linepos = CSRLIN ' show the program is running and progress LOCATE 25, 1: PRINT USING "###"; a; b; c; d; e; f; g; h; i; j; PRINT " a to j Pattern Star_6"; LOCATE linepos, 1 IF INKEY\$ = CHR\$(27) THEN ' abort the run PRINT startDate\$; " "; startTime\$; " "; DATE\$; " "; TIME\$ ' record length of run IF pflag THEN ' print length of run LPRINT startDate\$; " "; startTime\$; " "; DATE\$; " "; TIME\$; " Run Aborted!" END IF OPEN "Star_6.dat" FOR APPEND AS #1 ' open & save to file WRITE #1, startDate\$, startTime\$, DATE\$, TIME\$, "Run was Aborted !" CLOSE #1 END ' exit program END IF FOR k = a + 1 TO 12 ' position 11 - point nflag = false: index = 11 clearused DO UNTIL nflag = true forthline: usedtest (k) IF NOT nflag THEN k = k + 1 IF k > 12 THEN k = a + 1: EXIT FOR IF j + c + e + k <> 26 THEN ' make forth line correct before proceeding k = k + 1 IF k > 12 THEN k = a + 1: EXIT FOR ' i.e. go back for next k GOTO forthline ' loop to make 4th line correct END IF LOOP FOR l = a + 1 TO 12 ' position 12 - point nflag = false: index = 12 clearused DO UNTIL nflag = true fifthline: usedtest (l) IF NOT nflag THEN l = l + 1 IF l > 12 THEN l = a + 1: EXIT FOR IF k + f + h + l <> 26 THEN ' make fifth line correct before proceeding l = l + 1 IF l > 12 THEN l = a + 1: EXIT FOR ' i.e. go back for next k GOTO fifthline ' loop to make 5th line correct END IF LOOP IF l + i + b + j = 26 THEN ' now test line 6 - if O.K. print solution ' this test isn't necessary but ... counter = counter + 1 'print to screen PRINT a; b; c; d; " "; e; f; g; " "; h; i; " "; j; k; " "; l; " "; counter IF pflag THEN ' print to paper LPRINT a; b; c; d; " "; e; f; g; " "; h; i; " "; j; k; " "; l; " "; counter LineNum = LineNum + 1 IF LineNum = 64 THEN LineNum = 2: LPRINT : LPRINT : LPRINT : LPRINT END IF OPEN "Star_6.dat" FOR APPEND AS #1 ' write to a file WRITE #1, a, b, c, d, e, f, g, h, i, j, k, l CLOSE #1 END IF NEXT l, k, j, i, h, g, f, e, d, c, b ' go find more solutions NEXT a ' increment the first position PRINT startDate\$; " "; startTime\$; " "; DATE\$; " "; TIME\$ ' record length of run IF pflag THEN LPRINT startDate\$; " "; startTime\$; " "; DATE\$; " "; TIME\$, "Run completed !" ' record length of run OPEN "Star_6.dat" FOR APPEND AS #1 ' open & save to file WRITE #1, startDate\$, startTime\$, DATE\$, TIME\$, "Run completed !" CLOSE #1 END SUB clearused ' resets the used() array for the position of letter calling & all above ' this is done when incrementing a previous position so all subsequent positions are ' vacant and the numbers previously used for them are freed up FOR index2 = index TO 12 used(index2) = 0 NEXT index2 END SUB SUB usedtest (number) ' test if a number is used yet ' number is the number to be tested FOR index2 = 1 TO 12 ' search to see if number being used IF used(index2) = number THEN ' yes - so indicate nflag = false EXIT FOR ' and end search ELSE nflag = true ' no - (this will toggle, final is what counts END IF NEXT index2 IF nflag = true THEN used(index) = number ' OK so store this number @ correct position END SUB