Browse Source

initial commit

master
Jim Infield 3 years ago
commit
05e97b0391
  1. 1
      .gitignore
  2. 5
      Cargo.lock
  3. 8
      Cargo.toml
  4. 43
      src/main.rs

1
.gitignore

@ -0,0 +1 @@
/target

5
Cargo.lock

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "deadfish"
version = "0.1.0"

8
Cargo.toml

@ -0,0 +1,8 @@
[package]
name = "deadfish"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

43
src/main.rs

@ -0,0 +1,43 @@
/****
*
* Deadfish has 4 commands, each 1 character long:
*
* i increments the value (initially 0)
* d decrements the value
* s squares the value
* o outputs the value into the return array
* Invalid characters should be ignored.
*
*/
fn main() {
println!("\n{:?}\n", parse("ioxiosydoioz"));
}
fn parse(code: &str) -> Vec<i32> {
let mut n: i32 = 0;
let mut v = vec![];
for c in code.chars() {
match c {
'i' => n += 1,
'd' => n -= 1,
's' => n *= n,
'o' => v.push(n),
_ => ()
}
}
v
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sample_tests() {
assert_eq!(parse("iiisdoso"),
vec![8, 64]);
assert_eq!(parse("iiisdosodddddiso"),
vec![8, 64, 3600]);
}
}
Loading…
Cancel
Save