Tomorrow, 2024-11-20, at 1930 UTC, there'll be a new episode of the #Haskell #Unfolder, on concurrency and the FFI. Edsko will explain to me what exactly the difference is between "safe" and "unsafe" FFI calls and whether safe calls are actually safe ...
https://www.youtube.com/watch?v=IMrBTx7aYjs&list=PLD8gywOEY4HaG5VSrKVnHxCptlJv2GAn7&index=36
https://www.youtube.com/watch?v=IMrBTx7aYjs&list=PLD8gywOEY4HaG5VSrKVnHxCptlJv2GAn7&index=36
Comments
My initial thought is this is a great problem to use lazy array for, where each location in the array counts how many XMAS's start from it - something like:
res =sum $ array dims
[( xy, if input xy /= 'X' then 0 else sum (countMAS'sFrom xy input)) | xy <- ...]
avoiding the O(log(N)) Data.Map overhead.
And the more I think about it, the more I realise that Repa's stencil support is perfect for this: https://hackage.haskell.org/package/repa-3.4.1.5/docs/Data-Array-Repa-Stencil-Dim2.html
andAll [i == 'A', shift I (1,1) == 'M', shift i (-1,-1) == 'S', ...]