Comment detail

与えられた文字列でピラミッド (Nested Flatten)

This comment is reply for 2626 hirataka: (与えられた文字列でピラミッド). Go to thread root.

ちょっと修正。
trim取ったり、substrの引数取ったり。
1
2
3
4
5
6
7
8
<?php
function pyramid($str){
	for($i=$n=strlen($str); $i>=0; $i--, $n=strlen($str)*2-$i+1)
		printf("% {$n}s\n", join(" ", preg_split("//", substr($str, $i))));
}

pyramid("abracadabra");
?>

Index

Feed

Other

Link

Pathtraq

loading...