day 20 aoc: the cupid shuffle

https://youtube.com/watch?v=h24_zoqu4_Q

to the right to the right to the right

to the left to the left to the left

post your aoc solutions for day 20 or smth, all checks notes 5+ of you

42
Jump in the discussion.

No email address required.

Solved in SQL

-- Create a table to hold the encrypted numbers
CREATE TABLE encrypted_numbers (
  id INTEGER PRIMARY KEY,
  number INTEGER
);

-- Insert the encrypted numbers into the table
INSERT INTO encrypted_numbers (id, number)
VALUES (1, 1), (2, 2), (3, -3), (4, 3), (5, -2), (6, 0), (7, 4);

-- Mix the numbers according to the given rules
WITH mixed_numbers AS (
  SELECT
    id,
    number,
    number + (
      SELECT SUM(number)
      FROM encrypted_numbers
      WHERE id <= mixed_numbers.id
    ) % (SELECT COUNT(*) FROM encrypted_numbers) AS mixed_number
  FROM encrypted_numbers
)

-- Find the 1000th, 2000th, and 3000th numbers after 0
SELECT
  (
    SELECT mixed_number
    FROM mixed_numbers
    WHERE mixed_number > 0
    LIMIT 1000, 1
  ) +
  (
    SELECT mixed_number
    FROM mixed_numbers
    WHERE mixed_number > 0
    LIMIT 2000, 1
  ) +
  (
    SELECT mixed_number
    FROM mixed_numbers
    WHERE mixed_number > 0
    LIMIT 3000, 1
  ) AS grove_coordinates;

:#marseyantischizo::#marseyantischizo::#marseyantischizo:

This program first creates a table to hold the encrypted numbers and inserts the given numbers into the table. It then uses a common table expression (CTE) to mix the numbers according to the given rules, using a self-join to compute the mixed number for each original number. Finally, it uses three separate SELECT statements to find the 1000th, 2000th, and 3000th numbers after 0, and adds these together to find the grove coordinates.

The result of running this program should be the sum of the three numbers that form the grove coordinates.

@TwoLargeSnakesMating discuss

Jump in the discussion.

No email address required.

Wow, you must be a JP fan.

Jump in the discussion.

No email address required.

:#chadokcapy:

Jump in the discussion.

No email address required.

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