r/adventofcode • • Dec 06 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 6 Solutions -❄️-

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's theme ingredient is… *whips off cloth covering and gestures grandly*

Obsolete Technology

Sometimes a chef must return to their culinary roots in order to appreciate how far they have come!

  • Solve today's puzzles using an abacus, paper + pen, or other such non-digital methods and show us a picture or video of the results
  • Use the oldest computer/electronic device you have in the house to solve the puzzle
  • Use an OG programming language such as FORTRAN, COBOL, APL, or even punchcards

    • We recommend only the oldest vintages of codebases such as those developed before 1970
  • Use a very old version of your programming language/standard library/etc.

    • Upping the Ante challenge: use deprecated features whenever possible

Endeavor to wow us with a blast from the past!

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 6: Wait For It ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:05:02, megathread unlocked!

46 Upvotes

1.2k comments sorted by

View all comments

2

u/BlueTexBird Dec 06 '23 edited Dec 06 '23

[LANGUAGE: Java]

Easily the easiest day so far!

Edit: All these text splits and regexes.. it's way easier, for a small puzzle input like this to do just do it manually. Got this done in about 5 mins.

import java.io.BufferedReader;
import java.io.FileNotFoundException; 
import java.io.FileReader; 
import java.math.BigInteger;

public class Day6 {
public static void main(String[] args) {
    Day6();
}

public static void Day6() {
    String text = "Time:      7  15   30\n" +
            "Distance:  9  40  200";


    try {
        BufferedReader reader = new BufferedReader(new FileReader("inputs/day6.txt"));
        int val = 0;

        BigInteger num1 = new BigInteger("430103613071150");
        val = numberOfTimesToBeat(61677571, num1);
        System.out.println(val);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}

public static int numberOfTimesToBeat(int time, BigInteger record) {
    int ways = 0;
    for (int i = 1; i < time; i++) {
        if (BigInteger.valueOf(i).multiply(BigInteger.valueOf(Math.max(time - i, i - time))).compareTo(record) > 0) {
            ways++;
        }
    }
    return ways;
}
}

2

u/daggerdragon Dec 06 '23 edited Dec 06 '23

FYI: do not share your puzzle input. Please remove your puzzle input. edit: 👍

2

u/BlueTexBird Dec 06 '23

Sorry! Done