Skip to content

Instantly share code, notes, and snippets.

View HoangPV's full-sized avatar

Hoang Phan HoangPV

  • Ho Chi Minh City, Vietnam
View GitHub Profile
@HoangPV
HoangPV / reverse_letters_in_sentence.php
Created July 25, 2017 14:59
Take a string, then for every words we reverse the order of character.
<?php
echo strRevCha("Take a string, then for every words we reverse the order of character.");
/**
* Take a string, then for every words we reverse the order of character.
*
* @param String $str a string
* @return String|null $strOutput
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
@HoangPV
HoangPV / backward_read_primes.php
Created July 27, 2017 23:40
return backward read primes
<?php
/**
* return backward read primes
*
* Find all Backwards Read Primes between two positive given numbers
* (both inclusive), the second one being greater than the first one.
* The resulting array or the resulting string will be ordered
* following the natural order of the prime numbers.
*
@HoangPV
HoangPV / Factory.php
Created July 28, 2017 03:09
have the factory create the Automobile object
<?php
class Automobile
{
private $vehicleMake;
private $vehicleModel;
public function __construct($make, $model)
{
$this->vehicleMake = $make;
<?php
/**
* You'll have to translate a string to Pilot's alphabet (NATO phonetic alphabet) wiki.
*
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
*/
function to_nato($words) {
$lib['a']="Alpha";
@HoangPV
HoangPV / contain_all_rots.php
Last active July 30, 2017 17:25
return a boolean true if all rotations of strng are included in arr (C returns 1
<?php
/**
* return a boolean true if all rotations of strng are included in arr (C returns 1)
*
* @param string $s
* @param array $arr
* @return boolean
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
*/
@HoangPV
HoangPV / non-descending-order.php
Last active July 30, 2017 21:39
check whether an array can be turn to non-descending order by a single swap 2 elements
<?php
/**
* check whether an array can be turn to non-descending order by a single swap 2 elements
*
* @param array $a
* @return bool
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
*/
function solution($a)
@HoangPV
HoangPV / max-words-of-sentences.php
Created July 30, 2017 21:50
return the max words of sentences, which is from a text
<?php
/**
* return the max words of sentences, which is from a text
*
* @param $s
* @return mixed
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
*/
function solution($s)
@HoangPV
HoangPV / str_putcsv.php
Created September 13, 2017 08:41
Convert a multi-dimensional, associative array to CSV data
<?php
/**
* Convert a multi-dimensional, associative array to CSV data
* @param array $data the array of data
* @return string CSV text
*/
function str_putcsv($data) {
# Generate CSV data from array
$fh = fopen('php://temp', 'rw'); # don't create a file, attempt
# to use memory instead
@HoangPV
HoangPV / replace-w-alphabet-position.php
Created September 18, 2017 03:18
Replace With Alphabet Position
<?php
/**
* Replace With Alphabet Position
*
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
*/
function alphabet_position(string $str) {
$ar_pos = [];
@HoangPV
HoangPV / alphabet_position.php
Created September 18, 2017 06:25
Replace With Alphabet Position (alt solution)
<?php
function alphabet_position( $str ) {
$str = strtolower( $str );
$alphabetChars = 'abcdefghijklmnoqrstuvwxyz';
$report=[];
foreach (str_split($str) as $char) {
$g = (strpos($alphabetChars, $char) !== false) ? strpos($alphabetChars, $char) : '';
if ($g!=='') {