6 kyu

The Arithmetic Progression Detective

71 of 97iedayan03

Description:

Imagine you're a master codebreaker or an archaeologist of ancient math puzzles. You've stumbled upon an arithmetic sequence, a harmonious string of numbers where each term follows a fixed step. But something is wrong—one number has been corrupted, disturbing the pattern.

Your mission: identify the intruder and restore the sequence to its original perfection.

Task

Write a function that takes a nearly correct arithmetic sequence with exactly one corrupted value and fixes the sequence by replacing the incorrect number with the correct one.

Rules

  1. The sequence contains exactly one incorrect value.
  2. The repaired sequence must be a valid arithmetic progression.
  3. The input sequence will always have at least one solution.

Edge Cases

  • If the sequence has 1, 2, or 3 elements, return it unchanged (since there is no definitive way to detect corruption).

More By Author:

Check out these other kata created by iedayan03

Stats:

CreatedJan 16, 2025
PublishedJan 25, 2025
Warriors Trained362
Total Skips6
Total Code Submissions1450
Total Times Completed97
Python Completions71
Java Completions26
Go Completions7
Total Stars8
% of votes with a positive feedback rating92% of 30
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes1
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • iedayan03 Avatar
  • dfhwze Avatar
Ad