7 kyu

Cats and shelves

957 of 13,421RealSup

Description:

Description

An infinite number of shelves are arranged one above the other in a staggered fashion.
The cat can jump either one or three shelves at a time: from shelf i to shelf i+1 or i+3 (the cat cannot climb on the shelf directly above its head), according to the illustration:

                 ┌────────┐
                 │-6------│
                 └────────┘
┌────────┐       
│------5-│        
└────────┘  ┌─────► OK!
            │    ┌────────┐
            │    │-4------│
            │    └────────┘
┌────────┐  │
│------3-│  │     
BANG!────┘  ├─────► OK! 
  ▲  |\_/|  │    ┌────────┐
  │ ("^-^)  │    │-2------│
  │ )   (   │    └────────┘
┌─┴─┴───┴┬──┘
│------1-│
└────────┘

Input

Start and finish shelf numbers (always positive integers, finish no smaller than start)

Task

Find the minimum number of jumps to go from start to finish

Example

Start 1, finish 5, then answer is 2 (1 => 4 => 5 or 1 => 2 => 5)

Inspirers

inspirers

Algorithms

Similar Kata:

More By Author:

Check out these other kata created by RealSup

Stats:

CreatedJul 9, 2022
PublishedJul 10, 2022
Warriors Trained28026
Total Skips808
Total Code Submissions66897
Total Times Completed13421
C# Completions957
JavaScript Completions4041
Python Completions4046
Ruby Completions166
Java Completions1608
Go Completions377
PHP Completions343
TypeScript Completions336
C Completions396
COBOL Completions23
Scala Completions65
SQL Completions549
Rust Completions222
Groovy Completions33
C++ Completions813
PowerShell Completions47
CoffeeScript Completions18
Raku Completions14
Prolog Completions15
Haskell Completions59
VB Completions36
Crystal Completions14
CFML Completions9
Lua Completions41
Pascal Completions16
NASM Completions11
Kotlin Completions80
Dart Completions48
Shell Completions29
Total Stars344
% of votes with a positive feedback rating93% of 1141
Total "Very Satisfied" Votes1006
Total "Somewhat Satisfied" Votes116
Total "Not Satisfied" Votes19
Total Rank Assessments10
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • RealSup Avatar
  • SagePtr Avatar
  • anter69 Avatar
  • JohanWiltink Avatar
  • hobovsky Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • 66  Avatar
  • cwps Avatar
  • KayleighWasTaken Avatar
Ad