7 kyu

Monotone travel

582 of 6,772bkaes

Description:

Story

Peter lives on a hill, and he always moans about the way to his home. "It's always just up. I never get a rest". But you're pretty sure that at least at one point Peter's altitude doesn't rise, but fall. To get him, you use a nefarious plan: you attach an altimeter to his backpack and you read the data from his way back at the next day.

Task

You're given a list of compareable elements:

double heights[n]
heights = new int[0 ... 100]
Ord a => [a]
heights = [h1, h2, h3, , hn]
heights = [Integers or Floats]
heights = [Integers or Floats]
      heights = [pic s9(2)]

Your job is to check whether for any x all successors are greater or equal to x.

is_monotone(3, {1, 2, 3}) == true
is_monotone(3, {1, 1, 2}) == true
is_monotone(1, {1})       == true
is_monotone(3, {3, 2, 1}) == false
is_monotone(3, {3, 2, 2}) == false
Kata.IsMonotone(new int[] {1,2,3}) => true
Kata.IsMonotone(new int[] {1,1,2}) => true
Kata.IsMonotone(new int[] {1})     => true
Kata.IsMonotone(new int[] {3,2,1}) => false
Kata.IsMonotone(new int[] {3,2,2}) => false
isMonotone [1,2,3] == True
isMonotone [1,1,2] == True
isMonotone [1]     == True
isMonotone [3,2,2] == False
isMonotone([1,2,3]) == true
isMonotone([1,1,2]) == true
isMonotone([1])     == true
isMonotone([3,2,1]) == false
isMonotone([3,2,2]) == false
is_monotone([1,2,3]) == True
is_monotone([1,1,2]) == True
is_monotone([1])     == True
is_monotone([3,2,1]) == False
is_monotone([3,2,2]) == False
is_monotone([1,2,3]) == True
is_monotone([1,1,2]) == True
is_monotone([1])     == True
is_monotone([3,2,1]) == False
is_monotone([3,2,2]) == False
      IsMonotone([1,2,3]) = 1
      IsMonotone([1,1,2]) = 1
      IsMonotone([1]) = 1
      IsMonotone([3,2,1]) = 0
      IsMonotone([3,2,2]) = 0

If the list is empty, Peter has probably removed your altimeter, so we cannot prove him wrong and he's still right:

is_monotone(0, NULL) => true
Kata.IsMonotone(new int[] {}) => true
isMonotone []      == True
isMonotone([])     == True
is_monotone([])     == True
isMonotone([])     == True

Such a sequence is also called monotone or monotonic sequence, hence the name isMonotone.

Lists
Fundamentals

Similar Kata:

Stats:

CreatedOct 21, 2014
PublishedOct 21, 2014
Warriors Trained10964
Total Skips995
Total Code Submissions23035
Total Times Completed6772
Haskell Completions582
Python Completions2877
JavaScript Completions2672
Ruby Completions766
C# Completions230
C Completions86
COBOL Completions6
Total Stars91
% of votes with a positive feedback rating91% of 665
Total "Very Satisfied" Votes566
Total "Somewhat Satisfied" Votes84
Total "Not Satisfied" Votes15
Ad
Contributors
  • bkaes Avatar
  • xcthulhu Avatar
  • Azuaron Avatar
  • GiacomoSorbi Avatar
  • kazk Avatar
  • Voile Avatar
  • Souzooka Avatar
  • rowcased Avatar
  • hobovsky Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • saudiGuy Avatar
Ad