Wednesday, May 22, 2013

File compare

Today's problem must be solved in C++ without any special libraries (namely boost). There's an unknown number of  files of the format:

File1_1.txt // the files all start with File, followed by some number < 9999
followed by _1.txt
There's 5 lines of comments about this file.
These comments can contain any characters
such as `~!@#$%^&*()_+-=[]{};':",./<>? and not be disrupted
156 1.569e-1
200 0.5e+09
215 569
289 159E+009
350 150

For each of these files, there's a file with the exact same name in a folder in the parent directory of the current working directory. That file with the same name looks exactly the same, except for when we get to the numbers. Specifically the second number is different, i.e. :
156 1.568e-1
200 0.5e+09
215 569
289 159E+009
350 159

Within two same name files we will need to calculate the difference of the second number and find the largest difference in this file. Because 150 - 159 gives us abs(-9) == 9, 9 is the biggest difference for this particular file. We will not need to compare different lines.

The goal is to find the largest difference (absolute value of the difference) among all the files.

Friday, May 17, 2013

Contains Palindrome

The problem is, given any size string (has to fit in the String class) check to see if it contains a palindrome. We'll define a palindrome as longer than 2 characters. If the string contains a palindrome, print out true, otherwise print out false. I.E. abby -> false, abba -> true, repelevilasaliveleper -> true

Thursday, May 16, 2013

Next Palindrome

Given any number up to 1000000 digits long (far too large for any int double long float or any other number format common to programming languages) find the next lowest palindrome. So for example, if the number is 5, the next lowest is 6, given 9 the next lowest is 11, given 12 the next lowest is 22, given 123123 the next lowest is 123321, and the final example given 9877899835481354687 the next lowest would be 9877899836389987789. If the current number is a palindrome, find the next lowest after the current number.

Wednesday, May 15, 2013

Line Spacing?

So Irealized in my comments to my previous post, the line spacing of my code was not maintained. Does anyone know how to maintain it for comments? I supposed the same problem will occurr for the actual posts too.

Island Problem

Alright, now that that class is over I've decided that I'm actually going to keep this blog. I'm going to turn it into a programming blog of sorts, and if people start following it great. I program mainly in Java, however I'm fairly adequate in C++ as well. Let's jump straight into things, and here's the first problem that I'm trying to solve.

There's an island, and it is broken up into sections (similiar to a 2-d array). Each section is associated with a height. Unlike most islands that have mountains in the middle, this island has mountains on the edges. Assuming there's no water evaporation happening during a rainstorm the island could potentially form lakes. The problem is to be given a random island, and to calculate the maximum amount of water it can hold. Each height increment can hold 1 million gallons of water.

example:
We have the island

5 6 4
3 1 5
9 8 7

This island can hold 2 million gallons of water because the height in the middle can be raised by 2 before water starts leaking out into the ocean.

For simplicity we'll always deal with a square island (of sizes up to 20x20), and we can say that water does not leak diagonally. However the edges are not always higher than the middle spots.