Every week, we will be releasing a new puzzle for you to solve. You may use any language you want but feel free to try something new. After completing puzzles, create a ticket on our Discord server and send us your solution. At the end of every week, we will review the problem during our meeting.

View the leaderboard **[here]**

This week, you'll be executing a series of instructions on a 1000x1000 light grid.

Lights in your grid are numbered from 0 to 999 in each direction; the lights at each corner are at 0,0, 0,999, 999,999, and 999,0. The instructions include whether to turn on, turn off, or toggle various inclusive ranges given as coordinate pairs. Each coordinate pair represents opposite corners of a rectangle, inclusive; a coordinate pair like 0,0 through 2,2 therefore refers to 9 lights in a 3x3 square. The lights all start turned off.

To defeat your neighbors this year, all you have to do is set up your lights by doing the instructions Santa sent you in order.

For example:

- "turn on 0,0 through 999,999" would turn on (or leave on) every light.
- "toggle 0,0 through 999,0" would toggle the first line of 1000 lights, turning off the ones that were on, and turning on the ones that were off.
- "turn off 499,499 through 500,500" would turn off (or leave off) the middle four lights.

After following the instructions, how many lights are lit?

turn on 489,959 through 759,964 turn off 820,516 through 871,914 turn off 427,423 through 929,502 turn on 774,14 through 977,877 turn on 410,146 through 864,337 turn on 931,331 through 939,812 turn off 756,53 through 923,339 turn off 313,787 through 545,979 turn off 12,823 through 102,934 toggle 756,965 through 812,992 turn off 743,684 through 789,958 toggle 120,314 through 745,489 toggle 692,845 through 866,994 turn off 587,176 through 850,273 turn off 674,321 through 793,388 toggle 749,672 through 973,965 turn on 943,30 through 990,907 turn on 296,50 through 729,664 turn on 212,957 through 490,987 toggle 171,31 through 688,88 turn off 991,989 through 994,998 turn off 913,943 through 958,953 turn off 278,258 through 367,386 toggle 275,796 through 493,971 turn off 70,873 through 798,923 toggle 258,985 through 663,998 turn on 601,259 through 831,486 turn off 914,94 through 941,102 turn off 558,161 through 994,647 turn on 119,662 through 760,838 toggle 378,775 through 526,852 turn off 384,670 through 674,972 turn off 249,41 through 270,936 turn on 614,742 through 769,780 turn on 427,70 through 575,441 turn on 410,478 through 985,753

This week, you will be driving a ship across an ocean by following detailed instructions left by the coast guard.

Each instruction begins with a letter code followed by a number, indicating the action that is to be performed.

- N - move North a number of units
- S - move South a number of units
- E - move East a number of units
- W - move West a number of units
- L - turn left a number of
**degrees** - R - turn right a number of
**degrees** - F - move forward in the direction you are facing a number of units

Your ship starts facing east at position (0,0).

After completing all your instructions, what position do you end up at?

The instructions are listed below:

F70 S4 E3 S4 L90 N4 R90 W3 F75 S5 L90 E1 S4 F98 N4 R90 S3 L90 W1 F39 W2 L90 E1 F99 S3 E5 F63 N4 F26 E1 R180 F58 N3 F4 E1 F45 E4 R90 E3 F76 S1 F22 R90 N1 W1 F76 W1 N5 E3 L180 S5 F87 W4 L90 F9 S2 F11 N4 L180 S3 R90 F92 L90 S1 E4 R90 W1 F1 S2 L90 F27 N3 E1 N1 E3 L180 S1 S5 R180 W5 W5 F60 S5 W5 L270 N3 R90 F65 S5 F53 W5 L90 N1 W5 L180 F87 W2 R180 S2 F77 N1 F81 L180 E5 N5 W4 L90 W4 L90 E3 N2 L90 W2 S1 F19 W1 F82 N4 R270 E5 L90 N3 R90 F81 L270 W3 R90 L270 N3 F53 E2 F84 R90 S2 F39 R180 N1 L90 F11 S2 W5 F20 W1 N4 R90 F76 E3 S5 E3 S5 W5 S2 L90 N3 E3 S5 F27 W1 L90 F65 W3 R180 F84 W2 N5 F43 L180 W3 F11 W2 R90 N1 R90 N5 W1 S4 N4 F88 N3 F87 W3 L90 F77 S5 F18 N4 F97 E5 S5 R90 F94 N5 L180 F8 N4 R90 W2 N2 L180 F4 R90 W4 S3 R90 F38 S3 E1 N5 F4 E3 R90 S4 F95 E5 F77 F32 W5 F3 R90 N1 W3 F96 L270 N2 E2 F30 S3 W2 R90 F57 R90 E1 R90 N5 E1 N4 W4 N1 W2 F47 N5 W3 L90 N4 F50 E3 R90 F27 N3 F78 N2 R90 F100 S3 F67 R90 N4 R90 N4 F88 S4 E2 S2 F31 S5 R90 W3 R180 W2 F97 F31 N1 L90 S4 F50 N3 W2 L180 F85 L180 E3 L90 F95 N4 L90 E1 S2 R180 N2 F19 N5 E5 S1 W5 R90 N1 L180 F76 S4 E5 S2 S5 E3 F53 L90 S3 E4 S1 E1 L90 F54 W1 S1 E2 N1 R90 S3 R90 F63 L90 W4 L90 F47 L90 E5 F23 W2 F97 E3 L90 N4 F54 W3 S4 W3 S2 F67 W1 S4 R90 S5 R90 W4 L180 L90 S4 F19 F42 S4 F91 R90 L180 F64 L180 W4 R90 F32 N3 F18 E2 L180 N4 E2 N1 E4 N4 F54 W5 F50 N3 L90 N5 R90 F100 E4 N1 E3 L90 F8 L90 E4 L270 F95 L90 F44 E5 R90 F79 N5 F61 S2 F71 L90 F4 N3 F25 L180 F7 W4 F96 R90 S1 R90 W1 F9 N2 W5 F1 R90 N2 F36 W4 R90 F96 W2 F26 S2 F28 E4 N1 F33 N5 F51 W2 S1 F40 N3 F67 E3 S2 R90 W1 S3 E3 L90 F75 E3 N5 E2 F52 E3 F7 N4 F4 S4 L90 S2 W5 F85 F7 L180 E1 L90 E2 S3 R180 N3 E2 R90 N5 F6 N2 L90 W1 R90 R90 F91 E2 N4 R90 S2 E3 S3 L90 W3 F61 S1 L90 W3 N2 E1 R180 E2 W5 R90 F65 N4 W3 F54 E1 N3 E5 L180 S4 N3 E5 R90 S3 R90 S4 W4 F31 S5 R90 N2 E3 F49 F47 W3 F79 R270 W2 F90 S3 F73 L180 F14 W4 F27 R90 F75 L90 N5 R90 N4 L90 N4 E2 S1 W1 S4 W5 W1 F7 W5 L180 E1 S1 F82 F36 N2 L90 E1 L90 S4 L180 N2 W3 F21 R270 F18 R180 F93 L90 W2 F4 E1 R90 E2 S3 W4 F30 E1 F69 W5 R90 E2 L180 S4 W1 N1 E3 L90 E3 R90 F69 R90 S2 L90 N4 F13 L90 E2 L90 N2 W2 N5 S4 F70 R90 F67 E4 F62 L270 F98 L90 E5 F15 E5 R90 W3 E2 F25 R180 F7 L180 W4 S3 F42 R180 R270 N1 R180 S2 F37 E2 F72 N5 W5 F61 F43 W3 R90 R270 N5 R270 E4 L90 W4 F31 F43 L180 S3 W4 R90 F20 E2 S5 L90 F75 R90 F52 W3 L90 N5 W5 N4 R90 F52 W3 F91 E1 N2 F81 R90 E2 L90 F24 E2 L180 E1 F55 E1 L90 E5 R90 F23 S3 R180 S3 F8 L180 S1 N3 F90 N5 W3 N4 L90 N3 W5 R90 E4 S4 F89 W3 N2 R90 F18 R180 W5 E4 F100 N4 F40 E3 S2 E2 F16 R90 S2 L180 F58 W1 F70 S1 R90 W3 L90 S4 F48 R90 W1 N5 E3 R90 E1 L90 F1 R90 N1 E3 F39 W3 R90 E3 L90 N5 R90 S3 W4 R180 E1 S3 F56 L90 F98 N2 W4 F67 R90 W3 S1 F33 R90 F42 L90 R90 E4 R90 E3 F74 E4 R270 F62 S5 L90 E4 F21

This week, you will be simulating a cryptographic handshake involving a card which unlocks a door.

The handshake used by the card and the door involves an operation that transforms a subject number. To transform a subject number, start with the value 1. Then, a number of times called the loop size, perform the following steps:

- Set the value to itself multiplied by the subject number.
- Set the value to the remainder after dividing the value by 20201227.

The card always uses a specific, secret loop size when it transforms a subject number. The door always uses a different, secret loop size.

The cryptographic handshake works like this:

- The card transforms the subject number of 7 according to the card's secret loop size. The result is called the card's public key.
- The door transforms the subject number of 7 according to the door's secret loop size. The result is called the door's public key.
- The card and door use the wireless RFID signal to transmit the two public keys to the other device. Now, the card has the door's public key, and the door has the card's public key. Because you can eavesdrop on the signal, you have both public keys, but neither device's loop size.
- The card transforms the subject number of the door's public key according to the card's loop size. The result is the encryption key.
- The door transforms the subject number of the card's public key according to the door's loop size. The result is the same encryption key as the card calculated.

If you can use the two public keys to determine each device's loop size, you will have enough information to calculate the secret encryption key that the card and door use to communicate; this would let you send the unlock command directly to the door!

For example, suppose you know that the card's public key is 5764801. With a little trial and error, you can work out that the card's loop size must be 8, because transforming the initial subject number of 7 with a loop size of 8 produces 5764801.

Then, suppose you know that the door's public key is 17807724. By the same process, you can determine that the door's loop size is 11, because transforming the initial subject number of 7 with a loop size of 11 produces 17807724.

At this point, you can use either device's loop size with the other device's public key to calculate the encryption key. Transforming the subject number of 17807724 (the door's public key) with a loop size of 8 (the card's loop size) produces the encryption key, 14897079. (Transforming the subject number of 5764801 (the card's public key) with a loop size of 11 (the door's loop size) produces the same encryption key: 14897079.)

Your two public keys are: **15628416** & **11161639**

What encryption key is the handshake trying to establish?

This weekend, you head to your local grocery store to get ingredients for your thanksgiving dinner. After entering, you are given the following map:

################################################################################# # # # # # C # # # # # A# A # A# # # # ##### # ##### ### # # # # ###C# # # # # #######E# # ### # ##### # ##### # ### # # # # # # # # # # # # N # # # # # # # # # A# # ##### ##### ####### # ########### ### # # # # ##### # # ##### # # ### #O### # # # # # # # # # # # # # # # # # # # # # # # # # # ### # ####### # # ########### ### ##### # # ### # # # # ##### ######### ##### # # # # # # # # # # # # # # # # # # # # # ### # ##### # ### ##### ######### ### # # # ####### ##### # # ### # ##### # ##### # # C# # # # # # # # # # AAAA# # # # # # # # # ### # ####### ######### ##### # # ### # ##### # ##### ### # # ##### ##### ### # # # # TTTTTTTT # # # # # # # # # # # # # # # # # # # ############# # ##### ### # # ##### ##### ##### # ### # # # # ##### # ### # # # # # # # # # # # # # # # # # # # # # # # # # # # ### # # # # ### ### # ### # # # # ### # ### # # ##### # # ######### # # # ### # # # # # #C # # # # # # # # # # # # # # # # PPP # # # # # # ### # ###F##### ### ##### ### # ##### # # ##### # # ##### # ##### ### # ##### # # # # # # # # # # AAA # # # # # # # # # # # # # # # ### ### # ### # # # ########### # ### ####### ##### # ####### ##### # ##### # # P # # # # # # # # # # # # # # # #PPPPPPP# # # # # #################################################################################

The letters in this map represent the locations of certain food items. An "A" represents the location of an apple. How many apples are available?

In preparation for the Advent of Code competition, this week's puzzle will be in the same style and format.

Santa is having trouble finding gifts in his workshop and calls on you to help. You find what appears to be a log of where Santa went. The log looks like this:

32, 43, 24, 43, 27, -25, -1, 6, -39, -11, 33, 10, 29, 41, -17, -24, -44, 25, -22, -17, 27, 23, -5, 11, 31, 11, 32, 6, -36, 4, -34, 7, 19, 17, 28, 49, 43, 47, 22, 43, -20, 33, 4, -11, 19, 14, -49, 46, 30, -27, -49, 28, 35, 5, 13, -45, -29, 20, -50, 25, 36, -13, 1, 37, -44, -7, -49, 21, -35, 4, -23, 1, -6, -22, -43, 28, 38, 35, 40, -10, 48, 23, -37, -20, 8, 48, -4, 44, 21, -16, 39, -12, 40, 21, 42, -19, -3, -1, 5, -2

Santa started on **Floor 0** of his workshop when he started his log. Each number represents the number of floors he traveled. A positive number means that he traveled to a higher floor, while a negative number means that he traveled to a lower floor. After Santa finished his travel, he placed the gifts on the floor he ended up on.

Note that Santa's workshop has floors below Floor 0.

On what floor are the gifts located?

After completing part 1, enter your answer below to view part 2.

Enter your answer:

This Saturday, you go trick or treating in your neighborhood. After a few hours, you no longer recognize any of the houses and you realize that you're lost. You see a very long street of houses and decide to get candy from that street, then find out where you are.

You ring on the door of the first house on this very long street and a witch greets you. She says,

If you have an even number of candies, you give me half your candy. But if you have an odd number of candies I triple your candy amount and then add one more.

You think this sounds a little fishy, so you turn to walk away, but the entrance is gone. Seeing no escape, you have no choice but to listen.

After making your way past this house, you notice that this was only the first of a row of 250 houses, all with the same strange deal. You must visit each house in order before exiting this strange street.

**Assuming you can bring a maximum of 100,000 candies into the first house, what is the maximum number of candy you can exit with after visiting all 250 houses?**

A magician has a deck of 52 cards, and performs a magic trick. During the magic trick, cards are pulled out and replaced under specific conditions.

The magician checks each of these conditions in order. If the condition is satisfied, the magician performs the associated action, which may affect the next condition.

- If the number of cards is even, remove 4 cards from the deck
- If the number of cards is odd, remove 2 cards from the deck.
- If the there are more than 30 cards in the deck, remove 1 card from the deck.
- If the there are less than 20 cards in the deck, add 1 card to the deck.

Cards are removed and added from a secondary hidden pile. The number of cards in the secondary pile is unlimited. During the magic trick, the number of cards in the main deck may exceed 52.

The magician repeats this magic trick until there is only one card left in the pile. **How many times does the magician perform this trick?**

A palindromic number is one such that written backward, its digits match that of the original value.

Examples of palindromic numbers include: 262, 27972, 62988926

Find the **smallest number above 1000 that is both palindromic and prime.**