2006/06/27

ひさびさにAppleScriptエディタ使った

By:“midore” at:2006/06/27(火曜) 13:10曇り

ぐるりさん,http://www.gururi.com/applescript /2006-06-21T010223.htm に触発されて私も考えてみたです。100以下の素数という条件なのでとても素直に考えてみたつもり。けど、seedに予めいれておくのはやっぱ反則なのかな???これダメな感じか?そんな気もしつつ...。

set seed to {2, 3, 5, 7}

repeat with targetnum from 2 to 100
my check(targetnum, seed)
end repeat
return seed

to check(targetnum, seed)

set checklist to {}
repeat with i in seed
set end of checklist to targetnum mod i
end repeat

if checklist does not contain 0 then
set end of seed to targetnum
end if

end check

=> {2, 3, 5, 7, 13, 11, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}

--imported_from
http://www.midore.net/daybook/2006/5-9/1151381435.html

0 件のコメント: