[ create a new paste ] login | about

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

PHP, pasted on Aug 23:
<?php

$input='MINAOLENTUBLI 
TUBLIOLENMINA';

go($input);

function go($input){
	
	$i=explode("\n", $input);
	$b=$i[0];
	$d=$i[1];
	
	while(strlen($b)>0){
		
		$l=compute($b, $d);
		
		if($l===false)
			break;
					
		$arr[]=substr($b,0,$l);
		$b=substr($b, $l);
		$d=substr($d, 0, -$l);
		
	}
	
	echo count($arr)."\n";
	
	foreach($arr as $v){
		echo "$v\n";
	}
};


function compute($b, $d){
	for($i=strlen($b); $i>0 ;$i--){
		if (substr($b,0,$i)===substr($d,-$i)){
			return $i;
		}
	}
	
	return false;
}

?>


Output:
1
2
3
4
3
MINA
OLEN
TUBLI


Create a new paste based on this one


Comments: