Cover....1
Title Page....2
Copyright and Credits....3
Dedication....4
Packt Upsell....5
Contributors....6
Table of Contents....8
Preface....14
Chapter 1: Mathematics....20
Problems....20
1. Statistical functions....20
2. Permutations....22
3. Combinations....23
4. Factorials....24
5. Fibonacci numbers....24
6. Binomial coefficients....25
7. Pascal's triangle....26
8. Greatest common divisors....26
9. Least common multiples....26
10. Sums of multiples....27
11. Primality testing....27
12. Prime table....27
13. Prime factors....27
14. Unique prime factors....28
15. Prime tuples....28
16. Proper divisors....28
17. Amicable numbers....29
18. Perfect numbers....29
19. Armstrong numbers....29
Solutions....29
1. Statistical functions....30
2. Permutations....35
3. Combinations....39
4. Factorials....41
5. Fibonacci numbers....43
6. Binomial coefficients....48
7. Pascal's triangle....52
8. Greatest common divisors....56
9. Least common multiples....58
10. Sums of multiples....59
11. Primality testing....63
12. Prime table....64
13. Prime factors....68
14. Unique prime factors....71
15. Prime tuples....73
16. Proper divisors....75
17. Amicable numbers....77
18. Perfect numbers....79
19. Armstrong numbers....80
Chapter 2: Geometry....82
Problems....82
20. Monte Carlo π....82
21. Newton's π....83
22. Bisection root-finding....83
23. Newton's method....84
24. Gaussian elimination....85
25. Monte Carlo integration....89
26. Rectangle rule integration....90
27. Trapezoid rule integration....91
28. Arrowheads....92
29. Line-line intersection....93
30. Point-line distance....93
31. Point-segment distance....94
32. Segment-segment distance....94
33. Circle selection....94
34. Line-circle intersection....95
35. Circle-circle intersection....95
36. Circle-line tangents....95
37. Polygon area....96
38. Point in a polygon....96
39. Convexity testing....96
40. Stars....96
Solutions....97
20. Monte Carlo π....98
21. Newton's π....101
22. Bisection root-finding....102
23. Newton's method....105
24. Gaussian elimination....106
25. Monte Carlo integration....112
26. Rectangle rule integration....114
27. Trapezoid rule integration....116
28. Arrowheads....118
29. Line-line intersection....123
30. Point-line distance....127
31. Point-segment distance....128
32. Segment-segment distance....129
33. Circle selection....132
34. Line-circle intersection....134
35. Circle-circle intersection....137
36. Circle-line tangents....141
37. Polygon area....143
38. Point in a polygon....145
39. Convexity testing....148
40. Stars....150
Chapter 3: Dates and Times....152
Problems....152
41. Days of the week....152
42. Date and time picker....152
43. Time zone chart....153
44. Scheduling meetings....153
45. Time zone clocks....153
46. Local time zone clocks....154
47. Calculating duration....155
48. Calculating age....155
Solutions....155
41. Days of the week....155
42. Date and time picker....157
43. Time zone chart....159
44. Scheduling meetings....164
45. Time zone clocks....164
46. Local time zone clocks....166
47. Calculating duration....167
48. Calculating age....168
Chapter 4: Randomization....171
Problems....171
49. Random doubles....171
50. Random items....171
51. Randomize items....172
52. Random groups....172
53. Choose items with probabilities....172
54. Random passwords....172
55. Random walks....173
Solutions....173
49. Random doubles....173
50. Random items....174
51. Randomize items....175
52. Random groups....176
53. Choose items with probabilities....178
54. Random passwords....178
55. Random walks....180
Chapter 5: Strings....182
Problems....182
56. Roman numerals....182
57. Bytes to hex....183
58. Removing punctuation....183
59. Palindromic substrings....183
60. Validating passwords....184
61. Edit distance....184
62. Soundex....185
63. Longest common substring....186
Solutions....187
56. Roman numerals....187
57. Bytes to hex....191
58. Removing punctuation....192
59. Palindromic substrings....193
60. Validating passwords....196
61. Edit distance....197
62. Soundex....204
63. Longest common substring....205
Chapter 6: Files and Directories....211
Problems....211
64. Removing blank lines....211
65. Directory size....212
66. Finding duplicate files....212
67. Thumbnails....212
68. Thumbnail web page....213
69. Find files....213
70. Find and Replace....213
71. Saving images....214
72. Compressing images....214
Solutions....214
64. Removing blank lines....214
65. Directory size....215
66. Finding duplicate files....217
67. Thumbnails....221
68. Thumbnail web page....225
69. Find files....227
70. Find and Replace....229
71. Saving images....231
72. Compressing images....233
Chapter 7: Advanced C# and .NET Features....235
Problems....235
73. Directory size, LINQ style....236
74. Directory size, PLINQ style....236
75. Find files, LINQ style....236
76. Parallel primes table....236
77. Parallel prime tuples....236
78. Parallel Monte Carlo π....236
79. Yielding primes....237
80. Yielding Fibonacci numbers....237
81. Complex numbers....237
Solutions....238
73. Directory size, LINQ style....238
74. Directory size, PLINQ style....239
75. Find files, LINQ style....241
76. Parallel primes table....242
77. Parallel primes tuple....247
78. Parallel Monte Carlo π....252
79. Yielding primes....255
80. Yielding Fibonacci numbers....256
81. Complex numbers....257
Chapter 8: Simulations....269
Problems....270
82. Dawkins' weasel....270
83. Hailstone sequence....271
84. Hailstone sequence, Redux....272
85. Langton's Ant....273
86. Life....274
87. Sharks and Fish....275
88. Slingshot....276
89. Slingshot refinements....278
90. Space Force....279
Solutions....279
82. Dawkins' weasel....280
83. Hailstone sequence....283
84. Hailstone Sequence, Redux....286
85. Langton's Ant....288
86. Life....291
87. Sharks and Fish....294
88. Slingshot....296
Projectile motion....297
Example solution....297
89. Slingshot refinements....300
90. Space Force....303
Sprite classes....303
Bubble....306
Ship....307
Keyboard events....310
Other details....312
Chapter 9: Cryptography....313
Problems....314
91. Caesar cipher....314
92. Vigenère cipher....314
93. Cryptographic pseudorandom numbers....315
94. Primality testing, redux....316
95. Find primes....318
96. Hash files....318
97. Steganography....319
98. Encrypt and decrypt strings....319
99. Encrypt and decrypt files....320
100. CryptoPad....321
Solutions....321
91. Caesar cipher....321
92. Vigenère cipher....324
93. Cryptographic random numbers....324
94. Primality testing, redux....329
95. Find primes....331
96. Hash files....332
97. Steganography....333
98. Encrypt and decrypt strings....338
99. Encrypt and decrypt files....343
100. CryptoPad....345
Other Books You May Enjoy....350
Index....353
Learn advanced C# concepts and techniques such as building caches, cryptography, and parallel programming by solving interesting programming challenges
C# is a multi-paradigm programming language. The Modern C# Challenge covers with aspects of the .NET Framework such as the Task Parallel Library (TPL) and CryptoAPI. It also encourages you to explore important programming trade-offs such as time versus space or simplicity. There may be many ways to solve a problem and there is often no single right way, but some solutions are definitely better than others. This book has combined these solutions to help you solve real-world problems with C#.
In addition to describing programming trade-offs, The Modern C# Challenge will help you build a useful toolkit of techniques such as value caching, statistical analysis, and geometric algorithms.
By the end of this book, you will have walked through challenges in C# and explored the .NET Framework in order to develop program logic for real-world applications.
The Modern C# Challenge is for all C# developers of different abilities wanting to solve real-world problems. There are problems for everyone at any level of expertise in C#