Monday, April 23, 2012

1.3 Problem 76: Mixing Milk

Only 2 failures due to the final cost costing the product of the available number and required, not the price and required number.

I didn't use qsort for it like the analysis. It looks like my solution is similar to the good exemplars.
This one is easy, as two farmers selling the same same price could be combined into one "provider" selling both amounts at the same price each. Since this is a greedy match, take as many as possible from the lowest price, and move on to the next expensive, ..., until there's no more.

Friday, April 20, 2012

Problem 90: Dual Palindromes

I accidentally thought it was "dual square palindromes", which made me fail until I noticed it.

This one is the last for Chapter 1's Section 1.2!

Monday, April 16, 2012

Problem 81: Palindromic Squares

This one requires base conversion, but I'm basically testing every square from 1 to 300 (90 000 fits into a 32-bit signed int; no intervention required). I reverse the string and test if it matches. If so, print the number and its palindromic square, in the requested base.

Friday, April 13, 2012

Problem 29: Name That Number

Friday the 13th...

Another first-attempt! w00t again! This one is done differently then their analysis.
C++ allows you to use std::string, so you can check length. The length of the serial must be equal to the name.

Then I "serialize" or "hash" every name that has the same length, and check if it matches the number.

This is better than doing a binary search of each possible number upon the dictionary.

Monday, April 9, 2012

Problem 75: Transformations

Failed a quite few times, as usual...

This one requires a variable-sized matrix to be rotated/flipped. I just had to check every operation in the order provided. The analysis wastes more approximately 7 times memory than mine; thus, I consider mine is better.

Friday, April 6, 2012

1.2 Problem 101: Milking Cows

I failed this, the first challenge in Section 1.2, a few times. It won't be easy to get another perfect submission, like last time.

This is basically handling timespans, and merging them. Then traverse over them to find the following:
  • The maximum timespan length, and
  • The maximum delay between timespans, but not
    • between 0 and t[0].start
    • between t[n-1].end and infinity

Monday, April 2, 2012

Problem 99: Broken Necklace

First attempt! w00t! For the last Section 1.1 too!

We're clearly supposed to brute-force every possibility.
Just traverse the maximum number of beads from each possible starting point.