BackmediumRecursion Infosys

Galactic Supply Chain Optimizer Solution

Problem Statement

In a galactic supply chain, cargo shipments are calculated using two recursive sequences: the fuel sequence where each term is the sum of the previous two terms (starting with 23 and 17), and the resource sequence which alternates between the sum and difference of the previous two terms (starting with 11 and 7).

Example 1
Input
Get the 9th term of the fuel sequence and the 9th term of the resource sequence.
Output
57, -18

Explanation: To get the 9th term of the fuel sequence, we start with 23 and 17. We calculate the next terms as follows: 23 + 17 = 40, 17 + 40 = 57. The 9th term of the fuel sequence is 57. Then, we get the 9th term of the resource sequence by alternating between the sum and difference of the previous two terms. The 8th term of the fuel sequence is 40, so the 9th term of the resource sequence is 24 (sum of 40 and 57), and the 10th term of the fuel sequence is 57 (sum of 40 and 17). The 10th term of the resource sequence is -18 (difference of 57 and 40).

Example 2
Input
Get the 8th term of the fuel sequence and the 8th term of the resource sequence.
Output
40, 24

Explanation: To get the 8th term of the fuel sequence, we start with 23 and 17. We calculate the next terms as follows: 23 + 17 = 40, 17 + 40 = 57, 40 + 57 = 97, 57 + 97 = 154, 97 + 154 = 251, 154 + 251 = 405, 251 + 405 = 656. The 8th term of the fuel sequence is 40. Then, we get the 8th term of the resource sequence by alternating between the sum and difference of the previous two terms. The 7th term of the fuel sequence is 57, so the 8th term of the resource sequence is 24 (sum of 57 and 40).

Constraints

  • 1 <= n <= 20
  • All terms are integers
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free