scene.org File Archive

File download

<root>­/­parties­/­2023­/­vccc23­/­christmas-diamonds/sergey_any_c_vc3-2023.zip

File size:
25 950 bytes (25.34K)
File date:
2024-01-03 14:15:18
Download count:
all-time: 1

Preview

  • diamonds.c 98B
  • diamonds.png 27.19K
  • file_id.diz.txt 1.26K

file_id.diz

VC3 Challenge - C Diamonds

Author: Sergey Kiselev
Category: Christmas Challenge
System:   Any system that can run complied C code
Language: C
Len source code: 98
Len exe file:    depends on the compiler and system, about 16 KiB on Linux/x86-64
Len code only:   depends on the compiler and system
Instructions:

Build the code using your favorite C compiler. E.g., on Linux using GCC:
$ gcc -o diamonds diamonds.c

Run the code:
$ ./diamonds

Description:
This is mostly a straight-forward implementation.

The program has two nested loops that run for 19 iterations each and scan all the
columns and rows. At each iteration of the inner loop a character - either a star
or a space are printed on the screen. At each iteration of the outer loop
a carriage return and a new line characters are printed, moving the cursor to
the next line.

The star is printed when (column-row) mod 6 == 3 or (column+row) mod 6 == 3.
To reduce the size and the complexity of the program, the starting value of
column selected in such a way, that column-row is always positive, and 3 added,
so that the modulo equations above become (column-row) mod 6 == 0 and
(column+row) mod == 0.

Comments:
I am curious to see if it can be made any smaller than that using C language...