Batch Script, need help generating lines of six different numbers (between 1 and 39) that have no more than 2 numbers in common with any previous line

huangapple go评论49阅读模式
英文:

Batch Script, need help generating lines of six different numbers (between 1 and 39) that have no more than 2 numbers in common with any previous line

问题

Batch脚本,需要帮助生成六个不同数字的行,这些数字与任何前一行的数字最多有2个相同

目标是生成一个包含300组1到39之间的6个随机数字的CSV文件,每组6个数字在单独的行上,每行最多有两个数字与任何前一行相同(与所有以前行的任何一行相同的两个数字)。 这是目标。 我遇到了问题。 我希望有人可能会看到更简单的方法。

我制作(拼凑)的脚本生成了一个无重复的行列表文件,但行本身不断变长,而不是在6处截断。 我还需要检查所有以前的行以确保最多有两个重复的部分。 如果有人有解决办法(真诚的),我非常感激任何帮助以更快地实现目标。

以下是到目前为止的脚本:

@echo off
setlocal enabledelayedexpansion 

for /L %%j in (1 1 10) do (
    call:get_rand
    echo %%j;!NUM[1]!;!NUM[2]!;!NUM[3]!;!NUM[4]!;!NUM[5]!;!NUM[6]! >> test.txt

    sort "get_six.txt" >> "get_sort.txt"
    for /f %%b in (get_sort.txt) do findstr "%%~b" "get_tmp.txt" >nul 2>&1 || echo %%b>>"get_tmp.txt"
    call:get_horiz
)
goto:EOF

:get_horiz
set var=
for /f "tokens=*" %%c in (get_tmp.txt) do (
    call set var=%%var%%,%%c
)
SET var=%var:~1%
echo !var! >> list.txt
goto:EOF

:get_rand
for /L %%i in (1 1 6) do (
    call:get_n %%i
    echo !num[%%i]! >> get_six.txt
)
goto:EOF

:get_n
set /a num[%1] = %RANDOM% * 39 / 32768 + 1
goto:EOF

==========

list.txt(预期):

03,11,17,24,28,37
11,13,25,26,36,39
02,09,15,23,28,37
03,13,14,26,28,32
08,11,21,22,34,36
02,13,16,26,27,31
01,06,14,20,27,31
07,09,20,23,33,34
...

条件1:每行没有重复的数字

条件2:与其他任何行不匹配超过两个数字

(我只是目测检查了这些,可能会漏掉一些,但例如,第四行“03,13,14,26,28,32”与第一行“03,11,17,24,28,37”有03和28相同,与第二行“11,13,25,26,36,39”有13和26相同-这是可以的,它在允许的最大范围内)。

list.txt(当前):

10,28,39 
10,28,39,14,20,22,36 
10,28,39,14,20,22,36,25,34,35 
10,28,39,14,20,22,36,25,34,35,18,31,32 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37,24 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37,24,15 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37,24,15,27

:/

英文:

Batch Script, need help generating lines of six different numbers that have no more than 2 numbers in common with any previous line

The goal is to generate a csv file of 300 sets of 6 random numbers between 1 and 39, each set of 6 on a separate line, and each line with a maximum of two numbers in common with any previous line (two numbers with any one line of all previous lines).  That's the goal.  I've hit a snag.  I'm hoping someone might see an easier way.

The script I've made (pieced together) generates a list file without repetition in the row, but the row itself gets longer and longer instead of cutting off at 6.  I also still need the part that checks all previous rows to ensure a max of two duplicates.  If someone has a workaround (a sincere one), I greatly appreciate any to help reach the goal sooner.

Here's the script so far:


@echo off
setlocal enabledelayedexpansion 

for /L %%j in (1 1 10) do (
	call:get_rand
	echo %%j  ;!NUM[1]!;!NUM[2]!;!NUM[3]!;!NUM[4]!;!NUM[5]!;!NUM[6]! >> test.txt

	sort "get_six.txt" >> "get_sort.txt"
	for /f %%b in (get_sort.txt) do findstr "%%~b" "get_tmp.txt" >nul 2>&1 || echo %%b>>"get_tmp.txt"
	call:get_horiz
rem	call:del_get_files
)
goto:EOF


rem delete extra files:
rem	:del_get_files
rem	for %%z in (get_six.txt,get_sort.txt,get_tmp.txt) do (
rem		if exist "%%z" del /q /f "%%z"
rem	)
rem	goto:EOF


rem get_tmp.txt vertical list to csv horizontal list.txt
:get_horiz
set var=
for /f "tokens=*" %%c in (get_tmp.txt) do (
	call set var=%%var%%,%%c
)
SET var=%var:~1%
echo !var! >> list.txt
goto:EOF


rem get first set of six random numbers
:get_rand
for /L %%i in (1 1 6) do (
	call:get_n %%i
	rem get random number, 1 is the min, 39 is the max
	echo !num[%%i]! >> get_six.txt
)
goto:EOF


rem get random num[%%i] between 1 and 39
:get_n
set /a num[%1] = %RANDOM% * 39 / 32768 + 1
goto:EOF

==========

list.txt (expected):

03,11,17,24,28,37
11,13,25,26,36,39
02,09,15,23,28,37
03,13,14,26,28,32
08,11,21,22,34,36
02,13,16,26,27,31
01,06,14,20,27,31
07,09,20,23,33,34
...

Condition 1: no duplicate numbers per line

Condition 2: not matching more than two numbers with any other line

(I've only checked these visually, I might have missed some, but, for example, the fourth line "03,13,14,26,28,32" has 03 and 28 in common with the first line, "03,11,17,24,28,37", and 13 and 26 with the second, "11,13,25,26,36,39"--that's ok, it's within the permitted maximum)

list.txt (current):

10,28,39 
10,28,39,14,20,22,36 
10,28,39,14,20,22,36,25,34,35 
10,28,39,14,20,22,36,25,34,35,18,31,32 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37,24 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37,24,15 
10,28,39,14,20,22,36,25,34,35,18,31,32,19,29,7,11,17,21,23,33,12,37,24,15,27

:/

答案1

得分: 1

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

:: 删除以#开头的变量
FOR /F "delims==" %%e IN ('set # 2^>Nul') DO SET "%%e="

SET #combos=0

:newcombo
SET /a #nums=0
:: 删除以$开头的变量
FOR /F "delims==" %%e IN ('set $ 2^>Nul') DO SET "%%e="
:newrnd
SET /a nextrand=%RANDOM%
IF %nextrand% gtr 32759 GOTO newrnd
SET /a nextrand=101+(nextrand%%39)
IF DEFINED $%nextrand% GOTO newrnd
SET "$%nextrand%=%nextrand:~-2%"
SET /a #nums+=1
IF %#nums% lss 6 GOTO newrnd
SET "#c="
FOR /F "tokens=2 delims==" %%e IN ('set $ 2^>Nul') DO SET "#c=!#c!,%%e"
FOR /L %%y IN (1,1,%#combos%) DO (
 SET /a matchcount=0
 FOR %%o IN (!#c%%y!) DO IF DEFINED $1%%o set /a matchcount+=1
 IF !matchcount! gtr 2 GOTO newcombo
)
SET /a #combos+=1

ECHO %#combos% generated

SET "#c%#combos%=%#c:~1%"
IF %#combos% lss 300 GOTO newcombo
(
 FOR /L %%y IN (1,1,%#combos%) DO ECHO !#c%%y!
) >u:\combos.txt

TYPE u:\combos.txt

GOTO :EOF
英文:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

:: remove variables starting #
FOR  /F "delims==" %%e In ('set # 2^>Nul') DO SET "%%e="

SET #combos=0

:newcombo
SET /a #nums=0
:: remove variables starting $
FOR  /F "delims==" %%e In ('set $ 2^>Nul') DO SET "%%e="
:newrnd
SET /a nextrand=%RANDOM%
IF %nextrand% gtr 32759 GOTO newrnd
SET /a nextrand=101+(nextrand%%39)
IF DEFINED $%nextrand% GOTO newrnd
SET "$%nextrand%=%nextrand:~-2%"
SET /a #nums+=1
IF %#nums% lss 6 GOTO newrnd
SET "#c="
FOR  /F "tokens=2delims==" %%e In ('set $ 2^>Nul') DO SET "#c=!#c!,%%e"
FOR /L %%y IN (1,1,%#combos%) DO (
 SET /a matchcount=0
 FOR %%o IN (!#c%%y!) DO IF DEFINED $1%%o set/a matchcount+=1
 IF !matchcount! gtr 2 GOTO newcombo
)
SET /a #combos+=1

ECHO %#combos% generated

SET "#c%#combos%=%#c:~1%"
IF %#combos% lss 300 GOTO newcombo
(
 FOR /L %%y IN (1,1,%#combos%) DO ECHO !#c%%y!
)>u:\combos.txt

TYPE u:\combos.txt

GOTO :EOF

Well - it'll not break any speed records. Overnight run - at least.

Set a new random into nextrand. Check that it is not >32759 as values over this would bias the processed random number (which isn't linear in any case)

Calculate 101+(random mod 39) -> 101..139

if $selection is set, then that number has already been chosen, so choose again. Otherwise, set $selection to 01..39.

repeat until we have chosen 6 numbers

Build #c from $valuesselected values, which will be in sorted order (characteristic of set) and insert commas before each, so #c might become ,05,07,12,17,22,31 for instance

for each combination already recorded, count the number of matches against the current set of 6 $1xx values chosen. If more than 2 are found, find another combo. Otherwise, record the new combination and count until the limit is reached.

But - it really is slow...

答案2

得分: 1

I've translated the provided text as you requested. Here's the translation:

"Mmmm... Your problem seems simple at first, but it's not at all!

Before trying to write any code, let's analyze the problem for a moment.

The "base set" are the first 39 natural numbers:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

How many different sets of 6 numbers with no repetitions can be assembled from this base set? It seems that is just 6. How many sets with 1 repetition can be assembled? It seems that some multiple of 7 (I am not good enough with mathematics). My point is that I really doubt that with a maximum of 2 repetitions, 300 sets could be assembled... Perhaps someone with better math knowledge could give us an exact answer, but if the answer is less than 300, then any program will never stop no matter the method used to write it.

On the other hand, the problem is complex and convoluted to solve. Suppose we develop a method to create sets of 6 numbers with a maximum of 2 repetitions, and we create 50 sets. Then, after we create set #51, there are 3 numbers that are the same as in another previously generated set. What should we do now? We could eliminate one of the 3 repeated elements in the new set and insert the next valid number in that place. However, depending on which one element be eliminated, the final result could be very different...

We should save the state of all sets up to that moment, continue generating sets and check if we could generate the required 300. If not, then we should backtrack to that state, eliminate another number of the repeated 3, and repeat the process again until the end. In this way, this method to solve this problem is similar to the one for chess game (my code below does not use any backtracking). You should also consider that this method would require a huge number of data movements, so the program must be designed with optimization as the primary goal; otherwise (or anyway), the program will run for several hours for sure...

Below is my first attempt to solve this problem in a suitable way. I don't generate random numbers one by one until collecting the non-repeated 6. Instead, I use an array with the 39 numbers placed in 39 successive elements. Then, I randomly (1-39) select one of them and move to that place the last (39th) number and decrease the "number of numbers" count to 38. For the second number, I do the same: randomly (1-38) select a number, move to that place the 38th number, and decrease the counter. In this way, I can generate 6 non-repeated numbers in random order in just 6 cycles via 6 random numbers.

(Question: why the numbers must be generated in random order? When the results are displayed, the numbers are sorted in natural order again.)

I also store the generated numbers as indices of arrays (not as values). This point allows me to test numbers via the simpler "if defined element[%num%] ..." that runs faster than the usual "if !element[%index%]! equ %num% ..."

@echo off
setlocal EnableDelayedExpansion

rem The 300 lines are generated as a 2-dimensional matrix called "n" with this shape:
rem n[%line%][%num%]=1
rem Where "line" is the index of the line: from 1 to 300
rem and "num" is each number (value between 1 and 39) that comprises such a line
rem
rem Each new line is previously generated in "num" array with 6 elements in the same way

rem Randomize
for /L %%i in (0,1,%time:~-1%) do set "x=!random!"

rem Generate 300 lines with 6 numbers each
set "line=0"
set "num[0]=0"
:nextLine

rem Set numbers 1..39 as "available"
for /L %%i in (1,1,39) do set "avail[%%i]=%%i"
set "numsAvail=39"

rem Remove previously generated numbers
for /F "tokens=2 delims==" %%n in ('set num[') do set "num[%%n]="
set "numbers=0"

rem Generate 6 random numbers (from "available" ones):

rem Get the index of anyone (random order) of available numbers
rem Insert such an available number in "num" array
rem Move to the (position of the) used available number the last one, and eliminate (the last) one available number
rem And pass to the next number

英文:

Mmmm... Your problem seems simple at first, but it's not at all!

Before try to write any code, let's analyze the problem for a moment.

The "base set" are the first 39 natural numbers:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

How many different sets of 6 numbers with no repetitions can be assembled from this base set? It seems that is just 6. How many sets with 1 repetition can be assembled? It seems that some multiple of 7 (I am not good enough with mathemathics). My point is that I really doubt that with a max of 2 repetitions could be assembled 300 sets... Perhaps someone with better math knowledge could give us an exact answer, but if the answer is less than 300, then any program will never stop no matters the method used to write it.

On the other hand, the problem is complex and convoluted to solve. Suppose we develop a method to create sets of 6 numbers with a max of 2 repetitions and we create 50 sets. Then, after we create the set # 51, there are 3 numbers that are the same than in another previously generated set. What we must do now? We could eliminate one of the 3 repeated elements in the new set and insert the next valid number in that place. However, depending on which one element be eliminated, the final result could be very different...

We should save the state of all sets up to that moment, continue generating sets and check if we could generate the required 300. If not, then we should backtrack to that state, eliminate another number of the repeated 3 and repeat the process again until the end. In this way, this method to solve this problem is similar to the one for chess game (my code below does not use any backtracking). You should also consider that this method would require a huge number of data movements, so the program must be designed with optimization as the primary goal; otherwise (or anyway) the program will run for several hours for sure...

Below is my first attempt to solve this problem in a suitable way. I don't generate random numbers one by one until collect the non-repeated 6. Instead, I use an array with the 39 numbers placed in 39 succesive elements. Then, I randomly (1-39) select one of them and move to that place the last (39th) number and decrease the "number of numbers" count to 38. For the second number I do the same: randomly (1-38) select a number, move to that place the 38th number and decrease the counter. In this way I can generate 6 non-repeated numbers in random order in just 6 cycles via 6 random numbers.

(Question: why the numbers must be generated in random order? When the results are displayed the numbers are sorted in natural order again.)

I also store the generated numbers as indices of arrays (not as values). This point allows me to test numbers via the simpler "if defined element[%num%] ..." that run faster than the usual "if !element[%index%]! equ %num% ..."

@echo off
setlocal EnableDelayedExpansion


rem The 300 lines are generated as a 2-dimensional matrix called "n" with this shape:
rem    n[%line%][%num%]=1
rem Where "line" is the index of the line: from 1 to 300
rem and "num" is *each number* (value between 1 and 39) that comprise such a line
rem
rem Each new line is previously generated in "num" array with 6 elements in the same way


rem Randomize
for /L %%i in (0,1,%time:~-1%) do set "x=!random!"

rem Generate 300 lines with 6 numbers each
set "line=0"
set "num[0]=0"
:nextLine

   rem Set numbers 1..39 as "available"
   for /L %%i in (1,1,39) do set "avail[%%i]=%%i"
   set "numsAvail=39"

   rem Remove previously generated numbers
   for /F "tokens=2 delims==" %%n in ('set num[') do set "num[%%n]="
   set "numbers=0"

   rem Generate 6 random numbers (from "available" ones):

   rem Get the index of anyone (random  order) of available numbers
   rem Insert such available number in "num" array
   rem Move to the (position of the) used available number the *last one*, and eliminate (the last) one available number
   rem And pass to the next number
   :nextAvail
      set /A indexAvail=%random% %% numsAvail + 1
      set /A num[!avail[%indexAvail%]!]=avail[%indexAvail%], avail[%indexAvail%]=avail[%numsAvail%], numsAvail-=1, numbers+=1
   if %numbers% lss 6 (
      if %numsAvail% gtr 0 (
         goto nextAvail
      ) else (
         goto nextLine
      )
   )

   rem Compare the new 6 numbers vs. *all* previously generated lines
   rem and eliminate the (last) number that cause to have more than 2 repeated numbers:

   for /L %%i in (1,1,%line%) do (
      set "repeated=0"
      for /F "tokens=2 delims==" %%j in ('set num[') do (
         if defined n[%%i][%%j] set /A repeated+=1
         if !repeated! gtr 2 (
            set "num[%%j]="
            set /A numbers-=1
            if %numsAvail% gtr 0 (
               goto nextAvail
            ) else (
               goto nextLine
            )
         )
      )
   )

   rem Insert (and show) the new line:
   set /A line+=1
   < NUL (
   set /P "=%time:~0,-3%  %line%- "
   for /F "tokens=2 delims==" %%n in ('set num[') do (
      set "n[%line%][%%n]=1"
      set /P "=%%n "
   ))
   echo/

if %line% lss 300 goto nextLine

I run this code for 1 hour and 50 minutes in my old-and-slow machine until it generates 100 sets. Obviously, the first sets are generated very fast and the time increases with the number of sets. This is the listing of the first 100 results:

21:52:36  1- 15 18 21 34 5 6
21:52:36  2- 10 14 15 26 33 6
21:52:36  3- 13 16 25 30 32 33
21:52:36  4- 14 23 29 2 35 39
21:52:36  5- 14 25 27 34 36 4
21:52:37  6- 12 18 20 22 36 7
21:52:37  7- 12 20 21 24 27 37
21:52:37  8- 22 28 30 35 6 9
21:52:38  9- 12 18 28 35 38 5
21:52:38  10- 18 23 25 30 36 8
21:52:39  11- 15 17 24 3 5 8
21:52:39  12- 17 22 24 26 29 31
21:52:40  13- 21 2 32 37 39 7
21:52:41  14- 11 23 28 2 33 7
21:52:41  15- 16 19 1 30 34 36
21:52:43  16- 15 21 32 38 4 9
21:52:43  17- 12 21 25 33 34 39
21:52:44  18- 16 24 32 6 8 9
21:52:46  19- 12 1 27 35 36 8
21:52:48  20- 15 18 20 33 35 3
21:52:49  21- 11 14 18 28 34 37
21:52:51  22- 20 22 25 26 35 39
21:52:53  23- 10 11 26 34 35 38
21:52:54  24- 18 19 22 28 2 39
21:52:56  25- 12 16 20 30 31 5
21:52:57  26- 15 16 23 27 36 6
21:52:59  27- 10 12 23 32 39 4
21:53:09  28- 17 23 26 28 34 4
21:53:11  29- 16 17 1 25 26 9
21:53:14  30- 12 13 15 16 2 7
21:53:15  31- 10 20 24 2 36 3
21:53:20  32- 10 11 17 1 20 23
21:53:24  33- 11 13 15 20 21 22
21:53:28  34- 14 15 20 28 29 36
21:53:30  35- 15 16 18 19 25 31
21:53:33  36- 10 15 17 18 32 37
21:53:47  37- 11 14 15 25 2 32
21:53:49  38- 19 21 28 7 8 9
21:53:55  39- 11 1 22 24 27 30
21:53:58  40- 10 14 18 20 30 4
21:54:01  41- 1 21 26 27 28 39
21:54:03  42- 10 13 25 34 6 9
21:54:04  43- 19 23 27 30 33 38
21:54:17  44- 10 12 13 18 27 3
21:54:25  45- 11 18 26 29 30 32
21:54:28  46- 13 14 15 37 38 39
21:54:30  47- 14 18 1 23 3 9
21:54:36  48- 12 13 20 23 28 6
21:54:48  49- 11 15 1 26 7 8
21:55:05  50- 11 12 13 17 26 39
21:55:10  51- 11 18 21 24 35 36
21:55:23  52- 10 12 15 29 38 8
21:55:46  53- 10 11 12 14 5 7
21:55:50  54- 13 26 27 2 33 36
21:55:58  55- 16 17 20 22 34 37
21:56:20  56- 10 11 13 31 33 4
21:56:23  57- 13 18 29 2 4 5
21:56:25  58- 1 22 23 2 31 5
21:56:30  59- 14 16 17 19 35 6
21:56:53  60- 10 12 16 17 21 36
21:57:29  61- 13 1 20 25 5 7
21:57:51  62- 10 14 17 24 25 38
21:58:03  63- 11 13 14 16 1 29
21:58:13  64- 10 15 16 28 30 39
21:58:20  65- 10 16 19 37 3 4
21:59:37  66- 10 11 21 25 37 8
21:59:40  67- 19 1 28 31 38 3
21:59:46  68- 15 25 26 27 30 3
22:00:10  69- 11 12 19 20 3 8
22:01:36  70- 11 13 30 35 3 7
22:02:09  71- 24 29 34 4 6 7
22:03:36  72- 24 26 35 37 7 9
22:05:18  73- 11 12 15 24 28 4
22:05:41  74- 22 23 24 33 34 36
22:07:15  75- 12 17 1 30 33 7
22:07:17  76- 19 25 32 4 5 6
22:07:35  77- 10 12 19 1 22 6
22:07:57  78- 12 14 15 17 22 23
22:08:57  79- 10 11 19 27 32 36
22:08:59  80- 11 25 31 36 5 9
22:10:39  81- 13 1 22 26 32 3
22:11:41  82- 11 12 22 29 33 35
22:11:54  83- 12 14 24 31 34 8
22:15:02  84- 12 13 14 19 30 9
22:17:18  85- 10 19 24 28 29 33
22:19:24  86- 17 1 24 37 39 6
22:21:04  87- 11 16 17 18 27 33
22:21:14  88- 12 1 20 2 32 38
22:22:37  89- 11 16 22 38 39 7
22:22:50  90- 10 18 1 29 31 39
22:27:39  91- 15 17 19 1 27 2
22:29:04  92- 13 19 21 23 24 2
22:36:51  93- 12 14 32 33 36 3
22:43:11  94- 13 18 20 24 31 32
22:53:34  95- 16 18 20 21 23 38
23:00:23  96- 11 14 30 31 38 6
23:02:39  97- 10 1 27 34 37 7
23:04:17  98- 13 16 17 23 31 3
23:08:38  99- 19 20 21 29 31 4
23:42:58  100- 10 12 26 28 31 37

I know there are several "cosmetic" details that had not been solved yet in my code, but IMHO it is much more important to clearly define the problem's solution first, before waste more CPU time in a not useful code...

Perhaps a much simpler solution would be to generate all sets of 6 numbers with up to 2 repeated elements (that can be generated under precise rules in a very fast way) and then randomly choose 300 from those sets... I am currently working in such a solution.


EDIT: First two parts of new solution are ready

The first two parts of the new solution are ready: sets of 6 numbers with NO and with ONE repetitions. Only the part with TWO repetitions is missing.

@echo off
setlocal EnableDelayedExpansion

set /A last=39, n=6, nM1=n-1

echo Combinations of 6 numbers with No repetitions:
set /A lastI=(last/n-1)*n+1, count=0
< NUL (
for /L %%i in (1,%n%,%lastI%) do (
   set /A lastJ=%%i+nM1
   for /L %%j in (%%i,1,!lastJ!) do (
      set /P "=%%j "
   )
   echo/
   set /A count+=1
))
echo Total = %count%

echo/
echo Combinations of 6 numbers with ONE repetition:
set /A lastI=last-(n-1)*2, count=0
< NUL (
for /L %%i in (1,1,%lastI%) do (
   set /A "firstJ=%%i+1, lastJ=firstJ+((last-firstJ+1)/nM1-1)*nM1"
   for /L %%j in (!firstJ!,%nM1%,!lastJ!) do (
      set /P "=%%i "
      set /A lastK=%%j+n-2
      for /L %%k in (%%j,1,!lastK!) do (
         set /P "=%%k "
      )
      echo/
      set /A count+=1
   )
))
echo Total = %count%

Output:

Combinations of 6 numbers with No repetitions:
1 2 3 4 5 6 
7 8 9 10 11 12 
13 14 15 16 17 18 
19 20 21 22 23 24 
25 26 27 28 29 30 
31 32 33 34 35 36 
Total = 6

Combinations of 6 numbers with ONE repetition:
1 2 3 4 5 6 
1 7 8 9 10 11 
1 12 13 14 15 16 
1 17 18 19 20 21 
1 22 23 24 25 26 
1 27 28 29 30 31 
1 32 33 34 35 36 
2 3 4 5 6 7 
2 8 9 10 11 12 
2 13 14 15 16 17 
2 18 19 20 21 22 
2 23 24 25 26 27 
2 28 29 30 31 32 
2 33 34 35 36 37 
3 4 5 6 7 8 
3 9 10 11 12 13 
3 14 15 16 17 18 
3 19 20 21 22 23 
3 24 25 26 27 28 
3 29 30 31 32 33 
3 34 35 36 37 38 
4 5 6 7 8 9 
4 10 11 12 13 14 
4 15 16 17 18 19 
4 20 21 22 23 24 
4 25 26 27 28 29 
4 30 31 32 33 34 
4 35 36 37 38 39 
5 6 7 8 9 10 
5 11 12 13 14 15 
5 16 17 18 19 20 
5 21 22 23 24 25 
5 26 27 28 29 30 
5 31 32 33 34 35 
6 7 8 9 10 11 
6 12 13 14 15 16 
6 17 18 19 20 21 
6 22 23 24 25 26 
6 27 28 29 30 31 
6 32 33 34 35 36 
7 8 9 10 11 12 
7 13 14 15 16 17 
7 18 19 20 21 22 
7 23 24 25 26 27 
7 28 29 30 31 32 
7 33 34 35 36 37 
8 9 10 11 12 13 
8 14 15 16 17 18 
8 19 20 21 22 23 
8 24 25 26 27 28 
8 29 30 31 32 33 
8 34 35 36 37 38 
9 10 11 12 13 14 
9 15 16 17 18 19 
9 20 21 22 23 24 
9 25 26 27 28 29 
9 30 31 32 33 34 
9 35 36 37 38 39 
10 11 12 13 14 15 
10 16 17 18 19 20 
10 21 22 23 24 25 
10 26 27 28 29 30 
10 31 32 33 34 35 
11 12 13 14 15 16 
11 17 18 19 20 21 
11 22 23 24 25 26 
11 27 28 29 30 31 
11 32 33 34 35 36 
12 13 14 15 16 17 
12 18 19 20 21 22 
12 23 24 25 26 27 
12 28 29 30 31 32 
12 33 34 35 36 37 
13 14 15 16 17 18 
13 19 20 21 22 23 
13 24 25 26 27 28 
13 29 30 31 32 33 
13 34 35 36 37 38 
14 15 16 17 18 19 
14 20 21 22 23 24 
14 25 26 27 28 29 
14 30 31 32 33 34 
14 35 36 37 38 39 
15 16 17 18 19 20 
15 21 22 23 24 25 
15 26 27 28 29 30 
15 31 32 33 34 35 
16 17 18 19 20 21 
16 22 23 24 25 26 
16 27 28 29 30 31 
16 32 33 34 35 36 
17 18 19 20 21 22 
17 23 24 25 26 27 
17 28 29 30 31 32 
17 33 34 35 36 37 
18 19 20 21 22 23 
18 24 25 26 27 28 
18 29 30 31 32 33 
18 34 35 36 37 38 
19 20 21 22 23 24 
19 25 26 27 28 29 
19 30 31 32 33 34 
19 35 36 37 38 39 
20 21 22 23 24 25 
20 26 27 28 29 30 
20 31 32 33 34 35 
21 22 23 24 25 26 
21 27 28 29 30 31 
21 32 33 34 35 36 
22 23 24 25 26 27 
22 28 29 30 31 32 
22 33 34 35 36 37 
23 24 25 26 27 28 
23 29 30 31 32 33 
23 34 35 36 37 38 
24 25 26 27 28 29 
24 30 31 32 33 34 
24 35 36 37 38 39 
25 26 27 28 29 30 
25 31 32 33 34 35 
26 27 28 29 30 31 
26 32 33 34 35 36 
27 28 29 30 31 32 
27 33 34 35 36 37 
28 29 30 31 32 33 
28 34 35 36 37 38 
29 30 31 32 33 34 
29 35 36 37 38 39 
Total = 128

EDIT: New correct method to get combinations with ONE repeated element

echo off
setlocal EnableDelayedExpansion

echo Combinations with ONE repeated element:
echo/

rem Initialize output file and available numbers
rem/> lines.txt
set "avail= "
for /L %%n in (2,1,39) do set "avail=!avail!%%n "
set /A numAvail=38, lines=0, base=0

:nextBase
   set /A base+=1

   :nextLine
      set "line= %base% "

      if %base% gtr 1 (

         rem Initialize available numbers
         set "avail= "
         for /L %%n in (1,1,39) do set "avail=!avail!%%n "
         set "numAvail=39"

         rem Remove available numbers that appears in previous lines for this base number
         for /F "delims=" %%a in ('findstr /C:" %base% " lines.txt') do (
            for %%b in (%%a) do if "!avail!" neq "!avail: %%b = !" (
               set "avail=!avail: %%b = !" & set /A numAvail-=1
            )
         )

      )

      rem Insert 5 numbers taking they from available ones
      set "nums=0"
      for /L %%n in (1,1,5) do if !numAvail! neq 0 (
         for /F "tokens=1*" %%x in ("!avail!") do (
            set "line=!line!%%x " & set "avail= %%y" & set /A nums+=1, numAvail-=1

            rem Remove available numbers that appears in previous lines for this new number
            for /F "delims=" %%a in ('findstr /C:" %%x " lines.txt') do (
               for %%b in (%%a) do if "!avail!" neq "!avail: %%b = !" (
                  set "avail=!avail: %%b = !" & set /A numAvail-=1
               )
            )

         )
      )

      if %nums% equ 5 (
         echo %line%
         >> lines.txt echo %line%
         set /A lines+=1
      )

   if %numAvail% geq 5 goto nextLine

if %base% lss 34 goto nextBase

echo/
echo %lines% lines created

Output:

Combinations with ONE repeated element:

 1 2 3 4 5 6
 1 7 8 9 10 11
 1 12 13 14 15 16
 1 17 18 19 20 21
 1 22 23 24 25 26
 1 27 28 29 30 31
 1 32 33 34 35 36
 2 7 12 17 22 27
 2 8 13 18 23 28
 2 9 14 19 24 29
 2 10 15 20 25 30
 2 11 16 21 26 31
 3 7 13 19 25 31
 3 8 12 20 24 32
 4 7 14 18 26 30
 4 8 15 17 29 33
 5 7 15 21 23 32
 6 7 16 20 28 33
 7 24 34 37 38 39
 8 5 14 22 31 34
 9 3 15 18 22 35
 10 3 14 17 23 36
 12 4 9 21 25 28
 12 5 10 18 29 37
 13 4 10 22 32 38
 14 6 11 25 27 32
 17 5 9 13 26 39
 22 6 19 30 36 37
 31 4 20 23 35 37

29 lines created

EDIT: Results of my new (I hope correct) method for combinations with TWO repeated numbers

1- 1 2 3 4 5 6 
2- 1 2 7 8 9 10 
3- 1 2 11 12 13 14 
4- 1 2 15 16 17 18 
5- 1 2 19 20 21 22 
6- 1 2 23 24 25 26 
7- 1 2 27 28 29 30 
8- 1 2 31 32 33 34 
9- 1 2 35 36 37 38 
10- 1 3 7 11 15 19 
11- 1 3 8 12 16 20 
12- 1 3 9 13 17 21 
13- 1 3 10 14 18 22 
14- 1 3 23 27 31 35 
15- 1 3 24 28 32 36 
16- 1 3 25 29 33 37 
17- 1 3 26 30 34 38 
18- 1 4 7 12 17 22 
19- 1 4 8 11 18 21 
20- 1 4 9 14 15 20 
21- 1 4 10 13 16 19 
22- 1 4 23 28 33 38 
23- 1 4 24 27 34 37 
24- 1 4 25 30 31 36 
25- 1 4 26 29 32 35 
26- 1 5 7 13 18 20 
27- 1 5 8 14 17 19 
28- 1 5 9 11 16 22 
29- 1 5 10 12 15 21 
30- 1 5 23 29 34 36 
31- 1 5 24 30 33 35 
32- 1 5 25 27 32 38 
33- 1 5 26 28 31 37 
34- 1 6 7 14 16 21 
35- 1 6 8 13 15 22 
36- 1 6 9 12 18 19 
37- 1 6 10 11 17 20 
38- 1 6 23 30 32 37 
39- 1 6 24 29 31 38 
40- 1 6 25 28 34 35 
41- 1 6 26 27 33 36 
42- 2 3 7 12 18 21 
43- 2 3 8 11 17 22 
44- 2 3 9 14 16 19 
45- 2 3 10 13 15 20 
46- 2 3 23 28 34 37 
47- 2 3 24 27 33 38 
48- 2 3 25 30 32 35 
49- 2 3 26 29 31 36 
50- 2 4 7 11 16 20 
51- 2 4 8 12 15 19 
52- 2 4 9 13 18 22 
53- 2 4 10 14 17 21 
54- 2 4 23 27 32 36 
55- 2 4 24 28 31 35 
56- 2 4 25 29 34 38 
57- 2 4 26 30 33 37 
58- 2 5 7 14 15 22 
59- 2 5 8 13 16 21 
60- 2 5 9 12 17 20 
61- 2 5 10 11 18 19 
62- 2 5 23 30 31 38 
63- 2 5 24 29 32 37 
64- 2 5 25 28 33 36 
65- 2 5 26 27 34 35 
66- 2 6 7 13 17 19 
67- 2 6 8 14 18 20 
68- 2 6 9 11 15 21 
69- 2 6 10 12 16 22 
70- 2 6 23 29 33 35 
71- 2 6 24 30 34 36 
72- 2 6 25 27 31 37 
73- 2 6 26 28 32 38 
74- 3 4 7 8 13 14 
75- 3 4 9 10 11 12 
76- 3 4 15 16 21 22 
77- 3 4 17 18 19 20 
78- 3 4 23 24 29 30 
79- 3 4 25 26 27 28 
80- 3 4 31 32 37 38 
81- 3 4 33 34 35 36 
82- 3 5 7 9 23 25 
83- 3 5 8 10 24 26 
84- 3 5 11 13 27 29 
85- 3 5 12 14 28 30 
86- 3 5 15 17 31 33 
87- 3 5 16 18 32 34 
88- 3 5 19 21 35 37 
89- 3 5 20 22 36 38 
90- 3 6 7 10 27 30 
91- 3 6 8 9 28 29 
92- 3 6 11 14 23 26 
93- 3 6 12 13 24 25 
94- 3 6 15 18 35 38 
95- 3 6 16 17 36 37 
96- 3 6 19 22 31 34 
97- 3 6 20 21 32 33 
98- 3 7 16 24 31 39 
99- 3 8 15 23 32 39 
100- 4 5 7 10 28 29 
101- 4 5 8 9 27 30 
102- 4 5 11 14 24 25 
103- 4 5 12 13 23 26 
104- 4 5 15 18 36 37 
105- 4 5 16 17 35 38 
106- 4 5 19 22 32 33 
107- 4 5 20 21 31 34 
108- 4 6 7 9 24 26 
109- 4 6 8 10 23 25 
110- 4 6 11 13 28 30 
111- 4 6 12 14 27 29 
112- 4 6 15 17 32 34 
113- 4 6 16 18 31 33 
114- 4 6 19 21 36 38 
115- 4 6 20 22 35 37 
116- 4 9 16 23 34 39 
117- 4 10 15 24 33 39 
118- 4 32 7 18 25 39 
119- 5 6 7 8 11 12 
120- 5 6 9 10 13 14 
121- 5 6 15 16 19 20 
122- 5 6 17 18 21 22 
123- 5 6 23 24 27 28 
124- 5 6 25 26 29 30 
125- 5 6 31 32 35 36 
126- 5 6 33 34 37 38 
127- 5 34 7 17 24 39 
128- 6 19 8 24 32 39 
129- 6 20 7 23 31 39 
130- 7 8 15 16 25 26 
131- 7 8 17 18 23 27 
132- 7 8 19 20 28 30 
133- 7 8 21 22 24 29 
134- 7 9 11 13 31 32 
135- 7 9 12 14 33 34 
136- 7 9 15 17 28 35 
137- 7 9 16 18 29 30 
138- 7 9 19 21 27 39 
139- 7 10 11 14 35 36 
140- 7 10 12 13 37 38 
141- 7 10 15 18 31 34 
142- 7 10 16 17 32 33 
143- 7 10 19 22 23 26 
144- 7 11 17 21 25 30 
145- 7 11 18 22 28 33 
146- 7 12 15 20 24 27 
147- 7 13 15 21 23 33 
148- 7 13 16 22 27 34 
149- 7 14 17 20 26 29 
150- 7 14 18 19 24 37 
151- 8 7 31 33 35 37 
152- 8 7 32 34 36 38 
153- 8 9 11 14 37 38 
154- 8 9 12 13 35 36 
155- 8 9 15 18 24 33 
156- 8 10 11 13 33 34 
157- 8 10 12 14 31 32 
158- 8 10 15 17 29 30 
159- 8 10 16 18 28 35 
160- 8 11 15 20 31 36 
161- 8 11 16 19 23 29 
162- 8 12 17 21 26 28 
163- 8 12 18 22 25 30 
164- 8 12 23 24 34 37 
165- 8 13 17 20 24 38 
166- 8 13 18 19 26 31 
167- 8 14 15 21 27 34 
168- 8 14 16 22 33 36 
169- 8 21 3 25 31 38 
170- 8 22 4 26 34 39 
171- 9 5 15 26 32 39 
172- 9 10 15 16 27 36 
173- 9 10 17 18 25 26 
174- 9 10 19 20 24 29 
175- 9 10 21 22 28 30 
176- 9 10 23 31 33 37 
177- 9 11 17 19 33 36 
178- 9 11 18 20 23 27 
179- 9 12 15 22 23 29 
180- 9 12 16 21 24 31 
181- 9 13 15 19 25 30 
182- 9 13 16 20 26 28 
183- 9 14 17 22 24 27 
184- 9 14 18 21 32 35 
185- 9 16 6 25 32 38 
186- 9 22 3 26 33 35 
187- 10 11 15 22 25 32 
188- 10 11 16 21 26 37 
189- 10 12 17 19 27 34 
190- 10 12 18 20 33 36 
191- 10 13 17 22 31 35 
192- 10 13 18 21 24 27 
193- 10 13 23 28 32 36 
194- 10 14 15 19 28 38 
195- 10 14 16 20 23 30 
196- 10 19 3 25 36 39 
197- 11 12 15 16 28 34 
198- 11 12 17 18 24 29 
199- 11 12 19 20 25 26 
200- 11 12 21 22 27 35 
201- 11 12 23 30 33 39 
202- 11 13 15 17 26 39 
203- 11 13 16 18 25 36 
204- 11 17 4 23 31 37 
205- 11 20 3 24 34 35 
206- 11 20 5 28 32 39 
207- 12 5 16 25 37 39 
208- 12 14 15 17 25 36 
209- 12 14 16 18 26 38 
210- 13 14 15 16 24 29 
211- 13 14 17 18 28 33 
212- 13 14 19 20 27 32 
213- 13 14 21 22 25 26 
214- 13 15 4 27 31 38 
215- 13 21 4 29 37 39 
216- 14 16 4 28 32 37 
217- 16 19 7 12 35 36 
218- 16 20 17 21 27 39 
219- 16 22 17 19 25 28 
220- 18 5 8 29 38 39 
221- 18 20 15 21 25 28 
222- 18 22 15 19 27 39 
223- 21 22 23 31 32 36 
224- 23 27 10 29 38 39 
225- 23 38 3 12 17 19 
226- 24 26 11 22 30 31 
227- 24 29 25 27 35 36 
228- 24 29 26 28 33 34 
229- 25 30 10 24 37 38 
230- 28 29 11 14 21 31 

答案3

得分: 1

我在这里发布了一个新答案,因为之前的答案太长了,不接受任何进一步的文字。

这个问题很复杂,因为输入数据的数量很大(3,262,623个可能的组合)!解决这个问题有两种方法:“蛮力”方法(如Magoo的方法)或“智能”方法,可以避免处理整个输入集(如我的方法)。要更好地了解蛮力方法需要的时间,请先运行这个小程序,显示3,262,623个数字:

请注意,这个程序只是生成数字。在实际解决方案中,必须将数字组合成6组,不能重复,并完成所有必要的额外测试,因此时间会增加。

现在运行这个程序,它只显示相同的数字,但使用一个“跳转到组装循环”(类似Magoo的程序):

你应该明白“蛮力”方法只是无法接受的,如果你想生成一个完整的、真正的解决方案(即使它们被转换成Python或任何其他语言)...

以下是我程序的最后(已更正)生成的结果。请注意,这个问题很复杂,难以开发出解决它的“智能”方法。也许它仍然存在可以修复的小错误。重要提示:请注意,这种方法在15分钟内生成所有解决方案!(是的:15分钟)。因此,如果你想得到一个真正的解决方案,最好尝试修复这个方法中的所有细节,而不是试图让“蛮力”方法更快。请查看第215个结果,并报告任何问题...

编辑:新的“蛮力”方法

我写了一个“蛮力”程序,它生成了3,262,623个组合中的每一个,并对每一个组合计算重复元素与所有先前生成的有效组合的数量,如果数量小于或等于2,则生成一个新的有效组合。

尽管这种方法是“蛮力”方法,但它是以最快的方式编程的。该程序足够简单,即使你对批处理文件不太了解,也可以理解,所以你可以以非常简单的方式修改最后一个数字和最大重复次数。然而,请注意,每个组合中的数字(在这种情况下为6个)在代码中是固定的,尽管你也可以通过仔细审查其他行来修改它们。

【后续内容省略】

英文:

I posted a new answer here because the previous one is too large and don't accept any further text.

This problem is complex and convoluted because the number of input data is huge (3,262,623 possible combinations)! There are two ways to solve this problem: "brute force" methods (like Magoo's one) or "smart" methods that avoids to process the entire input set (like the mine). To have a better understanding of the time that brute force methods requires, run first this small program that show 3,262,623 numbers:

@echo off
set "start=%time%"
for /L %%i in (1,1,3262623) do echo %%i
echo Start: %start%
echo End:   %time%

Note that this program just generates the numbers. In a real solution, the numbers must be combined in groups of 6 with no repetitions and complete all the required additional tests, so the time increases.

Now run this program that just show the same numbers, but uses a "goto assembled loop" (like Magoo's program):

@echo off
set "start=%time%"
set number=0
:nextNum
set /A number+=1
echo %number%
if %number% lss 3262623 goto nextNum
echo Start: %start%
echo End:   %time%

You should understand that "brute force" methods are just unnaceptable if you want to generate a complete and real solution (even if they are translated to Phyton or any other language)...

Below are the last (corrected) results generated by the last version of my program. Please, note that the problem is complex and convoluted, so a "smart" method that solve it is difficult to develop. Perhaps it still have small bugs that can be fixed. IMPORTANT: please note that this method generates all solutions in 15 minutes! (Yes: fifteen minutes). So, if you want a real solution to your problem, it is much better to try to fix all details in this method instead of try to make faster the "brute force" one. Please, review the 215 result and report any problem...

1-  01 02 03 04 05 06 
2-  01 02 07 08 09 10 
3-  01 02 11 12 13 14 
4-  01 02 15 16 17 18 
5-  01 02 19 20 21 22 
6-  01 02 23 24 25 26 
7-  01 02 27 28 29 30 
8-  01 02 31 32 33 34 
9-  01 02 35 36 37 38 
10-  01 03 07 11 15 19 
11-  01 03 08 12 16 20 
12-  01 03 09 13 17 21 
13-  01 03 10 14 18 22 
14-  01 03 23 27 31 35 
15-  01 03 24 28 32 36 
16-  01 03 25 29 33 37 
17-  01 03 26 30 34 38 
18-  01 04 07 12 17 22 
19-  01 04 08 11 18 21 
20-  01 04 09 14 15 20 
21-  01 04 10 13 16 19 
22-  01 04 23 28 33 38 
23-  01 04 24 27 34 37 
24-  01 04 25 30 31 36 
25-  01 04 26 29 32 35 
26-  01 05 07 13 18 20 
27-  01 05 08 14 17 19 
28-  01 05 09 11 16 22 
29-  01 05 10 12 15 21 
30-  01 05 23 29 34 36 
31-  01 05 24 30 33 35 
32-  01 05 25 27 32 38 
33-  01 05 26 28 31 37 
34-  01 06 07 14 16 21 
35-  01 06 08 13 15 22 
36-  01 06 09 12 18 19 
37-  01 06 10 11 17 20 
38-  01 06 23 30 32 37 
39-  01 06 24 29 31 38 
40-  01 06 25 28 34 35 
41-  01 06 26 27 33 36 
42-  02 03 07 12 18 21 
43-  02 03 08 11 17 22 
44-  02 03 09 14 16 19 
45-  02 03 10 13 15 20 
46-  02 03 23 28 34 37 
47-  02 03 24 27 33 38 
48-  02 03 25 30 32 35 
49-  02 03 26 29 31 36 
50-  02 04 07 11 16 20 
51-  02 04 08 12 15 19 
52-  02 04 09 13 18 22 
53-  02 04 10 14 17 21 
54-  02 04 23 27 32 36 
55-  02 04 24 28 31 35 
56-  02 04 25 29 34 38 
57-  02 04 26 30 33 37 
58-  02 05 07 14 15 22 
59-  02 05 08 13 16 21 
60-  02 05 09 12 17 20 
61-  02 05 10 11 18 19 
62-  02 05 23 30 31 38 
63-  02 05 24 29 32 37 
64-  02 05 25 28 33 36 
65-  02 05 26 27 34 35 
66-  02 06 07 13 17 19 
67-  02 06 08 14 18 20 
68-  02 06 09 11 15 21 
69-  02 06 10 12 16 22 
70-  02 06 23 29 33 35 
71-  02 06 24 30 34 36 
72-  02 06 25 27 31 37 
73-  02 06 26 28 32 38 
74-  03 04 07 08 13 14 
75-  03 04 09 10 11 12 
76-  03 04 15 16 21 22 
77-  03 04 17 18 19 20 
78-  03 04 23 24 29 30 
79-  03 04 25 26 27 28 
80-  03 04 31 32 37 38 
81-  03 04 33 34 35 36 
82-  03 05 07 09 23 25 
83-  03 05 08 10 24 26 
84-  03 05 11 13 27 29 
85-  03 05 12 14 28 30 
86-  03 05 15 17 31 33 
87-  03 05 16 18 32 34 
88-  03 05 19 21 35 37 
89-  03 05 20 22 36 38 
90-  03 06 07 10 27 30 
91-  03 06 08 09 28 29 
92-  03 06 11 14 23 26 
93-  03 06 12 13 24 25 
94-  03 06 15 18 35 38 
95-  03 06 16 17 36 37 
96-  03 06 19 22 31 34 
97-  03 06 20 21 32 33 
98-  03 07 16 24 31 39 
99-  03 08 15 23 32 39 
100-  04 05 07 10 28 29 
101-  04 05 08 09 27 30 
102-  04 05 11 14 24 25 
103-  04 05 12 13 23 26 
104-  04 05 15 18 36 37 
105-  04 05 16 17 35 38 
106-  04 05 19 22 32 33 
107-  04 05 20 21 31 34 
108-  04 06 07 09 24 26 
109-  04 06 08 10 23 25 
110-  04 06 11 13 28 30 
111-  04 06 12 14 27 29 
112-  04 06 15 17 32 34 
113-  04 06 16 18 31 33 
114-  04 06 19 21 36 38 
115-  04 06 20 22 35 37 
116-  04 09 16 23 34 39 
117-  04 10 15 24 33 39 
118-  04 32 07 18 25 39 
119-  05 06 07 08 11 12 
120-  05 06 09 10 13 14 
121-  05 06 15 16 19 20 
122-  05 06 17 18 21 22 
123-  05 06 23 24 27 28 
124-  05 06 25 26 29 30 
125-  05 06 31 32 35 36 
126-  05 06 33 34 37 38 
127-  06 21 08 24 35 39 
128-  06 22 07 23 36 39 
129-  07 08 15 16 25 26 
130-  07 08 17 18 23 24 
131-  07 08 19 20 27 28 
132-  07 08 21 22 29 30 
133-  07 09 11 13 31 32 
134-  07 09 12 14 33 34 
135-  07 09 15 17 27 29 
136-  07 09 16 18 28 30 
137-  07 10 11 14 35 36 
138-  07 10 12 13 37 38 
139-  07 10 15 18 31 34 
140-  07 10 16 17 32 33 
141-  07 10 19 21 23 26 
142-  07 10 20 22 24 25 
143-  07 11 17 21 25 28 
144-  07 11 18 22 26 27 
145-  07 12 15 20 23 30 
146-  07 12 16 19 29 35 
147-  07 13 15 21 24 36 
148-  07 14 17 20 26 31 
149-  08 07 31 33 35 37 
150-  08 07 32 34 36 38 
151-  08 09 11 14 37 38 
152-  08 09 12 13 35 36 
153-  08 10 11 13 33 34 
154-  08 10 12 14 31 32 
155-  08 10 15 17 28 30 
156-  08 10 16 18 27 29 
157-  08 10 19 22 35 38 
158-  08 10 20 21 36 37 
159-  08 11 15 20 24 29 
160-  08 11 16 19 23 30 
161-  08 12 17 21 26 27 
162-  08 12 18 22 25 28 
163-  08 13 17 20 25 32 
164-  08 13 18 19 26 31 
165-  08 17 04 29 31 39 
166-  09 10 15 16 35 37 
167-  09 10 17 18 25 26 
168-  09 10 19 20 29 30 
169-  09 10 21 22 27 28 
170-  09 10 23 24 31 36 
171-  09 11 17 19 24 33 
172-  09 11 18 20 23 35 
173-  09 11 25 27 34 36 
174-  09 12 15 22 24 32 
175-  09 12 16 21 25 31 
176-  09 13 15 19 23 28 
177-  09 13 16 20 24 27 
178-  09 14 17 22 23 30 
179-  09 14 18 21 24 29 
180-  09 18 03 27 37 39 
181-  10 12 17 19 34 36 
182-  10 14 15 19 25 27 
183-  10 14 16 20 23 28 
184-  10 21 03 25 34 39 
185-  11 12 15 16 27 28 
186-  11 12 17 18 29 30 
187-  11 12 19 20 25 26 
188-  11 12 21 22 23 33 
189-  11 13 15 17 26 35 
190-  11 13 16 18 25 37 
191-  11 14 15 18 32 33 
192-  12 06 15 26 31 39 
193-  13 14 15 16 29 30 
194-  13 14 17 18 27 28 
195-  13 14 19 20 33 35 
196-  13 14 21 22 25 26 
197-  13 14 23 24 32 34 
198-  13 14 31 36 37 39 
199-  14 05 16 26 33 39 
200-  15 20 17 21 38 39 
201-  16 18 12 14 36 38 
202-  16 20 17 22 29 34 
203-  16 21 10 11 24 38 
204-  17 05 07 30 34 39 
205-  17 20 23 27 33 37 
206-  18 21 10 13 30 32 
207-  18 22 15 19 29 39 
208-  20 22 08 09 26 33 
209-  24 26 11 28 34 39 
210-  24 26 12 14 35 37 
211-  27 29 19 21 31 32 
212-  27 29 20 25 35 39 
213-  27 30 11 14 20 21 
214-  27 30 12 13 19 22 
215-  33 38 07 11 29 39 

EDIT: New "Brute force" method

I wrote a "Brute force" program that generates each one of the 3,262,623 combinations and, for each one, count the number of repeated elements versus all previously generated valid combinations and, if the number is less or equal 2, generate a new valid combination.

Although the method is "brute force", it is programmed in the fastest possible way. The program is simple enough to be understood even if you don't know too much about Batch files, so you can modify the last number and the max number of repetitions in a very simple way. However, note that the numbers in each combination (6 in this case) is hard programmed in the code, although you could also modify it via a careful review of the other lines.

@echo off
setlocal EnableDelayedExpansion

rem "Brute force" method to get all combinations of N numbers in sets of 6 elements
rem with a maximum of Rep repetitions

rem Set last number and max number of repetitions
set /A n=39, rep=2
rem In this version the number of elements in combination is fixed to 6!

set /A nM1=n-1, nM2=n-2, nM3=n-3, nM4=n-4, nM5=n-5,  lines=1
set "c[1,2,3,4,5,6]=1"
echo 1- 1,2,3,4,5,6
> lines.txt echo 1,2,3,4,5,6
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
set "start=%time:~0,-3%"

< NUL (
for /L %%i in (1,1,%nM5%) do (
   echo !time:~0,-3!          
   set /A iP1=%%i+1
   for /L %%j in (!iP1!,1,%nM4%) do (
      set /A jP1=%%j+1
      for /L %%k in (!jP1!,1,%nM3%) do (
         set /A kP1=%%k+1
         for /L %%l in (!kP1!,1,%nM2%) do (
            set /A lP1=%%l+1
            for /L %%m in (!lP1!,1,%nM1%) do (
               set /A mP1=%%m+1
               for /L %%n in (!mP1!,1,%n%) do (
                  set /P "=%%i,%%j,%%k,%%l,%%m,%%n      !CR!"
                  set "reps=0"
                  for /F "tokens=2 delims=[]" %%a in ('set c[') do (
                     if !reps! leq %rep% (
                        for %%b in (%%a) do set /A "reps+=^!(%%b-%%i)+^!(%%b-%%j)+^!(%%b-%%k)+^!(%%b-%%l)+^!(%%b-%%m)+^!(%%b-%%n)"
                        if !reps! leq %rep% set "reps=0"
                     )
                  )
                  if !reps! leq %rep% (
                     set "c[%%i,%%j,%%k,%%l,%%m,%%n]=1"
                     set /A lines+=1
                     echo !lines!- %%i,%%j,%%k,%%l,%%m,%%n      
                     >> lines.txt echo %%i,%%j,%%k,%%l,%%m,%%n
                  )
               )
            )
         )
      )
   )
))

echo Start: %start%
echo End:   %time:~0,-3%

huangapple
  • 本文由 发表于 2023年5月10日 22:08:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定