In Code: Terraform, some contracts look much more complicated than they actually are once I understand what information each system gives me. In this guide, I explain how I solve several contracts, including Orbital Relay Hack, Xenogenetics Survey, Corrupted Archive, Underground Data Tablet, Alien Terminal Breach, and Sealed Vault.
Contract Solutions Guide: Scripts & Puzzle Answers
Below, I share the scripts I use for these Code: Terraform contracts and explain how each solution works. I also cover a few useful approaches I use when dealing with matching data, large result lists, locks, grids, and hidden maze layouts.
Table of Contents:
Orbital Relay Hack
The Orbital Relay uses a 6-tumbler lock, and each tumbler can contain a value from 0 to 99.
The key detail I use here is that every call to lock.intercept() tells me whether each individual tumbler position is correct.
- True = the tumbler is correct
- False = the tumbler is incorrect
Because every tumbler is checked separately, I do not need to brute-force every possible six-number combination. Instead, I test each value from 0 to 99 across all six tumblers at the same time.
Orbital Relay Hack Solution
I use the following script:
lock = self.contract.lock
code = [0] * lock.tumblers
found = [False] * lock.tumblers
for value in range(lock.range):
result = lock.intercept([value] * lock.tumblers)
for i in range(lock.tumblers):
if result[i]:
code[i] = value
found[i] = True
if all(found):
break
transmitter = get_component("transmitter")
transmitter.connect("earth")
transmitter.transmit(self.contract.id, code)
How the Orbital Relay Script Works
I test every possible tumbler value from 0 to 99. For each value, I place the same number in all six positions at once.
For example:
[25, 25, 25, 25, 25, 25]
If one position returns True, I know that value belongs to that tumbler, so the script saves it. I continue doing this until all six positions have been found.
After the complete code is discovered, I automatically transmit it to Earth.
Maximum intercept calls: 100
The complete lock theoretically has:
100 × 100 × 100 × 100 × 100 × 100
or 1,000,000,000,000 possible combinations.
Since the contract tells me which individual tumbler is correct, I can reduce the search to no more than 100 tests.
Xenogenetics Survey
For the Xenogenetics Survey, Earth gives me 50 known Earth gene sequences, while the contract contains 1000 collected DNA samples.
My goal is to transmit every DNA sample that does not appear in the Earth reference set.
Xenogenetics Survey Solution
I use this script:
c = self.contract
earth = set(c.earth_ref)
alien_list = [
sample
for sample in c.samples
if sample not in earth
]
transmitter = get_component("transmitter")
transmitter.connect("earth")
transmitter.transmit(c.id, alien_list)
How the Xenogenetics Survey Script Works
I first convert the Earth reference sequences into a Python set. This lets me quickly check whether each collected sample already appears in the known Earth data.
I then go through all 1000 samples and keep only the sequences that are not present in the Earth reference set. These sequences are stored in alien_list and transmitted.
Important: I do not print the complete alien_list.
The resulting list can be very large, and Code: Terraform may stop the script with an error such as:
string length 10,001 exceeds the current limit of 10,000
If I only want to check how many alien sequences were found, I can temporarily add:
print("Alien count:", len(alien_list))
This print line is not required to complete the contract.
Corrupted Archive
The Corrupted Archive contains a 10 × 10 grid with 100 cells in total.
- There are 50 unique words
- Each word appears exactly twice
I need to find both locations for every matching word. Each pair must use this format:
[row1, col1, row2, col2]
For example:
[0, 0, 3, 7]
Corrupted Archive Solution
I use this script:
archive = self.contract.archive
seen = {}
pairs = []
for row in range(archive.rows):
for col in range(archive.cols):
word = archive.flip(row, col)
if word in seen:
r1, c1 = seen[word]
pairs.append([r1, c1, row, col])
else:
seen[word] = (row, col)
transmitter = get_component("transmitter")
transmitter.connect("earth")
transmitter.transmit(self.contract.id, pairs)
How the Corrupted Archive Script Works
I visit every cell in the archive exactly once. When I see a word for the first time, I store that word together with its coordinates.
When the same word appears again, I combine its first position with its second position and add the result to my list of matching pairs.
After checking all 100 cells, I have all 50 matching pairs and transmit them.
Required archive reads: 100
General Contract Tips
When I work through Code: Terraform contracts, I pay close attention to exactly what information each function returns. Some contracts reveal more than they may appear to at first.
The Orbital Relay Hack is a good example. It does not only tell me whether the complete code is correct. It tells me which individual tumbler positions are correct, turning a huge brute-force problem into a much smaller search.
Use Sets for Membership Checks
When I repeatedly need to check whether values exist inside reference data, I can convert that collection into a set:
reference = set(data)
I can then check values with:
if value in reference:
Use Dictionaries for Matching Data
When I need to remember where a value appeared earlier, I can use a dictionary:
seen = {}
I find this especially useful for matching, grouping, and coordinate-based puzzles.
Avoid Printing Huge Results
Some Code: Terraform scripts can produce very large lists. I avoid printing the entire result:
print(huge_list)
Instead, I prefer checking the size:
print(len(huge_list))
I can also print only a small part of the result when needed.
Underground Data Tablet
The Underground Data Tablet contains a 30 × 30 grid of characters. Most cells contain noise, but some of them belong to the hidden message.
Every probe gives me two values:
- char = the character stored in the cell
- distance = Manhattan distance to the nearest message character
If a cell returns distance = 0, I know that cell belongs to the hidden message.
I need to read the message from left to right and then top to bottom.
Underground Data Tablet Solution
I use the following script:
tablet = self.contract.tablet
chars = []
for row in range(tablet.rows):
for col in range(tablet.cols):
result = tablet.probe(row, col)
if result.distance == 0:
chars.append(result.char)
message = "".join(chars)
print("Message:", message)
transmitter = get_component("transmitter")
transmitter.connect("earth")
transmitter.transmit(self.contract.id, message)
How the Underground Data Tablet Script Works
The tablet contains 30 × 30 = 900 cells, so I check every cell once.
My outer loop moves through the rows from top to bottom, while the inner loop moves from left to right across each row. This naturally gives me the reading order required by the contract.
Whenever I receive distance = 0, I add that cell’s character to my message.
After scanning the complete grid, I join the collected characters together:
message = "".join(chars)
I then transmit the completed message to Earth.
Maximum probe calls: 900
I do not need the additional distance information for this straightforward method because scanning all 900 cells guarantees that I find every message character.
Alien Terminal Breach
The Alien Terminal is protected by a 15-digit passcode. Each position can contain one of five possible values: 1, 2, 3, 4, or 5.
Every valid guess returns two values:
- correct = correct digit in the correct position
- misplaced = correct digit in the wrong position
For this solution, I only need the correct value. Instead of brute-forcing every possible passcode, I first work out how often each digit appears and then solve the code one position at a time.
Alien Terminal Breach Solution
I use this script:
terminal = self.contract.terminal
length = terminal.length
# Count how often each digit occurs in the code.
counts = {}
for digit in range(1, 6):
result = terminal.guess([digit] * length)
counts[digit] = result.correct
# Use the most common digit as the baseline.
base = 1
for digit in range(2, 6):
if counts[digit] > counts[base]:
base = digit
# If all positions contain the same digit, we are already done.
if counts[base] == length:
code = [base] * length
else:
code = [None] * length
base_correct = counts[base]
# Only test digits that actually appear in the code.
probe_digits = []
for digit in range(1, 6):
if digit != base and counts[digit] > 0:
probe_digits.append(digit)
# Find the value of each position.
for pos in range(length):
found = False
for digit in probe_digits:
guess = [base] * length
guess[pos] = digit
result = terminal.guess(guess)
# The alternative digit is correct at this position.
if result.correct == base_correct + 1:
code[pos] = digit
found = True
break
# Replacing the baseline digit removed one correct match.
if result.correct == base_correct - 1:
code[pos] = base
found = True
break
# If none of the alternatives changed the score,
# this position must contain the baseline digit.
if not found:
code[pos] = base
print("Code:", code)
transmitter = get_component("transmitter")
transmitter.connect("earth")
transmitter.transmit(self.contract.id, code)
How the Alien Terminal Breach Script Works
Step 1 – Count the digits
I start with five special guesses. For example:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Because every position contains the same value, the returned correct number tells me exactly how many times that digit appears in the hidden passcode.
I repeat this for digits 1 through 5. After five guesses, I know the complete digit distribution.
Step 2 – Choose a baseline
I select the most common digit as my baseline. For example, if the baseline is 3 and a guess containing fifteen 3s returns 6 correct, I know the hidden passcode contains six 3s.
Step 3 – Test individual positions
I then change only one position at a time. For example:
[3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
Compared with my baseline score, I use three possible outcomes:
- Score increases by 1 – the tested digit is correct at that position
- Score decreases by 1 – the baseline digit belongs at that position
- Score stays the same – neither the baseline nor the tested digit belongs there
I repeat the process until every position has been identified. Once I know all 15 digits, I automatically transmit the completed passcode to Earth.
Alien Terminal Breach Efficiency
A normal brute-force search would contain:
5^15 = 30,517,578,125 possible codes
With this method, I only need 5 initial guesses to count the digits, up to 4 tests per position, and there are 15 positions in total.
Even in the worst straightforward case, this means no more than roughly 65 guesses. In practice, I may need fewer because digits that do not appear in the passcode are never tested.
I do not need the misplaced value for this solution.
Sealed Vault
The Sealed Vault contains a hidden square maze. I cannot see the maze directly, so I have to explore it one movement at a time.
I can move in four directions:
- north
- south
- east
- west
Each movement returns one of three results:
- path = the move succeeded
- wall = that edge is blocked
- exit = I entered the exit cell
I always start at (0, 0), while the exit is always located at (size – 1, size – 1).
My goal is to navigate the unknown maze, reach the exit, call vault.escape(), and transmit the key it returns.
Sealed Vault Solution
I use this script:
vault = self.contract.vault
directions = [
("east", "west"),
("south", "north"),
("west", "east"),
("north", "south"),
]
start = vault.position
start_pos = (start.row, start.col)
visited = {start_pos}
# Each stack entry:
# [row, col, next_direction_index, direction_back_to_parent]
stack = [[start.row, start.col, 0, None]]
found_exit = False
while stack:
frame = stack[-1]
# All directions from this cell have been checked.
if frame[2] >= len(directions):
back = frame[3]
stack.pop()
# Move back to the previous cell.
if back is not None:
result = vault.move(back)
if result.status == "exit":
found_exit = True
break
continue
direction, opposite = directions[frame[2]]
frame[2] += 1
result = vault.move(direction)
# Blocked edge.
if result.status == "wall":
continue
# Exit reached.
if result.status == "exit":
found_exit = True
break
# Successful normal movement.
pos = vault.position
current = (pos.row, pos.col)
# If this cell was already explored, move back immediately.
if current in visited:
vault.move(opposite)
continue
visited.add(current)
# Explore the new cell.
stack.append([
pos.row,
pos.col,
0,
opposite
])
if found_exit:
escape = vault.escape()
if escape.status == "ok":
print("Vault escaped!")
print("Cells visited:", len(visited))
transmitter = get_component("transmitter")
transmitter.connect("earth")
transmitter.transmit(self.contract.id, escape.key)
else:
print(escape.message)
else:
print("No path to the exit was found.")
How the Sealed Vault Script Works
I solve the Sealed Vault with a Depth-First Search and backtracking. The main idea is to remember every maze cell I have already visited so the script does not get trapped in loops.
Step 1 – Track visited cells
I add the starting position to a set:
visited = {(0, 0)}
Whenever I enter a new cell, I save its position. If the script later reaches a cell that has already been explored, it immediately moves back.
Step 2 – Try every direction
At each cell, I try east, south, west, and north. I test east and south first because the exit is toward the bottom-right corner of the grid.
This does not guarantee the shortest route, but it can move the search toward the general direction of the exit earlier.
Step 3 – Handle walls
If a move returns wall, I remain in the current cell and try another direction.
A wall only blocks the edge between my current cell and the neighboring cell. It does not mean that the neighboring cell cannot be reached from another direction.
Step 4 – Backtracking
If every direction from a cell has already been explored, I move back to the previous cell.
- east → return with west
- west → return with east
- north → return with south
- south → return with north
This lets me explore dead ends and then continue searching from an earlier junction.
Step 5 – Escape the vault
When a movement returns exit, I stop exploring and call:
vault.escape()
If the returned status is ok, I transmit the vault key to Earth.
Important Sealed Vault Note
I do not stop the script while it is exploring the maze unless I want to restart from the beginning.
The maze layout remains the same, but my current position does not persist between script runs. If I stop and restart the script, I return to (0, 0).
Why the Sealed Vault Solution Works
The script systematically explores the reachable maze because I keep track of visited cells, check every available direction, back out of dead ends, and continue searching until I find the exit. I do not need to know the maze layout beforehand.
