How to resolve the algorithm Averages/Mode step by step in the Oz programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Mode step by step in the Oz programming language
Table of Contents
Problem Statement
Write a program to find the mode value of a collection. The case where the collection is empty may be ignored. Care must be taken to handle the case where the mode is non-unique. If it is not appropriate or possible to support a general collection, use a vector (array), if possible. If it is not appropriate or possible to support an unspecified value type, use integers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Mode step by step in the Oz programming language
Source code in the oz programming language
declare
fun {Mode Xs}
Freq = {Dictionary.new}
for X in Xs do
Freq.X := {CondSelect Freq X 0} + 1
end
MaxCount = {FoldL {Dictionary.items Freq} Max 0}
in
for Value#Count in {Dictionary.entries Freq} collect:C do
if Count == MaxCount then
{C Value}
end
end
end
in
{Show {Mode [1 2 3 3 2 1 1]}}
{Show {Mode [1 2 3 3 2 1]}}
You may also check:How to resolve the algorithm Self numbers step by step in the Ring programming language
You may also check:How to resolve the algorithm Pythagorean triples step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Nim programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Tcl programming language
You may also check:How to resolve the algorithm Include a file step by step in the Ring programming language