How to resolve the algorithm Averages/Pythagorean means step by step in the Oz programming language

Published on 12 May 2024 09:40 PM
#Oz

How to resolve the algorithm Averages/Pythagorean means step by step in the Oz programming language

Table of Contents

Problem Statement

Compute all three of the Pythagorean means of the set of integers 1 through 10 (inclusive). Show that

A (

x

1

, … ,

x

n

) ≥ G (

x

1

, … ,

x

n

) ≥ H (

x

1

, … ,

x

n

)

{\displaystyle A(x_{1},\ldots ,x_{n})\geq G(x_{1},\ldots ,x_{n})\geq H(x_{1},\ldots ,x_{n})}

for this set of positive integers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Pythagorean means step by step in the Oz programming language

Source code in the oz programming language

declare
  %% helpers
  fun {Sum Xs} {FoldL Xs Number.'+' 0.0} end
  fun {Product Xs} {FoldL Xs Number.'*' 1.0} end
  fun {Len Xs} {Int.toFloat {Length Xs}} end

  fun {AMean Xs}
     {Sum Xs}
     /
     {Len Xs}
  end

  fun {GMean Xs}
     {Pow
      {Product Xs}
      1.0/{Len Xs}}
  end

  fun {HMean Xs}
     {Len Xs}
     /
     {Sum {Map Xs fun {$ X} 1.0 / X end}}
  end

  Numbers = {Map {List.number 1 10 1} Int.toFloat}

  [A G H] = [{AMean Numbers} {GMean Numbers} {HMean Numbers}]
in
  {Show [A G H]}
  A >= G = true
  G >= H = true

  

You may also check:How to resolve the algorithm Rot-13 step by step in the Factor programming language
You may also check:How to resolve the algorithm Input loop step by step in the Picat programming language
You may also check:How to resolve the algorithm Permutation test step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Pinstripe/Display step by step in the Julia programming language
You may also check:How to resolve the algorithm General FizzBuzz step by step in the Ruby programming language