— 2014-10-06 Original By Nigel Garvey@macscripter.net — 2019-06-19 Modified By Takaaki Naganoya — 2024-02-18 Modified By Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation"
script spdPerm property permutations : missing value property allRes : {} end script
on run set allList to {{"A", "T", "G", "C"}, {"A", "T", "G", "C", "1"}, {"A", "T", "G", "C", "1", "2"}, {"A", "T", "G", "C", "1", "2", "3"}, {"A", "T", "G", "C", "1", "2", "3", "4"}, {"A", "T", "G", "C", "1", "2", "3", "4", "5"}} repeat with i in allList set theList to contents of i set a1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate() set aRes to permute(theList) of me set b1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate() set c1Dat to (b1Dat – a1Dat) set the end of (allRes of spdPerm) to {length of theList, c1Dat} end repeat return (allRes of spdPerm) — MacBook Pro 2012 Retina Core i7 2.6GHz@macOS 10.14.6 の実行結果 –> {{4, 0.01 }, {5, 0.010347008705}, {6, 0.05}, {7, 1.44}, {8, 11.54}, {9, 107.271}} –M1 Mac mini@macOS 13.6.5 の実行結果 –> {{4, 0.005248069763}, {5, 0.01240503788}, {6, 0.063866019249}, {7, 0.434872984886}, {8, 3.519423961639}, {9, 31.62052500248}} end run
on permute(theList as list) set theArray to current application’s NSMutableArray’s arrayWithArray:theList set (permutations of spdPerm) to current application’s NSMutableArray’s array() prmt(theArray, 0, (count theList) – 1) –Return AppleScript string list set aFinishArray to current application’s NSMutableArray’s new() set anEnum to (permutations of spdPerm)’s objectEnumerator() repeat set aValue to anEnum’s nextObject() if aValue = missing value then exit repeat set aStr to aValue’s componentsJoinedByString:"" (aFinishArray’s addObject:aStr) end repeat return aFinishArray as list end permute
on prmt(theArray, theStart as number, theEnd as number) if (theStart = theEnd) then (permutations of spdPerm)’s addObject:theArray else repeat with x from theStart to theEnd set theCopy to theArray’s mutableCopy() –swap if (x > theStart) then (theCopy’s exchangeObjectAtIndex:theStart withObjectAtIndex:x) prmt(theCopy, theStart + 1, theEnd) end repeat end if end prmt
|