Re: 成分分析
ついでに、どんなつくりになっているのか想像してみました。
はじめてみたときには、だいたんこんな感じだろうとちょっと
作ってみるつもりで2時間くらいかかってしまった。
しかし、文字コードを替えても同じ成分構成にならないところ
をみるとなにかもっと加工しているようです。
#!/usr/bin/perl
# -*- Mode: Perl -*-
#
# Time-stamp: <2006-04-08 15:03:00 Norimasa Nabeta>
#
# 成分解析
#
#
eval 'exec perl -S $0 "$@"'
if 0;
#
# 素数に『組成物質』を割り付ける表
#
my @primeMap =
(
{ prime => 2, name => 'あか', cnt => 0},
{ prime => 3, name => 'あお', cnt => 0},
{ prime => 5, name => 'きいろ', cnt => 0},
{ prime => 7, name => 'みどり', cnt => 0},
{ prime => 11, name => 'ちゃ', cnt => 0},
{ prime => 13, name => 'くろ', cnt => 0},
{ prime => 17, name => 'しろ', cnt => 0},
{ prime => 19, name => 'あずき', cnt => 0},
{ prime => 23, name => 'こうひい', cnt => 0},
{ prime => 29, name => 'ゆず', cnt => 0},
{ prime => 31, name => 'さくら', cnt => 0},
{ prime => 37, name => 'うぐいす', cnt => 0},
{ prime => 41, name => 'うめ', cnt => 0},
{ prime => 43, name => 'もも', cnt => 0},
{ prime => 47, name => 'ききょう', cnt => 0},
{ prime => 53, name => 'わらび', cnt => 0},
{ prime => 59, name => 'しめじ', cnt => 0},
{ prime => 61, name => 'とらのお', cnt => 0},
{ prime => 67, name => 'さる', cnt => 0},
{ prime => 71, name => 'ぜんまい', cnt => 0},
{ prime => 73, name => 'ふき', cnt => 0},
{ prime => 79, name => 'とき', cnt => 0},
{ prime => 83, name => 'とび', cnt => 0},
{ prime => 97, name => 'ひすい', cnt => 0},
{ prime => 101, name => 'ひわ', cnt => 0},
{ prime => 103, name => 'きつね', cnt => 0},
{ prime => 107, name => 'しょうじょう', cnt => 0},
{ prime => 109, name => 'らくだ', cnt => 0},
{ prime => 113, name => 'こはく', cnt => 0},
{ prime => 127, name => 'とるこ', cnt => 0},
{ prime => 131, name => 'からし', cnt => 0},
{ prime => 137, name => 'なす', cnt => 0},
{ prime => 139, name => 'にんじん', cnt => 0},
{ prime => 149, name => 'わさび', cnt => 0},
{ prime => 151, name => 'あずき', cnt => 0},
{ prime => 157, name => 'いまよう', cnt => 0},
{ prime => 163, name => 'えんじ', cnt => 0},
{ prime => 167, name => 'きはだ', cnt => 0},
{ prime => 173, name => 'きゃら', cnt => 0},
{ prime => 179, name => 'かりやす', cnt => 0},
{ prime => 181, name => 'きんちゃ', cnt => 0},
{ prime => 191, name => 'うこん', cnt => 0},
{ prime => 193, name => 'むらさき', cnt => 0},
{ prime => 197, name => 'しののめ', cnt => 0},
{ prime => 199, name => 'そら', cnt => 0},
{ prime => 211, name => 'すみ', cnt => 0},
{ prime => 223, name => 'ひ', cnt => 0},
{ prime => 227, name => 'はい', cnt => 0},
{ prime => 229, name => 'けしずみ', cnt => 0},
{ prime => 233, name => 'あく', cnt => 0},
{ prime => 239, name => 'あさぎ', cnt => 0},
{ prime => 241, name => 'くちなし', cnt => 0},
{ prime => 251, name => 'こう', cnt => 0}
);
if (@ARGV < 1) {
die "NO ARGUMENT\n";
}
# FOR DEBUG
#my $target = "あかさたなはまやらわおこそとのほもよおろ";
#print join(" ", map { sprintf "%#02x", $_ } unpack("C*", $target)), "\n";
#
# 組成分析
#
my @tmp = unpack("C*", $ARGV[0]);
my $total = 0;
for(my $i = 0; $i < $#tmp; $i++){
# FOR DEBUG
# printf(">%#02x<\n", $tmp[$i]);
for my $tref (@primeMap) {
if(($tmp[$i] % $tref->{prime}) == 0){
$tref->{ cnt }++;
$total++;
}
}
}
#
# 成分表示
#
foreach my $tref (@primeMap) {
if($tref->{ cnt } > 0){
printf("%sの%d%は %s でできています。\n",
$ARGV[0],
((100 * ($tref->{ cnt }))/$total),
$tref->{ name });
}
}
Fnews-brouse 1.9(20180406) -- by Mizuno, MWE <mwe@ccsf.jp>
GnuPG Key ID = ECC8A735
GnuPG Key fingerprint = 9BE6 B9E9 55A5 A499 CD51 946E 9BDC 7870 ECC8 A735