aboutsummaryrefslogtreecommitdiffstats
path: root/scratch/semgrep/server.py
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2024-03-01 16:45:37 +0100
committerOscar Najera <hi@oscarnajera.com>2024-04-01 01:40:43 +0200
commit6d0820bee59fb94712dec94975cc7a8f2f0c9bb8 (patch)
tree51f01bf237b84f65529b20be08625cfd6b7b16c7 /scratch/semgrep/server.py
parent84bbea70169207c4e6ab89d20e35c543dd40b7f9 (diff)
downloaddotfiles-6d0820bee59fb94712dec94975cc7a8f2f0c9bb8.tar.gz
dotfiles-6d0820bee59fb94712dec94975cc7a8f2f0c9bb8.tar.bz2
dotfiles-6d0820bee59fb94712dec94975cc7a8f2f0c9bb8.zip
ignore compiled objects in backup
Diffstat (limited to 'scratch/semgrep/server.py')
0 files changed, 0 insertions, 0 deletions
} /* Generic.Error */ .highlight .gh { color: #C3E88D } /* Generic.Heading */ .highlight .gi { color: #C3E88D } /* Generic.Inserted */ .highlight .go { color: #546E7A } /* Generic.Output */ .highlight .gp { color: #FFCB6B } /* Generic.Prompt */ .highlight .gs { color: #FF5370 } /* Generic.Strong */ .highlight .gu { color: #89DDFF } /* Generic.Subheading */ .highlight .gt { color: #FF5370 } /* Generic.Traceback */ .highlight .kc { color: #89DDFF } /* Keyword.Constant */ .highlight .kd { color: #BB80B3 } /* Keyword.Declaration */ .highlight .kn { color: #89DDFF; font-style: italic } /* Keyword.Namespace */ .highlight .kp { color: #89DDFF } /* Keyword.Pseudo */ .highlight .kr { color: #BB80B3 } /* Keyword.Reserved */ .highlight .kt { color: #BB80B3 } /* Keyword.Type */ .highlight .ld { color: #C3E88D } /* Literal.Date */ .highlight .m { color: #F78C6C } /* Literal.Number */ .highlight .s { color: #C3E88D } /* Literal.String */ .highlight .na { color: #BB80B3 } /* Name.Attribute */ .highlight .nb { color: #82AAFF } /* Name.Builtin */ .highlight .nc { color: #FFCB6B } /* Name.Class */ .highlight .no { color: #EEFFFF } /* Name.Constant */ .highlight .nd { color: #82AAFF } /* Name.Decorator */ .highlight .ni { color: #89DDFF } /* Name.Entity */ .highlight .ne { color: #FFCB6B } /* Name.Exception */ .highlight .nf { color: #82AAFF } /* Name.Function */ .highlight .nl { color: #82AAFF } /* Name.Label */ .highlight .nn { color: #FFCB6B } /* Name.Namespace */ .highlight .nx { color: #EEFFFF } /* Name.Other */ .highlight .py { color: #FFCB6B } /* Name.Property */ .highlight .nt { color: #FF5370 } /* Name.Tag */ .highlight .nv { color: #89DDFF } /* Name.Variable */ .highlight .ow { color: #89DDFF; font-style: italic } /* Operator.Word */ .highlight .pm { color: #89DDFF } /* Punctuation.Marker */ .highlight .w { color: #EEFFFF } /* Text.Whitespace */ .highlight .mb { color: #F78C6C } /* Literal.Number.Bin */ .highlight .mf { color: #F78C6C } /* Literal.Number.Float */ .highlight .mh { color: #F78C6C } /* Literal.Number.Hex */ .highlight .mi { color: #F78C6C } /* Literal.Number.Integer */ .highlight .mo { color: #F78C6C } /* Literal.Number.Oct */ .highlight .sa { color: #BB80B3 } /* Literal.String.Affix */ .highlight .sb { color: #C3E88D } /* Literal.String.Backtick */ .highlight .sc { color: #C3E88D } /* Literal.String.Char */ .highlight .dl { color: #EEFFFF } /* Literal.String.Delimiter */ .highlight .sd { color: #546E7A; font-style: italic } /* Literal.String.Doc */ .highlight .s2 { color: #C3E88D } /* Literal.String.Double */ .highlight .se { color: #EEFFFF } /* Literal.String.Escape */ .highlight .sh { color: #C3E88D } /* Literal.String.Heredoc */ .highlight .si { color: #89DDFF } /* Literal.String.Interpol */ .highlight .sx { color: #C3E88D } /* Literal.String.Other */ .highlight .sr { color: #89DDFF } /* Literal.String.Regex */ .highlight .s1 { color: #C3E88D } /* Literal.String.Single */ .highlight .ss { color: #89DDFF } /* Literal.String.Symbol */ .highlight .bp { color: #89DDFF } /* Name.Builtin.Pseudo */ .highlight .fm { color: #82AAFF } /* Name.Function.Magic */ .highlight .vc { color: #89DDFF } /* Name.Variable.Class */ .highlight .vg { color: #89DDFF } /* Name.Variable.Global */ .highlight .vi { color: #89DDFF } /* Name.Variable.Instance */ .highlight .vm { color: #82AAFF } /* Name.Variable.Magic */ .highlight .il { color: #F78C6C } /* Literal.Number.Integer.Long */
use std::fs;
use std::io::{self, BufRead};

fn probe(cycle: &i32, register: &i32) -> Option<i32> {
    let probes = vec![20, 60, 100, 140, 180, 220];

    if probes.contains(cycle) {
        Some(cycle * register)
    } else {
        None
    }
}

fn draw_pixel(cycle: &i32, register: &i32) {
    let pixel = (cycle - 1) % 40;
    if pixel == 0 {
        println!("");
    }
    let mark = if (register - 1) <= pixel && pixel <= (register + 1) {
        "#"
    } else {
        "."
    };
    print!("{}", mark);
}
fn main() {
    let file = fs::File::open("input").unwrap();
    let lines = io::BufReader::new(file).lines();
    let mut register = 1;
    let mut cycle = 1;
    let mut measures = Vec::<i32>::new();

    for line in lines {
        draw_pixel(&cycle, &register);
        cycle += 1;
        let step1 = probe(&cycle, &register);
        let inst = line.expect("valid instruction");
        let inst = inst.split(" ").collect::<Vec<&str>>();
        let step2 = if inst[0] == "addx" {
            draw_pixel(&cycle, &register);
            cycle += 1;
            register += inst[1].parse::<i32>().unwrap();
            probe(&cycle, &register)
        } else {
            None
        };

        match [step1, step2] {
            [Some(x), _] => measures.push(x),
            [None, Some(y)] => measures.push(y),
            _ => (),
        }
    }
    println!("\n{:?} {}", measures, measures.iter().sum::<i32>());
}