| Bytes | Lang | Time | Link |
|---|---|---|---|
| 023 | Jelly | 181103T190015Z | Jonathan |
| 058 | Perl 6 | 181103T123553Z | Jo King |
| 084 | JavaScript Node.js | 181103T133242Z | tsh |
| 045 | Charcoal | 181103T125822Z | Neil |
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].
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).
Perl 6, 59 58 bytes
{6+@_,|((2,3 X*4+@_)X-(@_ X~@_)∩~<<ords "% 286
>C/")}
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.
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]
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.