beercode20150806/README.md

48 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

2015-08-06 20:24:40 +00:00
# Purpose
2015-08-06 20:40:14 +00:00
This was a résumé test question given to someone else, who had brought
it to the August 7th, 2015 Beer && Coding, in the hopes that we would
help him solve it. We were not successful, although I did get pretty
far on my own with a solution written in Scheme.
2016-07-23 00:15:53 +00:00
# Status
This code is **complete**. It is not being maintained.
2016-07-23 00:16:28 +00:00
# Description
2015-08-06 20:40:14 +00:00
The problem stated was:
Given a number (assume base 10) less than 10,000, write a program in
C++ that will reverse the digits of that number, calculate the
original number to the power of the new number, and print it out.
You may not use Boost, GMP, or any library other than that provided
2015-08-06 20:40:14 +00:00
by the C++ Standard Library.
I don't know C++. I haven't ever written C++ profesionally, and I
haven't actually *looked* at C++ since 1999 or so. As a professional,
I'm aware of what's going on in the zeitgeist, and at my job at Spiral
Genetics I interacted with two very talented C++ developers a lot, so I
was aware of things like the emerging C++ Standard Library and RAII and
so forth. I didn't know what they *meant*, but I had heard of them.
I've also been aware of the emerging standards in C++11 and C++14,
mostly thanks to Slashdot, Hacker News, and their ilk (don't read the
comments, don't **ever** read the comments), so I'd *heard* about
auto_ptr and C++11 lambdas and the like.
2015-08-06 20:40:14 +00:00
It took about an hour of googling to get up to speed on things like
namespaces, containers, for_each, lambdas, and the like. I really like
the new unique\_ptr construction. That's very nice.
My basic solution degrades to 4th-grade mathematics: Break the
multiplicand up into a list of single digits, multiply each digit
with the multiplier, then redistribute the values up the tens, hundreds,
etc., etc. This solution is not particularly fast or space-efficient,
2015-08-06 20:40:14 +00:00
but it has the virtue of being comprehensible by any ten-year-old.
2015-08-06 20:24:40 +00:00
As usual, I've provided a test suite, as well as a pair of utility
functions for converting the list to a string, or an unsigned long. The
latter only works with very small results. The executable, "cheapgmp",
works as specified in the problem statement.
2015-08-06 20:24:40 +00:00