Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Carry Forge

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Separate partial sum from carry: The Carry Forge.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Add without plus matches the clues
  2. 2Keep this true after every move: sum plus carry equals the original mathematical total in 32-bit arithmetic
  3. 3Reach the result within O(32) time and O(1) space

Rules and pressure

  • Target cost: O(32) time and O(1) space
  • State rule: sum plus carry equals the original mathematical total in 32-bit arithmetic
Lesson 1 of 3

Live algorithm trace

Add without plus

Complete execution
1 of 4

Begin adding 1 and 2 as fixed-width bit patterns.

1while carry operand is not zero
2partial = a XOR b
3carry = (a AND b) << 1
4a = partial; b = carry
5return a
a = 001b = 010
Truth to preserve / Cost target
Truth to preserve

sum plus carry equals the original mathematical total in 32-bit arithmetic

Cost target

O(32) time and O(1) space

XOR adds bits without carrying. AND identifies positions that generate a carry, which shifts left and repeats until no carry remains.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead