i'm trying to code a program in pascal that makes all the possible combinations (by 4 numbers) from 6 digits. For example if we have the digits [1 2 3 4 5 6] the possible combinations by 4 are 15:

1234 1235 1236

1245 1246 1256

1345 1346 1356

1456 2345 2346

2356 2456 3456

The combinations that can be made from 5 digits are only 5 and i've already done that in my program, but trying to make combinations from 6 digits is much more complicated. The code for combinations by 4 from 5 digits is this:

for i:=1 to 5 do

begin

for j:=1 to 5 do

if (cm[j]<>cm[i]) then write(cm[j]);

writeln;

end;

If anyone knows how to make the code that finds all the possible combinations by 4 numbers from 6 digits then please help me and write back to me.. thanks

It looks like you're new here. If you want to get involved, click one of these buttons!

- 140.8K All Categories
- 103.6K Programming Languages
- 6.4K Assembler Developer
- 401 Assembly Code Share
- 239 Getting started in assembly
- 4.6K x86 Assembly
- 1.9K Basic
- 97 Qbasic
- 39.9K C and C++
- 5.6K Beginner C/C++
- 330 C/C++ on Linux/Unix
- 450 C/C++ Windows API
- 522 C++ Builder
- 253 C++ Game Development
- 3.3K C++ MFC
- 103 C++.NET
- 404 Visual C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 334 Advanced Delphi
- 360 Delphi beginners
- 4 Haskell
- 9.7K Java
- 56 Enterprise JavaBeans
- 1.3K Java Beginners
- 304 Java Server Pages
- 4.1K Pascal
- 1.3K Perl
- 11 Perl 6
- 2K PHP
- 546 Python
- 37 Ruby
- 4.4K VB.NET
- 258 Advanced VB.Net
- 1.6K VBA
- 20.8K Visual Basic
- 767 Access databases and VB
- 831 Advance Visual Basic
- 1.2K Beginner VB
- 2.6K Game programming
- 315 Console programming
- 90 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 279 3D Graphics
- 129 DirectX
- 125 OpenGL
- 740 Computer Hardware
- 9 Cooling & Overclocking
- 3.4K Database & SQL
- 1.1K Access
- 91 ADO Programming
- 288 MySQL
- 358 Oracle
- 440 SQL-Server
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 25 DirectSound
- 257 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 603 Jobs Wanted
- 209 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 22 .NET WEB-Services
- 129 .NET WinForms
- 14 .NET XML
- 50 ADO.NET
- 142 C# & VB.NET School Support
- 3.4K Miscellaneous
- 4 Join the Team
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 621 Off topic board
- 200 Mobile & Wireless
- 72 Android
- 126 Palm Pilot
- 338 Multimedia
- 154 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 27 Cloud Computing
- 1 Witsbits Go Cloud
- 53 FreeBSD
- 1.7K LINUX programming
- 1 Awk scripting
- 332 Linux Support
- 0 Sed scripting
- 370 MS-DOS
- 0 Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 177 COM/DCOM
- 61 Networking And Security
- 17 Windows 2003 Server
- 6 Windows Vista
- 176 Windows XP
- 939 Software Development
- 416 Algorithms
- 68 Object Orientation
- 24 RUP & UML
- 91 Project Management
- 95 Quality & Testing
- 268 Security
- 63 Evil Scripting
- 81 Hacking
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 4 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 131 Mobile Internet & Messaging
- 211 Wireless development
- 2.2K JavaScript
- 37 JQuery
- 304 WEB Servers
- 153 Apache
- 79 IIS
- 150 WEB-Services / SOAP

## Comments

for C1:=1 to 6 do

for C2:=1 to 6 do

for C3:=1 to 6 do

for C4:=1 to 6 do begin

D1:=C1;

D2:=C2;

D3:=C3;

D4:=C4;

writeln(d1,d2,d3,d4);

end;

:

: i'm trying to code a program in pascal that makes all the possible combinations (by 4 numbers) from 6 digits. For example if we have the digits [1 2 3 4 5 6] the possible combinations by 4 are 15:

:

: 1234 1235 1236

: 1245 1246 1256

: 1345 1346 1356

: 1456 2345 2346

: 2356 2456 3456

:

: The combinations that can be made from 5 digits are only 5 and i've already done that in my program, but trying to make combinations from 6 digits is much more complicated. The code for combinations by 4 from 5 digits is this:

:

: for i:=1 to 5 do

: begin

: for j:=1 to 5 do

: if (cm[j]<>cm[i]) then write(cm[j]);

: writeln;

: end;

:

: If anyone knows how to make the code that finds all the possible combinations by 4 numbers from 6 digits then please help me and write back to me.. thanks

:

You mean something like this:

[code]

var n1,n2,n3,n4:byte;

begin

for n1:=1 to 6 do

for n2:=1 to 6 do

for n3:=1 to 6 do

for n4:=1 to 6 do

if

(n1<>n2) and

(n1<>n3) and

(n1<>n4) and

(n2<>n3) and

(n2<>n4) and

(n3<>n4) then

write(n1*1000+n2*100+n3*10+n4,' ');

end.

[/code]

Iby

[code]

var

largestnumber:integer;

numberofnumbers:integer;

function IntToStr(io:integer):string;

begin

Str(i,IntToStr);

end;

procedure AddNumber(s:string);

var

i:integer;

begin

if length(s)<numberofnumbers then begin

for i:=1 to largestnumber do

if Pos(IntToStr(i),s)=0 then

AddNumber(s+IntToStr(i));

end else

write(s,' ');

end;

procedure GetCombinations;

begin

AddNumber('');

end;

[/code]

This code is untested.

---

Number 1: When i'm talking about number combinations, i'm not talking about mathematic combinations because in maths the digits in this order:1234

and in this order:4321

are a different thing. The code that i wrote for the possible combinations from 5 digits (i'm talking about the code in my 1st message) doesnt make a difference between those combinations - its the same thing with the digits placed in a different order. But each of the combinations must be printed from the smaller to the greater number. For example the combination 4321 will only be written like this: 1234. So now you can understand that this code will only print 5 combinations from 5 digits: (1234 1235 1245 1345 and 2345).

---

Number 2: There's also one thing, we dont know what those 6 digits are, they might be any number between 1-10. Suppose we have the 1-d array cm[1..6]:

cm[1]:=1;

cm[2]:=5;

cm[3]:=8;

cm[4]:=6;

cm[5]:=3;

cm[6]:=9;

Each number cannot be used again in an other assignment, for example if number 5 has been assigned to cm[2] then we cant assign it again to i.e cm[6].

---

The program must take all those 6 digits, and find all their combinations (not with the mathematics meaning) by 4 numbers, which in this case are 15 and only 15 (they're all written in my first message). How can i do that?

Like i said in my previous msg its easy to find the combinations from 5 digits but its more complicated when trying to do the same from 6 digits.. and i'm stuck. I hope that you can now understand and help me - and thanks for your responses.

: ---

: Number 1: When i'm talking about number combinations, i'm not talking about mathematic combinations because in maths the digits in this order:1234

: and in this order:4321

: are a different thing. The code that i wrote for the possible combinations from 5 digits (i'm talking about the code in my 1st message) doesnt make a difference between those combinations - its the same thing with the digits placed in a different order. But each of the combinations must be printed from the smaller to the greater number. For example the combination 4321 will only be written like this: 1234. So now you can understand that this code will only print 5 combinations from 5 digits: (1234 1235 1245 1345 and 2345).

: ---

: Number 2: There's also one thing, we dont know what those 6 digits are, they might be any number between 1-10. Suppose we have the 1-d array cm[1..6]:

:

: cm[1]:=1;

: cm[2]:=5;

: cm[3]:=8;

: cm[4]:=6;

: cm[5]:=3;

: cm[6]:=9;

:

: Each number cannot be used again in an other assignment, for example if number 5 has been assigned to cm[2] then we cant assign it again to i.e cm[6].

: ---

: The program must take all those 6 digits, and find all their combinations (not with the mathematics meaning) by 4 numbers, which in this case are 15 and only 15 (they're all written in my first message). How can i do that?

:

: Like i said in my previous msg its easy to find the combinations from 5 digits but its more complicated when trying to do the same from 6 digits.. and i'm stuck. I hope that you can now understand and help me - and thanks for your responses.

:

Your first post didn't include numbers like 4123 or 4612 or 3214 or 2146. I'm not sure what exactly you are after. If you replace in my code [red]<>[/red] with [red]<[/red] it should generate sequence you are after (I hope).

Iby

:

: Iby

:

Yepp, that's the way to generate the sequence.

All digits must be different (no repetition) and

each digit must be smaller than the next one.

[code]

var n1,n2,n3,n4:byte;

begin

for n1:=1 to 6 do

for n2:=1 to 6 do

for n3:=1 to 6 do

for n4:=1 to 6 do

if

(n1<n2) and

(n1<n3) and

(n1<n4) and

(n2<n3) and

(n2<n4) and

(n3<n4) then

write(n1*1000+n2*100+n3*10+n4,' ');

end.

[/code]

Iby

:

:

:

I think so, but only if you run it with a known combination, can you be sure.

: :

: : Iby

: :

:

:

: Yepp, that's the way to generate the sequence.

: All digits must be different (no repetition) and

: each digit must be smaller than the next one.

:

: [code]

: var n1,n2,n3,n4:byte;

:

: begin

:

: for n1:=1 to 6 do

: for n2:=1 to 6 do

: for n3:=1 to 6 do

: for n4:=1 to 6 do

: if

: (n1<n2) and

: (n1<n3) and

: (n1<n4) and

:

: (n2<n3) and

: (n2<n4) and

:

: (n3<n4) then

:

: write(n1*1000+n2*100+n3*10+n4,' ');

: end.

: [/code]

:

: Iby

:

And if you want to shuffle ANY six characters (not only digits)

try this code. It simply uses small string as lookup table:

[code]

var n1,n2,n3,n4:byte;

const my_six_char_set:string='3QfZw&';

{ Or you could first try '123456' to check the sequence... }

begin

for n1:=1 to 6 do

for n2:=1 to 6 do

for n3:=1 to 6 do

for n4:=1 to 6 do

if

(n1<n2) and

(n1<n3) and

(n1<n4) and

(n2<n3) and

(n2<n4) and

(n3<n4) then

write(my_six_char_set[n1],

my_six_char_set[n2],

my_six_char_set[n3],

my_six_char_set[n4],' ');

readln;

end.

[/code]

Iby

thanks a lot that's what i was looking for..