|
839 | 839 | # @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early |
840 | 840 | # =begin |
841 | 841 | # (let data [0 1 2 3]) |
842 | | -# (list:permutations data 3 (fun (perm) (print perm))) |
| 842 | +# (list:combinations data 3 (fun (perm) (print perm))) |
843 | 843 | # # [0 1 2] |
844 | 844 | # # [0 1 3] |
845 | 845 | # # [0 2 3] |
846 | 846 | # # [1 2 3] |
847 | 847 | # =end |
848 | 848 | # @author https://github.com/SuperFola |
849 | | -(let permutations (fun ((ref _L) _r _f) { |
| 849 | +(let combinations (fun ((ref _L) _r _f) { |
850 | 850 | (let _len (len _L)) |
851 | 851 | (if (and (<= _r _len) (> _r 0)) |
852 | 852 | { |
|
873 | 873 | (set _continue false)) } |
874 | 874 | (set _continue false)) }) }) }) })) |
875 | 875 |
|
| 876 | +# @brief Compute permutations of length _r from a given list |
| 877 | +# @details The original list is not modified. |
| 878 | +# @param _L list to get values from |
| 879 | +# @param _r number of elements per permutation |
| 880 | +# @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early |
| 881 | +# @deprecated Use list:combinations. Will be removed in ArkScript 4.5.0 |
| 882 | +# =begin |
| 883 | +# (let data [0 1 2 3]) |
| 884 | +# (list:permutations data 3 (fun (perm) (print perm))) |
| 885 | +# # [0 1 2] |
| 886 | +# # [0 1 3] |
| 887 | +# # [0 2 3] |
| 888 | +# # [1 2 3] |
| 889 | +# =end |
| 890 | +# @author https://github.com/SuperFola |
| 891 | +(let permutations combinations) |
| 892 | + |
876 | 893 | # @brief Compute permutations of length _r from a given list, allowing individual elements to be repeated more than once |
877 | 894 | # @details The original list is not modified. |
878 | 895 | # @param _L list to get values from |
879 | 896 | # @param _r number of elements per permutation |
880 | 897 | # @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early |
881 | 898 | # =begin |
882 | 899 | # (let data [0 1 2]) |
883 | | -# (list:permutationsWithReplacement data 2 (fun (perm) (print perm))) |
| 900 | +# (list:combinationsWithReplacement data 2 (fun (perm) (print perm))) |
884 | 901 | # # [0 0] |
885 | 902 | # # [0 1] |
886 | 903 | # # [0 2] |
|
889 | 906 | # # [2 2] |
890 | 907 | # =end |
891 | 908 | # @author https://github.com/SuperFola |
892 | | -(let permutationsWithReplacement (fun ((ref _L) _r _f) { |
| 909 | +(let combinationsWithReplacement (fun ((ref _L) _r _f) { |
893 | 910 | (let _len (len _L)) |
894 | 911 | (if (and (!= 0 _len) (> _r 0)) |
895 | 912 | { |
|
915 | 932 | (if (= stopIteration (_f (select _L _indices))) |
916 | 933 | (set _continue false)) } |
917 | 934 | (set _continue false)) }) }) }) })) |
| 935 | + |
| 936 | +# @brief Compute permutations of length _r from a given list, allowing individual elements to be repeated more than once |
| 937 | +# @details The original list is not modified. |
| 938 | +# @param _L list to get values from |
| 939 | +# @param _r number of elements per permutation |
| 940 | +# @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early |
| 941 | +# @deprecated Use list:combinationsWithReplacement. Will be removed in ArkScript 4.5.0 |
| 942 | +# =begin |
| 943 | +# (let data [0 1 2]) |
| 944 | +# (list:permutationsWithReplacement data 2 (fun (perm) (print perm))) |
| 945 | +# # [0 0] |
| 946 | +# # [0 1] |
| 947 | +# # [0 2] |
| 948 | +# # [1 1] |
| 949 | +# # [1 2] |
| 950 | +# # [2 2] |
| 951 | +# =end |
| 952 | +# @author https://github.com/SuperFola |
| 953 | +(let permutationsWithReplacement combinationsWithReplacement) |
0 commit comments