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
| error_reporting(E_ALL);
set_time_limit(0);
/****
* $pos is an array which contains numerical values that correspond to the keys of the values in $characters
* each key in $pos serves as a slot that contains these values.
* so, the value in each slot represents a key in $characters
*/
// this funtion increases the values in each of the 'slots' in $pos
function increase(&$pos, $length, $characters)
{
if ($length > 0)
{
// $length will trigger the right 'slot'.
if ($pos[$length] < (count($characters)-1))
$pos[$length]++;
// if the value in that 'slot' is greater then the key-value in characters,
// we need to move on to the next slot
else
{
increase(&$pos, ($length-1), $characters);
$pos[$length] = 0;
}
return True;
}
// if $length is 0 we've reached the last posibility (actually we've passed it)
else
die("mooi weest");
}
// function that checks if a combination of 3 of the same succesive characters occur in the string
// if so, we return False, indicating this string should not be saved
function check_string($pos, $characters)
{
$threshold = 1;
foreach ($pos AS $value)
{
// we increase the threshold if the last inserted string (in a 'slot') is the same as the current one
// this is case INsensitive
if (isset($old_value) && strtolower($old_value) == strtolower($value))
$threshold++;
else
$threshold=1;
if ($threshold == 3)
{
return False;
break;
}
$old_value = $value;
}
return True;
}
$characters = array(
"0","1","2","3","4","5","6","7","8","9",
"a","b","c","d","e","f","g","h","i","j","k","l","m",
"n","o","p","q","r","s","t","u","v","w","x","y","z",
"A","B","C","D","E","F","G","H","I","J","K","L","M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
/* $characters = array(
"0","1","2","3","4","5","6","7","8","9",
"a","b","c","d","e","f","g","h","i","j","k","l","m",
"n","o","p","q","r","s","t","u","v","w","x","y","z"); */
$length = 4; // the length of the strings that are saved
for ($x = 1; $x <= $length; $x++)
{
$pos[$characters[$x]] = 0;
}
$martijn = "goed_bezig";
$handle = fopen("blob4.txt", "w+");
while ($martijn == "goed_bezig")
{
$string = "";
for ($x = 1; $x <= $length; $x++)
{
$string .= $characters[$pos[$x]];
}
if (check_string($pos, $characters))
fputs($handle, $string."\n");
increase($pos, $length, $characters);
}
fclose($handle); |