March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,22 @@
Floyds_triangle(row){
i = 0
loop %row%
{
n := A_Index
loop, %n%
{
m := n, j := i, i++
while (m<row)
j += m , m++
res .= spaces(StrLen(j+1)-StrLen(i) +(A_Index=1?0:1)) i
}
if (A_Index < row)
res .= "`r`n"
}
return res
}
Spaces(no){
loop, % no
res.=" "
return % res
}

View file

@ -0,0 +1 @@
MsgBox % Floyds_triangle(14)

View file

@ -0,0 +1,3 @@
F(n)=my(fmt=Str("%"1+#Str(n*(n+1)/2)"d"),t);for(i=1,n,for(j=1,i,printf(fmt,t++));print)
F(5)
F(14)

View file

@ -4,13 +4,14 @@ floyds_triangle(14);
function floyds_triangle($n) {
echo "n = " . $n . "\r\n";
$count = 1;
for ($i = $n; $i > 0; $i--) {
for ($j = $i; $j < $n + 1; $j++) {
printf("%4s", $count);
$count++;
for($r = 1, $i = 1, $c = 0; $r <= $n; $i++) {
$cols = ceil(log10($n*($n-1)/2 + $c + 2));
printf("%".$cols."d ", $i);
if(++$c == $r) {
echo "\r\n";
$r++;
$c = 0;
}
echo "\r\n";
}
?>

View file

@ -0,0 +1,20 @@
@(do
(defun flotri (n)
(let* ((last (trunc (* n (+ n 1)) 2))
(colw (mapcar [chain tostring length]
(range (- last n -1) last)))
(x 0))
(each ((r (range* 0 n)))
(each ((c (range 0 r)))
(format t " ~*a" [colw c] (inc x)))
(put-line))))
(defun usage (msg)
(put-line `error: @msg`)
(put-line `usage:\n@(ldiff *full-args* *args*) <smallish-positive-integer>`)
(exit 1))
(tree-case *args*
((num blah . etc) (usage "too many arguments"))
((num) (flotri (int-str num)))
(() (usage "need an argument"))))