Skip to content

Instantly share code, notes, and snippets.

@itsazzad
Created September 7, 2015 12:00
Show Gist options
  • Save itsazzad/28886371d5b1a61d5067 to your computer and use it in GitHub Desktop.
Save itsazzad/28886371d5b1a61d5067 to your computer and use it in GitHub Desktop.
Special multiplication
<?php
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
$handle = fopen ("php://stdin","r");
$t = fgets($handle);
$LIMIT=100000;
function specialX($number){
global $LIMIT;
for($i=$number;$i<$LIMIT;$i++){
if(($fours=strpos($i,'0'))===false){
$forfours=$i;
}else{
$forfours=substr($i, 0, $fours);
}
$fours=strlen($forfours);
if(count(array_diff(str_split($forfours), array_fill(0, $fours,'4')))==0){
$zeros=strlen($i)-$fours;
return 2*$fours+$zeros;
}
}
}
for($i=0; $i<$t; $i++)
{
$number = trim(fgets($handle));
print(specialX($number)."\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment