public function testGettersAndSetters()
 {
     $palindrome = new Palindrome();
     $palindrome->setId(1);
     $palindrome->setString("test");
     $palindrome->setIsPalindrome(false);
     $this->assertEquals($palindrome->getId(), 1);
     $this->assertEquals($palindrome->getString(), "test");
     $this->assertEquals($palindrome->isPalindrome(), false);
 }
Example #2
0
 function test_palindrome_string()
 {
     $test = new Palindrome();
     $word = "Hello olleH";
     $result = $test->isPalindrome($word);
     $this->assertEquals(true, $result);
 }
Example #3
0
 function test_identify_punctuation()
 {
     //Arrange
     $test_Palindrome = new Palindrome();
     $word = 'A Santa at NASA!';
     //Act
     $result = $test_Palindrome->identify($word);
     //Assert
     $this->assertEquals(TRUE, $result);
 }
Example #4
0
 function test_complex_string_false()
 {
     $check_Palindrome = new Palindrome();
     $input = "#@\$ LKJSD sf3123";
     $result = $check_Palindrome->test_Palindrome($input);
     $this->assertEquals(false, $result);
 }
Example #5
0
<?php

function __autoload($class_name)
{
    include $class_name . '.php';
}
/**
 * Palindrome test cases
 */
echo "---------------PALINDROMOS-----------------------------<br>";
$cases = ["Ana", "se van sus naves", "Esto no es un palíndromo"];
foreach ($cases as $case) {
    if (Palindrome::isPalindrome($case)) {
        echo "<strong>" . $case . "</strong> Es un Palindromo<br>";
    } else {
        echo "<strong>" . $case . "</strong> No es un Palindromo<br>";
    }
}
/**
 * Find repeated number
 */
echo "<br>---------------FIND REPEATED NUMBER IN ARRAY-------------------<br>";
$array1 = [1, 4, 1, 3, 2, 5];
$array2 = [3, 1, 2, 2];
echo FindRepeated::find($array1) . '<br>';
echo FindRepeated::find($array2) . '<br>';
/**
 * Recipe
 */
echo "<br>---------------FIND THE RECIPE-------------------<br>";
$recipe1 = new Recipe(12);
Example #6
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Palindrome.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('palindrome.html.twig');
});
$app->get('id', function () use($app) {
    $my_Letters = new Palindrome();
    $letters = $my_Letters->identify($_GET['word']);
    return $app['twig']->render('id.html.twig', array('letters' => $letters));
});
return $app;
            $newNode = new Node($value);
            $this->queueTail->next = $newNode;
            $this->queueTail = $newNode;
        }
    }
    function dequeueCharacter()
    {
        $retValue = $this->queueHead->value;
        $this->queueHead = $this->queueHead->next;
        return $retValue;
    }
}
// read the string s
$s = fgets(STDIN);
// create the Palindrome class object p
$p = new Palindrome();
$len = strlen($s);
$f = true;
//push all the characters of string s to stack
for ($i = 0; $i < $len; $i++) {
    $p->pushCharacter($s[$i]);
}
//enqueue all the characters of string s to queue
for ($i = 0; $i < $len; $i++) {
    $p->enqueueCharacter($s[$i]);
}
/*
pop the top character from stack
dequeue the first character from queue
compare both the characters*/
for ($i = 0; $i < $len; $i++) {
Example #8
0
                return false;
            }
        }
        return true;
    }
    /**
     * Checks if a string has palindrome substring.
     * If it has, returns such substring with max length.
     * if no such a substring returns first letter of a string.
     * @param string $str
     * @return string
     */
    public static function getMaxPalindrome($str)
    {
        $l = mb_strlen($str);
        for ($i = $l; $i > 1; $i--) {
            for ($j = 1; $j <= $l - $i + 1; $j++) {
                if (self::isPalindrome(mb_substr($str, $j - 1, $i))) {
                    return mb_substr($str, $j - 1, $i);
                }
            }
        }
        return mb_substr($str, 0, 1);
    }
}
$str = 'gggПаліндром - і ні морд, ні лап';
if (Palindrome::isPalindrome($str)) {
    echo 'Палиндром:' . $str;
} else {
    echo 'Не палиндром <br>', Palindrome::getMaxPalindrome($str);
}
Example #9
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Palindrome.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('input.html.twig');
});
$app->get("/true_false", function () use($app) {
    $my_Palindrome = new Palindrome();
    $result = $my_Palindrome->test_Palindrome($_GET['input']);
    return $app['twig']->render('results.html.twig', array('result' => $result));
});
return $app;
Example #10
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Palindrome.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('home.html.twig');
});
$app->get("/view_translate", function () use($app) {
    $palindrome = new Palindrome();
    $answer = $palindrome->isPalindrome($_GET['phrase']);
    return $app['twig']->render('result.html.twig', array('result' => $answer));
});
return $app;
<?php

// euler36_array_reduce.php
$start = microtime(true);
require "Palindrome.class.php";
$decPalindromes = [];
foreach (Palindrome::createPalindromeSequence(1000000) as $x) {
    $decPalindromes[] = $x;
}
$sum = array_reduce($decPalindromes, function ($reduction, $current) {
    $asBinary = decbin($current);
    if (Palindrome::isPalindrome($asBinary)) {
        echo $current . " " . $asBinary . "<br>";
        $reduction += $current;
    }
    return $reduction;
}, 0);
echo $sum . "<hr>";
$end = microtime(true);
printf("Execution time: %dms", ($end - $start) * 1000);
Example #12
0
/*
A palindrome is a word, phrase, verse, or sentence that reads the same backward or forward. Only the order of English alphabet letters (A-Z and a-z) should be considered, other characters should be ignored. Write a function that returns true if a given sentence is a palindrome; false otherwise.

For example, Palindrome::isPalindrome(‘Noel sees Leon.’) should return true as spaces, period, and case should be ignored resulting with 'noelseesleon' which is a palindrome since it reads same backward and forward.
*/
class Palindrome
{
    public static function isPalindrome($str)
    {
        $str_array = str_split(trim($str));
        $cleaned = '';
        foreach ($str_array as $letter) {
            if (ctype_alpha($letter)) {
                $cleaned .= strtolower($letter);
            }
        }
        $size = strlen($cleaned);
        $half1 = substr($cleaned, 0, $size / 2);
        $half2 = substr($cleaned, $size / 2, $size);
        if ($half1 == strrev($half2)) {
            return true;
        } else {
            return false;
        }
        return false;
    }
}
// For testing purposes (do not submit uncommented):
echo Palindrome::isPalindrome('Noel sees Leon');