28 votes

Topic deleted by author

35 comments

  1. [13]
    Deimos
    Link
    Are there enough people planning to participate this year that it would be good to set up a temporary subgroup again with daily topics, like we did last year? I'll watch to see how many people...

    Are there enough people planning to participate this year that it would be good to set up a temporary subgroup again with daily topics, like we did last year?

    I'll watch to see how many people respond to this thread, or reply to this comment and let me know if you're planning to participate (even if you're not starting quite yet). If it looks like we have a decent size group, I'll set that up again.

    19 votes
    1. wycy
      Link Parent
      Here to chime in that I'll be participating as well

      Here to chime in that I'll be participating as well

      5 votes
    2. 3d12
      Link Parent
      I plan to participate! Hopefully I can make it all the way through this year.

      I plan to participate! Hopefully I can make it all the way through this year.

      5 votes
    3. unknown user
      Link Parent
      I shall try this year... But I'll probably only get the first couple done... I'm pretty bad! lol

      I shall try this year... But I'll probably only get the first couple done... I'm pretty bad! lol

      5 votes
    4. andre
      Link Parent
      I did 20/25 in 2018, skipped 2019, but am planning on giving it another go this year.

      I did 20/25 in 2018, skipped 2019, but am planning on giving it another go this year.

      5 votes
    5. Gyrfalcon
      Link Parent
      I will be participating, and I would love to have the posts like we did last year!

      I will be participating, and I would love to have the posts like we did last year!

      4 votes
    6. Crestwave
      Link Parent
      Might not have time for the later ones, but I'll definitely be participating for the first few!

      Might not have time for the later ones, but I'll definitely be participating for the first few!

      3 votes
    7. 0d_billie
      (edited )
      Link Parent
      I'm willing to give it a go this year. I've never tried before, but my Python is at a reasonable enough level to give it a whirl, I think Edit: I take it back. I am struggling to concentrate even...

      I'm willing to give it a go this year. I've never tried before, but my Python is at a reasonable enough level to give it a whirl, I think

      Edit: I take it back. I am struggling to concentrate even on day 1's challenge TT_TT

      3 votes
    8. PapaNachos
      (edited )
      Link Parent
      I'm going to participate, at least until I lose steam

      I'm going to participate, at least until I lose steam

      3 votes
    9. Liru
      Link Parent
      I'm joining in; going to be coding mostly in C#, unfortunately. I may go back and redo some questions in other languages if I think it's a good exercise.

      I'm joining in; going to be coding mostly in C#, unfortunately. I may go back and redo some questions in other languages if I think it's a good exercise.

      3 votes
    10. balooga
      Link Parent
      I'm in! Finished the first two in JS, will keep going as time allows.

      I'm in! Finished the first two in JS, will keep going as time allows.

      3 votes
    11. Deimos
      Link Parent
      Alright, I created the sub-group (and moved this topic into there): ~comp.advent_of_code If you posted solutions inside this topic, please copy/move them into the threads for Day 1 and Day 2....

      Alright, I created the sub-group (and moved this topic into there): ~comp.advent_of_code

      If you posted solutions inside this topic, please copy/move them into the threads for Day 1 and Day 2.

      Mentions for people with solutions in here: @Bauke @clone1 @petrichor @andre @PapaNachos @blitz

      3 votes
  2. [2]
    blitz
    Link
    Time to play with a bit of Rust again! Maybe this year I won't peter off at day 10 :)

    Time to play with a bit of Rust again! Maybe this year I won't peter off at day 10 :)

    8 votes
    1. thorondir
      Link Parent
      I started off trying to solve things in Rust, but... It's so much work to do even simple things, I feel. I've got a background in Perl, and it took me maybe three minutes to solve the first task...

      I started off trying to solve things in Rust, but... It's so much work to do even simple things, I feel.

      I've got a background in Perl, and it took me maybe three minutes to solve the first task of day one.
      Doing the same thing in Rust requires a whole lot of boilerplate.
      I still got it done, but it seemed much harder than it should be.
      Or maybe I'm just not used to learning things anymore. Which is a bit of a scary thought.

      3 votes
  3. bloup
    Link
    There's a fun and interesting way to quickly solve the first puzzle (both parts) without doing any programming at all! Give it a try! :)

    There's a fun and interesting way to quickly solve the first puzzle (both parts) without doing any programming at all! Give it a try! :)

    4 votes
  4. [8]
    tomf
    (edited )
    Link
    oh man, I need to learn a language quick. I did the first three(!!) in Sheets... but I doubt I'll be able to hack through most of them this way. edit: If anyone wants to see my sheet so far, you...

    oh man, I need to learn a language quick. I did the first first two three(!!) in Sheets... but I doubt I'll be able to hack through most of them this way.

    edit: If anyone wants to see my sheet so far, you can see it here.

    4 votes
    1. [2]
      Liru
      Link Parent
      If it's anything like last year, where you had to implement a bytecode interpreter and build upon it in subsequent days, then yeah, Sheets may be a bit unsuitable.

      If it's anything like last year, where you had to implement a bytecode interpreter and build upon it in subsequent days, then yeah, Sheets may be a bit unsuitable.

      Intcode is an esoteric programming language created purely to annoy programmers competing in the Advent of Code 2019.

      4 votes
      1. tomf
        Link Parent
        good Lord. There's a guy in the sub that has been doing everything with Excel -- so there is still hope. But yes, I am also doubting I can complete it with sheets alone. I've dipped into a little...

        good Lord. There's a guy in the sub that has been doing everything with Excel -- so there is still hope. But yes, I am also doubting I can complete it with sheets alone. I've dipped into a little python, but not a lot.

        1 vote
    2. [2]
      fazit
      Link Parent
      =ARRAYFORMULA( COUNTIF( REGEXEXTRACT( A1:A, REPT( ".", MOD( TRANSPOSE( SEQUENCE(1,COUNTA(A1:A),4,3)-3)-1, LEN($A1:A)))& "(.)"), "#")) wow, I'm stunned. If anything, this is even more impressive...

      =ARRAYFORMULA( COUNTIF( REGEXEXTRACT( A1:A, REPT( ".", MOD( TRANSPOSE( SEQUENCE(1,COUNTA(A1:A),4,3)-3)-1, LEN($A1:A)))& "(.)"), "#"))
      wow, I'm stunned. If anything, this is even more impressive than using a "real" language.

      4 votes
      1. tomf
        Link Parent
        Thanks! It's a goofy way to approach it, but it appears to be leaner than the stuff the other spreadsheet folks are doing. :)

        Thanks! It's a goofy way to approach it, but it appears to be leaner than the stuff the other spreadsheet folks are doing. :)

        1 vote
    3. [3]
      jackson
      Link Parent
      Highly recommend Python. It has a relatively simple syntax that's pretty close to plain english and it's incredibly powerful. I started learning with a raspberry pi and I'd highly recommend it to...

      Highly recommend Python. It has a relatively simple syntax that's pretty close to plain english and it's incredibly powerful.

      I started learning with a raspberry pi and I'd highly recommend it to anyone who can swing the $20-35 pricetag.

      2 votes
      1. [2]
        clone1
        Link Parent
        Raspberry PIs are really cool and a great learning tool, but there isn't really anything special about using them for python. You can install python on your windows machine in 5 minutes!

        Raspberry PIs are really cool and a great learning tool, but there isn't really anything special about using them for python. You can install python on your windows machine in 5 minutes!

        3 votes
        1. jackson
          Link Parent
          I started with GPIO stuff, was still in school and having that concrete connection to reality seemed to make it more "real" to me.

          I started with GPIO stuff, was still in school and having that concrete connection to reality seemed to make it more "real" to me.

          1 vote
  5. [4]
    Comment deleted by author
    Link
    1. [3]
      blitz
      Link Parent
      This is really cool! I like the way you've built some sort of run harness for all your days! I end up creating a separate crate for each day so I have to start from scratch. Making a runner like...

      This is really cool! I like the way you've built some sort of run harness for all your days! I end up creating a separate crate for each day so I have to start from scratch. Making a runner like this might make doing the rest of the days less tedious.

      3 votes
      1. [3]
        Comment deleted by author
        Link Parent
        1. blitz
          Link Parent
          Sure! I have two separate solutions for day 1. I made a simple iterative solution that isn't very interesting, but I also made a generalized recursive solution that will find any sum and any...

          Sure! I have two separate solutions for day 1. I made a simple iterative solution that isn't very interesting, but I also made a generalized recursive solution that will find any sum and any number of terms. It's suuuper slow though, like half a second to do 3 terms. I haven't spent any time looking into why that is, I'm sure there's some allocations or moves that I'm doing that I shouldn't be.

          Day1
          use std::io;
          use std::process;
          use std::env;
          
          fn recursive_sum(remaining_entries: &[i32], considered: &mut Vec<i32>, target_num_terms: i32, target_sum: i32) {
              if considered.len() as i32 == target_num_terms - 1 {
                  for x in remaining_entries {
                      if considered.iter().sum::<i32>() + x == target_sum {
                          let product: i32 = considered.iter().product::<i32>() * x;
                          println!("{}", product);
                          process::exit(0);
                      }
                  }
              } else {
                  for x in 0..remaining_entries.len() {
                      considered.push(remaining_entries[x]);
                      recursive_sum(&remaining_entries[x+1..], considered, target_num_terms, target_sum);
                      considered.pop();
                  }
              }
          }
          
          fn main() -> io::Result<()> {
              let args: Vec<String> = env::args().collect();
          
              let target_num_terms: i32 = args[1].parse().unwrap();
              let target_sum: i32 = args[2].parse().unwrap();
          
              let mut entries = Vec::new();
              let mut buffer = String::new();
              let mut considered = Vec::new();
          
              let stdin = io::stdin();
          
          
              while let Ok(_) = stdin.read_line(&mut buffer) {
                  let new = buffer.trim().parse::<i32>().unwrap();
                  buffer.clear();
          
                  entries.push(new);
          
                  if entries.len() >= target_num_terms as usize {
                      recursive_sum(&entries, &mut considered, target_num_terms, target_sum);
          	    considered.clear();
                  }
              }
          
              Ok(())
          }
          
          2 votes
        2. blitz
          Link Parent
          Followup: I finished and posted my day 2 here

          Followup: I finished and posted my day 2 here

          2 votes
  6. teaearlgraycold
    Link
    I only really attempted AoC once before, doing each day's challenge in a different programming language. I didn't get very far. This year I'm focusing on completion and to a lesser degree speed....

    I only really attempted AoC once before, doing each day's challenge in a different programming language. I didn't get very far. This year I'm focusing on completion and to a lesser degree speed. So Python it is.

    3 votes
  7. clone1
    Link
    I've been reading SICP so I want to do it in scheme, but I also like (attempting) to race and scheme is too slow for me, so I'm hacking it out in python then making a nice scheme solution. Day one...

    I've been reading SICP so I want to do it in scheme, but I also like (attempting) to race and scheme is too slow for me, so I'm hacking it out in python then making a nice scheme solution.

    Day one
    (define (get-lines parse-line)
      (with-input-from-file "input"
        (lambda ()
          (let loop ((line (read-line))
                     (lines '()))
            (if (eof-object? line)
                (reverse lines)
                (loop (read-line)
                      (cons (parse-line line) lines)))))))
    
    (define lines (get-lines string->number))
    
    (define (2sum target numbers)
      (let ((passed (make-weak-eq-hash-table)))
        (let loop ((numbers numbers))
          (if (null? numbers) #f
              (let ((x (car numbers)))
                (let ((complement (- target x)))
                  (if (and (>= complement 0)
                           (hash-table/get passed complement #f))
                      (* x complement)
                      (begin
                        (hash-table/put! passed x #t)
                        (loop (cdr numbers))))))))))
    
    (define (3sum target numbers)
      (if (null? numbers) #f
          (let ((x (car numbers))
                (remaining (cdr numbers)))
            (let ((complement (- target x)))
              (if (>= complement 0)
                  (let ((complement-product (2sum complement remaining)))
                    (if complement-product
                        (* x complement-product)
                        (3sum target remaining)))
                  (3sum target remaining))))))
    
    (define (one numbers) (2sum 2020 numbers))
    (define (two numbers) (3sum 2020 numbers))
    (one lines)
    (two lines)
    
    Day two
    (define (get-lines parse-line)
      (with-input-from-file "input"
        (lambda ()
          (let loop ((line (read-line))
                     (lines '()))
            (if (eof-object? line)
                (reverse lines)
                (loop (read-line)
                      (cons (parse-line line) lines)))))))
    
    (define (make-pass-line start end char pass)
      (list start end char pass))
    (define (get-start x)
      (car x))
    (define (get-end x)
      (cadr x))
    (define (get-char x)
      (caddr x))
    (define (get-pass x)
      (cadddr x))
    
    (define (parse-password pass-line)
      (let ((split-line ((string-splitter) pass-line)))
        (let ((range ((string-splitter 'delimiter #\-) (car split-line)))
              (char (string-ref (cadr split-line) 0))
              (password (caddr split-line)))
          (let ((start (string->number (car range)))
                (end (string->number (cadr range))))
            (make-pass-line start end char password)))))
    
    (define lines (get-lines parse-password))
    
    (define (count-char char string)
      (string-count (lambda (char2) (eq? char char2)) string))
    
    (define (is-valid-one? pass-line)
      (let ((char-count (count-char (get-char pass-line)
                                    (get-pass pass-line))))
        (and (>= char-count (get-start pass-line))
             (<= char-count (get-end pass-line)))))
    
    (define (is-valid-two? pass-line)
      (let ((pass (get-pass pass-line))
            (char (get-char pass-line))
            (start (- (get-start pass-line) 1))
            (end (- (get-end pass-line) 1)))
        (let ((a (string-ref pass start))
              (b (string-ref pass end)))
          (and (or (eq? a char)
                   (eq? b char))
               (not (eq? a b))))))
    
    (count is-valid-one? lines)
    (count is-valid-two? lines)
    
    3 votes
  8. andre
    Link
    I did 2017 and 2018 in JS, will be doing 2020 in the same. Here's my run harness and solutions. I'm happy with the workflow: run tests in watch mode (so they immediately execute when I save a file...

    I did 2017 and 2018 in JS, will be doing 2020 in the same. Here's my run harness and solutions. I'm happy with the workflow: run tests in watch mode (so they immediately execute when I save a file in vim) while writing the answer, followed by yarn run solve 2020 02 1, which downloads the input from AoC, executes your solution, and puts the answer in your clipboard.

    Day 01
    export function solvePart1(input) {
      input = U.linesToNumbers(input)
      for (let i = 0; i < input.length; i++) {
        for (let k = 0; k < input.length; k++) {
          if (input[i] + input[k] === 2020) {
            return input[i] * input[k]
          }
        }
      }
    }
    
    export function solvePart2(input) {
      input = U.linesToNumbers(input)
      for (let i = 0; i < input.length; i++) {
        for (let j = 0; j < input.length; j++) {
          for (let k = 0; k < input.length; k++) {
            if (input[i] + input[k] + input[j] === 2020) {
              return input[i] * input[k] * input[j]
            }
          }
        }
      }
    }
    
    Day 02
    export function solvePart1(input) {
      return input.split('\n').filter(line => {
        let [, min, max, letter, str] = /(\d+)-(\d+) (.): (.*)/.exec(line)
        min = Number(min)
        max = Number(max)
    
        const count = str.split('').filter(c => c === letter).length
        return count >= min && count <= max
      }).length
    }
    
    export function solvePart2(input) {
      return input.split('\n').filter(line => {
        let [, min, max, letter, str] = /(\d+)-(\d+) (.): (.*)/.exec(line)
        min = Number(min)
        max = Number(max)
    
        return U.xor(str[min - 1] === letter, str[max - 1] === letter)
      }).length
    }
    
    2 votes
  9. PapaNachos
    (edited )
    Link
    I'm using Python using Anaconda and Jupyter Notebook. I love Advent of Code because it's a great chance to stretch my coding muscles. Day 1 A For this one I just brute forced it. This rechecks...

    I'm using Python using Anaconda and Jupyter Notebook. I love Advent of Code because it's a great chance to stretch my coding muscles.

    Day 1 A For this one I just brute forced it. This rechecks several time, both 'A' + 'B' = 2020 and 'B' + 'A' = 2020 show up as valid results. If you wanted to be more efficient, you could make sure that each combination only gets checked once.
    test_data = '''1721
    979
    366
    299
    675
    1456'''
    
    numbers = test_data.split('\n')
    
    for i in range(0, len(numbers)): 
        numbers[i] = int(numbers[i]) 
        
        
    for num1 in numbers:
        for num2 in numbers:
             if num1 != num2 and num1 + num2 == 2020:
                    print(f"Match Found: {num1} + {num2} = 2020")
                    print(f"{num1} * {num2} = {num1 * num2}")
    
    Day 1 B This is basically the same as part A, but with an added layer. So instead of checking 'A' + 'B', you're checking 'A' + 'B' + 'C'. This is far, far less efficient because of that added step, but with a data set this small it didn't really matter.
    test_data = '''1721
    979
    366
    299
    675
    1456'''
    
    numbers = test_data.split('\n')
    
    for i in range(0, len(numbers)): 
        numbers[i] = int(numbers[i]) 
        
        
    for num1 in numbers:
        for num2 in numbers:
            for num3 in numbers:
                if num1 != num2 and num1 != num3 and num2 != num3 and num1 + num2 + num3 == 2020:
                    print(f"Match Found: {num1} + {num2} + {num3} = 2020")
                    print(f"{num1} * {num2} * {num3} = {num1 * num2 * num3}")
    
    Day 2 A For this one I wrote a regular expression and broke up each line into it's component pieces. From there it was a matter of using each of the pieces to check if the password fit.

    Regular expressions are somewhat cryptic, and if you haven't learned how to deal with them, I highly recommend https://regexone.com/
    It does take a bit of work to learn how to use them, but they are excellent at solving certain types of problems

    import re
    test_data = '''1-3 a: abcde
    1-3 b: cdefg
    2-9 c: ccccccccc'''
    
    passwords = test_data.split('\n')
    
    pattern = re.compile(r'(\d+)-(\d+)\s(\w):\s(\w+)')
    
    valid_passwords = 0
    for password in passwords:
        match = pattern.match(password)
        min_val = int(match.group(1))
        max_val = int(match.group(2))
        important_char = match.group(3)
        passphrase = match.group(4)
        count = passphrase.count(important_char)
        if count >= min_val and count <= max_val:
            valid_passwords = valid_passwords + 1
            #print(f"{password} meets the criteria")
        else:
            pass
            #print(f"{password} does not meet the criteria")
    print(f'A total of {valid_passwords} passwords were valid')
    
    Day 2 B For this one my regex solution was robust enough that I didn't have to rework it. Though I did rename some of the variables for added readability. I did need to redo the password validation check though.

    This is basically an XOR logic gate, where it will be true if exactly one of the parameters is TRUE and FALSE if neither or both of the parameters are TRUE. I put a quick one together by starting with 0. Each of the criteria that was TRUE would add +1. If the value at the end was exactly 1, I knew my result was valid. If it was anything other than 1, I knew the result was invalid.

    In the code below I separated out 0 and 2 as results for my own debugging purposes, but really the only check you need to make is if it equals 1.

    import re
    test_data = '''1-3 a: abcde
    1-3 b: cdefg
    2-9 c: ccccccccc'''
    
    passwords = test_data.split('\n')
    
    pattern = re.compile(r'(\d+)-(\d+)\s(\w):\s(\w+)')
    
    valid_passwords = 0
    for password in passwords:
        match = pattern.match(password)
        first_val = int(match.group(1))
        second_val = int(match.group(2))
        important_char = match.group(3)
        passphrase = match.group(4)
        first_char = passphrase[first_val - 1]
        second_char = passphrase[second_val - 1]
        check = 0
        if first_char == important_char:
            check = check + 1
        if second_char == important_char:
            check = check + 1
        if check == 0:
            pass
            #print('Invalid: No characters matched')
        elif check == 1:
            valid_passwords = valid_passwords + 1
            #print('Valid: Exactly 1 character matched')
        else:
            pass
            #print('Invalid: Both characters matched')
    
    
    Tips for Beginners
    • Don't worry about the competition part, just compete against yourself.

    • Don't be afraid to ask for help. But if you ask for help, try to understand what people are telling you, rather than just copying it

    • These will get substantially harder as time goes one. The later ones especially will be a challenge even for experienced programmers. Don't beat yourself up if you can't figure them out

    • Sometimes the hardest part is just getting started. Even getting to the point where you can even start working on the problem takes some effort. Before you even start trying to solve it you need 1)Somewhere to run the code. 2)The problem data in a place you can work with it. I recommend downloading Anaconda and using Jupyter Notebook. Then you can just copy-paste the data into a variable (but you'll need to reformat it or use triple quotes like in my examples

    2 votes
  10. blitz
    Link
    In these early days I usually like to make things more difficult for myself. I'm doing these in Rust. My solution to Day 1 is generalized to any sum and number of terms: Day 1 use std::io; use...

    In these early days I usually like to make things more difficult for myself. I'm doing these in Rust.

    My solution to Day 1 is generalized to any sum and number of terms:

    Day 1
    use std::io;
    use std::process;
    use std::env;
    
    fn recursive_sum(remaining_entries: &[i32], considered: &mut Vec<i32>, target_num_terms: i32, target_sum: i32) {
        if considered.len() as i32 == target_num_terms - 1 {
            for x in remaining_entries {
                if considered.iter().sum::<i32>() + x == target_sum {
                    let product: i32 = considered.iter().product::<i32>() * x;
                    println!("{}", product);
                    process::exit(0);
                }
            }
        } else {
            for x in 0..remaining_entries.len() {
                considered.push(remaining_entries[x]);
                recursive_sum(&remaining_entries[x+1..], considered, target_num_terms, target_sum);
                considered.pop();
            }
        }
    }
    
    fn main() -> io::Result<()> {
        let args: Vec<String> = env::args().collect();
    
        let target_num_terms: i32 = args[1].parse().unwrap();
        let target_sum: i32 = args[2].parse().unwrap();
    
        let mut entries = Vec::new();
        let mut buffer = String::new();
        let mut considered = Vec::new();
    
        let stdin = io::stdin();
    
        while let Ok(_) = stdin.read_line(&mut buffer) {
            let new = buffer.trim().parse::<i32>().unwrap();
            buffer.clear();
    
            entries.push(new);
    
            if entries.len() >= target_num_terms as usize {
                recursive_sum(&entries, &mut considered, target_num_terms, target_sum);
    	    considered.clear();
            }
        }
    
        Ok(())
    }
    

    I noticed Day 2 is easily parallelizable so I took a multithreaded approach to the problem:

    Day 2
    extern crate crossbeam;
    
    use std::io;
    use std::io::prelude::*;
    
    use crossbeam::channel::{unbounded};
    use crossbeam::thread;
    
    fn find_range(range_str: &str) -> (usize, usize) {
        let mut range_iter = range_str.split('-');
    
        let lower = range_iter.next().unwrap().parse::<usize>().unwrap();
        let upper = range_iter.next().unwrap().parse::<usize>().unwrap();
    
        (lower, upper)
    }
    
    fn part1_test(range: (usize, usize), test_char: char, test_password: &str) -> bool {
        let mut test_char_count = 0;
    
        for c in test_password.chars() {
            if c == test_char {
                test_char_count += 1;
            }
        }
    
        range.0 <= test_char_count && test_char_count <= range.1
    }
    
    fn part2_test(indices: (usize, usize), test_char: char, test_password: &str) -> bool {
        let pw_bytes = test_password.as_bytes();
        let mut num_pos = 0;
    
        if pw_bytes[indices.0 - 1] as char == test_char {
            num_pos += 1;
        }
    
        if pw_bytes[indices.1 - 1] as char == test_char {
            num_pos += 1;
        }
    
        num_pos == 1
    }
    
    fn process_line(line: &str) ->  (bool, bool) {
        let mut line_iter = line.split_whitespace();
        let range = find_range(line_iter.next().unwrap());
        let subject_char = line_iter.next().unwrap().chars().next().unwrap();
        let subject_password = line_iter.next().unwrap();
    
        (
            part1_test(range, subject_char, subject_password),
            part2_test(range, subject_char, subject_password),
        )
    }
    
    fn main() {
        let stdin = io::stdin();
        let num_threads = 2;
    
    
        let lines: Vec<String> = stdin.lock().lines().collect::<Result<_, _>>().unwrap();
        let mut p1_matches = 0;
        let mut p2_matches = 0;
    
        let (line_send, line_recv) = unbounded();
        let (result_send, result_recv) = unbounded();
    
        thread::scope(|s| {
            for l in lines.iter() {
                line_send.send(l).unwrap();
            }
    
            drop(line_send);
    
            for _ in 0..num_threads {
                let r_clone = line_recv.clone();
                let s_clone = result_send.clone();
    
                s.spawn(move |_| {
                    let mut p1_valid_count = 0;
                    let mut p2_valid_count = 0;
    
                    while let Ok(line) = r_clone.recv() {
                        let (p1_valid, p2_valid) = process_line(line);
    
                        if p1_valid {
                            p1_valid_count += 1;
                        }
                        if p2_valid {
                            p2_valid_count += 1;
                        }
                    }
    
                    s_clone.send((p1_valid_count, p2_valid_count)).unwrap();
                    drop(s_clone);
                });
            }
    
        }).unwrap();
    
        drop(line_recv);
        drop(result_send);
    
        while let Ok((p1_valid_count, p2_valid_count)) = result_recv.recv() {
            p1_matches += p1_valid_count;
            p2_matches += p2_valid_count;
        }
    
        println!("Part1: {}", p1_matches);
        println!("Part2: {}", p2_matches);
    }
    
    2 votes
  11. [3]
    ali
    Link
    Looking at the global leaderboards: how do people solve a challenge faster than it takes me to read the task? Are the problems similar to last years? I could, for example see myself running tons...

    Looking at the global leaderboards: how do people solve a challenge faster than it takes me to read the task?
    Are the problems similar to last years? I could, for example see myself running tons of programs on an input and seeing whether one of them yields a result. Or do people actually just speed read and code a quick hack in literally under 2 minutes ?

    1 vote
    1. andre
      Link Parent
      If you want to see one of the consistent leaderboard finishers solve the puzzles live, check out Jonathan Paulson's YouTube channel.

      If you want to see one of the consistent leaderboard finishers solve the puzzles live, check out Jonathan Paulson's YouTube channel.

      6 votes
    2. petrichor
      Link Parent
      The latter, I think. Some people are into "competitive programming" - solving Advent of Code-style problems quickly - and that kind of practice, alongside knowing a language very well, leads to...

      The latter, I think. Some people are into "competitive programming" - solving Advent of Code-style problems quickly - and that kind of practice, alongside knowing a language very well, leads to the crazy / scary sub-two minute times on the leaderboard.

      4 votes