Find the security code of the longest successful Mars mission from a complex log file containing thousands of space mission records.
- Goal: Find the longest successful Mars mission and extract its security code
- Criteria:
- Destination must be "Mars"
- Status must be "Completed"
- Find the one with maximum duration
- Expected output format: ABC-123-XYZ
First, I examined the log file to understand its format:
head -50 challenges/hiring-challenge/space_missions.logKey findings:
- File contains ~105,000 lines
- Fields are separated by
|characters - Contains noise data (comments, system lines, checkpoints)
- Field format:
Date | Mission ID | Destination | Status | Crew Size | Duration (days) | Success Rate | Security Code - Fields have inconsistent whitespace padding
Identified data to skip:
- Lines starting with
#(comments) - Lines starting with
SYSTEM:,CONFIG:,CHECKSUM: - Lines starting with
CHECKPOINT: - Empty lines
- Lines with less than 8 fields
Created an AWK script with the following logic:
BEGIN {
max_duration = 0
security_code = ""
}
# Skip unwanted lines
/^#/ { next }
/^SYSTEM:/ { next }
/^CONFIG:/ { next }
/^CHECKSUM:/ { next }
/^CHECKPOINT:/ { next }
/^$/ { next }
# Process valid data lines
NF >= 8 {
# Clean whitespace from all fields
for(i=1; i<=NF; i++) {
gsub(/^[ \t]+|[ \t]+$/, "", $i)
}
# Filter for Mars missions with Completed status
if ($3 == "Mars" && $4 == "Completed") {
duration = $6
if (duration > max_duration) {
max_duration = duration
security_code = $8
}
}
}
END {
print "Longest successful Mars mission duration:", max_duration, "days"
print "Security code:", security_code
}Execute the AWK command:
awk -F'|' -f mars_mission.awk space_missions.logVerified the result by:
- Checking all Mars completed missions with high duration (>= 900 days):
awk -F'|' '... if ($3 == "Mars" && $4 == "Completed" && $6 >= 900) ...'
- Finding the specific record:
grep "GDH-7476" space_missions.log
- Mission ID: GDH-7476
- Duration: 997 days (longest among all completed Mars missions)
- Security Code: GDJ-466-NVT