Created
July 2, 2014 13:58
-
-
Save mikecat/38c21a7bb0a8fd2602a9 to your computer and use it in GitHub Desktop.
CodeIQ 第4回デスマコロシアム 開発補助ツール群
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
# read the file | |
Encoding.default_external = 'UTF-8' | |
file = ARGV.size > 0 ? open(ARGV[0]) : $stdin | |
code = file.read | |
file.close | |
# count the length | |
length_score = code.size | |
# count duperecate characters | |
dupe_chars = {} | |
code.split(//).each do |ch| | |
dupe_chars[ch] = (dupe_chars[ch] || 0) + 1 | |
end | |
# sum up number of duperecate characters | |
dupe_score = 0 | |
dupe_chars.each_value do |value| | |
dupe_score += value - 1 | |
end | |
print(" score = ", length_score * (dupe_score + 1), "\n") | |
print("length = ", length_score, "\n") | |
print(" dupe = ", dupe_score, "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use File::Copy; | |
my $default_file_name="dsmk4_head_paper_auto.asm"; | |
my $commit_paper_prefix="./release/dsmk4_paper_"; | |
my $commit_paper_suffix=".asm"; | |
#my $commit_source_prefix="./release/dsmk4_src_"; | |
#my $commit_source_suffix=".asm"; | |
my $file_name=$default_file_name; | |
if(@ARGV>0) { | |
$file_name=$ARGV[0]; | |
} | |
unless(open(SCORE,"ruby ./calc_score.rb < \"$file_name\" |")) { | |
die("Running judge failed!\n"); | |
} | |
my $score=<SCORE>; | |
close(SCORE); | |
$score =~ s/^[^0-9]+//; | |
$score =~ s/[^0-9]+$//; | |
if(!-e $commit_paper_prefix.$score.$commit_paper_suffix) { | |
copy($file_name,$commit_paper_prefix.$score.$commit_paper_suffix); | |
} else { | |
my $id=2; | |
while(-e $commit_paper_prefix.$score."_rev".$id.$commit_paper_suffix) {$id++;} | |
copy($file_name,$commit_paper_prefix.$score."_rev".$id.$commit_paper_suffix); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
my $source_file="dsmk4_head_src.asm"; | |
my $binary_file="dsmk4_head.bin"; | |
my $binary_dump_file="dsmk4_head_bin.txt"; | |
my $disasm_file="dsmk4_head_disasm.txt"; | |
my $paper_file="dsmk4_head_paper.asm"; | |
system("nasm -o \"$binary_file\" \"$source_file\""); | |
system("objdump -b binary -m i386 -D \"$binary_file\" > \"$disasm_file\""); | |
# assumes that $binary_file ends with "int 0x80" | |
if(open(IN,"< $binary_file")) { | |
my $bin=""; | |
read(IN,$bin,-s IN); | |
close(IN); | |
if(open(OUT,"> $paper_file")) { | |
printf OUT "dw '%s',80cDh",substr($bin,0,length($bin)-2); | |
close(OUT); | |
system("ruby ./calc_score.rb < \"$paper_file\""); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
my $paper_file_default="dsmk4_head_paper_auto.asm"; | |
my $paper_file=$paper_file_default; | |
if(@ARGV>0) { | |
$paper_file=$ARGV[0]; | |
} | |
system("ruby ./calc_score.rb < \"$paper_file\""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment