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

2006/06/19

文字コードの和

By:“midore” at:2006/06/19(月曜) 18:29曇のち雨

特に意味もなく自分の名前の文字コードの和が素数だったらいいなと期待したが、

def my_no(str)
  #unsigned char (8bit 符号なし整数)
  a = "#{str}".unpack("C*")
  mynum = 0
  a.each{|str|
    a_x = sprintf("%x", str).to_i
    mynum = mynum + a_x
    }
    return mynum
end
puts "sum = " + my_no("midore").to_s + "?n"
exit


=> sum = 282

素数じゃなかった...

http://ruby-lang.org/ja/man/?cmd=view;name=pack%A5%C6%A5%F3%A5%D7%A5%EC%A1%BC%A5%C8%CA%B8%BB%FA%CE%F3;em=unpack;em=C

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