Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Scheme/DrRacket

Name: Anonymous 2013-01-10 13:28

How do I write a function that takes any integers in a list and produces the number of values in the list whose one's digit (i.e. the least significant or rightmost digit) is 1. For example,
(ones (list 82 231 1 22 1000)) => 2?

Name: Anonymous 2013-01-10 13:31

read SICP

Name: Anonymous 2013-01-10 13:50

Symta:

yoba Xs = Xs | m (? | digits 10 | rhd) | k 1 | sum

//usage:
yoba [82 231 1 22 1000] // gives 2

Name: Anonymous 2013-01-10 13:53


ones :: Integral a => [a] -> Int
ones = foldr step 0
    where step x z | x `mod` 10 == 1 = succ z
                   | otherwise = z

Name: Anonymous 2013-01-10 13:53


ones :: Integral a => [a] -> Int
ones = foldr step 0
    where step x z | x `mod` 10 == 1 = succ z
                   | otherwise = z

Name: Anonymous 2013-01-10 13:56

>>5>>4

Lisp                        | Haskell
----------------------------|---------------------------------------------------
reduce                      | fold, foldl, foldr, foldl',
                            | foldr1, foldl1, foldl1...
----------------------------|---------------------------------------------------
map                         | map, mapM, mapM_, mapAccumL, mapAccumR, mapAccum,
                            | mapAndUnzipM, mempty, mappend, mapAccumRWithKey,
                            | mapAccumWithKey, mapMaybe, mapMaybeT mapEither,
                            | mapEitherWithKey, mapMaybeWithKey, mapFst, mapSnd,
                            | mapIndices, mapArray, mapListT, mapMonotonic,
                            | concatMap, amap, ixmap...
----------------------------|---------------------------------------------------
elt                         | fst snd thd fth ffth...

Name: Anonymous 2013-01-10 13:58

>>6

Lisp   | Haskell
-------|------------------------------------------------------------------------
lambda | inference, lambda cube, strongly normalizing, equality-qualified types,
       | algebraic types, existential types, phantom types, dependent types,
       | higher-kinded types, linear types, inductive types, unique types,
       | nominal types, recursive types, type classes, bounded quantification,
       | type annotations, principal types, higher-order abstract syntax,
       | generalized algebraic types, robinson unification, hindley-milner,
       | constrained types, polymorphic recursion, parametric polymorphism,
       | equivalence classes, type order, judgments, curry-howard isomorphism,
       | system t, system f, products, coproducts, categorial sum, call-by-name,
       | inhabited types, higher-rank impredicative polymorphism, covariance,
       | subtype polymorphism, ad-hoc polymorphism, predicative types,
       | signatures types, contravariance, affine types, structural subtyping...

Name: Anonymous 2013-01-10 14:00

>>7

Lisp             | Haskell
-----------------|--------------------------------------------------------------
Prefix notation. | flip flip snd . (ap .) . flip flip fst . ((.) .) . flip .
                 | (((.) . (,)) .) (`ap` snd) . (. fst) . (flip =<< (((.) .
                 | (,)) .)) (`ap` snd) . (. fst) . flip
                 | (. ((. ((. return) . (:))) . (.) . (:))) . (.) . (.) . (:)

Name: Anonymous 2013-01-10 14:03

>>8
Lisp:

(ask-password ()
  (say "Insert your new password:")
  (match (read-line)
    (valid-password? (say "Storing in database")
                     It)
    (otherwise (ask-password))))



Haskell (http://en.wikibooks.org/wiki/Haskell/Monad_transformers):

newtype (Monad m) => MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }

instance Monad m => Monad (MaybeT m) where
    return  = MaybeT . return . Just

instance Monad m => MonadPlus (MaybeT m) where
    mzero     = MaybeT $ return Nothing
    mplus x y = MaybeT $ do maybe_value <- runMaybeT x
                            case maybe_value of
                                 Nothing    -> runMaybeT y
                                 Just value -> runMaybeT x
 
instance MonadTrans MaybeT where
    lift = MaybeT . (liftM Just)



getValidPassword :: MaybeT IO String
getValidPassword = do s <- lift getLine
                      guard (isValid s)
                      return s
 
askPassword :: MaybeT IO ()
askPassword = do lift $ putStrLn "Insert your new password:"
                 value <- getValidPassword
                 lift $ putStrLn "Storing in database..."

Name: Anonymous 2013-01-10 14:04

>>7

Haskell doesn't have subtype polymorphism and can only emulate dependent types. Unique types are in Clean, but not Haskell. And I don't think haskell has the principle type property.

Name: Anonymous 2013-01-10 14:06



shift :: ((a -> r) -> Cont r r) -> Cont r a
shift e = cont $ \k -> reset (e k)

reset :: Cont a a -> a
reset e = e `runCont` id


in lisp?

Name: Anonymous 2013-01-10 14:09

This actually is quite retarded:

newtype (Monad m) => MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }

It is a pain in the ass, and if you switched to a cps'ed version of the MaybeT monad, you don't care anymore if it is a monad or not.

Name: Anonymous 2013-01-10 14:14

(define (one? n) (= 0 (remainder (- n 1) 10)))
(define (ones l) (define (ones l) (foldl (λ (c e) (if (one? e) (+ c 1) c)) 0 l))


Lazy, and only works on n > 0

Name: Anonymous 2013-01-10 14:15

>>13
Actually it's an easy fix, I feel stupid.
(define (one? n) (= 0 (remainder (- (abs n) 1) 10)))

Name: Anonymous 2013-01-10 14:57

In your declarative next-generation non-shit programming language that currently doesn't exist outside your brain, should cardinals (and thus the entire numerical tower) be defined in terms of Church numerals?

Discuss.

Name: Anonymous 2013-01-10 14:59

>>15
What's a cardinal?

Name: Anonymous 2013-01-10 15:04

>>15
What's a number?

Name: Anonymous 2013-01-10 15:18

>>16
Elements of \mathbb{N}.

>>17
Baby don't hurt me, don't hurt me, no more.

Name: Anonymous 2013-01-10 16:43

>>6
Lisp has other fold procedures too, check srfi-1. I'm curious though, what's the difference between fold, reduce, and fold-right?

Name: %10 2013-01-10 16:50

#include <stdio.h>
#define SILLY_MAX_HEAP_BETTER 100
int main (void)
{
 long int le-numbers[SILLY_MAX_HEAP_BETTER];
 int counter = 0;
 short int le_great_decimal, tmp_holder;
 char terminator;
 
 printf("Tell me the number goyim.");

 do {
 scanf("%d%c", &le_numbers, &terminator);
 counter++;
}while (terminator != EOF);

 for (int i = 0; i < counter; i++)
 {
  tmp_holder = le_numbers[i] % 10;
  if (tmp_holder > le_great_decimal)
   le_great_decimal = tmp_holder;
 }

 printf(\nHere is your silly number: %d", le_great_decimal);
return 0;
}

Name: Anonymous 2013-01-10 17:09

>>19
fold = fold-left = reduce
fold-right = (fold (reverse _))

Name: Anonymous 2013-01-10 17:21

>>21
Oh, I see. Thanks.

Name: Anonymous 2013-01-10 17:41

TRUE := λx.λy.x
FALSE := λx.λy.y
AND := λp.λq.p q p
IF := λp.λa.λb.p a b
CONS := λx.λy.λf.f x y
CAR := λp.p TRUE
CDR := λp.p FALSE
NIL := λx.TRUE
NULL := λp.p (λx.λy.FALSE)
0 := λf.λx.x
SUCC := λn.λf.λx.f (n f x)
1 := SUCC 0
10 := λf.λx.f (f (f (f (f (f (f (f (f (f x)))))))))
PRED := λn.λf.λx.n (λg.λh.h (g f)) (λu.x) (λu.u)
SUB := λm.λn.n PRED m
ISZERO := λn.n (λx.FALSE) TRUE
LEQ := λm.λn.ISZERO (SUB m n)
EQ := λm.λn.AND (LEQ m n) (LEQ n m)
Y := λg.(λx.g (x x)) (λx.g (x x))
MOD10 := Y (λr.λx.IF (LEQ 10 x) (r (SUB x 10)) x)
COUNT := Y (λr.λf.λx. (IF (NULL x) 0 ((IF (f (CAR x)) SUCC 1) (r (CDR x)))))
COUNT-ONE-DIGITS := COUNT (λx.EQ (MOD10 x) 1)

Name: Anonymous 2013-01-10 17:47

Expanded:

COUNT-ONE-DIGITS := ((λg.(λx.g (x x)) (λx.g (x x))) (λr.λf.λx. ((λp.λa.λb.p a b) ((λp.p (λx.λy.(λx.λy.y))) x) (λf.λx.x) (((λp.λa.λb.p a b) (f ((λp.p (λx.λy.x)) x)) (λn.λf.λx.f (n f x)) (λf.λx.f x)) (r ((λp.p (λx.λy.y)) x)))))) (λx.(λm.λn.(λp.λq.p q p) ((λm.λn.(λn.n (λx.(λx.λy.y)) (λx.λy.x)) ((λm.λn.n (λn.λf.λx.n (λg.λh.h (g f)) (λu.x) (λu.u)) m) m n)) m n) ((λm.λn.(λn.n (λx.(λx.λy.y)) (λx.λy.x)) ((λm.λn.n (λn.λf.λx.n (λg.λh.h (g f)) (λu.x) (λu.u)) m) m n)) n m)) (((λg.(λx.g (x x)) (λx.g (x x))) (λr.λx.(λp.λa.λb.p a b) ((λm.λn.(λn.n (λx.(λx.λy.y)) (λx.λy.x)) ((λm.λn.n (λn.λf.λx.n (λg.λh.h (g f)) (λu.x) (λu.u)) m) m n)) (λf.λx.f (f (f (f (f (f (f (f (f (f x)))))))))) x) (r ((λm.λn.n (λn.λf.λx.n (λg.λh.h (g f)) (λu.x) (λu.u)) m) x (λf.λx.f (f (f (f (f (f (f (f (f (f x)))))))))))) x)) x) (λf.λx.f x))

Name: Anonymous 2013-01-10 18:26

>>23-24
Stop spamming /prog/ with walls of random characters, please.

Name: Anonymous 2013-01-10 18:39

>>24
O(2dicks)

Name: Anonymous 2013-01-10 18:51

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

>>23-24
I fucking love you. Please, stay here and post more.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iF4EAREKAAYFAlDvVAsACgkQGRQwWY30ng1WGQD/Q0Z3xf7ZmYs63QTj+Av4oc3o
4q1aHRcmvD+xeFvGlnIA/RiJ28JdlFIwAoGKTPwl6K71P7sXuVSTrB9yHifIveF8
=TsVW
-----END PGP SIGNATURE-----

Name: Anonymous 2013-01-10 21:18

>>13
>>14
Doesn't actually work. Just returns 1000.

Name: Anonymous 2013-01-10 21:22

All so uglii lol
number1s = sum( mod(myList(:),10)==1 );
Assumes myList is a vector / matrix or scalar

Name: Anonymous 2013-01-10 21:44

Name: Anonymous 2013-01-10 22:04

>>28-30
Sorry it was terrible in all ways.

(define (one? n) (= 0 (remainder (- (abs n) 1) 10)))
(define (ones l) (foldl (λ (e c) (if (one? e) (+ c 1) c)) 0 l))

Name: Anonymous 2013-01-10 23:35

>>31
Is there a way to do this without using lambda?

Name: Anonymous 2013-01-11 0:09

>>32
Why?

Name: Anonymous 2013-01-11 0:13

>>33
Not allowed to use lambda.

Name: Anonymous 2013-01-11 0:29

length . filter (==True) . map ((==1) . (`mod` 10))

Name: Anonymous 2013-01-11 0:42

Name: Anonymous 2013-01-11 1:13

>>34
Why?

Name: Anonymous 2013-01-11 1:43

function ones(list) {
  return list.reduce(function(sum, cur) {
    return sum + (cur & 1);
  }, 0);
}

Name: Anonymous 2013-01-11 6:01

Name: Anonymous 2013-01-11 7:07

>>39
The ``G'' in ``GHC'' stands for ``goy''!

Name: Anonymous 2013-01-11 7:07

>>39
The ``G'' in ``GHC'' stands for ``goy''!

Name: Anonymous 2013-01-11 8:52

>>40,41
Hello, Cudder.

Name: Anonymous 2013-01-11 15:06

Bump.

Name: Anonymous 2013-01-11 17:52

>>39
100% kike free

Name: yesod 2013-01-11 19:05

yesod

Don't change these.
Name: Email:
Entire Thread Thread List