Advent of Code 2025: Solving Puzzles with Industrial Ladder Logic

Taking an unconventional approach to Advent of Code by solving puzzles using Allen-Bradley Micro870 PLCs and ladder logic programming

  • 2 min read
Contents
  1. The Challenge: Advent of Code Meets Industrial Automation
  2. Hardware Setup
  3. Day 1: Secret Entrance
  4. The Problem
  5. Video Demonstrations
  6. Day 1 Part 1
  7. Day 1 Part 2
  8. Part 1 Solution
  9. Rung 0 - Reset
  10. Rung 1 - Start Processing
  11. Rung 2 - Check If Complete
  12. Rung 3 - Get Direction From Array
  13. Rung 4 - Get Distance From Array
  14. Rung 5 - Subtract (Direction = Left)
  15. Rung 6 - Modulo Wraparound
  16. Rung 7 - Handle Negative Values
  17. Rung 8 - Count Zeros
  18. Rung 9 - Advance Step
  19. Part 2 Solution
  20. Rung 10 - Zero Crossing Calculation
  21. Rung 11 - Part 2 Processing
  22. Rung 12 - Part 2 Advance

The Challenge: Advent of Code Meets Industrial Automation#

What happens when you combine Advent of Code with industrial control systems? Ladder logic solutions running on actual PLCs.

This year, I solved Advent of Code 2025 puzzles using ladder logic on an Allen-Bradley Micro870 PLC, with a FactoryTalk Optix HMI for visualization.

Github Repo with Code: https://github.com/ladderlogix/Advent-of-Code-2025


Hardware Setup#

ComponentModel
PLCAllen-Bradley Micro870 (2080-L70E-24QBBN)
HMIFactoryTalk Optix
CommunicationEthernet/IP

Day 1: Secret Entrance#

The Problem#

You arrive at the secret entrance to the North Pole base, but the password has changed. A safe with a dial (numbers 0-99) holds the answer. Your puzzle input contains rotation instructions like L68 (left 68 clicks) or R48 (right 48 clicks).

The dial starts at 50 and wraps around (left from 0 goes to 99, right from 99 goes to 0).

Part 1: Count how many times the dial ends on position 0 after a rotation.

Part 2: Count how many times the dial passes through or lands on position 0 during ALL rotations (including mid-rotation).


Video Demonstrations#

Day 1 Part 1#

Day 1 Part 2#


Part 1 Solution#

The algorithm processes 4,146 rotation instructions, tracking position on a circular 0-99 dial.

Rung 0 - Reset#

Rung 1

Rung 1 - Start Processing#

Rung 2

Rung 2 - Check If Complete#

Rung 3

Rung 3 - Get Direction From Array#

Rung 4

Rung 4 - Get Distance From Array#

Rung 5

Rung 5 - Subtract (Direction = Left)#

Rung 6

Rung 6 - Modulo Wraparound#

Rung 7

Rung 7 - Handle Negative Values#

Rung 8

Rung 8 - Count Zeros#

Rung 9

Rung 9 - Advance Step#

Rung 10


Part 2 Solution#

Part 2 requires counting every time the dial crosses position 0, not just when it lands there. This adds significant complexity with 6 different cases to handle.

Rung 10 - Zero Crossing Calculation#

This massive branching rung handles all the edge cases for counting zero crossings:

Rung 11

Rung 11 - Part 2 Processing#

Rung 12

Rung 12 - Part 2 Advance#

Rung 13


Stay tuned for more days of Advent of Code solved with ladder logic!