Skip to main content

Posts

Showing posts from January, 2018

Featured Post

Your First Programming Language

What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.

Write a Web Client

Description Today's challenge is simple: write a web client from scratch. Requirements: Given an HTTP URL (no need to support TLS or HTTPS), fetch the content using a GET request Display the content on the console (a'la curl) Exit For the challenge, your requirements are similar to the HTTP server challenge - implement a thing you use often from scratch instead of using your language's built in functionality: You may not use any of your language's built in web client functionality or any third party library or tool. E.g. you can't use Python's urllib, httplib, or a third-party module like requests or curl. Same for any other language and their built in features; you may also not shell out to something like curl (e.g. no system("curl %s", url)). Your program should use string processing calls to dissect the URL (again, you cannot use any of the built in functionality like Python's urlparse module or Java's java.net.URL, or third-party

Change Calculator

Description You own a nice tiny mini-market that sells candies to children. You need to know if you'll be able to give the change back to those little cute creatures and it happens you don't know basic math because when you were a child you were always eating candies and did not study very well. So you need some help from a little tool that tell you if you can. Input Description On the line beginning "Input:" be given a single number that tells you how much change to produce, and then a list of coins you own. The next line, beginning with "Output:", tells you the number of coins to give back to achieve the change you need to give back (bounded by the number of coins you have). Here's one that says "give the customer 3 or fewer coins". Example: Input: 10 5 5 2 2 1 Output: n <= 3 Output Description Your progam should emit the coins you would give back to yield the correct value of change, if possible. Multiple solutions may be possib

The Rabbit Problem

Description Rabbits are known for their fast breeding, but how soon will they dominate the earth? Starting with a small population of male and female rabbits we have to figure out how long it will take for them to outnumber humans 2:1. Every month a fertile female will have 14 offspring (5 males and 9 females). A female rabbit is fertile when it has reached the age of 4 months, they never stop being fertile. Rabbits die at the age of 8 years (96 months). Input description You will be given a list of numbers as following: Male_rabbits Female_rabbits Rabbits_needed_alive The initial rabbits will always be 2 months old and fertile females will always produce 14 offspring (5 male, 9 female) Every month that passes things should be done in this order: Fertile female reproduce (so 7 year & 11 months old will reproduce) rabbits age (except newborn) (and rabbits reaching 8 years will die, the 7 year & 11 months old will die) fx: 2 4 1000000000 Output descript

Square Sums Chain

Description For this challenge your task is, given a number N, rearrange the numbers 1 to N so that all adjacent pairs of numbers sum up to square numbers. There might not actually be a solution. There also might be multiple solution. You are only required to find one, if possible. For example, the smallest number for which this is possbile is 15: 8 1 15 10 6 3 13 12 4 5 11 14 2 7 9  8 +  1 =  9 = 3^2  1 + 15 = 16 = 4^2 15 + 10 = 25 = 5^2 10 +  6 = 16 = 4^2 ... Example Input 15 8 Example Output 8 1 15 10 6 3 13 12 4 5 11 14 2 7 9 Not possible Challenge Input 23 24 25 256 Solution in C #include <stdio.h> #include <limits.h> #define MAX 1024 #define ULONG_BIT (sizeof(unsigned long) * CHAR_BIT) #define BITSET(b, i) b[i / ULONG_BIT] |= 1UL << (i % ULONG_BIT) #define BITGET(b, i) ((b[i / ULONG_BIT] >> (i % ULONG_BIT)) & 1UL) static unsigned long is_square[(MAX * (MAX - 1) + ULONG_BIT - 1) / ULONG_BIT]; static inline void

Bowling Frames Display

Description Today's challenge will be a variation on a popular introductory programming task, scoring a game of bowling. However, in this challenge, we won't even actually have to calculate the score. Today's challenge is to produce the display for the individual frames, given a list of the number of pins knocked down on each frame. The basic rules are as follows: The game of bowling consists of 10 frames, where a player gets 2 attempts to knock down 10 pins. If the player knocks down all 10 pins on the first roll, that should be displayed as X, and the next number will be the first roll of the next frame. If the player doesn't knock down any pins, that should be displayed as - If the player gets a spare (knocks down the remaining pins on the second roll of the frame, that should be displayed as / If you want more details about the rules, see: Challenge #235 [Intermediate] Scoring a Bowling Game Input Description You will be given a list of integers that re

Snake In The Box

Description The snake-in-the-box problem in graph theory and computer science deals with finding a certain kind of path along the edges of a hypercube. This path starts at one corner and travels along the edges to as many corners as it can reach. After it gets to a new corner, the previous corner and all of its neighbors must be marked as unusable. The path should never travel to a corner after it has been marked unusable. Imagine a 3-dimensional cube with corners labeled with three digit numbers of the x,y,z coordinates: 000, 001, 011, 010, 100, 101, 111, 110. The longest tour of this cube, given the rules above, follows the path 000 -> 001 -> 011 -> 111 -> 110 for a length of 4. As you may imagine, as the dimensionality of the hypercube grows the complexity also grows. For dimensions above 9 there is no concrete answer, only longest lengths found so far. Input Description You'll be given a single digit n per line indicating the dimensionality of the cube on w

Hue Drops Puzzle

Description I found the game Hue Drops on a recent flight, turns out it's also a mobile game. One reviewer described it: You start with one dot, and you can change the colours of the adjacent dots. It's like playing with the paint bucket tool in MS Paint! You slowly change the colour of the entire board one section at a time. The puzzle opens with a group of tiles of six random colors. The tile in the upper left remains wild for you to change. Tile colors change by flooding from the start tile to directly connected tiles in the four cardinal directions (not diagonals). Directly connected tiles convert to the new color, allowing you to extend the size of the block. The puzzle challenges you to sequentially change the color of the root tile until you grow the block of tiles to the target color in 25 moves or fewer. Today's challenge is to read a board tiled with six random colors (R O Y G B V), starting from the wild (W) tile in the upper left corner and to produce a