All pastes #49579 Raw Edit

Mine

public text v1 · immutable
#49579 ·published 2006-04-17 08:01 UTC
rendered paste body
;ROOMMATES IN A HAT
;SPEC:  Every roommate gets a respective weight, based on which two are chosen (not the same two)
;       to clean the house.
;       Using a "pseudo-array" of strings bsaed on $ROOMMATE[1-6], we'll prompt the
;       caller for a weight [1-9], and make a corresponding array of integers (called $MATEWEIGT[1-6]).
;       Finally, bsaed on roommates weight, roommates are given a relative probability of drawing the
;       cleaning straw.

[riah]
;who are the roommates?
exten => s,1,set(__ROOMMATE[1]=Brad)
exten => s,2,set(__ROOMMATE[2]=Brian)
exten => s,3,set(__ROOMMATE[3]=James)
exten => s,4,set(__ROOMMATE[4]=Jeff)
exten => s,5,set(__ROOMMATE[5]=Marc)
exten => s,6,set(__ROOMMATE[6]=Aubrey)

;for each roommate prompt for a weight
exten => s,7,set(__COUNT=1)                             ;set roommate counter
exten => s,8,while($[${COUNT}<7])                       ;while we havent assigned a weight to all the roommates...
exten => s,9,background(beep)                           ;prompt with a tone...
exten => s,10,waitexten(5)                              ;and givem five seconds to enter an extension 0-9
exten => s,11,set(__COUNT=$[${COUNT}+1])                ;then increment the counter
exten => s,12,endwhile

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;take the weight and build the array;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => _X,1,set(__MATEWEIGHT[${COUNT}]= ${EXTEN})     ;give each roommate a relative weight using the counter
        exten => _X,n,goto(s,11)                                ;then repeat
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;after weights are assigned, pick roommates until we have two winners
exten => s,13,set(__WINNERS=0)                          ;at first we have no winners
exten => s,14,noop("winners ="${WINNERS})                               ;and we'll use a new counter
exten => s,15,while($[${WINNERS} < 2])                        ;while we dont have two winners...
        exten => s,17,goto(Brad,1)              ;go to an extension based on roommate name below
        exten => s,18,goto(Brian,2)             ;go to an extension based on roommate name below
        exten => s,19,goto(James,3)             ;go to an extension based on roommate name below
        exten => s,20,goto(Jeff,4)              ;go to an extension based on roommate name below
        exten => s,21,goto(Marc,5)              ;go to an extension based on roommate name below
        exten => s,22,goto(Aubrey,6)            ;go to an extension based on roommate name below
        exten => s,23,noop(weve looked at all the roomates)     ;should i just reset the old counter?  who cares.
exten => s,24,endwhile


        ;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => Brad,1,noop(we made it here)                           ;jump to three if we have a winner
        exten => Brad,2,random(${MATEWEIGHT[1]},Brad,3)                         ;jump to three if we have a winner
        exten => Brad,3,goto(s,18)                                                              ;or else draw again. 
        exten => Brad,4,gotoif(${ROOMMATE[1]}!=${CLEANER[1]}]?4|6)                              ;did we just pick him?
        exten => Brad,5,set(__WINNERS = $[${WINNERS} + 1])                                      ;if not we have a winner
        exten => Brad,6,set(__CLEANER[${WINNERS}]=${ROOMMATE[1])                        ;and we set the CLEANER variable
        exten => Brad,7,noop("we made it here).                                         ;and draw again
        exten => Brad,8,goto(s,18)                                              ;and draw again
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => Brian,1,random(${MATEWEIGHT[2]},Brian,3)                               ;jump to three if we have a winner
        exten => Brian,2,goto(s,19)                                                             ;or else draw again. 
        exten => Brian,3,gotoif(${ROOMMATE[2]}!=${CLEANER[1]}]?4|6)                             ;did we just pick him?
        exten => Brian,4,set(__WINNERS = $[${WINNERS} + 1])                                     ;if not we have a winner
        exten => Brian,5,set(__CLEANER[${WINNERS}]=${ROOMMATE[2])                       ;and we set the CLEANER variable
        exten => Brian,6,goto(s,19)                                             ;and draw again
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => James,1,random(${MATEWEIGHT[3]},James,3)                               ;jump to three if we have a winner
        exten => James,2,goto(s,20)                                                             ;or else draw again. 
        exten => James,3,gotoif(${ROOMMATE[3]}!=${CLEANER[1]}]?4|6)                             ;did we just pick him?
        exten => James,4,set(__WINNERS = $[${WINNERS} + 1])                                     ;if not we have a winner
        exten => James,5,set(__CLEANER[${WINNERS}]=${ROOMMATE[3])                       ;and we set the CLEANER variable
        exten => James,6,goto(s,20)                                             ;and draw again
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => Jeff,1,random(${MATEWEIGHT[4]},Jeff,3)                         ;jump to three if we have a winner
        exten => Jeff,2,goto(s,21)                                                              ;or else draw again.
        exten => Jeff,3,gotoif(${ROOMMATE[4]}!=${CLEANER[1]}]?4|6)                              ;did we just pick him?
        exten => Jeff,4,set(__WINNERS = $[${WINNERS} + 1])                                      ;if not we have a winner
        exten => Jeff,5,set(__CLEANER[${WINNERS}]=${ROOMMATE[4])                        ;and we set the CLEANER variable
        exten => Jeff,6,goto(s,21)                                              ;and draw again
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => Marc,1,random(${MATEWEIGHT[5],Marc,3)                          ;jump to three if we have a winner
        exten => Marc,2,goto(s,22)                                                              ;or else draw again.
        exten => Marc,3,gotoif(${ROOMMATE[5]}!=${CLEANER[1]}]?4|6)                              ;did we just pick him?
        exten => Marc,4,set(__WINNERS = $[${WINNERS} + 1])                                      ;if not we have a winner
        exten => Marc,5,set(__CLEANER[${WINNERS}]=${ROOMMATE[5])                        ;and we set the CLEANER variable
        exten => Marc,6,goto(s,22)                                              ;and draw again
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => Aubrey,1,random(${MATEWEIGHT[1]},Brad,3)                               ;jump to three if we have a winner
        exten => Aubrey,2,goto(s,23)                                                            ;or else draw again.
        exten => Aubrey,3,gotoif(${ROOMMATE[6]}!=${CLEANER[1]}]?4|6)                            ;did we just pick him?
        exten => Aubrey,4,set(__WINNERS = $[${WINNERS} + 1])                                    ;if not we have a winner
        exten => Aubrey,5,set(__CLEANER[${WINNERS}]=${ROOMMATE[6])                      ;and we set the CLEANER variable
        exten => Aubrey,6,goto(s,23)                                            ;and draw again
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;spit out the winners at the end
exten => s,25,noop("${CLEANER[1]} and ${CLEANER[2]} are the winners."


:::::::C L I    O U T P U T;;;;;;;;;;;;;;;;;;;;;
    -- Executing WaitExten("SIP/Brian-b918", "5") in new stack
  == CDR updated on SIP/Brian-b918
    -- Executing Set("SIP/Brian-b918", "__MATEWEIGHT[6]= 9") in new stack
    -- Executing Goto("SIP/Brian-b918", "s|11") in new stack
    -- Goto (riah,s,11)
    -- Executing Set("SIP/Brian-b918", "__COUNT=7") in new stack
    -- Executing EndWhile("SIP/Brian-b918", "") in new stack
    -- Executing While("SIP/Brian-b918", "0") in new stack
    -- Executing Set("SIP/Brian-b918", "__WINNERS=0") in new stack
    -- Executing NoOp("SIP/Brian-b918", ""winners ="0") in new stack
    -- Executing While("SIP/Brian-b918", "1") in new stack
Apr 17 01:41:23 WARNING[31547]: pbx.c:2403 __ast_pbx_run: Timeout, but no rule 't' in context 'riah'
    -- Remote UNIX connection disconnected