10
\$\begingroup\$

Coming from this sandbox post

This is inspired from an 8th graders math test

Intro

We have a cube with following corners

A(0, 0, 0)
B(1, 0, 0)
C(1, 1, 0)
D(0, 1, 0)
E(0, 0, 1)
F(1, 0, 1)
G(1, 1, 1)
H(0, 1, 1)

This cube clearly has 8 corners, 12 edges and 6 faces. If we now cut off corner G, such that our cut plane goes exactly through the middle of each adjacent original edge, we add 2 new corners, 3 new edges and one new face. Please enjoy this hand drawn piece of art, for better clarification

enter image description here

Input

Given a list of corners (in this example identified by A-H), that will be cut off, compute the new number of corners, edges and faces.

You make take the input in any form you like, as long as it responds to the same corners (e.g. instead of A-H you can use 1-8 or 0-7, you can assume it to be a list, csv, whatever)

You can assume the list to be distinct (every corner will appear once at most), but it may be empty. The list will never contain non existing corners.

Output

Output three numbers corresponding to the number of corners, edges and faces. Output as a list is explicitly allowed. Trailing whitespaces are allowed

Examples

{}        ->  8, 12,  6 (empty list)  
{A}       -> 10, 15,  7  
{A,C}     -> 12, 18,  8   
{A,C,F}   -> 14, 21,  9  
{A,B,C}   -> 12, 19,  9  
{A,B,C,D} -> 12, 20, 10  

Finally, this is codegolf, thus the shortest answer in bytes wins. Please refrain from standard loopholes.

\$\endgroup\$
7
  • 2
    \$\begingroup\$ Interesting... So cutting off adjacent corners will mean they share one corner, and eliminate one edge? This is more complex than it seems at first \$\endgroup\$
    – Jo King
    Nov 3, 2018 at 11:57
  • \$\begingroup\$ Since imgur being blocked in Turkey, I can not see the image. Can you please send an alternate image link \$\endgroup\$ Nov 3, 2018 at 11:57
  • \$\begingroup\$ @JoKing yes that is correct. \$\endgroup\$ Nov 3, 2018 at 12:06
  • \$\begingroup\$ @WindmillCookies I'm sorry, I didn't know that. I've used a different host now. \$\endgroup\$ Nov 3, 2018 at 12:36
  • 2
    \$\begingroup\$ For example, may I use 0 for A, 1 for C, 2 for B, 3 for D, 4 for E, 5 for G, 6 for F, 7 for H? Or should I keep the order of ABCDEFGH? \$\endgroup\$
    – tsh
    Nov 3, 2018 at 13:14

4 Answers 4

2
\$\begingroup\$

Jelly, 23 bytes

3R×L+“©®€‘ɓŒcn/€§ċ1;`Żạ

A monadic Link. Input is a list of corners of the cube as Cartesian co-ordinates (cube aligned with the co-ordinate system). Output is a list of integers, [faces, corners, edges].

Try it online!

How?

3R×L+“©®€‘ɓŒcn/€§ċ1;`Żạ - Link: list of lists, C          e.g. [[0,1,1],[1,1,0],[1,1,1],[0,0,0]] -- this could represent "FHGA"
3R                      - range of 3                           [1,2,3]
   L                    - length of C                          4
  ×                     - multiply                             [4,8,12]
     “©®€‘              - list of code-page indices            [6,8,12]
    +                   - add                                  [10,16,24]
          ɓ             - start a new dyadic chain, f(C,X) where X is the above result
           Œc           - pairs of C                           [[[0,1,1],[1,1,0]],[[0,1,1],[1,1,1]],[[0,1,1],[0,0,0]],[[1,1,0],[1,1,1]],[[1,1,0],[0,0,0]],[[1,1,1],[0,0,0]]]
              /€        - reduce €ach with:
             n          -   (vectorising) not equal?           [[1,0,1],[1,0,0],[0,1,1],[0,0,1],[1,1,0],[1,1,1]]
                §       - sum each                             [2,1,2,1,2,3]
                 ċ1     - count ones                           2
                   ;`   - concatenate with itself              [2,2]
                     Ż  - prepend a zero                       [0,2,2]
                      ạ - absolute difference with X           [10,14,22]

If the corners must be "ordered" as they are in the question then this works with integers 0-7 as A-H for 25 bytes: 3R×L+“©®€‘ɓŒc^/€ḟ2<5S;`Żạ (reduces using XOR, filters out twos, then counts those less than five).

\$\endgroup\$
2
\$\begingroup\$

Charcoal, 48 45 bytes

≔Eθ↨℅ι²η≔⊘№⭆η⭆ηΣEι↔⁻§λξν1ηIE⟦⁶⁻⁸η⁻¹²η⟧⁺ι×⊕κLθ

Try it online! Link is to verbose version of code. Uses digits 0-7 to represent the letters ABDCEFHG in the diagram. Outputs in the order faces, corners, edges. Explanation:

≔Eθ↨℅ι²η

Take the ASCII code of each character and convert it to base 2.

≔⊘№⭆η⭆η

Take the cartesian product of the list of base 2 numbers with itself.

ΣEι↔⁻§λξν1η

XOR the pairs of base 2 numbers together and sum the number of 1 bits. Count how many pairs have a sum of 1 and divide that by 2. This gives the number of coincident corners.

IE⟦⁶⁻⁸η⁻¹²η⟧⁺ι×⊕κLθ

Calculate and print the number of faces, corners and edges.

\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 84 bytes

a=>[a.map(u=>a.map(v=>j-=!!'ABCDAEFGHEFBCGHD'.match(u+v),n++,j+=2),n=j=6)|2+j,n+j,n]

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Perl 6, 59 58 bytes

{6+@_,|((2,3 X*4+@_)X-(@_ X~@_)∩~<<ords "% 286
>C/")}

Try it online!

Uses the numbers 0 to 7 to represent the corners. I probably should have matched them up to the same order as in the question... oops? Outputs a list in the order faces, corners, edges.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.