-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
414 lines (372 loc) · 12.2 KB
/
Program.cs
File metadata and controls
414 lines (372 loc) · 12.2 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
using System;
using System.Collections.Generic;
namespace WeeklyChallenge
{
class Program
{
static void Main(string[] args)
{
Boolean exit = false;
while (!exit)
{
Console.WriteLine();
List<string> options = new List<string>() { "q", "1", "2", "3", "4", "5", "6" };
Console.WriteLine("1: Rock Paper Scissors");
Console.WriteLine("2: OverTime");
Console.WriteLine("3: UniqueFract");
Console.WriteLine("4: AlmostPalindrome");
Console.WriteLine("5: RecursionStaircase");
Console.WriteLine("6: MaxThrowDistance");
Console.WriteLine("q: Exit");
Console.Write("Select a choice: ");
string input = Console.ReadLine();
while (!(options.Contains(input)))
{
Console.Write("Please select a valid choice: ");
input = Console.ReadLine();
}
switch(input)
{
case "q":
exit = true;
break;
case "1":
RockPaperScissors();
break;
case "2":
OverTime();
break;
case "3":
UniqueFract();
break;
case "4":
AlmostPalindrome();
break;
case "5":
RecursionStaircase();
break;
case "6":
MaxThrowDistance();
break;
default:
Console.WriteLine("You're not meant to get here.");
exit = true;
break;
}
}
}
private static void RockPaperScissors()
{
string c1 = "", c2 = "";
bool cont = true;
while (cont)
{
Console.Write("Player one, choose rock, paper, or scissors: ");
c1 = Console.ReadLine();
if (c1.Equals("rock") || c1.Equals("paper") || c1.Equals("scissors"))
{
cont = false;
}
}
cont = true;
while (cont)
{
Console.Write("Player two, choose rock, paper, or scissors: ");
c2 = Console.ReadLine();
if (c2.Equals("rock") || c2.Equals("paper") || c2.Equals("scissors"))
{
cont = false;
}
}
Console.WriteLine(RockPaperScissorsLogic(c1, c2));
}
private static string RockPaperScissorsLogic(string first, string second)
{
string P1 = "Player 1 wins";
string P2 = "Player 2 wins";
if (first == second)
{
return "TIE";
}
else if (first == "rock")
{
if (second == "scissors")
{
return P1;
}
else if (second == "paper")
{
return P2;
}
}
else if (first == "scissors")
{
if (second == "rock")
{
return P2;
}
else if (second == "paper")
{
return P1;
}
}
else if (first == "paper")
{
if (second == "scissors")
{
return P2;
}
else if (second == "rock")
{
return P1;
}
}
return "CONFUSION";
}
private static void OverTime()
{
double[] parameters = new double[4];
string[] queries = new string[] {"Start time: ", "End time: ", "Hourly rate: ", "Overtime multiplier: "};
for(int i = 0; i < 4; i++)
{
double temp;
bool cont = true;
while (cont)
{
Console.Write(queries[i]);
try
{
temp = Double.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Please input a number.");
continue;
}
parameters[i] = temp;
cont = false;
}
}
OverTimePay(parameters[0], parameters[1], parameters[2], parameters[3]);
}
private static void OverTimePay(double start, double end, double rate, double multiplier)
{
// 9-17 is regular hours
// after 17 is overtime
double total = 0;
if (end <= 17)
{
// no overtime
total = (end-start) * rate;
}
else
{
double baseTotal = (17-start) * rate;
double overTotal = (end-17) * rate * multiplier;
total = baseTotal + overTotal;
}
if (start < 9)
{
Console.WriteLine("You should not begin work before 9am. Please check with your manager to ensure proper compensation.");
}
Console.WriteLine($"{total:C}");
}
private static void UniqueFract()
{
double total = 0;
List<double> holder = new List<double>();
for (double d = 1; d < 10; d++)
{
for (double n = 1; n < 9; n++)
{
double fraction = n/d;
if (fraction >= 1)
{
break;
}
if (holder.Contains(fraction))
{
continue;
}
else
{
holder.Add(fraction);
total += fraction;
}
}
}
Console.WriteLine($"Total of all unique fractions whose numerator and denominator are less than 1: {total}");
}
private static void AlmostPalindrome()
{
Console.Write("What is the string you'd like to check? ");
string palindoom = Console.ReadLine();
bool doomed = CheckPalindrome(palindoom);
if (doomed)
{
Console.WriteLine("This string is or is almost a palindrome!");
}
else
{
Console.WriteLine("This string is not nearly a palindrome.");
}
}
private static bool CheckPalindrome(string palindoom)
{
int check = 0;
for (int i = 0; i < palindoom.Length; i++)
{
int j = palindoom.Length - i - 1;
if (j <= i)
{
break;
}
if (palindoom[i] != palindoom[j])
{
check++;
}
}
if (check > 1)
{
return false;
}
else
{
return true;
}
}
private static void RecursionStaircase()
{
Console.Write("How many stairs are there? ");
int n = 0;
int ways = 0;
bool contain = true;
do
{
string input = Console.ReadLine();
try
{
n = Int32.Parse(input);
contain = false;
}
catch
{
Console.WriteLine("That is not an integer. Try again.");
}
if (n < 0)
{
Console.WriteLine("Please input a positive integer.");
contain = true;
}
} while (contain);
ways = StaircaseCounter(n);
Console.WriteLine($"There are {ways} way(s) to climb these steps.");
}
private static int StaircaseCounter(int n)
{
int x = 1;
int y = 1;
if (n < 2)
{
return 1;
}
for (int i = 1; i < n; i++)
{
int z = x + y;
x = y;
y = z;
}
return y;
}
private static void MaxThrowDistance()
{
Console.WriteLine("How high are you in meters?");
int h = 0;
bool check = true;
do
{
string input = Console.ReadLine();
try
{
h = Int32.Parse(input);
check = false;
}
catch
{
Console.WriteLine("That is not an integer. Try again.");
}
if (h < 0)
{
Console.WriteLine("Please input a positive integer.");
check = true;
}
} while (check);
Console.WriteLine("How hard will you throw the ball in meters per second?");
int v = 0;
check = true;
do
{
string input = Console.ReadLine();
try
{
v = Int32.Parse(input);
check = false;
}
catch
{
Console.WriteLine("That is not an integer. Try again.");
}
if (v < 0)
{
Console.WriteLine("Please input a positive integer.");
check = true;
}
} while (check);
double maxDistance = 0;
double maxAngle = 90; // straight up
double highDistance = DistanceThrown(h, v, maxAngle);
double minAngle = 0; // straight right
double lowDistance = DistanceThrown(h, v, minAngle);
check = true;
double[] modifier = new double[] {5, 1, 0.1};
int i = 0;
while(check) // get the best angle within 10 degrees
{
if (minAngle != maxAngle)
{
if (highDistance < lowDistance)
{
maxAngle = Math.Round(maxAngle - modifier[i],1);
highDistance = DistanceThrown(h, v, maxAngle);
}
else
{
minAngle = Math.Round(minAngle + modifier[i],1);
lowDistance = DistanceThrown(h, v, minAngle);
}
}
else if (i != 2)
{
minAngle -= modifier[i];
maxAngle += modifier[i];
i++;
}
else
{
check = false;
maxDistance = Math.Max(highDistance, lowDistance);
}
}
Console.WriteLine($"The maximum distance is {maxDistance} meters at {minAngle} degrees.");
Console.WriteLine(check);
}
private static double DistanceThrown(int h, int v, double angle)
{
double xVel = Math.Round(Math.Cos((Math.PI/180)*angle),5) * v;
double yVel = Math.Round(Math.Sin((Math.PI/180)*angle),5) * v;
double g = 9.8;
double time = (yVel + Math.Sqrt( yVel*yVel + 2*g*h)) / g;
return Math.Round(xVel * time,2);
}
}
}