[ create a new paste ] login | about

Link: http://codepad.org/sjzrVAAg    [ raw code | output | fork ]

PHP, pasted on Aug 25:
<?php

function abc($test, $depth) {
    $alpha = 'abcdefghijklmnopqrstuvwxyz';
    $matches = 0;
    $length = strlen($test);

    while ($length--) {
        $char = substr($test, $length, $depth);

        if (strlen($char) == $depth && 
            (strpos($alpha, $char) !== false || 
             strpos(strrev($alpha), $char) !== false)) {
            echo "match: $char\n";
            $matches++;
        }

        if ($matches == $depth) return true;
    }

    return false;
}

var_dump(abc('this is abc lmn xyz', 3));
var_dump(abc('youlookgreatbcdetoday', 3));
var_dump(abc('youlookgreatklmtoday', 3));
var_dump(abc('youlookgreattoday', 3));
var_dump(abc('cbanmllookgreattodayzyx', 3));
var_dump(abc('abcnmllookgreattodayzyx', 3));

?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
match: xyz
match: lmn
match: abc
bool(true)
match: cde
match: bcd
bool(false)
match: klm
bool(false)
bool(false)
match: zyx
match: nml
match: cba
bool(true)
match: zyx
match: nml
match: abc
bool(true)


Create a new paste based on this one


Comments: