Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,30 @@
PROGRAM SIERP_CARPET
! for rosettacode.org
!$INTEGER
BEGIN
OPEN("O",1,"OUT.PRN")
PRINT(CHR$(12);) !CLS
DEPTH=3
DIMM=1
FOR I=0 TO DEPTH-1 DO
DIMM=DIMM*3
END FOR
FOR I=0 TO DIMM-1 DO
FOR J=0 TO DIMM-1 DO
D=DIMM DIV 3
REPEAT
EXIT IF ((I MOD (D*3)) DIV D=1 AND (J MOD (D*3)) DIV D=1)
D=D DIV 3
UNTIL NOT(D>0)
IF D>0 THEN PRINT(#1," ";) ELSE PRINT(#1,"##";) END IF
END FOR
PRINT(#1,)
END FOR
! PRINT(#1,CHR$(12);) for printer only!
CLOSE(1)
END PROGRAM

View file

@ -0,0 +1,32 @@
proc `^`*(base: int, exp: int): int =
var (base, exp) = (base, exp)
result = 1
while exp != 0:
if (exp and 1) != 0:
result *= base
exp = exp shr 1
base *= base
proc inCarpet(x, y): bool =
var x = x
var y = y
while true:
if x == 0 or y == 0:
return true
if x mod 3 == 1 and y mod 3 == 1:
return false
x = x div 3
y = y div 3
proc carpet(n) =
for i in 0 .. <(3^n):
for j in 0 .. <(3^n):
if inCarpet(i, j):
stdout.write "* "
else:
stdout.write " "
echo ""
carpet(3)

View file

@ -0,0 +1,15 @@
: carpet(n)
| dim i j k |
3 n pow ->dim
0 dim 1 - for: i [
0 dim 1 - for: j [
dim 3 / ->k
while(k) [
i k 3 * mod k / 1 == j k 3 * mod k / 1 == and ifTrue: [ break ]
k 3 / ->k
]
k ifTrue: [ " " ] else: [ "#" ] print
]
printcr
] ;

View file

@ -0,0 +1,19 @@
constant order = 4
function InCarpet(atom x, atom y)
while x!=0 and y!=0 do
if floor(mod(x,3))=1 and floor(mod(y,3))=1 then
return ' '
end if
x /= 3
y /= 3
end while
return '#'
end function
for i=0 to power(3,order)-1 do
for j=0 to power(3,order)-1 do
puts(1,InCarpet(i,j))
end for
puts(1,'\n')
end for

View file

@ -0,0 +1,56 @@
load "guilib.ring"
new qapp
{
win1 = new qwidget() {
etwindowtitle("drawing using qpainter")
setgeometry(100,100,500,500)
label1 = new qlabel(win1) {
setgeometry(10,10,400,400)
settext("")
}
new qpushbutton(win1) {
setgeometry(200,450,100,30)
settext("draw")
setclickevent("draw()")
}
show()
}
exec()
}
func draw
p1 = new qpicture()
color = new qcolor() {
setrgb(0,0,255,255)
}
pen = new qpen() {
setcolor(color)
setwidth(1)
}
new qpainter() {
begin(p1)
setpen(pen)
order = 3
side = pow(3,order)
for y = 0 to side-1
for x = 0 to side-1
if carpet(self,x,y)
drawpoint(x*16,y*16+15)
drawpoint(x*16+1,y*16+16)
drawpoint(x*16+2,y*16+17) ok
next
next
endpaint()
}
label1 { setpicture(p1) show() }
func carpet myObj,x,y
myObj{while x!=0 and y!=0
if x % 3 = 1 if y % 3 = 1 return false ok ok
x = floor(x/3)
y = floor(y/3)
end
return true}

View file

@ -0,0 +1,7 @@
var c = ['##']
3.times {
c = (c.map{|x| x * 3 } +
c.map{|x| x + ' '*x.len + x } +
c.map{|x| x * 3 })
}
say c.join("\n")

View file

@ -0,0 +1,17 @@
import Foundation
func sierpinski_carpet(n:Int) -> String {
func middle(str:String) -> String {
let spacer = str.stringByReplacingOccurrencesOfString("#", withString:" ", options:nil, range:nil)
return str + spacer + str
}
var carpet = ["#"]
for i in 1...n {
let a = carpet.map{$0 + $0 + $0}
let b = carpet.map(middle)
carpet = a + b + a
}
return "\n".join(carpet)
}
println(sierpinski_carpet(3))

View file

@ -0,0 +1,18 @@
def inCarpet(x; y):
x as $x | y as $y |
if $x == -1 or $y == -1 then "\n"
elif $x == 0 or $y == 0 then "*"
elif ($x % 3) == 1 and ($y % 3) == 1 then " "
else inCarpet($x/3 | floor; $y/3 | floor)
end;
def ipow(n):
. as $in | reduce range(0;n) as $i (1; . * $in);
def carpet(n):
(3|ipow(n)) as $power
| [ inCarpet( range(0; $power) ; range(0; $power), -1 )]
| join("") ;
carpet(3)

View file

@ -0,0 +1 @@
jq -n -r -c -f sierpinski.jq