Skip Navigation
🌟 - 2023 DAY 6 SOLUTIONS -🌟
  • C++

    Yesterday, I decided to code in Tcl. That program is still running, i will go back to the day 5 post once it finishes :)

    Today was super simple. My first attempt worked in both cases, where the hardest part was really switching my ints to long longs. Part 1 worked on first compile and part 2 I had to compile twice after I realized the data type needs. Still, that change was made by search and replace.

    I guess today was meant to be a real time race to get first answer? This is like day 1 stuff! Still, I have kids and a job so I did not get to stay up until the problem was posted.

    I used C++ because I thought something intense may be coming on the part 2 problem, and I was burned yesterday. It looks like I spent another fast language on nothing! I think I'll keep zig in the hole for the next number cruncher.

    Oh, and yes my TCL program is still running...

    My solutions can be found here:

    // File: day-6a.cpp
    // Purpose: Solution to part of day 6 of advent of code in C++
    //          https://adventofcode.com/2023/day/6
    // Author: Robert Lowe
    // Date: 6 December 2023
    #include 
    #include 
    #include 
    #include 
    
    std::vector parse_line()
    {
        std::string line;
        std::size_t index;
        int num;
        std::vector result;
        
        // set up the stream
        std::getline(std::cin, line);
        index = line.find(':');
        std::istringstream is(line.substr(index+1));
    
        while(is>>num) {
            result.push_back(num);
        }
    
        return result;
    }
    
    int count_wins(int t, int d) 
    {
        int count=0;
        for(int i=1; i d) {
                count++;
            }
        }
        return count;
    }
    
    int main()
    {
        std::vector time;
        std::vector dist;
        int product=1;
    
        // get the times and distances
        time = parse_line();
        dist = parse_line();
    
        // count the total number of wins
        for(auto titr=time.begin(), ditr=dist.begin(); titr!=time.end(); titr++, ditr++) {
            product *= count_wins(*titr, *ditr);
        }
    
        std::cout << product << std::endl;
    }
    
    // File: day-6b.cpp
    // Purpose: Solution to part 2 of day 6 of advent of code in C++
    //          https://adventofcode.com/2023/day/6
    // Author: Robert Lowe
    // Date: 6 December 2023
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    std::vector parse_line()
    {
        std::string line;
        std::size_t index;
        long long num;
        std::vector result;
        
        // set up the stream
        std::getline(std::cin, line);
        line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end());
        index = line.find(':');
        std::istringstream is(line.substr(index+1));
    
        while(is>>num) {
            result.push_back(num);
        }
    
        return result;
    }
    
    long long count_wins(long long t, long long d) 
    {
        long long count=0;
        for(long long i=1; i d) {
                count++;
            }
        }
        return count;
    }
    
    int main()
    {
        std::vector time;
        std::vector dist;
        long long product=1;
    
        // get the times and distances
        time = parse_line();
        dist = parse_line();
    
        // count the total number of wins
        for(auto titr=time.begin(), ditr=dist.begin(); titr!=time.end(); titr++, ditr++) {
            product *= count_wins(*titr, *ditr);
        }
    
        std::cout << product << std::endl;
    }
    
  • β˜ƒοΈ - 2023 DAY 4 SOLUTIONS -β˜ƒοΈ
  • That's some elegant code! Then again, I suppose that's the beauty of nim.

  • β˜ƒοΈ - 2023 DAY 4 SOLUTIONS -β˜ƒοΈ
  • PHP

    Today was the easiest day so far IMHO. Today, I coded in PHP, a horrible language that produces even worse code. (Ok, full confession, I fed my family for about half a decade on PHP. I seemed to have gotten stuck with it, and so I earned a PhD to escape it.)

    Anyway, the only trouble I had was I forgot about the explode function's capacity to return empty strings. Once I filtered those I had the correct answer on the first one, and then 10 minutes later I had the second part. I wrote my code true to raw php's awful idioms, though I didn't make it web based. I read from stdin.

    My code is linked on github:

  • ❄️ - 2023 DAY 3 SOLUTIONS -❄️
  • I wrote today's program in Python. (I am going to do a different language each day.) The only thing that gave me a little trouble was I was counting "\n" as a part label. Once I realized that I was able to get both problems done very quickly.

    My code for the two parts is on github:-

  • pngwen pngwen @lemmy.sdf.org

    I am a professor of computer science at Southeast Missouri State university. I have been coding ever since I wrote my first line of BASIC back in the 1980s. I like reading, retrocomputing, modern computing, artificial intlligence, programming, electronics, and math.

    Posts 0
    Comments 4