Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,52 @@
|
|||
print "Part 1: Create a routine to generate the hailstone sequence for a number."
|
||||
print ""
|
||||
while hailstone < 1 or hailstone <> int(hailstone)
|
||||
input "Please enter a positive integer: "; hailstone
|
||||
wend
|
||||
print ""
|
||||
print "The following is the 'Hailstone Sequence' for your number..."
|
||||
print ""
|
||||
print hailstone
|
||||
while hailstone <> 1
|
||||
if hailstone / 2 = int(hailstone / 2) then hailstone = hailstone / 2 else hailstone = (3 * hailstone) + 1
|
||||
print hailstone
|
||||
wend
|
||||
print ""
|
||||
input "Hit 'Enter' to continue to part 2...";dummy$
|
||||
cls
|
||||
print "Part 2: Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with 27, 82, 41, 124 and ending with 8, 4, 2, 1."
|
||||
print ""
|
||||
print "No. in Seq.","Hailstone Sequence Number for 27"
|
||||
print ""
|
||||
c = 1: hailstone = 27
|
||||
print c, hailstone
|
||||
while hailstone <> 1
|
||||
c = c + 1
|
||||
if hailstone / 2 = int(hailstone / 2) then hailstone = hailstone / 2 else hailstone = (3 * hailstone) + 1
|
||||
print c, hailstone
|
||||
wend
|
||||
print ""
|
||||
input "Hit 'Enter' to continue to part 3...";dummy$
|
||||
cls
|
||||
print "Part 3: Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length.(But don't show the actual sequence)!"
|
||||
print ""
|
||||
print "Calculating result... Please wait... This could take a little while..."
|
||||
print ""
|
||||
print "Percent Done", "Start Number", "Seq. Length", "Maximum Sequence So Far"
|
||||
print ""
|
||||
for cc = 1 to 99999
|
||||
hailstone = cc: c = 1
|
||||
while hailstone <> 1
|
||||
c = c + 1
|
||||
if hailstone / 2 = int(hailstone / 2) then hailstone = hailstone / 2 else hailstone = (3 * hailstone) + 1
|
||||
wend
|
||||
if c > max then max = c: largesthailstone = cc
|
||||
locate 1, 7
|
||||
print " "
|
||||
locate 1, 7
|
||||
print using("###.###", cc / 99999 * 100);"%", cc, c, max
|
||||
scan
|
||||
next cc
|
||||
print ""
|
||||
print "The number less than 100,000 with the longest 'Hailstone Sequence' is "; largesthailstone;". It's sequence length is "; max;"."
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue