Monday, January 3, 2022

Algorithmic Thinking Snowflake Problem

The challenge in this problem is to identify identical snowflakes even when the data about the snowflakes are stored in the same sequence but in a different orientation. In this problem, snowflakes have six arms of lengths varying from 1 to 6. The snowflakes are randomly generated so one snowflake may have arms represented by [1, 2, 3, 4, 5, 6] and an identical snowflake have arms of [3, 4, 5, 6, 1, 2]. These are a match. These snowflakes are identical but were generated with different orientations. A snowflake with arms of [2, 1, 3, 4, 5, 6] is not a match because its arms, even though of the same lengths, do not occur in a sequence that can be made to match the first two.

In the function makeSnowflakes() my solution generates 2000 snowflakes as the problem set. Then in searchArrayForMatches() and identifyIdentical() the program compares each arm of each snowflake to the arms of every other snowflake.

I wrote and tested this in Xcode, the Mac IDE.

Caveat: I've coded very little C and it probably shows.

Program Output

. . .
match 1749 1824 
3 2 6 5 5 3 
5 3 3 2 6 5
match 1759 1859 
3 3 6 6 5 1 
3 6 6 5 1 3
match 1776 1900 
4 4 5 2 4 5 
2 4 5 4 4 5
match 1860 1905 
6 5 2 3 4 6 
6 5 2 3 4 6
match 1915 1977 
3 1 1 1 5 4 
1 1 1 5 4 3
match 1998 1999 
1 6 3 2 6 1 
6 1 1 6 3 2
Number Matched 244
Program ended with exit code: 0