Skip to content

Instantly share code, notes, and snippets.

@ratatosk
ratatosk / Adj.hs
Created August 26, 2024 16:55
Mental masturbation: state monad via product-reader adjunction.
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Use =<<" #-}
{-# HLINT ignore "Use section" #-}
module Adj () where
import Data.Tuple (swap)
import Control.Monad (replicateM_)
@ratatosk
ratatosk / gist:5427242
Last active December 16, 2015 11:28
histogram water volume under waterfall
module Main where
-- for each histogram column find maximum height to the left
maxima :: [Int] -> [Int]
maxima = scanl1 max
-- fill with water. level at every column is minimum of
-- right and left maximum heights
fill :: [Int] -> [Int]
fill l = zipWith min (maxima l) (reverse $ maxima $ reverse l)
#include <stdexcept>
#include <iostream>
#include <string>
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <boost/chrono.hpp>
using boost::asio::ip::tcp;
boost::asio::io_service io;
#include <iostream>
#include <string>
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <boost/chrono.hpp>
using boost::asio::ip::tcp;
boost::asio::io_service io;
tcp::socket sock(io);