-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGenerator.cs
More file actions
96 lines (91 loc) · 4.5 KB
/
NumberGenerator.cs
File metadata and controls
96 lines (91 loc) · 4.5 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
86
87
88
89
90
91
92
93
94
95
96
// +--------------------------------------------------------------+
// | Created by: Sean R Chappell |
// | Created on: April 13th, 2023 |
// | For: CSC 4101 - Extra Credit |
// +--------------------------------------------------------------+
using System.Diagnostics;
// +--------------------------------------------------------------+
// | The 'NumberGenerator' class will generate large numbers by |
// | concatenating strings of digits and saves them to their own |
// | files. |
// | |
// | The 'GenerateNumber1' method generates the 1st number & saves|
// | it to the file called "number1.txt". It creates a new |
// | Stopwatch instance to measure the time taken to generate the |
// | number and then prints the elapsed time. |
// | |
// | The 'GenerateNumber2' method does the exact same thing as |
// | the 'GenerateNumber1 method, except creates a different file |
// | called "number2.txt". |
// | |
// | The 'GenerateNumber' method generates a number and saves it |
// | to a file with the given file name. It creates a new |
// | StreamWriter instance to write to the file with the given |
// | file name. The number is generated by concatenating strings |
// | of digits using nested for loops. This method of creating a |
// | number will make a number that's 3,220,383,898 bytes big. |
// +--------------------------------------------------------------+
public class NumberGenerator
{
public void GenerateNumber1()
{
Stopwatch sw = Stopwatch.StartNew();
GenerateNumber("number1.txt");
sw.Stop();
Console.WriteLine("\t\t*** NUMBER 1 GENERATED ***");
Console.WriteLine($"*** TIME ELAPSED FOR GENERATING NUMBER 1: {sw.Elapsed} ***\n");
}
public void GenerateNumber2()
{
Stopwatch sw = Stopwatch.StartNew();
GenerateNumber("number2.txt");
sw.Stop();
Console.WriteLine("\t\t*** NUMBER 2 GENERATED ***");
Console.WriteLine($"*** TIME ELAPSED FOR GENERATING NUMBER 2: {sw.Elapsed} ***\n");
}
private void GenerateNumber(string fileName)
{
using (StreamWriter sw = new StreamWriter(fileName))
{
for (int i = 0; i < 166; i++)
{
for (int j = 0; j < 111111; j++)
{
sw.Write("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888");
}
for (int j = 0; j < 11111; j++)
{
sw.Write("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999");
}
}
}
}
}