Skip to content

Instantly share code, notes, and snippets.

@meganehouser
Created April 4, 2015 00:46
Show Gist options
  • Save meganehouser/14d255f336189b6f4603 to your computer and use it in GitHub Desktop.
Save meganehouser/14d255f336189b6f4603 to your computer and use it in GitHub Desktop.
Show LED numbers.
#![feature(core)]
#![feature(unicode)]
extern crate core;
use std::io;
use std::io::Write;
use core::str::FromStr;
static NUMS: [[&'static str; 3]; 10] = [
[" _ ", "| |", "|_|"],
[" ", " |", " |"],
[" _ ", " _|", "|_ "],
[" _ ", " _|", " _|"],
[" ", "|_|", " |"],
[" _ ", "|_ ", " _|"],
[" _ ", " _|", "|_|"],
[" _ ", " |", " |"],
[" _ ", "|_|", "|_|"],
[" _ ", "|_|", " |"]];
fn to_led(num: &str) -> String {
let ns = num.graphemes(true)
.filter_map(|s| usize::from_str(s).ok())
.collect::<Vec<_>>();
let mut led = String::new();
for i in 0..3 {
for n in ns.clone() {
led = led + NUMS[n][i];
}
led = led + "\n";
}
led
}
fn main() {
loop {
print!("input number: ");
io::stdout().flush().unwrap();
let mut num = String::new();
io::stdin().read_line(&mut num).unwrap();
let led = to_led(&num.trim_right());
println!("{}", led);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment