mod lamp { enum Direction { to_right, to_left } pub struct Lamp { direction: Direction, lamp_no: u32 } impl Lamp { pub fn duration(&self) -> f32 { match self.lamp_no { 1..=4 => 1.5, 5..=7 => 2.5, _ => unreachable!() } } pub fn next(&mut self) { use Direction::{to_left, to_right}; match (&self.direction, &mut self.lamp_no) { (to_right, 6) => *self = Self {direction: to_left, lamp_no: 7}, (to_left, 2) => *self = Self {direction: to_right, lamp_no: 1}, (to_right, n) => *n += 1, (to_left, n) => *n -= 1 } } } impl Default for Lamp { fn default() -> Self { Self { direction: Direction::to_right, lamp_no: 1 } } } impl ToString for Lamp { fn to_string(&self) -> String { match self.lamp_no { 1 => "K".into(), 2 => "L".into(), 3 => "M".into(), 4 => "N".into(), 5 => "P".into(), 6 => "R".into(), 7 => "S".into(), _ => unreachable!() } } } } fn main() { let mut my_lamp = lamp::Lamp::default(); let mut start_time = 0.0; let mut end_time = start_time + my_lamp.duration(); while end_time < 150.0 { my_lamp.next(); start_time = end_time; end_time = start_time + my_lamp.duration(); } println!("Lambanın yanmaya başlama süresi: {}, Lambanın sönme süresi: {}, Lambanın harfi: {}", start_time, end_time, my_lamp.to_string()) }