Problem of the Dayhttp://www.problemotd.com/blog/2015-07-31T00:00:00-05:04Latest problems from Problem of the DayCrossing The River2015-07-31T00:00:00-05:04http://www.problemotd.com/problem/crossing-the-river/<p>Two brothers come to a river. There is a boat, however, it can only carry one of them. How do they each get to the other side of the river using the boat assuming neither of them know how to swim?</p>You've Got Mail2015-07-27T00:00:00-05:04http://www.problemotd.com/problem/youve-got-mail/<p>Welcome to Monday</p>
<p>For today's problem we'll be working on a rather practical problem. The goal is to create a quick command line script that sends yourself an e-mail. The script will take in one command line argument which is the text of the e-mail. Something like ./send_email "hello world"</p>Trim2015-07-23T00:00:00-05:04http://www.problemotd.com/problem/trim/<p>Today's problem is to implement one of the most popular functions in programming languages, trim. The goal of trim is to remove whitespace from the beginning and end of a string. For bonus points you can make an ltrim and rtrim which remove whitespace only from the left and right respectively. While the worst case for your function should be O(n), you should include optimizations to not check every character if possible.</p>Next Life2015-07-20T00:00:00-05:04http://www.problemotd.com/problem/next-life/<p>Welcome back!</p>
<p>Today's problem is to create a function that returns the next iteration of <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Rules">Conway's Game of Life</a>. The link goes straight to the rules if you're unfamilar with the game. For today's problem we'll assume that 1 = alive cell and 0 = dead cell.</p>
<pre>
var generation = [
"111",
"110",
"100"
];
next_life(generation)
//Answer = ["101", "001", "110"]
</pre>Open Source Week2015-07-06T00:00:00-05:04http://www.problemotd.com/problem/open-source-week/<p>Every now and then I think it's always good to get back to roots and work on the software that helps make the world tick. This week will be dedicated to solving problems in the open source community. If you feel so inclined there are plenty of awesome problems to work on for this site <a href="https://github.com/mburst/problemotd">https://github.com/mburst/problemotd</a>, however, feel free to also take time to work on your own open source projects or other ones you enjoy using.</p>Gregorian To French2015-07-01T00:00:00-05:04http://www.problemotd.com/problem/gregorian-to-french/<p>Happy first day of July!</p>
<p>Today's problem is a fun one for the history buffs. You'll be creating a program that can convert a day from the Gregorian Calendar to one in the French Republican Calendar. Your program or function will take in a year, month, and day and return the converted result. You can read more about the French Republican Calendar on the Wikipedia page (<a href="https://en.wikipedia.org/wiki/French_Republican_Calendar">https://en.wikipedia.org/wiki/French_Republican_Calendar</a>) along with an example on how to do the conversion.</p>
<p>For bonus points create a way to convert from French back to Gregorian.</p>IRC Bot2015-06-29T00:00:00-05:04http://www.problemotd.com/problem/irc-bot/<p>Hooray for Monday!</p>
<p>Today's problem is a fun one. We'll be creating an IRC bot. Your bot can connect to any channel and on any network (<a href="http://freenode.net">freenode.net</a> is a good place to start if you're unsure). The goal of this bot is to print to console everything that is said in the irc channel. For bonus points have your both listen in on two channels and print both channels to the console.</p>Bit Saving2015-06-26T00:00:00-05:04http://www.problemotd.com/problem/bit-saving/<p>You have two 3-bit temperature sensors (A && B) that measure the same thing. Both sensors are hooked up to the same CPU, which takes in the sensor readings. You know that the sensors are designed so that their readings can be off by at most one bit. We claim that if B knows that A has sent the CPU a 3-bit sequence, then B only needs to send 2 bits, and the CPU will be able to reconstruct B's 3-bit measurement, thereby conserving bandwidth. How is this possible?</p>
<p>Enjoy your weekend!</p>List Segments2015-06-25T00:00:00-05:04http://www.problemotd.com/problem/list-segments/<p>If you're a unix user you may be familiar with the popular command 'ls'. The 'ls' command simply prints all the files and folders in a directory. Today's objective is to create a program that takes in an absolute folder path and prints out all the files and folders inside that directory. For bonus points make it also work with relative paths. If an invalid directory is passed simply print out "Invalid directory".</p>Dijkstra's Algorithm2015-06-23T00:00:00-05:04http://www.problemotd.com/problem/dijkstras-algorithm/<p>Today's goal is to implement one of the most classic algorithms in path finding and graph theory, Dijkstra's algorithm. If you're unfamiliar with it or graph theory you can head over to this <a href="http://www.maxburstein.com/blog/introduction-to-graph-theory-finding-shortest-path/">finding the shortest path</a> blog post to learn more.</p>
<p>For bonus points be sure to submit a PR to <a href="https://github.com/mburst/dijkstras-algorithm">https://github.com/mburst/dijkstras-algorithm</a> with your implementation.</p>
<p>Here is an example graph with some sample cases:</p>
<p><img src="http://i.imgur.com/acI5bOW.png" alt="Visual representation of the computer science graph that's being implemented" /></p>
<pre>
print graph.shortest_path('A', 'H')
[H, F, B]
print graph.shortest_path('B', 'C')
[C, F]
</pre>100m Dash2015-06-19T00:00:00-05:04http://www.problemotd.com/problem/100m-dash/<p>A brother and sister run the 100m dash after school to practice for an upcoming track meet. In the first race the sister beats her brother by 5 yards. They decide to race again but to make things more fair the sister then starts 5 yards behind the original starting line and they race again. Assuming the brother and sister run at the same speed as they did during the first race, who wins the second race?</p>
<p>Enjoy your weekend!</p>Filter Reduce2015-06-17T00:00:00-05:04http://www.problemotd.com/problem/filter-reduce/<p>Today's problem is a two part problem. You'll be implementing a filter function and a reduce function.</p>
<p>Filter is a function that takes in a function and an array and runs each value of the array through the filter. The function passed in to the filter will return either a true or false value. For all values in the array that evaluate to true return that value. One example is an isOdd function with an array [1,2,3] which would return [1,3].</p>
<p>Reduce is a function that takes in a function and an array and runs each value of the array through the reducer. The goal is to run each item in the array through the list and then combine the output in to a single value. One example is an adder function with an array [1,2,3] which would return 6.</p>Move Zeroes2015-06-15T00:00:00-05:04http://www.problemotd.com/problem/move-zeroes/<p>Given a number in array form, move all the 0's to the end of the array.</p>
<pre>[1,3,9,0,5,4,0,0,6,6,0,2,4,1,0,4,9,7,0,0,1,2,0]</pre>Half Full2015-06-12T00:00:00-05:04http://www.problemotd.com/problem/half-full/<p>You are in an empty room and you have a transparent glass of water. The glass is a right cylinder, and it looks like it's half full, but you're not really sure. How can you accurately figure out whether the glass is half full, more than half full, or less than half full? You have no rulers or writing utensils.</p>
<p>Enjoy your weekend!</p>
<p>P.S. don't drink the water</p>Invert Binary Tree2015-06-11T00:00:00-05:04http://www.problemotd.com/problem/invert-binary-tree/<p>A classic, but challenging programming problem for us to solve today. The goal is to create a function or method that takes in a binary tree and inverts it. It is safe to assume the tree has at least one node. For example:</p>
<pre>
1
/ \
2 3
\
4
4
/
2 3
\ /
1
</pre>Linked Stack2015-06-08T00:00:00-05:04http://www.problemotd.com/problem/linked-stack/<p>Happy Monday!</p>
<p>Today's problem is a classic data structures problem. The goal is to create a stack using a linked list as the backing structure. The stack should have a push and pop method implemented.</p>Pin Hack2015-06-05T00:00:00-05:04http://www.problemotd.com/problem/pin-hack/<p>Credit cards typically use a 4 digit pin. You've recently come across a credit card and are trying to guess the pin so that you can buy yourself a new TV or a pony.</p>
<p>You have a machine that lets you continuously enter digits until you've entered the correct 4 digit sequence. If the pin was 1234, then you could enter 1234, 096791234, 111234, etc to get in. Thus you can brute force the problem in around 40,000 steps. You don't want to spend the entire day entering numbers though. How can you solve this in less than 40,000 steps?</p>
<p>Enjoy your weekend!</p>Pattern Finding2015-06-04T00:00:00-05:04http://www.problemotd.com/problem/pattern-finding/<p>We often solve fun number pattern riddles on here. Let's see if we can write a program to solve basic ones. Today's problem is to create a program that determines if an array contains an arithmetic or geometric sequence (no sorting required). Arithmetic patterns always change by the same value 2,4,6. Geometric patterns always change by the same ratio 8,4,2. If the pattern doesn't match either algorithm then just return "no pattern".</p>
<p>For bonus points figure out if a sequence has a plus 1 increase pattern (2,4,7,11).</p>Balanced Partition2015-06-02T00:00:00-05:04http://www.problemotd.com/problem/balanced-partition/<p>Given a set of N integers, partition them in to two buckets such that |N1 - N2| is as small as possible where N1 and N2 are the sums of the partitions.</p>Minify Sum2015-06-01T00:00:00-05:04http://www.problemotd.com/problem/minify-sum/<p>Happy Monday!</p>
<p>Today's problem involves turning a long number in to a short number. The goal is to sum each digit of the number recursively until you reach a single digit. Here are a few test cases to make it easier to understand.</p>
<pre>
123456 = 1+2+3+4+5+6 = 2+1 = 3
99 = 9+9 = 1+8 = 9
</pre>