PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Citadel

Simulate 2048 and pack board into uint64

Last updated: Apr 8, 2026

Quick Overview

This question evaluates proficiency in implementing deterministic game-state logic and compact binary representations, specifically array manipulation and merge semantics for 2048 slide operations plus bit-level packing/unpacking of 4-bit exponent fields.

  • medium
  • Citadel
  • Coding & Algorithms
  • Software Engineer

Simulate 2048 and pack board into uint64

Company: Citadel

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem: 2048 move simulation + board compression You are implementing part of the **2048** game on a fixed **4×4** grid. ### Part A — Simulate a move Given a 4×4 board of non-negative integers (each is either 0 or a power of two), implement a function: - `move(board, dir) -> new_board` where `dir ∈ {LEFT, RIGHT, UP, DOWN}`. **Rules** (standard 2048): 1. All tiles slide as far as possible in the chosen direction. 2. If two adjacent tiles in the direction of movement have the same value, they merge into one tile of value `2x`. 3. Each tile can merge **at most once per move**. 4. Zeros represent empty cells. ### Part B — Encode/decode the board into a 64-bit integer Implement two functions: - `encode(board) -> uint64` - `decode(x) -> board` Constraints/assumptions for encoding: - The board is 4×4 = 16 cells. - Store each cell in **4 bits** as the exponent `e` where value = `2^e`. - Empty cell (0) is stored as `e = 0`. - Example: value 2 → e=1, 4 → e=2, … - Assume no cell exceeds `2^15` (so exponent fits in 4 bits). - You may choose any fixed cell order (e.g., row-major), but `decode(encode(board))` must reproduce the original board. ### Deliverables Describe/implement `move`, `encode`, and `decode` with correct handling of merges and bit packing.

Quick Answer: This question evaluates proficiency in implementing deterministic game-state logic and compact binary representations, specifically array manipulation and merge semantics for 2048 slide operations plus bit-level packing/unpacking of 4-bit exponent fields.

Related Interview Questions

  • Implement a single-producer multi-consumer ring buffer - Citadel (medium)
  • Sort a Nearly Sorted Array - Citadel (hard)
  • Compute BBO and NBBO from order data - Citadel (medium)
  • Design dynamic weighted random sampling with updates - Citadel (medium)
  • Compute maximum later-earlier difference - Citadel (medium)
Citadel logo
Citadel
Feb 11, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
16
0

Problem: 2048 move simulation + board compression

You are implementing part of the 2048 game on a fixed 4×4 grid.

Part A — Simulate a move

Given a 4×4 board of non-negative integers (each is either 0 or a power of two), implement a function:

  • move(board, dir) -> new_board

where dir ∈ {LEFT, RIGHT, UP, DOWN}.

Rules (standard 2048):

  1. All tiles slide as far as possible in the chosen direction.
  2. If two adjacent tiles in the direction of movement have the same value, they merge into one tile of value 2x .
  3. Each tile can merge at most once per move .
  4. Zeros represent empty cells.

Part B — Encode/decode the board into a 64-bit integer

Implement two functions:

  • encode(board) -> uint64
  • decode(x) -> board

Constraints/assumptions for encoding:

  • The board is 4×4 = 16 cells.
  • Store each cell in 4 bits as the exponent e where value = 2^e .
    • Empty cell (0) is stored as e = 0 .
    • Example: value 2 → e=1, 4 → e=2, …
  • Assume no cell exceeds 2^15 (so exponent fits in 4 bits).
  • You may choose any fixed cell order (e.g., row-major), but decode(encode(board)) must reproduce the original board.

Deliverables

Describe/implement move, encode, and decode with correct handling of merges and bit packing.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Citadel•More Software Engineer•Citadel Software Engineer•Citadel Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.