POV-Ray : Newsgroups : povray.off-topic : Code division multiplexing : Re: Code division multiplexing Server Time
29 Sep 2024 11:22:51 EDT (-0400)
  Re: Code division multiplexing  
From: Warp
Date: 22 Apr 2009 13:29:19
Message: <49ef53ef@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> I don't know why it works... but it does.

>  >module CDM where
>  >
>  >encode :: [Int] -> [Int] -> [Int]
>  >encode cs xs = do
>  >  x <- xs
>  >  c <- cs
>  >  let y = if x == 1 then 1 else -1
>  >  return (c*y)
>  >
>  >decode :: [Int] -> [Int] -> [Int]
>  >decode cs [] = []
>  >decode cs xs =
>  >  let
>  >    (xs0,xs1) = splitAt (length cs) xs
>  >    y = sum (zipWith (*) cs xs0)
>  >  in ((y `min` 1) `max` 0) : decode cs xs1

> OK, so let's encode something:

>    *CDM> encode [1,-1] [1, 0, 1]
>    [1,-1,-1,1,1,-1]

>    *CMD> decode [1,-1] [1,-1,-1,1,1,-1]
>    [1,0,1]

> Well that's nice. But now check this out:

>    *CDM> let x1 = encode [1,1,1,1] [1,1,0,1]
>    *CDM> let x2 = encode [1,-1,1,-1] [1,0,1,1]
>    *CDM> let x3 = encode [1,1,-1,-1] [0,0,1,1]
>    *CDM> let x4 = encode [1,-1,-1,1] [1,1,1,0]
>    *CDM> x1
>    [1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,1,1,1]
>    *CDM> x2
>    [1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,1,-1,1,-1]
>    *CDM> x3
>    [-1,-1,1,1,-1,-1,1,1,1,1,-1,-1,1,1,-1,-1]
>    *CDM> x4
>    [1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,-1,1,1,-1]
>    *CDM> let y = foldl1 (zipWith (+)) [x1,x2,x3,x4]
>    *CDM> y
>    [2,-2,2,2,0,0,0,4,2,-2,-2,-2,2,2,2,-2]
>    *CDM> decode [1,1,1,1] y
>    [1,1,0,1]
>    *CDM> decode [1,-1,1,-1] y
>    [1,0,1,1]
>    *CDM> decode [1,1,-1,-1] y
>    [0,0,1,1]
>    *CDM> decode [1,-1,-1,1] y
>    [1,1,1,0]

> Magic!

  Are you seriously expecting people to understand what's going on there,
without any kind of explanation?

  I'm a programmer and I haven't the slightest idea.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.