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

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

From: Robert Purves <robert.purves@...>
Date: Wed, 16 Jul 2003 23:01:40 +1200
On Wednesday, July 16, 2003, Steve Flavel wrote:
> How many ice-creams can be made from 6 flavors and 4 scoops?
> List all possible ice-creams, if;
> 1 Repeats of flavor are allowed
> 2 No repeats are allowed.
> (all ice-creams made must have the number of specified scoops, as in 4 
> for
> the example above)

If I understand right, you want to enumerate the combinations of 6 
things taken 4 at a time, with and without duplicates. The code below 
appears to solve the problems as described. Note that you can set 
_nFlavors to any value, but there is no _nScoops constant (it is 
implied by the number of nested loops). The writing of a general 
program for any _nScoops and _nFlavors would be a worthy challenge.

Robert P.

'-----------
'~'A
'                       Runtime : RNTM Lite.INCL
'~'B
end globals
dim as long  a, b, c, d, n

_nFlavors = 6

print "Combinations of 6 items, 4 at a time"
print "With duplicates"
n = 0
a = 1
while ( a <= _nFlavors )
b = a
while ( b <= _nFlavors )
c = b
while ( c <= _nFlavors )
d = c
while ( d <= _nFlavors )
n++
print n, a b c d
d++
wend
c++
wend
b++
wend
a++
wend

print : print "Without duplicates"
n = 0
a = 1
while ( a <= _nFlavors )
b = a + 1
while ( b <= _nFlavors )
c = b + 1
while ( c <= _nFlavors )
d = c + 1
while ( d <= _nFlavors )
n++
print n, a b c d
d++
wend
c++
wend
b++
wend
a++
wend
'-----------