Skip to content

Instantly share code, notes, and snippets.

@ahomu
Last active September 7, 2016 16: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 ahomu/fb3b35ee203f020cb774b97313378446 to your computer and use it in GitHub Desktop.
Save ahomu/fb3b35ee203f020cb774b97313378446 to your computer and use it in GitHub Desktop.
_人人人人人_ > 突然の死 <  ̄Y^Y^Y^Y^Y ̄
use std::env;
use std::process;
const HALF_WIDTH: f32 = 0.5_f32;
const FULL_WIDTH: f32 = 1_f32;
fn str_repeat(string: &str, count: i16) -> String {
(0..count).map(|_| string).collect::<String>()
}
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() < 2 {
println!("Usage: {} \"突然の死\"", args[0]);
process::exit(1);
}
let words = &args[1];
let width = words.chars().fold(0_f32, |acc, c| {
if c.len_utf8() < 3 { acc + HALF_WIDTH }
else { acc + FULL_WIDTH }
});
let count = width.ceil() as i16;
println!("_人人{}_\n> {} <\n ̄Y{} ̄",
str_repeat("人", count),
words,
str_repeat("^Y", count)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment