Initializing help system before first use

Smallest and largest value


Type: Programming
Rating: 2
Description: Find the smallest and the largest value in a set of integers
  • use of round, random, min, max
  • if-then-elif-then statement
File(s): minmax.mos


minmax.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file minmax.mos 
   ``````````````` 
   The 'if-then-elif-then' selection statement.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001
*******************************************************!)

model Minmax                   ! Start a new model

 declarations
  SNumbers: set of integer     ! Set of integer numbers
  LB=-1000                     ! Elements of SNumbers must be between LB
  UB=1000                      ! and UB
 end-declarations

                               ! Generate a set of 50 randomly chosen numbers
 forall(i in 1..50)
  SNumbers += {round(random*200)-100}

 writeln("Set: ", SNumbers, " (size: ", getsize(SNumbers), ")")

 minval:=UB
 maxval:=LB
 forall(p in SNumbers)
   if pmaxval then
     maxval:=p
   end-if    

 writeln("Min: ", minval, ", Max: ", maxval)

(! Instead of writing the loop above, it is of course possible to use
   the corresponding operators provided by Mosel:
  
 writeln("Min: ", min(p in SNumbers) p, ", Max: ", max(p in SNumbers) p)  

!) 

end-model