Should have been 1 byte less by replacing })}ې
with }){}
, but the many nested maps/loops cause a bug in 05AB1E here (})ê}
and })}€{
also doesn't work strangely enough..)
1ÝInãʒOQiyƶIô©Δ2Fø0δ.ø}2Fø€ü3}®Ā*εεÅsyøÅsM}}}˜Ùg<]εIô2Føʒà}}4FDíDø})}€êÙg
Basically the exact same approach as my answer for the related challenge, but with a single added D
uplicate (in step 4) to also remove reflections in addition to the rotations.
Extremely slow brute-force, so is only able to output up to \$a(4)\$ on TIO.
Try it online or verify the first few results.
Explanation:
Also mostly a copy-paste from my answer of the related challenge, except for step 4.
Step 1: Create all possible \$n^2\$-sized lists using 0
s and 1
s, consisting of \$n\$ amount of 1
s:
1Ý # Push pair [0,1]
In # Push the squared input
ã # Cartesian power
ʒ # Filter this list of lists by:
i # If
O # the sum of the current list
Q # is equal to the (implicit) input-integer:
# Continue with the check in step 2 below
# (implicit else: implicitly use the implicit input for the filter;
# this is only truthy for edge case n=1, which fails step 2 due to the `ü3`)
Try just this first step online (without trailing i
).
Step 2: Filter it further to only keep single polynominos, using a flood-fill approach:
y # Push the current list again
ƶ # Multiply each value by its 1-based index
Iô # Convert the list to an input-by-input block
© # Store this block in variable `®` (without popping)
Δ # Loop until the result no longer changes to flood-fill the matrix:
2Fø0δ.ø} # Add a border of 0s around the matrix:
2F } # Loop 2 times:
ø # Zip/transpose; swapping rows/columns
δ # Map over each row:
0 .ø # Add a leading/trailing 0
2Fø€ü3} # Convert it into overlapping 3x3 blocks:
2F } # Loop 2 times again:
ø # Zip/transpose; swapping rows/columns
€ # Map over each inner list:
ü3 # Convert it to a list of overlapping triplets
®Ā # Push matrix `®` and convert all its positive values back to 1s
* # Multiply each 3x3 block by this matrix of 0s/1s (so 0s will remain 0s)
εεÅsyøÅsM # Get the largest value from the horizontal/vertical cross of each 3x3 block:
εε # Nested map over each 3x3 block:
Ås # Pop and push its middle row
y # Push the 3x3 block again
ø # Zip/transpose; swapping rows/columns
Ås # Pop and push its middle rows as well (the middle column)
M # Push the flattened maximum of the entire (scoped) stack,
# which is the flattened maximum of the cross of the current 3x3 block
}} # Close the nested map
}˜ # After the flood-fill loop: flatten the block to a list
Ù # Uniquify its values
g # Pop and push its length
< # Decrease it by 1 to account for the 0s
# (only 1 is truthy in 05AB1E, so only single islands remain)
] # Close both the if-statement and filter
Try just the first two steps online.
Step 3: Convert all valid lists to matrices, and slash off any rows/columns of 0s to have the actual polynominos:
ε # Map over each inner list
Iô # Convert it to an n-by-n block
2F # Inner loop 2 times:
ø # Zip/transpose; swapping rows/columns
ʒ # Filter this list of rows by:
à # Get the maximum of the row (so if it only contains 0s, it'll be removed)
} # Close the filter
} # Close the inner loop
Try just the first three steps online.
Step 4: Remove all duplicated rotations and reflections, by first converting each polynomino to a quartet of its four sorted rotations, then get the reflection of each rotation, and then uniquify that list of octets.
4F # Inner loop 4 times:
D # Duplicate the current polynomino-matrix
í # Reverse each inner row to reflect it
D # Duplicate this new reflected polynomino-matrix again
ø # Zip/transpose the matrix; swapping rows/columns
}) # After the loop: wrap the eight rotations + reflections on the stack into a list
# Explanation if the 05AB1E bug mentioned at the top wasn't present:
{ # Sort the octet of rotations + reflections
}Ù # After the map: uniquify the list of polynomino-rotations/reflections
# Actual explanation with bug:
}€ # After the map: open a new map:
ê # Sort and uniquify each octet
Ù # After the map: uniquify the list of distinct polynomino-orientations/reflections
Try just the first four steps online.
Step 5: Get the amount of unique polynominos left, and output it as result:
g # Pop and push the length
# (which is output implicitly as result)