1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<?php
/*Bla Quiz - A Quiz program..*/
//Orginal Author: Phil Burton <philbeansburton@gmail.com>
// Version History
// 0.0.1 Created blaquiz.php
// 0.0.2 Added for questions and answers
$version = "BlaQuiz Version: 0.0.2";
$questions = array (
"How many bits in a byte?",
"What does TTP mean?",
"What does RAM stand for?",
"What does ROM stand for?",
"What does CPU stand for?",
"What does GPU stand for?",
"Checking a computer program for errors is called what?",
"The term BASIC is an acronym for what?",
"Grace thought of a number, added 7, multiplied by 3, took away 5 and divided by 4 to give an answer of 7. What was her starting number?",
"John starts with a number. He squares it, then takes away 5, next multiplies it by 4, takes away 7, divides it by 3 and finally adds 6. His answer is 9.What number did he start with? ",
"If ADD = 9, BAD = 7, and CAD = 8 what is the value of ADA?",
"If DATA = 52, CACHE = 40 and BIT = 62. What is the value of BABBAGE?",
"Who coined the term Web 2.0?",
"The Internet began with the development of?"
);
$answers = array (
"8",
"Time To Poo",
"Random Access Memory",
"Read Only Memory",
"Central Processing Unit",
"Graphical Processing Unit",
"Debugging",
"Beginner's All-purpose Symbolic Instruction Code",
"4",
"3",
"6",
"40",
"Dale Dougherty",
"ARPANET"
);
// get the input
$stdin = read_stdin();
$stdin = explode(" ", $stdin);
$out = "";
$token = "";
if(isset($stdin[0]))
{
switch ($stdin[0])
{
case "-q":
$id = rand(0,sizeof($questions) - 1);
$out = "ID: $id $questions[$id]";
break;
case "-a":
if(isset($stdin[1]) && isset($stdin[2]))
{
//Check question ID
$id = $stdin[1];
if($id < sizeof($questions))
{
//get answer
$answer = "";
for($i=2; $i<sizeof($stdin); $i++)
{
$answer .= $stdin[$i] . " ";
}
$answer = strtolower(substr($answer, 0 , -1));
if(strtolower($answers[$id]) == $answer)
{
$out = "Correct! $answer is the right answer!";
}
else
{
$out = "Nope, $answer is the wrong answer!";
}
}
else
{
$out = "Please give your answers like this: -a <answer>";
}
}
else
{
$out = "This question doesn't exist";
}
break;
default:
$out = "Please either ask for a new question: -q. Or guess at an answer -a <qid> <answer>.";
break;
}
}
else
{
$out = "Please either aska new question: -q or guess at an answer: -a <qid> <answer>.";
}
echo $out . "\n";
function read_stdin()
{
$fr=fopen("php://stdin","r"); // open our file pointer to read from stdin
$input = fgets($fr,128); // read a maximum of 128 characters
$input = rtrim($input); // trim any trailing spaces.
fclose ($fr); // close the file handle
return $input; // return the text entered
}
?>
|