Difference between revisions of "User:Woozle/trickyq.php"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(v1 - up to 99)
 
(latest (I hope) version)
 
Line 7: Line 7:
 
   HISTORY:
 
   HISTORY:
 
     2012-07-04 (Wzl) Started
 
     2012-07-04 (Wzl) Started
     2013-10-22 (Wzl) More or less working -- up to 99
+
     2013-10-22 (Wzl) More or less working -- 100-999
*/
+
    2014-01-01 (Wzl) method to return question and answer in a single array
 +
    */
 
$karSingles = array('one','two','three','four','five','six','seven','eight','nine',
 
$karSingles = array('one','two','three','four','five','six','seven','eight','nine',
 
   'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');
 
   'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');
Line 61: Line 62:
 
return $out;
 
return $out;
 
     }
 
     }
 +
    static public function Generate2() {
 +
$nA = rand(100,999); // generate correct answer (number)
 +
$sQ = self::SpellNumber($nA); // calculate question (string)
 +
$ar = array(
 +
'Q' => $sQ,
 +
'A' => $nA
 +
);
 +
return $ar;
 +
    }
 +
 
}
 
}
 
</php>
 
</php>

Latest revision as of 00:53, 21 March 2014

Code

<php> <?php /*

 FILE: trickyq.php -- Tricky Questions to stop bots
   Intended to work with the "QuestyCaptcha" mode of the ConfirmEdit extension
 HISTORY:
   2012-07-04 (Wzl) Started
   2013-10-22 (Wzl) More or less working -- 100-999
   2014-01-01 (Wzl) method to return question and answer in a single array
   */

$karSingles = array('one','two','three','four','five','six','seven','eight','nine',

 'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');

$karTens = array('twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety');

class BotTricks {

   static public $intNum;
   /*----
     INPUT: An integer between 1 and 99 inclusive
     RETURNS: That number, spelled out
     ASSUMES: iNum is an integer between 1 and 99 inclusive (no validity-checking)
   */
   static public function SpellNumber_99($iNum) {

global $karSingles,$karTens;

self::$intNum = $iNum; if ($iNum < 20) { if ($iNum == 0) { $out = 'zero'; } else { $out = $karSingles[$iNum-1]; } } else { $dec = (int)$iNum/10; $out = $karTens[$dec-2]; $digit = $iNum % 10; // mod 10 = last digit if ($digit > 0) { $out .= '-'.$karSingles[$digit-1]; } } return $out;

   }
   static public function SpellNumber($iNum) {

$n100 = floor($iNum/100); $n99 = $iNum-($n100*100); $s99 = self::SpellNumber_99($n99);

$sOut = ; if ($n100 > 0) { $s100 = self::SpellNumber_99($n100); $sOut .= $s100.' hundred and '; } $sOut .= $s99; return $sOut;

   }
   static public function Generate() {

$int = rand(100,999); $out = self::SpellNumber($int); return $out;

   }
   static public function Generate2() {

$nA = rand(100,999); // generate correct answer (number) $sQ = self::SpellNumber($nA); // calculate question (string) $ar = array( 'Q' => $sQ, 'A' => $nA ); return $ar;

   }

} </php>