Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Knuth-shuffle/CMake/knuth-shuffle-1.cmake
Normal file
33
Task/Knuth-shuffle/CMake/knuth-shuffle-1.cmake
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# shuffle(<output variable> [<value>...]) shuffles the values, and
|
||||
# stores the result in a list.
|
||||
function(shuffle var)
|
||||
set(forever 1)
|
||||
|
||||
# Receive ARGV1, ARGV2, ..., ARGV${last} as an array of values.
|
||||
math(EXPR last "${ARGC} - 1")
|
||||
|
||||
# Shuffle the array with Knuth shuffle (Fisher-Yates shuffle).
|
||||
foreach(i RANGE ${last} 1)
|
||||
# Roll j = a random number from 1 to i.
|
||||
math(EXPR min "100000000 % ${i}")
|
||||
while(forever)
|
||||
string(RANDOM LENGTH 8 ALPHABET 0123456789 j)
|
||||
if(NOT j LESS min) # Prevent modulo bias when j < min.
|
||||
break() # Break loop when j >= min.
|
||||
endif()
|
||||
endwhile()
|
||||
math(EXPR j "${j} % ${i} + 1")
|
||||
|
||||
# Swap ARGV${i} with ARGV${j}.
|
||||
set(t ${ARGV${i}})
|
||||
set(ARGV${i} ${ARGV${j}})
|
||||
set(ARGV${j} ${t})
|
||||
endforeach(i)
|
||||
|
||||
# Convert array to list.
|
||||
set(answer)
|
||||
foreach(i RANGE 1 ${last})
|
||||
list(APPEND answer ${ARGV${i}})
|
||||
endforeach(i)
|
||||
set("${var}" ${answer} PARENT_SCOPE)
|
||||
endfunction(shuffle)
|
||||
4
Task/Knuth-shuffle/CMake/knuth-shuffle-2.cmake
Normal file
4
Task/Knuth-shuffle/CMake/knuth-shuffle-2.cmake
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
shuffle(result 11 22 33 44 55 66)
|
||||
message(STATUS "${result}")
|
||||
# One possible output:
|
||||
# -- 66;33;22;55;44;11
|
||||
Loading…
Add table
Add a link
Reference in a new issue