[futurebasic] Re: [FB]Base conversion and repetition.

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2003 : Group Archive : Group : All Groups

From: Steve Flavel <sflavel@...>
Date: Fri, 18 Jul 2003 12:11:39 +0930
Bernie and others

I have pasted my code at the bottom

To get repeats I count by base nflavors .

I have been trying to get a function that Jay wrote (attached) to do the
case where _nflavors > _nScoops to work, but I am stuck.

 
Steve

'-----------
'~'A
'                       Runtime : RNTM Lite.INCL
'~'B
_nScoops   = 3
_nFlavours = 4

begin globals
dim as long gCount
dim gNorepeats(20000) as str15
dim gRepeats(20000) as str15
dim numString as str15
end globals
'~'2
clear local mode

dim i,strlen,count
LOCAL FN SpaceStrip$(theText$)
'remove all spaces from a string and return the result
strlen = theText$[0]: if strlen=0 then exit fn
for i=1 to strlen
long if theText$[i]<>_" "
inc(count)
if count<i then theText$[count] = theText$[i]
end if
next
theText$[0] = count
END FN = theText$
'~'2

local fn baseConversion$(num)
DIM baseNum As Str15
DIM digit As Str15
baseNum = ""
Do
digit = Str$(num Mod _nFlavours)
baseNum = digit + baseNum
num = fix(num / _nFlavours)
Until num = 0
baseNum = Fn spaceStrip$(baseNum)
long if len(baseNum)<_nScoops
baseNum="00000" + baseNum
baseNum = Fn spaceStrip$(baseNum)
baseNum=right$(baseNum,_nScoops)
end if
End Fn= baseNum
'~'2

local fn permutations(whichChar,NextStr as str15)
dim as short d
long if whichChar <  _nFlavours
fn permutations(whichChar+1,NextStr)
for d=whichChar+1 to _nScoops
swap NextStr[d],NextStr[whichChar]
gNoRepeats(gCount) = NextStr
print NextStr
gCount++
fn permutations(whichChar+1,NextStr)
next
end if
end fn
'~'2
local fn Repeats
DIM  As Long i,allNum

allNum = _nFlavours ^ _nScoops - 1
gCount = 0
For i = 0 To allNum
gRepeats(i) = fn baseConversion$(i)
gCount++
print gRepeats(i)
Next
print "Number ice-creams "; gCount
end fn
'~'2

print "Combinations of"_nFlavours" items,"_nScoops" at a time"
print "With duplicates"
fn Repeats

print:print "Without duplicates"
gCount=1
long if _nScoops <= _nFlavours

numString="123456789"
gNoRepeats(0)=left$(numString,_nFlavours)
 fn permutations(1,gNoRepeats(0))
print
print "Number ice-creams "; gCount
end if
'-