6 kyu
Progressive Spiral Number Distance
106 of 245GiacomoSorbi
Description:
Final kata of the series (highly recommended to compute layers and branch first to get a good idea), this is a blatant ripoff of the one offered on AoC.
Given a number, return the Manhattan distance considering the core of the spiral (the 1
cell) as 0 and counting each step up, right, down or left to reach a given cell.
For example, using our beloved 5x5 square:
17 16 15 14 13 4 3 2 3 4
18 05 04 03 12 3 2 1 2 3
19 06 01 02 11 => 2 1 0 1 2
20 07 08 09 10 3 2 1 2 3
21 22 23 24 25 4 3 2 3 4
And thus your code should behave like this:
distance(1) == 0
distance(5) == 2
distance(25) == 4
distance(30) == 5
distance(50) == 7
Just be ready for larger numbers, as usual always positive.
[Dedicated to swiftest learner I met in a long while]
Mathematics
Number Theory
Fundamentals
Similar Kata:
Stats:
Created | Dec 6, 2017 |
Published | Dec 7, 2017 |
Warriors Trained | 978 |
Total Skips | 99 |
Total Code Submissions | 953 |
Total Times Completed | 245 |
JavaScript Completions | 51 |
Ruby Completions | 18 |
Crystal Completions | 5 |
Python Completions | 106 |
C++ Completions | 74 |
C# Completions | 30 |
Total Stars | 24 |
% of votes with a positive feedback rating | 92% of 63 |
Total "Very Satisfied" Votes | 53 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 6 kyu |