Just adding some notes to this... On Wed, Mar 18, 2009 at 16:43:56 +0000, Eric Kow wrote: > Of course, we can't guarantee that you'll get your maximum, and we'll > try to distribute the money in an equitable fashion. The requirement > for eligibility is that you be on site and participating in darcs > development. The whole thing will be driven by the honour system.
Honour system or not, I'll also be asking you to please hold on to your receipts (just in case we have to do anything more formal). Also, I'll attach a crude calculator that I'll be using to compute the reimbursements (warning, it may have bugs), the core of which can be described by the following Haskell function: reimbursements pot [] = [] reimbursements pot (x:xs) = payment : reimbursements leftover xs where payment = min share x leftover = pot - payment share = pot / fromIntegral l l = 1 + length xs This is just a gauge, mind you. We haven't worked out exactly how to distribute these funds. My aim is for something which is simple and equitable. We'll probably decide the whole thing by consensus, if we do not reach one, then we can fall back to this code. -- Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow> PGP Key ID: 08AC04F9
import Data.Function ( on )
import Data.Char ( isSpace )
import Data.List ( intercalate, sort, zip4, sortBy )
import Data.Maybe ( fromMaybe )
import Numeric ( showFFloat )
import System.Environment ( getArgs, getProgName )
main =
do args <- getArgs
pname <- getProgName
case args of
[pot] -> interact $ go (readFloat pot)
_ -> error $ "Usage: " ++ pname ++ " max"
readL :: String -> (String, Float)
readL l =
case words l of
[n,c] -> (n, readFloat c)
_ -> oops l
readFloat f = fromMaybe (oops f) $ maybeRead f
oops c = error $ "could not read as float: " ++ c
go :: Float -> String -> String
go pot = unlines . map pretty . reimbursements pot . map readL . lines
pretty (n, c, payment, left) =
unwords [ padR 15 n, "asked for"
, showMoney c, "and gets"
, showMoney payment, ", leaving"
, showMoney left ]
where
showMoney x = padL 6 (showFFloat (Just 2) x "")
-- ----------------------------------------------------------------------
-- the main stuff
-- ----------------------------------------------------------------------
reimbursements pot = reimbursementsH pot . sortBy (compare `on` snd)
reimbursementsH pot [] = []
reimbursementsH pot ((k,x):kxs) =
(k,x,payment,leftover) : reimbursementsH leftover kxs
where
payment = min share x
leftover = pot - payment
share = pot / fromIntegral l
l = 1 + length kxs
-- ----------------------------------------------------------------------
-- odds and ends
-- ----------------------------------------------------------------------
padL n s = replicate (n - length s) ' ' ++ s
padR n s = s ++ replicate (n - length s) ' '
maybeRead :: Read a => String -> Maybe a
maybeRead s = case reads s of
[(x, rest)] | all isSpace rest -> Just x
_ -> Nothing
Alice 50 Bob 43 Charlie 138 Daniel 75 Elroy 900 Fitz 400 Gladys 400
signature.asc
Description: Digital signature
_______________________________________________ darcs-users mailing list [email protected] http://lists.osuosl.org/mailman/listinfo/darcs-users
