Skip to content

Instantly share code, notes, and snippets.

@papiron
Last active December 18, 2016 15:46
Show Gist options
  • Save papiron/b4e162e5a9658ee25e8f4ca55df2c37d to your computer and use it in GitHub Desktop.
Save papiron/b4e162e5a9658ee25e8f4ca55df2c37d to your computer and use it in GitHub Desktop.
10進数140桁の素数を見つける
<<<10進数140桁の素数を見つけ出す>>>
opensslコマンドをフィルタとして活用する。出力の行頭に OpenSSL> というプロンプトが付いてくるのが邪魔ね。
<<地道に順番に見つけ出す>>
# Mac (coreutilsとGNU sedを利用)
$ yes '0 9' | head -n 140 | rs -T | tr -d ' ' | sed '1s/0/1/' | xargs gseq | gsed -u 's/^/prime /' | openssl | grep --line-buffered -v not | awk '{print $2;fflush()}' | (echo 'obase=10;ibase=16'; cat) | BC_LINE_LENGTH=200 bc
## Ubuntu
$ yes '0 9' | head -n 140 | rs -T | tr -d ' ' | sed '1s/0/1/' | xargs seq | sed -u 's/^/prime /' | openssl | grep --line-buffered -v not | awk '{print $2;fflush()}' | (echo 'obase=10;ibase=16'; cat) | BC_LINE_LENGTH=0 bc
<<ランダムに見つけ出す>>
## Mac (GNU coreutilsとGNU sedを利用)
$ cat /dev/urandom | gtr -dc '0-9' | fold -w 140 | sed 's/^/prime /' | openssl | grep --line-buffered -v not | awk '{print $2;fflush()}' | (echo "obase=10;ibase=16"; cat) | BC_LINE_LENGTH=200 bc
## Ubuntu
$ cat /dev/urandom | tr -dc '0-9' | fold -w 140 | sed 's/^/prime /' | openssl | grep --line-buffered -v not | awk '{print $2;fflush()}' | (echo "obase=10;ibase=16"; cat) | BC_LINE_LENGTH=0 bc
参考(多分UbuntuなどのLinux)
https://twitter.com/grethlen/status/803131015908593665
$ shuf -er {0..9}|xargs -n140|ruby -pae'$_=sprintf("%X\n",$F.join.to_i)'|xargs -n1 openssl prime -hex|ruby -anle'p $F[0].hex if !/^0/&&!/not/'
https://twitter.com/eban/status/803226463717601281
$ shuf -er {0..9}|tr -d '\n'|fold -w140|grep -v '^0'|xargs -n1 openssl prime|ruby -ne 'p $_.hex if !/not/'
<openssl 1.0.0以上かつshufが新しめの場合>
## FreeBSD (GNU coreutilsとGNU sedを利用)
$ gshuf -re 'prime -generate -bits '{462..466} | openssl 2> /dev/null | gsed -u 's/^OpenSSL> //' | grep -E '^.{140}$'
## Ubuntu
$ shuf -re 'prime -generate -bits '{462..466} | openssl 2> /dev/null | sed -u 's/^OpenSSL> //' | grep -E '^.{140}$'
参考(多分UbuntuなどのLinux)
https://twitter.com/grethlen/status/803238776340291584
$ shuf -re 'openssl prime -generate -bits '{462..466} | sh | grep -E '^.{140}$'
http://stackoverflow.com/questions/19732162/openssl-generate-prime-number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment