Skip to content

Commit 67a5cf0

Browse files
stormoficeleios
andauthored
IFS: Standardize output files (#961)
* Output 10000 points instead of 1000 in C implementation * Change output file from "out.dat" to "sierpinski.dat" in lisp * Change output file from "out.dat" to "sierpinski.dat" in Haskell * Introduce constant for the amount of points to generate Co-authored-by: James Schloss <jrs.schloss@gmail.com>
1 parent d51c940 commit 67a5cf0

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

contents/IFS/code/c/IFS.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,22 @@ void chaos_game(struct point *in, size_t in_n, struct point *out,
2929
}
3030

3131
int main() {
32+
const int point_count = 10000;
33+
3234
struct point shape_points [3] = {{0.0,0.0}, {0.5,sqrt(0.75)}, {1.0,0.0}};
33-
struct point out_points[1000];
35+
struct point out_points[point_count];
3436

3537
srand(time(NULL));
3638

37-
chaos_game(shape_points, 3, out_points, 1000);
39+
chaos_game(shape_points, 3, out_points, point_count);
3840

3941
FILE *fp = fopen("sierpinksi.dat", "w+");
4042

41-
for (int i = 0; i < 1000; ++i) {
43+
for (int i = 0; i < point_count; ++i) {
4244
fprintf(fp, "%f\t%f\n", out_points[i].x, out_points[i].y);
4345
}
4446

4547
fclose(fp);
4648

4749
return 0;
4850
}
49-

contents/IFS/code/clisp/ifs.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
`((0 0) (0.5 ,(sqrt 0.75)) (1 0))))
2222

2323
;; output the data to the "out.dat" file
24-
(with-open-file (out "out.dat" :direction :output :if-exists :supersede)
24+
(with-open-file (out "sierpinski.dat" :direction :output :if-exists :supersede)
2525
(flet ((format-point (p)
2626
;; this is not very clean, but it's the simplest way to insert a tab into a string.
2727
(format nil "~f~c~f" (point-x p) #\tab (point-y p))))

contents/IFS/code/haskell/IFS.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ main = do
2727
points = chaosGame g 10000 sierpinski
2828
showPoint (Point x y) = show x ++ "\t" ++ show y
2929

30-
writeFile "out.dat" $ intercalate "\n" $ map showPoint points
30+
writeFile "sierpinski.dat" $ intercalate "\n" $ map showPoint points

0 commit comments

Comments
 (0)