6 kyu

Guess the array

35 of 342ice1000

Description:

In this kata, you should determine the values in an unknown array of numbers. You'll be given a function f, which you can call like this:

f a b -- returns an Integral
f(a, b);
f(a, b)
f(a, b)

where a and b are indexes of two different elements in the unknown array, 1 or 2 indexes apart. f will return the sum of those two elements.

The absolute difference between a and b must not be 0 nor greater than 2 (that is: the chosen indexes must be exactly 1 or 2 apart).

Your goal is to figure out the correct array.

The whole procedure is:

  1. You are given f and the length of the array n.
  2. Ask f for any element sums you want.
  3. Create and return the correct array according to the answers.

The array will always have at least 3 elements.

Don't forget to give upvotes and feedbacks!

Puzzles
Algorithms
Arrays

Stats:

CreatedJun 8, 2017
PublishedJun 8, 2017
Warriors Trained1721
Total Skips62
Total Code Submissions1467
Total Times Completed342
Haskell Completions35
JavaScript Completions122
C# Completions48
Python Completions141
Rust Completions33
Total Stars30
% of votes with a positive feedback rating98% of 107
Total "Very Satisfied" Votes102
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes0
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • ice1000 Avatar
  • natan Avatar
  • Voile Avatar
  • Souzooka Avatar
  • Awesome A.D. Avatar
  • hobovsky Avatar
  • logmkeys Avatar
Ad