# # Lenny Conundrum Round 287 # http://www.neopets.com/games/conundrum_feature.phtml?round=287 # # To celebrate Neopets's birthday, a huge cake was made. It was a three-tiered # cake, and each tier had three layers. The first tier had a total diameter of # 12 inches, the second had a total diameter of 10.5 inches, and the third had # a total diameter of 9 inches. Each layer of cake was 1.5 inches thick. Each # tier was frosted on the top and sides with one-third of an inch thickness of # frosting, frosted in such a way that each tier is a perfect cylinder. Within # each tier, a one-quarter-inch thick layer of jam separated each of the # layers. # # If the frosting weighs 0.48 ounces per cubic inch, and the cake weighs 0.35 # ounces per cubic inch, and the jam weighs 0.60 ounces per cubic inch, and # everything has 53.4 calories per ounce, how many calories are in the entire # cake? Please round to the nearest whole calorie. # use strict; use warnings; use Math::Trig qw( pi ); my @tot_d = ( 12, 10.5, 9 ); my $cake_thick = 1.5; my $jam_thick = 1/4; my $frost_thick = 1/3; my $cake_density = 0.35; my $jam_density = 0.60; my $frost_density = 0.48; my $cal_per_ounce = 53.4; my $tot_cal = 0; for my $tot_d (@tot_d) { # |----- tot_d -----| # |- inner_d -| # ___________ # / _______ \ # / / \ \ Top view # / / \ \ # / / \ \ # | | | | # \ \ / / # \ \ / / # \ \_______/ / # \___________/ my $tot_r = $tot_d/2; my $inner_r = $tot_r - $frost_thick; my $tot_a = pi * $tot_r * $tot_r; my $inner_a = pi * $inner_r * $inner_r; my $outer_a = $tot_a - $inner_a; my $cake_h = 0; my $jam_h = 0; my $ifrost_h = 0; my $ofrost_h = 0; $_ += $frost_thick for $ofrost_h, $ifrost_h; $_ += $cake_thick for $ofrost_h, $cake_h; $_ += $jam_thick for $ofrost_h, $jam_h; $_ += $cake_thick for $ofrost_h, $cake_h; $_ += $jam_thick for $ofrost_h, $jam_h; $_ += $cake_thick for $ofrost_h, $cake_h; my $cake_v = $inner_a * $cake_h; my $jam_v = $inner_a * $jam_h; my $frost_v = $inner_a * $ifrost_h + $outer_a * $ofrost_h; my $cake_w = $cake_v * $cake_density; my $jam_w = $jam_v * $jam_density; my $frost_w = $frost_v * $frost_density; my $tier_w = $cake_w + $jam_w + $frost_w; my $cake_c = $cake_v * $cake_density; my $jam_c = $jam_v * $jam_density; my $frost_c = $frost_v * $frost_density; my $tier_cal = $tier_w * $cal_per_ounce; $tot_cal += $tier_cal; } printf("%.0f\n", $tot_cal); # 29508