Advent-of-Nix-2024/day9/ideas.nix
2024-12-09 14:55:22 +01:00

34 lines
1.1 KiB
Nix

# compress = files: let
# compressionHead = head files;
# compressionTail = last files;
# tailContentLen = length compressionTail.content;
#
# toPop = max compressionHead.freeAfter tailContentLen;
#
# newCompressionHead = {
# content = compressionHead.content ++ (takeTail toPop compressionTail.content);
# freeAfter = compressionHead.freeAfter - toPop;
# };
#
# newTail = {
# content = dropTail toPop compressionTail.content;
# freeAfter = compressionTail.freeAfter + toPop;
# };
#
# newTail' = let second_to_last = last (init files); in{
# inherit (second_to_last) content;
# freeAfter = second_to_last.freeAfter ++ newTail.freeAfter;
# };
#
# reducedRight = if newTail.content != [] then (dropTail 1 (tail files)) ++ [ newTail ] else (dropTail 2 (tail files)) ++ [ newTail' ];
#
# in if length files <= 1 then
# files
# else if compressionHead.freeAfter == 0 then
# [ newCompressionHead ] ++ (compress reducedRight)
# else
# compress ([newCompressionHead] ++ reducedRight );
# link_disk = fs:
# disk_linked =