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,16 @@
(lib 'math)
(lib 'plot)
(define (points (n 100) (radius 10) (rmin 10) (rmax 15) (x) (y))
(plot-clear)
(plot-x-minmax (- rmax))
(plot-y-minmax( - rmax))
(for [(i n)]
(set! x (round (* (random -1) rmax)))
(set! y (round (* (random -1) rmax)))
#:when (in-interval? (pythagore x y) rmin rmax)
;; add a little bit of randomness : dots color and radius
(plot-fill-color (hsv->rgb (random) 0.9 0.9))
(plot-circle x y (random radius)))
(plot-edit))

View file

@ -0,0 +1,13 @@
(import
[math [sqrt]]
[random [choice]]
[matplotlib.pyplot :as plt])
(setv possible-points (list-comp (, x y)
[x (range -15 16) y (range -15 16)]
(<= 10 (sqrt (+ (** x 2) (** y 2))) 15)))
(setv [xs ys] (apply zip (list-comp (choice possible-points) [_ (range 100)])))
; We can't use random.sample because that samples without replacement.
(plt.plot xs ys "bo")
(plt.show)

View file

@ -0,0 +1,25 @@
import tables, math, strutils, complex
randomize()
proc random[T](a: openarray[T]): T =
result = a[random(low(a)..len(a))]
type Point = tuple[x, y: int]
var world = initCountTable[Point]()
var possiblePoints = newSeq[Point]()
for x in -15..15:
for y in -15..15:
if abs((x.float, y.float)) in 10.0..15.0:
possiblePoints.add((x,y))
for i in 0..100: world.inc possiblePoints.random
for x in -15..15:
for y in -15..15:
if world[(x,y)] > 0:
stdout.write min(9, world[(x,y)])
else:
stdout.write ' '
echo ""

View file

@ -0,0 +1,14 @@
sequence screen = repeat(repeat(' ',31),31)
integer x, y, count = 0
atom r
while 1 do
x = rand(31)
y = rand(31)
r = sqrt(power(x-16,2)+power(y-16,2))
if r>=10 and r<=15 then
screen[x][y] = 'x'
count += 1
if count>=100 then exit end if
end if
end while
puts(1,join(screen,"\n"))

View file

@ -0,0 +1,44 @@
load "guilib.ring"
new qapp
{
win1 = new qwidget() {
setwindowtitle("drawing using qpainter")
setgeometry(100,100,500,500)
label1 = new qlabel(win1) {
setgeometry(10,10,400,400)
settext("")
}
new qpushbutton(win1) {
setgeometry(200,400,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)
for i = 1 to 1000
x = random(31)-16
y = random(31)-16
r = sqrt (pow(x,2) + pow(y,2))
if r >= 10 if r <= 15 drawpoint(x*2, y*2) ok ok
next
endpaint()
}
label1 { setpicture(p1) show() }

View file

@ -0,0 +1,23 @@
var points = [];
while (points.len < 100) {
var (x, y) = 2.of{31.rand.int - 15}...;
var r2 = (x**2 + y**2);
if ((r2 >= 100) && (r2 <= 225)) {
points.append([x, y]);
}
}
print <<'HEAD';
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox 0 0 400 400
200 200 translate 10 10 scale
0 setlinewidth
1 0 0 setrgbcolor
0 0 10 0 360 arc stroke
0 0 15 360 0 arcn stroke
0 setgray
/pt { .1 0 360 arc fill } def
HEAD
points.each { |pt| say "#{pt.join(' ')} pt" };
print '%%EOF';