ARES-7

Qualcomm

Problem Description

You are the remote pilot for ARES-7, a solar-powered rover currently navigating the treacherous "Crater of Silence" on the Moon. Your goal is to reach the furthest possible survey point before the lunar night falls.

The terrain is represented as a series of Elevation Readings. Because the rover is solar-powered and uses regenerative braking, its battery levels fluctuate based on the slope it is climbing or descending.

The Rules of the Crater

  1. Climbing (Elevation Increase): For every 1 unit of elevation increase, the battery decreases by 3 units.

  2. Descending (Elevation Decrease): For every 1 unit of elevation decrease, the battery increases by 2 units (regenerative braking).

  3. Solar Patches: If the elevation of a point is a multiple of 10, the rover hits a "Solar Patch" and gains an immediate 15 units of battery before moving to the next point.

  4. The Ceiling: The battery can never exceed 100 units. If a gain would put it over 100, it stays at 100.

  5. The Failure: If the battery level drops to 0 or below at any point, the rover shuts down immediately at that coordinate.

    The Challenge

    Write a script to calculate the following:

    1. The Journey Log: For every movement between points, print the current elevation, the action (Climbing/Descending/Solar), and the resulting battery level.

    2. The Shutdown Point: Determine exactly which elevation point the rover reaches before it either finishes the list or runs out of power.

      Example Output: (Make sure spacing and format remains same otherwise question will fail)

      Point 1: Elevation 15 | Action: Starting | Battery 20
      Point 2: Elevation 20 | Action: Climbing | Solar Patch! | Battery 20
      Point 3: Elevation 18 | Action: Descending | Battery 24
      Point 4: Elevation 12 | Action: Descending | Battery 36
      Point 5: Elevation 10 | Action: Descending | Solar Patch! | Battery 55
      Point 6: Elevation 25 | Action: Climbing | Battery 10
      Point 7: Elevation 30 | Action: Climbing | Solar Patch! | Battery 10
      Point 8: Elevation 28 | Action: Descending | Battery 14
      Point 9: Elevation 20 | Action: Descending | Solar Patch! | Battery 45
      Point 10: Elevation 35 | Action: Climbing | Battery 0
      
      CRITICAL FAILURE: Battery out at 35
      
      Point 1: Elevation 15 | Action: Starting | Battery 50
      Point 2: Elevation 20 | Action: Climbing | Solar Patch! | Battery 50
      Point 3: Elevation 18 | Action: Descending | Battery 54
      Point 4: Elevation 12 | Action: Descending | Battery 66
      Point 5: Elevation 10 | Action: Descending | Solar Patch! | Battery 85
      Point 6: Elevation 25 | Action: Climbing | Battery 40
      Point 7: Elevation 30 | Action: Climbing | Solar Patch! | Battery 40
      Point 8: Elevation 28 | Action: Descending | Battery 44
      Point 9: Elevation 20 | Action: Descending | Solar Patch! | Battery 75
      Point 10: Elevation 35 | Action: Climbing | Battery 30
      Point 11: Elevation 40 | Action: Climbing | Solar Patch! | Battery 30
      Point 12: Elevation 38 | Action: Descending | Battery 34
      Point 13: Elevation 30 | Action: Descending | Solar Patch! | Battery 65
      
      MISSION SUCCESS: Reached the last point!



Perl

Code Editor Access

Log in to write, run and submit your solution to this interview question. It's free.

Output

Output goes here...