Initializing help system before first use

Smallest and largest value in a set


Type: Programming
Rating: 2 (easy-medium)
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 Example Problems                              *
  * ======================                              *
  *                                                     *
  * file minmax.mos                                     *
  * ```````````````                                     *
  * Example for the use of the Mosel language           *
  * (Min and max of a set of numbers)                   *
  *                                                     *
  * (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

 forall(i in 1..50)
  SNumbers += {round(random*200)-100}

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

 minval:=UB
 maxval:=LB
 forall(p in SNumbers)
   if p<minval then
     minval:=p
   elif p>maxval 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

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.