7 kyu

Consecutive Differences

512 of 827coder334

Description:

Given a list of integers, find the positive difference between each consecutive pair of numbers, and put this into a new list of differences. Then, find the differences between consecutive pairs in this new list, and repeat until the list has a length of 1. Then, return the single value.

The list will only contain integers, and will not be empty.

For example:

differences([1, 2, 3]) => [1, 1] => [0] => 0
differences([1, 5, 2, 7, 8, 9, 0]) => [4, 3, 5, 1, 1, 9] => [1, 2, 4, 0, 8] => ... => 1
differences([2, 3, 1]) => [1, 2] => 1
differences [1, 2, 3] -> [1, 1] -> [0] -> 0
differences [1, 5, 2, 7, 8, 9, 0] -> [4, 3, 5, 1, 1, 9] -> [1, 2, 4, 0, 8] -> .. -> 1
differences [2, 3, 1] -> [1, 2] -> [1] -> 1
differences([1, 2, 3]) => [1, 1] => [0] -> 0
differences([1, 5, 2, 7, 8, 9, 0]) => [4, 3, 5, 1, 1, 9] => [1, 2, 4, 0, 8] => .. => 1
differences([2, 3, 1]) => [1, 2] => [1] => 1
Algorithms

More By Author:

Check out these other kata created by coder334

Stats:

CreatedJan 3, 2021
PublishedJan 3, 2021
Warriors Trained1391
Total Skips22
Total Code Submissions2755
Total Times Completed827
Python Completions512
Haskell Completions49
JavaScript Completions295
Total Stars23
% of votes with a positive feedback rating91% of 193
Total "Very Satisfied" Votes162
Total "Somewhat Satisfied" Votes28
Total "Not Satisfied" Votes3
Total Rank Assessments6
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • coder334 Avatar
  • JohanWiltink Avatar
  • zLuki Avatar
Ad