Created
December 24, 2014 14:32
-
-
Save Jagua/99372b934d55dfce1282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scriptencoding utf-8 | |
function! harem#now(list, n) | |
return harem#_loop(a:list, [], 1, a:n) | |
endfunction | |
function! harem#_loop(list, result, count, n) | |
if len(a:list) > 0 | |
let result = harem#_loop(a:list[1:], a:result + ['.'], a:count, a:n) | |
if a:count <= a:n | |
let result += harem#_loop(a:list[1:], a:result + [a:list[0]], a:count + 1, a:n) | |
endif | |
return result | |
else | |
return [a:result] | |
endif | |
endfunction | |
" vim-prettyprint (by thinca) | |
echo PrettyPrint(harem#now(split('ABCDE', '\zs'), 2)) | |
" => | |
"[ | |
" ['.', '.', '.', '.', '.'], | |
" ['.', '.', '.', '.', 'E'], | |
" ['.', '.', '.', 'D', '.'], | |
" ['.', '.', '.', 'D', 'E'], | |
" ['.', '.', 'C', '.', '.'], | |
" ['.', '.', 'C', '.', 'E'], | |
" ['.', '.', 'C', 'D', '.'], | |
" ['.', 'B', '.', '.', '.'], | |
" ['.', 'B', '.', '.', 'E'], | |
" ['.', 'B', '.', 'D', '.'], | |
" ['.', 'B', 'C', '.', '.'], | |
" ['A', '.', '.', '.', '.'], | |
" ['A', '.', '.', '.', 'E'], | |
" ['A', '.', '.', 'D', '.'], | |
" ['A', '.', 'C', '.', '.'], | |
" ['A', 'B', '.', '.', '.'] | |
"] | |
echo len(harem#now(split('ABCDE', '\zs'), 2)) | |
" => 16 | |
" C(5,2)+C(5,1)+C(5,0)=10+5+1=16 ... Ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment