Determine the type of Cuboid

17

1

Introduction:

I'm a twisty puzzles collector. Here you can see my current collection of ± 300 puzzles.

I think everyone knows the regular Rubik's Cube (3x3x3 Cube), which is a NxNxN Cube. There are also Cuboids (block-shaped puzzles), which come in different forms, perhaps better explained by SuperAntionioVivaldi here:

  • Regular Domino Cuboids (like the 2x2x3; 2x3x3; 3x3x4; etc.) - They come in the form of NxNx(N+O) or Nx(N+O)x(N+O), which have either two odd dimensions and an even, or two even and an odd.
  • Shapeshifter Cuboids (like the 2x2x4; 3x3x5; 3x3x9; 4x4x6; etc.) - They come in the form of NxNx(N+P), which as the name suggests, shapeshifts (in all directions). All three dimensions are either odd or even.
  • Floppy Cuboids (like the 1x3x3; 2x4x4; etc.) - They come in the form of Nx(N+P)x(N+P), which are almost the same as the Shapeshifters, but with so-called Floppy Parities.
  • Brick Cuboids (like the 2x3x4; 3x4x5; 2x3x5; etc.) - They come in the form of Nx(N+O)x(N+P), which just like the Regular Domino Cuboids have either two odd dimensions and an even, or two even and an odd; but don't have any of the same dimensions.
  • Ultimate Shapeshifters (like the 2x4x6; 3x5x7; 2x4x10; etc.) - They come in the form of Nx(N+O)x(N+R), and shapeshift in any direction. All three dimensions are either odd or even; but don't have any of the same dimensions.

Challenge:

Input:

A positive integer n with the following restriction: 8 <= n <= 125.
n can be uniquely decoded as the product of three values (the dimensions), of which each is between 2 and 5 inclusive.

The reason I've restricted it to 2-5 is to prevent duplicated inputs (like 1x2x4 = 8 and 2x2x2 = 8), even though there are many lower/higher order Cuboids out there. This also means there are no test cases for Ultimate Shapeshifters.

Output / Test cases:

These are all the cases your program/function should support, ranging from edge lengths 2 through 5 in every possible three-dimensional configuration:

Input   Cuboid/Cube   Type/Output
8       2x2x2         Cube
12      2x2x3         Regular Domino Cuboid
16      2x2x4         Shapeshifter Cuboid
20      2x2x5         Regular Domino Cuboid
18      2x3x3         Regular Domino Cuboid
24      2x3x4         Brick Cuboid
30      2x3x5         Brick Cuboid
32      2x4x4         Floppy Cuboid
40      2x4x5         Brick Cuboid
50      2x5x5         Regular Domino Cuboid
27      3x3x3         Cube
36      3x3x4         Regular Domino Cuboid
45      3x3x5         Shapeshifter Cuboid
48      3x4x4         Regular Domino Cuboid
60      3x4x5         Brick Cuboid
75      3x5x5         Floppy Cuboid
64      4x4x4         Cube
80      4x4x5         Regular Domino Cuboid
100     4x5x5         Regular Domino Cuboid
125     5x5x5         Cube

Challenge rules:

  • Any non-Cube/non-Cuboid input within the 8-125 range should result in 'none' as output.
  • The output format is your own choice. I think the most reasonable is integers, like 0 = 'none'; 1 = Cube; 2 = Regular Domino Cuboid; 3 = Shapeshifter Cuboid; 4 = Floppy Cuboid; 5 = Brick Cuboid. Any other output format is also fine, as long as you specify which one you've used.

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
  • Default Loopholes are forbidden. (NOTE: Since I don't know if there is a smart formula for the input-to-output conversion, it is allowed to hardcode the answers based on the input.)
  • If possible, please add a link with a test for your code.
  • Also, please add an explanation if necessary.

Kevin Cruijssen

Posted 2017-02-08T09:33:19.003

Reputation: 67 575

2Been in the sandbox since October 2016. – Kevin Cruijssen – 2017-02-08T09:35:18.397

1There is no helicopter cube in your collection? – G B – 2017-02-08T11:24:57.063

@GB Nope. I do have a Curvy Copter, Curvy Copter Plus, Curvy Copter III, Curvy Chop Cube, Helicopter Dodecahedron and custom-made Super Truncated Curvy Copter III, but no Helicopter Cube. :) It's a bit too similar to the Curvy Copter, but I might get it some day. – Kevin Cruijssen – 2017-02-08T13:30:57.387

Is the input sorted? or do we have to sort manually? – Matthew Roh – 2017-02-08T13:45:25.040

@MatthewRoh The input is a single integer (i.e. 24), so I don't know what you want to sort about it? – Kevin Cruijssen – 2017-02-08T14:45:03.117

Oh. Nevermind. I didnt see that part. – Matthew Roh – 2017-02-08T16:05:11.917

Answers

6

05AB1E, 26 21 bytes

None: 0 Cube: 1 Regular Domino Cuboid: 2 Shapeshifter Cuboid: 3 Brick Cuboid: 4 Floppy Cuboid: 5

•S3X@I¨%÷'•5L¦3ãPÙIkè

Try it online! or as a Test suite

Explanation

•S3X@I¨%÷'•            # push base-214 compression of the number 123224454212324512210
           5L¦         # push the list [2,3,4,5]
              3ã       # cartesian product with repetion of size 3
                P      # product of each sublist
                 Ù     # remove duplicates
                  Ik   # get the index of input in that list (-1 if non-existant)
                    è  # get the element at this index in the above number

The only place I see that we could save bytes here is find a better way of generating the number 123224454212324512210.

It is only 1-off from a prime, so one possible save would be to find the index of that prime and generate the index in less than 9 bytes.
I don't know how well the pi-function works for 21-digit primes but that could be a possibility.

Emigna

Posted 2017-02-08T09:33:19.003

Reputation: 50 798

Nice, I'm curious for that explanation to see what formula/quirk/pattern you've used to determine the Cube/Cuboid. +1 – Kevin Cruijssen – 2017-02-08T10:20:05.293

1@KevinCruijssen: I might be able to save a byte or two still. I'll add the explanation after I've given that a try. I have a prime I want to find the order of (but I haven't found anything online to help me with that and I'm at work so I don't really have time to implement something myself :) – Emigna – 2017-02-08T10:22:49.933

@Emigna jeebus creezy, how long has k existed?!!??!?!?!?! – Magic Octopus Urn – 2017-02-08T13:53:27.270

@carusocomputing Since December 30, 2015. – Adnan – 2017-02-08T14:15:41.747

3

JavaScript (ES6), 97 92 86 bytes

This function first checks the validity of the input, then picks the correct value from a lookup table.

Surprisingly, the longest part is the validity check (is n of the form x*y*z with x, y and z in [2,3,4,5]?). There must be a shorter way of doing it, but I couldn't figure it out so far.

n=>'NBBF..CRCC.BRR..SFRRRRR.B..C'[[34707324,0x80000800,4240,262208][n&3]>>n/4&1&&n%29]

Returns a character:

  • N: None
  • C: Cube
  • R: Regular Domino Cuboid
  • S: Shapeshifter Cuboid
  • B: Brick Cuboid
  • F: Floppy Cuboid

Test

let f =

n=>'NBBF..CRCC.BRR..SFRRRRR.B..C'[[34707324,0x80000800,4240,262208][n&3]>>n/4&1&&n%29]

// invalid
;[9,13,99].map(
  n => { console.log(n, f(n)) }
)

// valid
;[8,12,16,20,18,24,30,32,40,50,27,36,45,48,60,75,64,80,100,125].map(
  n => { console.log(n, f(n)) }
)

Arnauld

Posted 2017-02-08T09:33:19.003

Reputation: 111 334

1

Ruby, 106 98 96 bytes

->n{[[x=25,2421],[15,53],[9,21],[4,1232504350200510002]].any?{|a,b|n%a<1&&x="00#{b}"[n/a]}?x:?0}

Because, why not, hardcoding.

As specified, 0 = 'none'; 1 = Cube; 2 = Regular Domino Cuboid; 3 = Shapeshifter Cuboid; 4 = Floppy Cuboid; 5 = Brick Cuboid

G B

Posted 2017-02-08T09:33:19.003

Reputation: 11 099

1

Perl 6, 69 58 bytes

{%(unique([X*] (2..5)xx 3)Z=>:32<AM0K21IHN61H5>.comb){$_}}

Uses the integer output format suggested in the task description, except that it returns the uninitialized value (Any) instead of 0 in case of inputs that don't form a valid cube/cuboid.

How it works

  1. unique([X*] (2..5)xx 3)

    Generates the list 8 12 16 20 18 24 30 32 40 50 27 36 45 48 60 75 64 80 100 125.

  2. :32<AM0K21IHN61H5>.comb

    Generates the list 1 2 3 2 2 5 5 4 5 2 1 2 3 2 5 4 1 2 2 1 (from a base-32 literal).

  3. %(   Z=>   )

    Generates a Hash (associative map) with the first list as the keys, and the second list as the values.

  4.    {$_}

    Indexes the Hash with the input number..

smls

Posted 2017-02-08T09:33:19.003

Reputation: 4 352

Heh, I see now that I've used the same approach as @Emigna's 05AB1E answer. But I came up with it independently, honest! :) – smls – 2017-02-09T15:07:33.837

1

Batch, 163 bytes

@set/as=0,c=29948521
@for /l %%i in (2,1,5)do @for /l %%j in (%%i,1,5)do @for /l %%k in (%%j,1,5)do @set/as+=c%%6*!(%%i*%%j*%%k-%1),c/=6,c+=14081593*!c
@echo %s%

Uses the suggested output format. Explanation: The basic idea is to loop over the list of cubes as defined in the question. For each cube, we calculate to see if its volume is the input integer, and if so, calculate the type of cube from a lookup table.

The original lookup table was a string of letters, but doing string manipulation in a for loop is tricky, so I switched to digits which can be extracted arithmetically. Sadly Batch is limited to 32-bit integers so I couldn't fit all of the digits into a single variable (even in base 5 you can only get 13 digits) so instead I split the variable up into two parts, encoded in base 6 for convenience. 29948521 is 2545522321 in base 6 which encodes the 10 smallest cuboids in reverse order; when it runs out of digits we add 14081593 which is 1221452321 in base 6 encoding the 10 biggest cuboids.

Neil

Posted 2017-02-08T09:33:19.003

Reputation: 95 035