Skip to content

Instantly share code, notes, and snippets.

@amatubu
Created March 15, 2013 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatubu/5169445 to your computer and use it in GitHub Desktop.
Save amatubu/5169445 to your computer and use it in GitHub Desktop.
Create spice matrix again
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
# スパイスのグループ
my @spices_strings = (
# グループ C
"Nercitoma Maceor Limeminnor Loveaneic Pamacetah Labcara Lovema Nillaneric Beba Rosery Spicechootal Qulabry Limemin Achiomaseic Mata Corma Ginitah Citograor Matatal Bebalemoma Licotaor Stachoooc Rumin Citoat Cardoquist Rinacardory Monmyraist Glaru Sumaricetah Myrarice Rosemaceoc Tamaoc Riceso Mahseoc",
# グループ B
"Limelicotah Anesuma Rose Xuoma Popxuoor Glaat Zamacetal Turry Gotah Sumabebatah Chimonma Carabaic Mupermin Roselabtal Anewatry Loveaniic Ciogoist Carapertah Chooperaly Nutscinmin Maserior Rinagla Limetal Matapermin Draat Peregrama Nige Masema Choopaly Rosetal Floic Riceturic Nerstamin Bebacorry Labry Munillaist Peratal Bapomely Anioc Zaor Rinawatry Peracassist Nutssery Baricema Soanior",
# グループ A
"Bebary Camin Caratah Chitamary Ciocitotah Cito Drama Draxuoly Ginima Jachooor Junisooc Junitah Laboc Labor Limeachioly Minnlabic Minnoc Monwatmin Muly Mupopoc Mury Nillawatat Nutslemoist Paic Paor Pertah Pomeat Primonmin Pripriist Rinacassoc Ruginitah Rury Sesaist Somutah Soxuooc Spicesesaoc Stacarary Staoc Suma Sumaloveat Tamamin Tamariic Tamastaat Tary Tatah Turcardoist Tursesaly Zaroseor Zaspiceoc",
);
my %group;
my $group_num = 0;
for my $spices_string ( @spices_strings ) {
my @spices = split " ", $spices_string;
for my $spice ( @spices ) {
$group{$spice} = $group_num;
}
$group_num++;
}
my %spices;
my %blends;
# ブレンドリストを開く
open my $blend_file, "blendlist.txt";
die "ブレンドリストが開けません。" if !$blend_file;
# ブレンドのカウント
while ( my $blend = <$blend_file> ) {
if ( $blend =~ m/(\w+)\s(\w+)/ ) {
my ( $spice1, $spice2 ) = sort ( $1, $2 );
$spices{$spice1}++;
$spices{$spice2}++;
# マトリックス
$blends{$spice1}{$spice2} = 1;
$blends{$spice2}{$spice1} = 1;
}
}
# マトリックス表を作成3
my %spice_blend_matrix3;
open my $matrix_file3, ">", "matrix3.txt";
for my $spice1 ( sort { ( $group{$a} ) <=> ( $group{$b} ) || $a cmp $b } keys %spices ) {
for my $spice2 ( sort { ( $group{$a} ) <=> ( $group{$b} ) || $a cmp $b } keys %spices ) {
if ( $spice1 ne $spice2 ) {
$spice_blend_matrix3{$spice1} .= $blends{$spice1}{$spice2} || "0";
} else {
$spice_blend_matrix3{$spice1} .= " ";
}
}
print $matrix_file3 "$spice_blend_matrix3{$spice1} $spice1 ($spices{$spice1})\n";
}
close $matrix_file3;
exit 0;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment