RPG   =   Role Playing Game.



You're running a tabletop RPG, and your players are creating characters.

Each character has six core attributes: strength, dexterity, constitution, intelligence, wisdom, and charisma.

One way of generating values for these attributes is to roll four, 6-sided dice (d6) and sum the three highest rolls, discarding the lowest roll.

Some players like to assign values to their attributes in the order they're rolled.

To ensure generated characters don't put players at a disadvantage, the following requirements must be satisfied:

 The total of all character attributes must be at least 75.
 At least two of the attributes must be at least 15.

However, this can require a lot of manual dice rolling. A programatic solution would be much faster.



Task

Write a program that:

 Generates 4 random, whole values between 1 and 6.
 Saves the sum of the 3 largest values.
 Generates a total of 6 values this way.
 Displays the total, and all 6 values once finished.

 The order in which each value was generated must be preserved.
 The total of all 6 values must be at least 75.
 At least 2 of the values must be 15 or more.

BEGIN # RPG attributes generator #
 
    INT attrib count = 6;
    MODE RESULT = STRUCT( BOOL success, INT sum, high count, [ 1 : attrib count ]INT a );
 
    PROC generate attrib = INT:
    BEGIN
        INT min := 255, sum := 0;
        FOR i FROM 0 TO 3 DO
            INT v = ENTIER( next random * 6 ) + 1;
            IF v < min THEN
                min := v
            FI;
            sum +:= v
        OD;
        sum - min
    END # generate attrib #;
 
    PROC generate = ( REF RESULT res )VOID:
    BEGIN
        high count OF res := 0;
        sum OF res        := 0;
        FOR i FROM LWB a OF res TO UPB a OF res DO
            INT v = generate attrib;
            IF v >= 15 THEN
               high count OF res +:= 1
            FI;
            sum OF res +:= v;
            ( a OF res )[ i ] := v
        OD;
        success OF res := ( high count OF res >= 2 AND sum OF res >= 75 )
    END # generate # ;
 
    RESULT res;
    success OF res := FALSE;
    WHILE NOT success OF res DO
        generate( res );
        print( ( "attribs: " ) );
        FOR i FROM LWB a OF res TO UPB a OF res DO
            print( ( whole( ( a OF res )[ i ], 0 ) ) );
            IF i < UPB a OF res THEN
                print( ( " " ) )
            FI
        OD;
        print( ( " sum=", whole( sum OF res, 0 )
               , " highCount=", whole( high count OF res, 0 )
               , " ", IF success OF res THEN "success" ELSE "failed" FI
               , newline
               )
             )
    OD
 
END