file_id.diz
Snowflake in a modern programming language, based on matrix operations and symmetry
Author: Mira
Category: Christmas Challenge
System: PC
Language: Julia
Len source code: 367
Len exe file: -
Len code only: -
Instructions:
You need to have Julia installed on your PC: https://julialang.org/downloads/
Run Julia in Terminal.
Run "include" function in Julia with an file path to the .jl source code. Backslashess need to be escaped by doubling.
Example: include("C:\\GitHub\\ChristmasChallenge2025\\julia\\vccc2025-modern-julia.jl")
Description:
This is NOT a vintage computing. Actually, it is an attempt to solve the same challenge in a modern programming language.
I took advantage of the snowflake having plenty of symmetries and Julia having good support for matrix operations that
can easily implement building symmetric objects out of their parts.
To create and store the snowflake's shape, I use a 19x19 matrix of boolean values.
Initially, all elements are set to false (or zero).
m = zeros(Bool, 19, 19)
Then, I draw one octant of the snowflake to the matrix.
Namely, this one (if you are a pilot, it is the one between 3:00 and 4:30 on the clock).
* * * * * * * * * *
* * *
* * *
*
*
* * *
*
*
By "drawing", I mean setting the respective entries of the matrix to true (or one).
As can be seen above, the shape of the octant can be drawn by five lines, two horizontal, three going 45 degrees down.
Therefore, I created "line" function that receives the matrix to be modified,
x and y coordinates of the starting point of the line, the length of the line
(technically it is number of steps, or asterisks to be printed),
and whether or not the line is horizontal (yIncr=0), or going 45 degrees down (yIncr=1).
To save code, the "line" method assumes that coordinates 0,0 are at the centre of the matrix. Therefore,
it adds 10 to both x and y coordinates.
function line(m, x, y, steps, yIncr)
for i in 0:steps-1
m[10 + y + i*yIncr, 10 + x + i] = true
end
end
To draw the 5 lines, I use this code:
line(m, 0, 0, 10, 0)
line(m, 3, 0, 3, 1)
line(m, 6, 0, 3, 1)
line(m, 1, 1, 7, 1)
line(m, 6, 5, 2, 0)
Note: 0, 0, corresponds with the upper left asterisk of the octant.
Then I translated the octant to the remaining 7 octants.
I did it by "or-ing" the matrix with a matrix that is a transformed version of it in three separate steps.
Step 1: or-ing the matrix with a transposed matrix
m .|= transpose(m)
Step 2: or-ing the matrix with a matrix rotated 90 degrees left
m .|= rotl90(m)
Step 3: or-ing teh matrix with a matrix rotated 180 degrees
m .|= rot180(m)
Now the matrix contains the full shape of the snowflake.
However, it still use only boolean values, not actuall asterisk symbols.
So, the final step is to map false to ' " and true to "* " and display it. To allow good formatting,
namely not separate matrix values with comma, I concatenated all such strings in the same row to one
using reduce function (Julia uses * symbol for concatenation).
display(reduce(*, map(x -> x ? "* " : " ", m), dims=2))
Note: I map each boolean value to 2 characters because of the aspect ratio of usual text displays.
Comments:
Thank you very much for this awesome competetion!