Skip to content

Commit 8fc1b86

Browse files
committed
Weekly challenge mvdoyle#2
1 parent d23b737 commit 8fc1b86

File tree

9 files changed

+101
-15
lines changed

9 files changed

+101
-15
lines changed
Binary file not shown.
Binary file not shown.

ChallengesWithTestsMark8.Tests/obj/Debug/net6.0/ChallengesWithTestsMark8.Tests.csproj.FileListAbsolute.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.csproj.AssemblyReference.cache
2-
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.GeneratedMSBuildEditorConfig.editorconfig
3-
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.AssemblyInfoInputs.cache
4-
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.AssemblyInfo.cs
5-
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.csproj.CoreCompileInputs.cache
61
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin\Debug\net6.0\ChallengesWithTestsMark8.deps.json
72
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin\Debug\net6.0\ChallengesWithTestsMark8.runtimeconfig.json
83
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin\Debug\net6.0\ChallengesWithTestsMark8.exe
@@ -96,6 +91,11 @@ C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin
9691
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin\Debug\net6.0\zh-Hant\Microsoft.VisualStudio.TestPlatform.Common.resources.dll
9792
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin\Debug\net6.0\ChallengesWithTestsMark8.dll
9893
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\bin\Debug\net6.0\ChallengesWithTestsMark8.pdb
94+
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.csproj.AssemblyReference.cache
95+
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.GeneratedMSBuildEditorConfig.editorconfig
96+
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.AssemblyInfoInputs.cache
97+
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.AssemblyInfo.cs
98+
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.csproj.CoreCompileInputs.cache
9999
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.csproj.CopyComplete
100100
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\ChallengesWithTestsMark8.Tests.dll
101101
C:\Users\dmcpe\Desktop\Repos\WeeklyChallenges\ChallengesWithTestsMark8.Tests\obj\Debug\net6.0\refint\ChallengesWithTestsMark8.Tests.dll
Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,144 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection.Metadata.Ecma335;
35

46
namespace ChallengesWithTestsMark8
57
{
68
public class ChallengesSet02
79
{
810
public bool CharacterIsALetter(char c)
911
{
10-
throw new NotImplementedException();
12+
return (char.IsLetter(c));
13+
14+
//throw new NotImplementedException();
1115
}
1216

1317
public bool CountOfElementsIsEven(string[] vals)
1418
{
15-
throw new NotImplementedException();
19+
return (vals.Length % 2 == 0);
20+
21+
//throw new NotImplementedException();
1622
}
1723

1824
public bool IsNumberEven(int number)
1925
{
20-
throw new NotImplementedException();
26+
return (number % 2 == 0);
27+
28+
//throw new NotImplementedException();
2129
}
2230

2331
public bool IsNumberOdd(int num)
2432
{
25-
throw new NotImplementedException();
33+
return (num % 2 != 0);
34+
//throw new NotImplementedException();
2635
}
2736

2837
public double SumOfMinAndMax(IEnumerable<double> numbers)
2938
{
30-
throw new NotImplementedException();
39+
// I had to look up a function to use with IEnumerable. I'd like to learn what this type is.
40+
double min = double.MaxValue;
41+
double max = double.MinValue;
42+
43+
if (numbers == null || numbers.Any() == false)
44+
{
45+
return 0;
46+
}
47+
else
48+
{
49+
50+
foreach (var number in numbers)
51+
{
52+
if (number < min)
53+
{
54+
min = number;
55+
}
56+
if (number > max)
57+
{
58+
max = number;
59+
}
60+
61+
}
62+
63+
}
64+
return (min + max);
65+
//throw new NotImplementedException();
3166
}
3267

3368
public int GetLengthOfShortestString(string str1, string str2)
3469
{
35-
throw new NotImplementedException();
70+
var result = str1.Length <= str2.Length ? str1.Length : str2.Length;
71+
72+
return result;
73+
74+
//throw new NotImplementedException();
3675
}
3776

3877
public int Sum(int[] numbers)
3978
{
40-
throw new NotImplementedException();
79+
if (numbers == null)
80+
{
81+
return 0;
82+
}
83+
84+
int sum = 0;
85+
foreach (int number in numbers)
86+
{
87+
sum += number;
88+
}
89+
return sum;
90+
91+
//throw new NotImplementedException();
4192
}
4293

4394
public int SumEvens(int[] numbers)
4495
{
45-
throw new NotImplementedException();
96+
if (numbers == null)
97+
{
98+
return 0;
99+
}
100+
101+
int sum = 0;
102+
foreach (int number in numbers)
103+
{
104+
if(number % 2 == 0)
105+
{
106+
sum += number;
107+
}
108+
109+
}
110+
return sum;
111+
//throw new NotImplementedException();
46112
}
47113

48114
public bool IsSumOdd(List<int> numbers)
49115
{
50-
throw new NotImplementedException();
116+
if (numbers == null)
117+
{
118+
return false;
119+
}
120+
121+
int sum = 0;
122+
foreach (int number in numbers)
123+
{
124+
sum += number;
125+
}
126+
127+
bool odd = (sum == 0 || sum % 2 == 0) ? false : true;
128+
return odd;
129+
130+
//throw new NotImplementedException();
51131
}
52132

53133
public long CountOfPositiveOddsBelowNumber(long number)
54134
{
55-
throw new NotImplementedException();
135+
long count = 0;
136+
for (int i = 1; i < number; i+=2)
137+
{
138+
count++;
139+
}
140+
return count;
141+
//throw new NotImplementedException();
56142
}
57143
}
58144
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)