Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
how to generate 4 numbers without repetition
Author Message
Blue_angel00

Posted: Sat Jun 05, 2004 7:44 pm   Post subject: how to generate 4 numbers without repetition

hi i'm new to this site and i haven't been doing programming for a while so i really need help.
i need to write a program to generate all the possibilities of 4 numbers from 1 to 40 in order and without repetition.
the first number has to be smaller than the second number and so on.
for example: 1,2,3,4 then next line has to be 1,2,3,5 all the way to 37,38,39,40.

if anyone knows how to write this program i would be greatly appreciated.

Delos

Posted: Sat Jun 05, 2004 8:06 pm   Post subject: (No subject)

Store the generated numbers temporarily in an array.
Each time a new number is generated, check through that array to see if it is already there...if it isn't, then add the next number to it.
Otherwise, generate a new number.
Cervantes

Posted: Sat Jun 05, 2004 8:09 pm   Post subject: (No subject)

arrays? dude, this isn't that difficullt

 code: const max_num := 40 var counter := 0 for a : 1 .. max_num     for b : 1 .. max_num         if b > a then             for c : 1 .. max_num                 if c > b then                     for d : 1 .. max_num                         if d > c then                             counter += 1                         end if                     end for                 end if             end for         end if     end for end for put counter

all logic 8)
Delos

Posted: Sat Jun 05, 2004 8:21 pm   Post subject: (No subject)

Cervantes wrote:
arrays? dude, this isn't that difficullt

I really should read the posts more carefully...hehehe.

C (40, 4) works.

 code: const maxNum : int := 40 const rowSize : int := 4 var count : int := 0 function factorial (num : real) : real     var temp : real := num     if index (realstr (temp, 0), ".") > 0 then         result - 1     end if     if temp > 169 then         result - 1     end if     var n : real := temp - 1     if temp = 0 then         result 1     else         temp := temp * factorial (n)     end if         result temp end factorial function comb (n : real, r : real) : real     % n choose r.     var temp : real     temp := round (factorial (n) / (factorial (n - r) * (factorial (r))))     result temp end comb put comb (maxNum, rowSize)

(I used the real type as opposed to ints as Turing's ints don't go all that high...)
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: