NERD SHIT :marseynerd: ADVENT OF CODE 10 M=E=G=A=T=H=R=E=A=D

LET'S SAVE THOSE ELVES, BROS

Okay it isn't even out yet, I'm sure it will be great, and the elves are in trouble, etc. I'm just beating you all to the bunch so I can tell you to explain your answers, we care about ALGORITHMIC COMPLEXITY now. What's the fastest and most efficient way to do it.

heymoon wtf is a big o

This is O(n)

x = REALLY_BIG_NUMBER
for i in range(x):
    process(i)

This is O(n^2)

x = REALLY_BIG_NUMBER
for i in range(x):
    for j in range(x)
        process(i,j)

There's more to it but that's the quick version. Also there are things like O(log(n)) (based), O(a^n) (cringe), and O(n!) (advanced cringe).

Okay, post ur code too but explain why its cool or no one will read it. I'll pin my favorite answers, other mods also do this

LET'S SAVE THOSE ELVES, BROS

42
Jump in the discussion.

No email address required.

Part Uno

import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String args[]) {
        try {
            BufferedReader br = new BufferedReader(new FileReader("betterName.txt"));
            String line = null;
            int cycle = 1;
            int signalTotal = 0;
            int x = 1;
            ArrayList<Integer> cyclesToCheck = new ArrayList<>(Arrays.asList(20, 60, 100, 140, 180, 220));
            while ((line = br.readLine()) != null) {
                if(line.contains("noop")) {
                    if(cyclesToCheck.contains(cycle)) {
                        signalTotal += cycle * x;
                    }
                    cycle++;
                }
                else {
                    if(cyclesToCheck.contains(cycle)) {
                        signalTotal += cycle * x;
                    }
                    cycle++;
                    if(cyclesToCheck.contains(cycle)) {
                        signalTotal += cycle * x;
                    }
                    cycle++;
                    x += Integer.parseInt(line.split(" ")[1]);
                }
            }
            System.out.println(signalTotal);
            br.close();
        }
        catch(FileNotFoundException ex) {
            System.out.println("1 Sad!");
        }
        catch(IOException ex) {
            System.out.println("2 Sad!");
        }
    }
}

Part Dos

import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String args[]) {
        try {
            BufferedReader br = new BufferedReader(new FileReader("betterName.txt"));
            String line = null;
            int cycle = 1;
            int x = 1;
            String[][] screen = new String[6][40];
            int currentSpot = 0;
            int currentLine = 0;
            while ((line = br.readLine()) != null) {
                if(line.contains("noop")) {
                    if(x == 0) {
                        if(currentSpot == 0 || currentSpot == 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else if(x == 40) {
                        if(currentSpot == 39 || currentSpot == 40) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else {
                        if(currentSpot == x - 1 || currentSpot == x || currentSpot == x + 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        } 
                    }
                    cycle++;
                }
                else {
                    if(x == 0) {
                        if(currentSpot == 0 || currentSpot == 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else if(x == 40) {
                        if(currentSpot == 39 || currentSpot == 40) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else {
                        if(currentSpot == x - 1 || currentSpot == x || currentSpot == x + 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        } 
                    }
                    cycle++;
                    if(x == 0) {
                        if(currentSpot == 0 || currentSpot == 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else if(x == 40) {
                        if(currentSpot == 39 || currentSpot == 40) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                    }
                    else {
                        if(currentSpot == x - 1 || currentSpot == x || currentSpot == x + 1) {
                            screen[currentLine][currentSpot++] = "#";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        }
                        else {
                            screen[currentLine][currentSpot++] = ".";
                            if(currentSpot == 40) {
                                currentSpot = 0;
                                currentLine++;
                            }
                        } 
                    }
                    cycle++;
                    x += Integer.parseInt(line.split(" ")[1]);
                }
            }
            System.out.println(Arrays.deepToString(screen));
            br.close();
        }
        catch(FileNotFoundException ex) {
            System.out.println("1 Sad!");
        }
        catch(IOException ex) {
            System.out.println("2 Sad!");
        }
    }
}
Jump in the discussion.

No email address required.

elseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseifelseif CATCH FINALLY!

t. javadev

:#marseytunaktunak::#marseytunaktunak::#marseytunaktunak:

also t. yanderedev or whatever :marseycatgirl3:

Jump in the discussion.

No email address required.

:#marseychadyes:

Jump in the discussion.

No email address required.

PLEASE SARR REVIEW CODE SARR

Jump in the discussion.

No email address required.

A rare Java cell

:!#marseydetective:

catch(FileNotFoundException ex) {

      System.out.println("1 Sad!");
  }
   catch(IOException ex) {
     System.out.println("2 Sad!");

}

:marseyblob:

Jump in the discussion.

No email address required.

K

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.