Skip to content
Snippets Groups Projects
Select Git revision
  • 4fa9ec81b16803d1387b0564d41ca06c9581b17f
  • master default
  • renovate/django-split-settings-1.x
  • renovate/djangorestframework-3.x
  • main
  • 520-improve-trackmanager
  • 520-fix-scheduling
  • 520-akowner
  • 520-status
  • 520-message-resolved
  • 520-improve-scheduling-2
  • renovate/django-bootstrap5-24.x
  • 520-improve-submission
  • 520-improve-scheduling
  • 520-improve-wall
  • 520-fix-event-wizard-datepicker
  • 520-upgrades
  • renovate/tzdata-2023.x
  • renovate/django-5.x
  • renovate/fontawesomefree-6.x
  • renovate/sphinx-rtd-theme-2.x
  • renovate/sphinxcontrib-apidoc-0.x
22 results

forms.py

Blame
  • Forked from KIF / AKPlanning
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    types.rs 1.21 KiB
    use std::{fs::read_to_string, path::Path};
    
    use regex::Regex;
    
    #[derive(Debug)]
    pub struct SensorData {
        pub position: Point,
        pub beacon: Point,
    }
    
    impl SensorData {
        pub fn new(position: Point, beacon: Point) -> Self {
            Self { position, beacon }
        }
    }
    
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub struct Point {
        pub x: i32,
        pub y: i32,
    }
    
    impl Point {
        pub fn new(x: i32, y: i32) -> Self {
            Self { x, y }
        }
    
        pub fn distance(&self, other: Point) -> u32 {
            self.x.abs_diff(other.x) + self.y.abs_diff(other.y)
        }
    }
    
    pub fn parse_input(path: impl AsRef<Path>) -> Vec<SensorData> {
        let data = read_to_string(path).unwrap();
    
        let mut sensors = Vec::new();
        let reg =
            Regex::new(r"x=(?P<s_x>-?\d+), y=(?P<s_y>-?\d+).*x=(?P<b_x>-?\d+), y=(?P<b_y>-?\d+)").unwrap();
        for cap in reg.captures_iter(&data) {
            sensors.push(SensorData::new(
                Point::new(
                    cap["s_x"].parse::<i32>().unwrap(),
                    cap["s_y"].parse::<i32>().unwrap(),
                ),
                Point::new(
                    cap["b_x"].parse::<i32>().unwrap(),
                    cap["b_y"].parse::<i32>().unwrap(),
                ),
            ));
        }
    
        sensors
    }