Ad
  • Custom User Avatar

    I don't think there's anything secret in there. Here it is:

    {-# Language RankNTypes #-}
    
    module Preloaded ( List(List), foldr
                     , Number, zero, Preloaded.succ, Preloaded.pred, plus, times
                     , Boolean, (?), true, false, or, and, not
                     , Option, option, nothing, just, fmap
                     , Pair, uncurry, pair, fst, snd, first, second, both, double
                     , ($), undefined, undefinedHelper
                     ) where
    
    import Prelude (Word,succ,pred,(+),(*),(.),($),errorWithoutStackTrace,(<>),String)
    
    newtype List a = List { foldr :: forall z. (a -> z -> z) -> z -> z }
    
    type Number = Word
    
    zero :: Number -> Boolean
    zero 0 = true
    zero _ = false
    
    succ,pred :: Number -> Number
    succ 18446744073709551615 = 18446744073709551615
    succ x = Prelude.succ x
    pred 0 = 0
    pred x = Prelude.pred x
    
    plus,times :: Number -> Number -> Number
    plus = (+)
    times = (*)
    
    newtype Boolean = Boolean { (?) :: forall a. a -> a -> a }
    
    true,false :: Boolean
    true = Boolean $ \ t _ -> t
    false = Boolean $ \ _ f -> f
    
    or,and :: Boolean -> Boolean -> Boolean
    or x y  = x ? x $ y
    and x y = x ? y $ x
    
    not :: Boolean -> Boolean
    not x = x ? false $ true
    
    newtype Option a = Option { option :: forall z. z -> (a -> z) -> z }
    
    nothing :: Option a
    nothing = Option $ \ z _ -> z
    
    just :: a -> Option a
    just a = Option $ \ _ fn -> fn a
    
    fmap :: (a -> b) -> Option a -> Option b
    fmap f x = option x nothing (just . f)
    
    newtype Pair a b = Pair { uncurry :: forall z. (a -> b -> z) -> z }
    
    pair :: a -> b -> Pair a b
    pair a b = Pair $ \ fn -> fn a b
    
    fst :: Pair a b -> a
    fst pair = uncurry pair $ \ a _ -> a
    
    snd :: Pair a b -> b
    snd pair = uncurry pair $ \ _ b -> b
    
    first :: (a -> z) -> Pair a b -> Pair z b
    first f pair = Pair $ \ g -> g (f $ fst pair) (snd pair)
    
    second :: (b -> z) -> Pair a b -> Pair a z
    second f pair = Pair $ \ g -> g (fst pair) (f $ snd pair)
    
    both :: (a -> z) -> Pair a a -> Pair z z
    both f = double f f
    
    double :: (a -> x) -> (b -> y) -> Pair a b -> Pair x y
    double f g pair = Pair $ \ h -> h (f $ fst pair) (g $ snd pair)
    
    undefined :: error
    undefined = errorWithoutStackTrace "undefined"
    
    undefinedHelper :: String -> error
    undefinedHelper name = errorWithoutStackTrace $ "undefined: " <> name
    
  • Custom User Avatar

    How can I get the Preloaded.hs to run / implement all locally first?

  • Custom User Avatar

    removed random tests from example tests. should have done that after copying them over before publishing.

    we apologise for the inconvenience.

  • Custom User Avatar
  • Custom User Avatar

    Haskell update

  • Custom User Avatar

    getting

    ReferenceError: rndList3 is not defined
        at Context.<anonymous> (file:///workspace/test.js:22:18)
        at processImmediate (node:internal/timers:464:21)
    

    in the random tests of the sample tests

  • Custom User Avatar

    Python forked and approved. I'll check invalidated solutions in a bit.

    ETA: yep, apparently no Python solutions were harmed by the fork ( some are now valid again actually )

  • Custom User Avatar

    self-approved because I need the description update

  • Custom User Avatar

    JavaScript translation

  • Custom User Avatar

    If it were work, I'd need another hobby :]

  • Custom User Avatar

    That would be great - thanks! (You really should get paid for all this.)

  • Custom User Avatar

    OK, I'll do that. Two forks and two translations coming up.

  • Custom User Avatar

    I'm willing to modify the code for you ( both Python and Haskell ). That should not invalidate existing solutions.

    I was doing the JS translation, and I was planning an LC translation as well. Writing a bit more code is not a problem.

  • Custom User Avatar

    Some solutions rely on the falsiness of the first element to fail the limit.

    Either the description should specify non-negative numbers, or there should be a test

    Test.assertEquals(smallEnough([-3,-2,-1,0], -1), false);
    

    This would invalidate the top voted solution, and make only a single solution possible ( typical golf kata .. :[ ).

  • Custom User Avatar

    If we are to remove "faster than O(n²)", do you still want biased random testing at all?

    Not really, but at this point, I don't want to go back and start modifying the code, particularly because there have been multiple solutions and the Haskell translation.

    I'd prefer "Five random ( but mostly left-leaning ) trees of 150,000 nodes"

    My concern with this wording is that the reader will be somewhat mystified by why the trees are left=leaning, and I don't think the description is the right place to try to explain that.

  • Loading more items...