Kerollmops / blog

A chill and fun blog about Rust stuff and the journey of building my company: Meilisearch
https://blog.kerollmops.com/
MIT License
10 stars 1 forks source link

Fillit in C compared with the Rust version #7

Open Kerollmops opened 11 months ago

Kerollmops commented 11 months ago

The Game Rules

The Input

The program will take a list of a maximum of twenty-six Tetriminos. This list comprises a four-line Tetriminos; an empty new line separates every Tetriminos.

A Tetriminos description must respect the following rules:

Here are examples of valid Tetriminos:

....  ....  ####  ....  .##.  ....  .#..  ....  ....
..##  ....  ....  ....  ..##  .##.  ###.  ##..  .##.
..#.  ..##  ....  ##..  ....  ##..  ....  #...  ..#.
..#.  ..##  ....  ##..  ....  ....  ....  #...  ..#.

Here are examples of invalid Tetriminos:

####  ...#  ##...  #.  ....  ..##  ####  ,,,,  .HH.
...#  ..#.  ##...  ##  ....  ....  ####  ####  HH..
....  .#..  ....   #.  ....  ....  ####  ,,,,  ....
....  #...  ....       ....  ##..  ####  ,,,,  ....

As each Tetriminos occupies only four of the sixteen available squares, it's possible to describe the same Tetriminos in several ways. However, the rotation of a Tetriminos describes a different Tetriminos from the original for this game. This means no rotation is possible on a Tetriminos when arranging it with the other Tetriminos.

Those four Tetriminos are, therefore, completely distinct:

##..  .###  ....  ....  ....
#...  ...#  ...#  ....  .##.
#...  ....  ...#  #...  .##.
....  ....  ..##  ###.  ....

Find the Smallest Square

This game aims to arrange the Tetriminos to form the smallest possible square. Tetriminos are placed in the order in which they appear in the file. Of the various possible solutions for achieving the smallest square, the one where each Tetrimino is placed as far up and as far to the left as possible will be chosen.

Your program must display the smallest solution square on the standard output. To identify each Tetrimino in the solution square, you will assign an uppercase letter (starting with A) to that Tetrimino in the order they appear in the description file.

Here is a link to a valid input file and to the only expected solution. You can find a lot of different input files along with the associated solutions on the fastest program's repository.


Context

Code in Rust (still compiles after a long time). Code in C (no more compile after a long time).

Technical

Algorithm tricks

Conclusion

Talk About Other Ideas

Asking Questions