Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Space Mission Log Analysis - Solution

Challenge Overview

Find the security code of the longest successful Mars mission from a complex log file containing thousands of space mission records.

Solution Steps

Step 1: Understanding the Problem

  • 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

Step 2: Analyzing the Data Structure

First, I examined the log file to understand its format:

head -50 challenges/hiring-challenge/space_missions.log

Key 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

Step 3: Data Cleaning Strategy

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

Step 4: AWK Script Development

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
}

Step 5: Running the Solution

Execute the AWK command:

awk -F'|' -f mars_mission.awk space_missions.log

Step 6: Verification

Verified the result by:

  1. Checking all Mars completed missions with high duration (>= 900 days):
    awk -F'|' '... if ($3 == "Mars" && $4 == "Completed" && $6 >= 900) ...'
  2. Finding the specific record:
    grep "GDH-7476" space_missions.log

Final Result

  • Mission ID: GDH-7476
  • Duration: 997 days (longest among all completed Mars missions)
  • Security Code: GDJ-466-NVT

About

Warp Mission Challenge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages