Everybody Codes is another programming puzzle site, much like Advent of Code. I thought I'd have a go at them. Each "quest" is a set of three connected puzzles that increase in difficulty. From the first few days, it seems that they three parts of each quest are very similar, but of increasing difficulty; each has its own data. That's different from Advent of Code, where the second part of a puzzle uses the same data in a different way.

Anyway, onto quest 1.

This is about arranging pine cones in different square-based shapes (a square, a hollow square, a slightly hollow square). For the first puzzle, about squares, you are given a number of pine cones. You have to determine how many more you need to make a compete square. For instance, if you have six pine cones, you need another three to make a three-by-three square.

I did this directly, making an infinite sequence of sizes of the various shapes.

conesForSquares, conesForFrames, conesForFilledFrames :: [Int]
conesForSquares = [ n ^ 2 | n <- [1, 2..]]
conesForFrames = [ n ^ 2 - (n - 2) ^ 2 | n <- [3, 4..]]
conesForFilledFrames = [ n ^ 2 - 1 | n <- [3, 5..]]

To count the missing cones to make the next shape in whatever sequence, I drop all the shapes that are smaller than the number of pine cones I have, and find the difference between the number I have and the next full shape.

countMissing :: [Int] -> Int -> Int
countMissing ks n = k - n
  where k = head $ dropWhile (< n) ks

Solving all three parts is then just plumbing.

main :: IO ()
main = 
  do  text1 <- readFile "../data/everybody_codes_e2026_q01_p1.txt"
      let instructions1 = fmap read $ splitOn "," text1 
      text2 <- readFile "../data/everybody_codes_e2026_q01_p2.txt"
      let instructions2 = fmap read $ splitOn "," text2
      text3 <- readFile "../data/everybody_codes_e2026_q01_p3.txt"
      let instructions3 = fmap read $ splitOn "," text3
      print $ fillMissing conesForSquares instructions1
      print $ fillMissing conesForFrames instructions2
      print $ fillMissing conesForFilledFrames instructions3

fillMissing :: [Int] -> [Int] -> Int
fillMissing ks instructions = sum $ fmap (countMissing ks) instructions

Code

You can get the code from Codeberg. or on my self-hosted Git site.