Book Image

The Modern C# Challenge

By : Rod Stephens
Book Image

The Modern C# Challenge

By: Rod Stephens

Overview of this book

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.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Free Chapter
1
Mathematics
3
Dates and Times
4
Randomization
6
Files and Directories
7
Advanced C# and .NET Features
Index

Problems


Use the following problems to test your geometric programming skills. Give each problem a try before you turn to the solutions and download the example programs. If you have trouble with the graphical part, try to implement the non-graphical pieces. Then, you can download the example solutions and replace the key parts of the program with your code.

20. Monte Carlo π

A Monte Carlo algorithm uses randomness to approximate the solution to a problem. Often, using more random samples gives you a more accurate approximated solution or gives a greater probability that the solution is correct.

For this problem, use a Monte Carlo algorithm to approximate π. To do that, generate random points in the square (0 ≤ X, Y ≤ 1) and then see how many fall within a circle centered in that square.

21. Newton's π

Various mathematicians have developed many different ways to approximate π over the years. Sir Isaac Newton devised the following formula to calculate π:

Use Newton's method to approximate π. Let...