It’s New Year’s Day and everyone’s in line for the Wonderland rollercoaster ride! There are a number of people queued up, and each person wears a sticker indicating their initial position in the queue. Initial positions increment by 1 from 1 at the front of the line to n at the back. Any person in the queue can bribe the person directly in front of them to swap positions. If two...
The problem of “Castle on the Grid” – C++ Source code
You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and an end position, determine the number of moves it will take to get to the end position. For example, you are given a grid with sides n=3 described as follows:. . .. X .. . . Your starting...
The problem of “Repeated String” – C Source code
Lilah has a string, s , of lowercase English letters that she repeated infinitely many times. Given an integer, n, find and print the number of letter a‘s in the first n letters of Lilah’s infinite string. For example, if the string s=’abcac’ and n=10, the substring we consider is ‘abcacabcac’ , the first 10 characters of her infinite string. There are...
The problem of “Sock Merchant” – C Source code
John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. For example, there are socks n=7 with colors ar=[1,2,1,2,1,3,2] . There is one pair of color and one of color . There are three odd socks left, one of each color. The...
The problem of “Counting Valleys” – C Source code
Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly n steps. For every step he took, he noted if it was an U uphill, , or a D downhill, step. Gary’s hikes start and end at sea level and each step up or down represents a unit change in altitude. We define the following terms: A mountain is a...
The problem of “Hash Tables: Ransom Notes” – C Source code
Harold is a kidnapper who wrote a ransom note, but now he is worried it will be traced back to him through his handwriting. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use only whole words available in the magazine. He cannot use substrings or...
Simple data buffering/streaming algorithm – helper functionality
In this tutorial, a simple but useful data buffering/streaming algorithm is presented. It is not optimal but easy to understand and modify according to your needs… This library assumes that we need to use a big amount of data in a memory limited system. The library handles the all the data transferring procedure in a way that the user is able to easily get the amount of data without...
Funny C# app for Mouse Faking
The purpose of this application is just for fun. It started initially by figuring out a way to fake skype that you are in front of your PC but also to randomly create a picture. The application takes control of your mouse and start drawing random pixels in the main area of the window thus generating mouse position and click events.
Below is a sample picture as well as the binary:
Extended functionalities of File Read/Write in C#
Messing around with files, i found that i needed some extra functionalities when i Read/Write in a (binary) file. For example i need to read a specific block of bytes with an offset (if exists – not out of bound) as well as write a given block of bytes to a certain address and select if the current block will override the existing data etc… Unfortunately, some of those functionalities...
HTTP-Request abstraction in C#
There are several ways to perform HTTP GET, POST.. requests in C#. The following example is using the legacy HttpRequest Class provided by .NetFramework without adding one more additional dependency (Nuget Packages) for something that works really well in .NET implementation and is usually unnecessary for small hobby projects but also not a good practice in professional projects. WebRequest and...