March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
22
Task/Floyds-triangle/AutoHotkey/floyds-triangle-1.ahk
Normal file
22
Task/Floyds-triangle/AutoHotkey/floyds-triangle-1.ahk
Normal 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
|
||||
}
|
||||
1
Task/Floyds-triangle/AutoHotkey/floyds-triangle-2.ahk
Normal file
1
Task/Floyds-triangle/AutoHotkey/floyds-triangle-2.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
MsgBox % Floyds_triangle(14)
|
||||
3
Task/Floyds-triangle/PARI-GP/floyds-triangle.pari
Normal file
3
Task/Floyds-triangle/PARI-GP/floyds-triangle.pari
Normal 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)
|
||||
|
|
@ -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";
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
20
Task/Floyds-triangle/TXR/floyds-triangle.txr
Normal file
20
Task/Floyds-triangle/TXR/floyds-triangle.txr
Normal 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"))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue