Skip to main content
deleted 1418 characters in body
Source Link
Bubbler
  • 78.4k
  • 52
  • 61

Let's build a chocolate pyramid!CGAC2022 Day 1: Let's build a chocolate pyramid!

  • Preferred date: Dec 1

I've got an infinite supply of two kinds of weirdly shaped chocolate:

  • White chocolate, a square pyramid of side lengths 1
  • Dark chocolate, a regular tetrahedon of side lengths 1

To celebrate the upcoming Christmas, I want to assemble them into a giant chocolate pyramid. When the base of the pyramid is a rectangle of size \$R \times C\$, the process to build such a pyramid is as follows:

  1. Fill the floor with \$RC\$ copies of White chocolate.
  2. Fill the gaps between White chocolate with Dark chocolate.
  3. Fill the holes between Dark chocolate with White chocolate. Now the top face is a rectangle of size \$(R-1) \times (C-1)\$.
  4. Repeat 1-3 until the top face has the area of 0.

The diagram below shows the process for \$2 \times 3\$. It takes 8 White and 7 Dark chocolate to complete the first floor, and 10 White and 8 Dark for the entire pyramid.

Given the width and height of the base rectangle, how many White and Dark chocolate do I need to form the chocolate pyramid?

You may assume the width and height are positive integers. You may output two numbers in any order.

Standard rules apply. The shortest code in bytes wins.

Test cases

(width, height) -> (white, dark)
(2, 3) -> (10, 8)
(10, 10) -> (670, 660)
(10, 1) -> (10, 9)

Let's build a chocolate pyramid!

  • Preferred date: Dec 1

I've got an infinite supply of two kinds of weirdly shaped chocolate:

  • White chocolate, a square pyramid of side lengths 1
  • Dark chocolate, a regular tetrahedon of side lengths 1

To celebrate the upcoming Christmas, I want to assemble them into a giant chocolate pyramid. When the base of the pyramid is a rectangle of size \$R \times C\$, the process to build such a pyramid is as follows:

  1. Fill the floor with \$RC\$ copies of White chocolate.
  2. Fill the gaps between White chocolate with Dark chocolate.
  3. Fill the holes between Dark chocolate with White chocolate. Now the top face is a rectangle of size \$(R-1) \times (C-1)\$.
  4. Repeat 1-3 until the top face has the area of 0.

The diagram below shows the process for \$2 \times 3\$. It takes 8 White and 7 Dark chocolate to complete the first floor, and 10 White and 8 Dark for the entire pyramid.

Given the width and height of the base rectangle, how many White and Dark chocolate do I need to form the chocolate pyramid?

You may assume the width and height are positive integers. You may output two numbers in any order.

Standard rules apply. The shortest code in bytes wins.

Test cases

(width, height) -> (white, dark)
(2, 3) -> (10, 8)
(10, 10) -> (670, 660)
(10, 1) -> (10, 9)
Source Link
Bubbler
  • 78.4k
  • 52
  • 61

Let's build a chocolate pyramid!

  • Preferred date: Dec 1

I've got an infinite supply of two kinds of weirdly shaped chocolate:

  • White chocolate, a square pyramid of side lengths 1
  • Dark chocolate, a regular tetrahedon of side lengths 1

To celebrate the upcoming Christmas, I want to assemble them into a giant chocolate pyramid. When the base of the pyramid is a rectangle of size \$R \times C\$, the process to build such a pyramid is as follows:

  1. Fill the floor with \$RC\$ copies of White chocolate.
  2. Fill the gaps between White chocolate with Dark chocolate.
  3. Fill the holes between Dark chocolate with White chocolate. Now the top face is a rectangle of size \$(R-1) \times (C-1)\$.
  4. Repeat 1-3 until the top face has the area of 0.

The diagram below shows the process for \$2 \times 3\$. It takes 8 White and 7 Dark chocolate to complete the first floor, and 10 White and 8 Dark for the entire pyramid.

Given the width and height of the base rectangle, how many White and Dark chocolate do I need to form the chocolate pyramid?

You may assume the width and height are positive integers. You may output two numbers in any order.

Standard rules apply. The shortest code in bytes wins.

Test cases

(width, height) -> (white, dark)
(2, 3) -> (10, 8)
(10, 10) -> (670, 660)
(10, 1) -> (10, 9)