Skip to main content

Posts

Showing posts with the label Problem Solving

Building a Tic Tac Toe Console Game in C#

When learning a new programming language, a common exercise is to create a classic game, such as Tic Tac Toe. In this post, I'll guide you through creating a simple, console-based Tic Tac Toe game in C#. First, let's start with the challenge we're trying to solve: Tic Tac Toe is a two-player game. We need to handle input from two players and alternate between them. The game is played on a 3x3 grid. We need to keep track of the state of this grid. A player wins by marking three spots in a row, either horizontally, vertically, or diagonally. The game continues until a player has won or all spots on the grid have been marked, in which case the game is a draw. To address these challenges, we need to develop a problem-solving mindset. Let's break down the problem into smaller, manageable pieces and think about how we could solve each one. This process is known as "decomposition" and it's a fundamental skill in programming and problem-solving in general. Step 1:

Total Number of Handshakes

Question:  At the annual meeting of Board of Directors of Acme Inc, every one starts shaking hands with everyone else in the room. Given the fact that any two persons shake hand exactly once, Can you tell the total count of handshakes? Answer: If there are n persons in the room, each person will have n-1 handshakes. There are n person in the room. So, total number of handshakes is n*(n-1). but we have counted each handshake twice. Like 1<=>2 and 2<=>1. If we divide the number by 2, we'll get the expected output. So the answer is (n*(n-1))/2. Again, if we consider this situation, first, the first person has n-1 handshakes. Then the second one has n-2. Similarly further, n-3, n-4....3, 2, 1. So the total number becomes (n-1)+(n-2)+(n-3)+....+3+2+1. if we use the formula for summation, we get the answer, that is (n*(n-1))/2.