Skip to content

Commit

Permalink
change solution script
Browse files Browse the repository at this point in the history
  • Loading branch information
ichyo committed Jun 21, 2019
1 parent c8385ae commit 5478a07
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 16 deletions.
140 changes: 140 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ authors = ["ichyo <ichyo00@gmail.com>"]
edition = "2018"

[dependencies]
clap = "2.33.0"
glob = "0.3.0"
6 changes: 1 addition & 5 deletions make_solution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ OUTPUT="./solutions/$(date +"%m%d")/$(date +"%H")/$(date +"%M%S")"

echo "Creating $OUTPUT"
mkdir -p $OUTPUT
export OUTPUT

echo "running..."
for f in ./input/prob-*.desc; do
./solve_single.sh $f $OUTPUT
done
./target/release/icfpc2019 --output $OUTPUT --input ./input

echo "Creating zip $OUTPUT/solutions.zip"
cd $OUTPUT
Expand Down
10 changes: 0 additions & 10 deletions solve_single.sh

This file was deleted.

50 changes: 49 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
use clap::{App, Arg};
use glob::glob;
use std::fs::File;
use std::io::Write;

fn find_files(input_root: &str) -> Vec<String> {
glob(&format!("{}/prob-*.desc", input_root))
.expect("glob pattern")
.map(|p| {
p.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
})
.collect::<Vec<String>>()
}

fn output_file(file_name: &str) -> String {
format!("prob-{}.sol", &file_name[5..8])
}

fn main() {
println!("W");
let matches = App::new("ICFPC 2019")
.version("0.1.0")
.arg(
Arg::with_name("input")
.long("input")
.takes_value(true)
.help("input root directory"),
)
.arg(
Arg::with_name("output")
.long("output")
.takes_value(true)
.help("output directory"),
)
.get_matches();

let input_root = matches.value_of("input").expect("no input specified");
let output_root = matches.value_of("output").expect("no output specified");

let files = find_files(&input_root);
for f in files {
let input_path = format!("{}/{}", input_root, f);
let output_path = format!("{}/{}", output_root, output_file(&f));
let mut file = File::create(output_path).unwrap();
writeln!(file, "W");
}
}

0 comments on commit 5478a07

Please sign in to comment.