-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagnet_particules.pas
More file actions
85 lines (80 loc) · 2.77 KB
/
magnet_particules.pas
File metadata and controls
85 lines (80 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
4 kyu
Magnet particules in boxes
https://www.codewars.com/kata/56c04261c3fcf33f2d000534
}
program magnet_particules;
{$mode objfpc}{$H+}
uses
magnet_particules_unit;
procedure DoTest(maxk, maxn: int64; Expected: double);
var
Actual: double;
begin
Actual := Doubles(maxk, maxn);
writeln('k max : ', maxk);
writeln('n max : ', maxn);
writeln('Expected: ', Expected: 18: 16);
writeln('Actual : ', Actual: 18: 16);
if Abs(Expected - Actual) <= 1e-12 then
writeln('-> OK', LineEnding)
else
writeln('-> FAIL', LineEnding);
end;
begin
DoTest(1, 1, 0.25);
DoTest(1, 2, 0.3611111111111111);
DoTest(1, 3, 0.4236111111111111);
DoTest(10, 100, 0.6832948559787737);
DoTest(1, 10, 0.5580321939764581);
DoTest(10, 1000, 0.6921486500921933);
DoTest(10, 10000, 0.6930471674194457);
DoTest(20, 10000, 0.6930471955575918);
DoTest(30, 10000, 0.693047195557606);
DoTest(90, 10000, 0.6930471955576123);
DoTest(100, 10000, 0.6930471955576123);
DoTest(10, 100, 0.6832948559787734);
DoTest(25, 12000, 0.6930638576419285);
DoTest(40, 15000, 0.6930805205592540);
DoTest(200, 15000, 0.6930805205592540);
DoTest(400, 20000, 0.6930971843096537);
DoTest(500, 25000, 0.6931071829597960);
DoTest(185, 15265, 0.6930816776614186);
DoTest(294, 11201, 0.6930579147709996);
DoTest(155, 8381, 0.6930278844071047);
DoTest(239, 1499, 0.6924807360167848);
DoTest(123, 22071, 0.6931018753158555);
DoTest(206, 6530, 0.6929940763722467);
DoTest(106, 12124, 0.6930647097339532);
DoTest(248, 17021, 0.6930884347822812);
DoTest(275, 1727, 0.6925686442406557);
DoTest(195, 18314, 0.6930925819958740);
DoTest(173, 837, 0.6919545745748222);
DoTest(289, 22802, 0.6931033276426229);
DoTest(205, 22876, 0.6931034694901099);
DoTest(238, 10640, 0.6930532088453622);
DoTest(287, 6322, 0.6929890402891959);
DoTest(272, 17864, 0.6930912067556711);
DoTest(247, 8940, 0.6930353425013374);
DoTest(151, 8370, 0.6930277276541113);
DoTest(164, 12729, 0.6930686290497521);
DoTest(170, 2123, 0.6926764815632576);
DoTest(289, 11908, 0.6930632139785953);
DoTest(126, 4420, 0.6929210129687969);
DoTest(291, 15593, 0.6930830553875869);
DoTest(196, 1487, 0.6924753632689735);
DoTest(203, 5703, 0.6929718803579012);
DoTest(190, 23167, 0.6931040185080147);
DoTest(294, 1268, 0.6923594688216960);
DoTest(287, 11702, 0.6930617360347513);
DoTest(109, 12441, 0.6930668108592792);
DoTest(208, 11384, 0.6930593495467581);
DoTest(220, 13691, 0.6930741478777876);
DoTest(214, 7153, 0.6930074083883571);
DoTest(212, 23168, 0.6931040203708970);
DoTest(113, 16155, 0.6930852859664183);
DoTest(182, 20056, 0.6930973238978385);
DoTest(272, 1644, 0.6925394625224025);
DoTest(102, 9492, 0.6930418453304804);
DoTest(191, 10102, 0.6930482049573505);
end.