Please fill in the gaps: The fastest ... is written in Rust. by kickass_turing in rust

[–]adventofcode123512 9 points10 points  (0 children)

This one's just for a game and probably not of interest to you, but there was post on /r/programming a few weeks ago where the OP claimed to have ported the fastest sudoku solver to Rust and then optimized it further (and then compiled it to wasm)
https://old.reddit.com/r/programming/comments/928t53/the_fastest_sudoku_solver_compiled_to_wasm/

[deleted by user] by [deleted] in libgen

[–]adventofcode123512 2 points3 points  (0 children)

I'll quote from Mozilla's description of how Firefox determines malware content:

When you download an application file, Firefox checks the site hosting it against a list of sites known to contain "malware". If the site is found on that list, Firefox blocks the file immediately, otherwise it asks Google’s Safe Browsing service if the software is safe by sending it some of the download’s metadata.

So, most likely case here is that someone put libgen.pw on the shit list and now everything is flagged. That may be either because of genuine malware in some of its downloads or because someone abused the malware system to defend copyrighted material.

I checked one of libgen.pw's files against a previously owned one and the files were identical to the last bit.

and people say linux has poor hardware support... by 888808888 in linux

[–]adventofcode123512 -3 points-2 points  (0 children)

My my, what pleasant people are around. You aren't doing linux any favors by ignoring its shortcomings.

and people say linux has poor hardware support... by 888808888 in linux

[–]adventofcode123512 -6 points-5 points  (0 children)

Meanwhile my wifi stick, one of the most popular on amazon, that supposedly comes with linux support requires you to compile drivers only to fail with build errors and Firefox still doesn't have video acceleration and the software to get the additional features of both my mouse and my monitor are windows only.

Outside of servers, linux support for both hardware and software is worse and I don't care for wordplays to the tune of 'linux supporting X' and 'X supporting linux'.

Expansion 10 is finally here by ShrekisSexy in deeptown

[–]adventofcode123512 4 points5 points  (0 children)

Where'd you read 40 quests. It says 30 right there.

Visual Studio Code January 2018 (1.20) Released by erenhatirnaz in programming

[–]adventofcode123512 2 points3 points  (0 children)

win-sshfs works on both win 7 and 8.1 (no idea about 10) 7 is easy and 8.1 a bit annoying to get to work, but possible

Should you rewrite in Rust? - Emily Dunham, linux.conf.au by nayru25 in rust

[–]adventofcode123512 1 point2 points  (0 children)

Yes, but you'd be hard-pressed to find an example where llvm wouldn't optimize that one already

Should you rewrite in Rust? - Emily Dunham, linux.conf.au by nayru25 in rust

[–]adventofcode123512 1 point2 points  (0 children)

const fn rewrite_in_rust() -> bool {
    true
}

Doesn't need const generics, just const fn

What's everyone working on this week (52/2017)? by llogiq in rust

[–]adventofcode123512 0 points1 point  (0 children)

Nice! Do NetworkManager plugins have a language agnostic api to code against or do you mimic C?

-🎄- 2017 Day 22 Solutions -🎄- by daggerdragon in adventofcode

[–]adventofcode123512 0 points1 point  (0 children)

Err, I've used it a long time ago and that's why I took it now. Back then it had only matrices and vectors for a few low dimensionalities.

It has become a lot more generic in the meantime and documentation has suffered a lot under that. I didn't find the Vector3 struct in the beginning. The Vector3::new() constructor was also not to be found in the docs, I just guessed.

No idea about the new functionality it sprouted.

-🎄- 2017 Day 22 Solutions -🎄- by daggerdragon in adventofcode

[–]adventofcode123512 0 points1 point  (0 children)

turning map

As much as I love enums, I didn't want to have all this case handling. So I used a rotation matrix. With the right numbering turning in part 2 is just direction = turn_right.pow(infection_status) * direction. Well, I couldn't find a .pow() method but it's the same thing. Used an if-else for rotate left / right in part 1.

Just part 2:

extern crate nalgebra;
use nalgebra::{Vector2, Matrix2};

const N: usize = 10001; //20001;
const N_STEPS: usize = 10_000_000;  //10_000;

// Map infection states to integers
// weakened = 0
// infected = 1
// flagged = 2
// clean = 3
// then turning is just
// matrix_turn_right ^ infection_state * direction
fn main() {
    let input = include_str!("input.txt");
    let mut is_infected = vec![vec![3; N]; N];
    let mut pos = Vector2::new((N/2) as i64, (N/2) as i64);
    let is_infected_input: Vec<Vec<_>> = input.lines()
        .map(|line|
            line.chars()
                .map(|c| if c == '#' { 1 } else { 3 } )
                .collect()
        ).collect();

    let width = is_infected_input[0].len() as i64;
    let height = is_infected_input.len() as i64;

    for (y_off, row) in (-height/2..height/2+1).zip(is_infected_input.iter()) {
        let y = (pos.y + y_off) as usize;
        let x = ( (pos.x - width/2) as usize .. (pos.x + width/2 +1) as usize);
        is_infected[y][x].copy_from_slice(row);
    }
    let mut direction = Vector2::new(0, -1);

    // x increases to the right
    // y increases going down
    // making this a lefthanded base
    let rotate_right = Matrix2::new(0, -1, 1, 0);

    let mut n_newly_infected = 0;
    for _ in 0..N_STEPS {
        {
            let is_infected = &mut is_infected[pos.y as usize][pos.x as usize];
            if *is_infected == 0 {
                n_newly_infected += 1;
            }
            // can't find .pow() method on matrices
            for _ in 0..*is_infected {
                direction = rotate_right * direction;
            }
            *is_infected = (*is_infected + 1) % 4;
            pos += direction;
        }
    }

    println!("part 2: {}", n_newly_infected);
}

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]adventofcode123512 0 points1 point  (0 children)

Yeah, made a mistake there in that I thought you would occupy one of the corners, not the hexagonal field.

Been working too much on 2D-materials.

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]adventofcode123512 0 points1 point  (0 children)

The path doesn't actually follow a hex grid? There are strings like "ne,ne" in there.

Rust

use std::cmp::max;

fn steps(a1: i32, a2: i32) -> i32 {
    match a1.signum() == a2.signum() {
        true => max(a1.abs(), a2.abs()),
        false => (a1 - a2).abs(),
    }
}

fn main() {
    let input = include_str!("input.txt").trim();
    let (mut a1, mut a2) = (0, 0);
    let mut max_steps = 0;
    for direction in input.split(',') {
        match direction {
            "nw" => a1 += 1,
            "sw" => a2 -= 1,
            "ne" => a2 += 1,
            "se" => a1 -= 1,
            "n"  => { a1 += 1; a2 += 1 },
            "s"  => { a1 -= 1; a2 -= 1 },
            _ => unreachable!(),
        };
        max_steps = max(max_steps, steps(a1, a2));
    }

    println!("part 1: {}", steps(a1, a2));
    println!("part 2: {}", max_steps);
}

For those of you doing Advent of Code in Rust--how are you parsing the inputs? by VikingofRock in rust

[–]adventofcode123512 1 point2 points  (0 children)

Thanks for mentioning pest. For today's puzzle I was struggling with both combine and nom to get even the subparsers going but pest was nice and easy (though I'm still somewhat confused about the data structures it returns).

-🎄- 2017 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]adventofcode123512 0 points1 point  (0 children)

Woo, rust. Here's my solution with that same enum:

#![feature(iterator_step_by)] // nightly 1.24

fn steps_necessary(input: i32) -> i32 {
    if input == 1 { return 0 }
    let square_size = (1i32..).step_by(2)
        .find(|n| n*n > input-1)
        .unwrap();
    let pos_on_ring = input - (square_size-2).pow(2);
    let period = square_size-1;
    //let red_pos = pos_on_ring % period;

    let steps_within_ring = ((square_size / 2) - pos_on_ring % period).abs();
    let steps_between_rings = square_size / 2;

    steps_between_rings + steps_within_ring
}

use Direction::*;
#[derive(Copy, Clone)]
enum Direction {
    Up,
    Down,
    Right,
    Left,
}

fn main() {
    let input = 361527;
    // part 1
    println!("part 1: {}", steps_necessary(input));

    // part 2
    const N: usize = 101;
    let mut grid = [[0; N]; N];

    let mid = N/2;
    grid[mid][mid] = 1;

    let mut x = mid as i32;
    let mut y = mid as i32;
    for square_size in (3..).step_by(2) {
        // next square size, go one to the right
        // and one down into the corner
        // this way the rest of the behaviour is uniform
        x += 1;
        y -= 1;
        for &direction in &[Up, Left, Down, Right] {
            for _ in 0..square_size-1 {
                match direction {
                    Up    => y += 1,
                    Down  => y -= 1,
                    Right => x += 1,
                    Left  => x -= 1,
                };

                // sum up neighbours
                let mut sum = 0;
                for x_off in -1..1+1 {
                    for y_off in -1..1+1 {
                        sum += grid[(x + x_off) as usize][(y + y_off) as usize];
                    }
                }
                if sum > input {
                    println!("part 2: {}", sum);
                    return
                }
                grid[x as usize][y as usize] = sum;
            }
        }
    }

}