Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #44095

Re: Unfeasible?

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail
From Melzzzzz <mel@zzzzz.com>
Newsgroups comp.lang.forth
Subject Re: Unfeasible?
Date Sun, 6 Dec 2015 01:01:33 +0100
Organization albasani.net
Lines 87
Message-ID <20151206010133.3820da9e@maxa-pc> (permalink)
References <n3q89d$9d1$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net G8SfZfcrRLEDCE+dSHYhCwY0GAxPP1ixuXs2eHpZTXpkTvl0ujtX0HRElco65Lfc8KrKa1UkpfY22Fsb+Q8ieQ==
NNTP-Posting-Date Sun, 6 Dec 2015 00:01:33 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="zoBjT4E8DG2Xti1EcWx6liuHnIhqbkgHJ50wj+dR7t5qsSGKuLwE0qUHnK0Em85pDUXlhxpAvX7H0BGPUYgs8sCeuL//1+eodirnRhoEkj3iB++kIBQH8WCMa5e+13vJ"; mail-complaints-to="abuse@albasani.net"
X-Newsreader Claws Mail 3.13.0 (GTK+ 2.24.28; x86_64-unknown-linux-gnu)
Cancel-Lock sha1:J2g2VCye9rCjDNScZbihDInAWfg=
Xref csiph.com comp.lang.forth:44095

Show key headers only | View raw


On Thu, 3 Dec 2015 20:22:07 -0000 (UTC)
"WJ" <w_a_x_man@yahoo.com> wrote:

> One has a function "get_list" that produces a list.
> He has another function "test" that determines whether
> a member of the list passes muster.
> He has a function "foo" that is used to transform
> an element of the list.
> 
> The task is to iterate through the list while
> printing each element with its index and collecting
> the transformations of the elements that fit the bill.
> 
> Wouldn't this be painful in the Toy Language (ANS Forth)?
> 
> Ruby:
> 
> def get_list; ('aa'..'zz').step(36).to_a ; end
> def test s; s == s.reverse ; end
> def foo x; x.upcase ; end
> 
> get_list.each_with_index.
>   grep->((x,i)){printf "%2d - %s\n", i, x; test x}{|x,_| foo x}
> 
>  0 - aa
>  1 - bk
>  2 - cu
>  3 - ee
>  4 - fo
>  5 - gy
>  6 - ii
>  7 - js
>  8 - lc
>  9 - mm
> 10 - nw
> 11 - pg
> 12 - qq
> 13 - sa
> 14 - tk
> 15 - uu
> 16 - we
> 17 - xo
> 18 - yy
>     ==>["AA", "EE", "II", "MM", "QQ", "UU", "YY"]  
> 
Haskell ;)

[bmaxa@maxa-pc haskell]$ ghc unfeasible.hs
[1 of 1] Compiling Main             ( unfeasible.hs, unfeasible.o )
Linking unfeasible ...
[bmaxa@maxa-pc haskell]$ ./unfeasible 
 0 - aa
 1 - bk
 2 - cu
 3 - ee
 4 - fo
 5 - gy
 6 - ii
 7 - js
 8 - lc
 9 - mm
10 - nw
11 - pg
12 - qq
13 - sa
14 - tk
15 - uu
16 - we
17 - xo
18 - yy

["AA","EE","II","MM","QQ","UU","YY"]
[bmaxa@maxa-pc haskell]$ cat unfeasible.hs
import Text.Printf
import Data.Char

get_list = takeEvery 36 [[a,b] | a <- ['a'..'z'], b <- ['a'..'z']]
    where
        takeEvery n (x:xs) = x : (takeEvery n $ drop (n-1) xs)
        takeEvery _ [] = []

main = do
    putStrLn $ unlines 
             $ map (\(a,b) -> printf "%2d - %s" (a::Int) b)
             $ zip [0..] get_list
    print $ map (map toUpper) $ filter (\x -> x == reverse x) get_list

Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Unfeasible? "WJ" <w_a_x_man@yahoo.com> - 2015-12-03 20:22 +0000
  Re: Unfeasible? Julian Fondren <julian.fondren@gmail.com> - 2015-12-03 16:17 -0800
    Re: Unfeasible? Paul Rubin <no.email@nospam.invalid> - 2015-12-03 17:47 -0800
      Re: Unfeasible? Julian Fondren <julian.fondren@gmail.com> - 2015-12-03 19:48 -0800
        Re: Unfeasible? Paul Rubin <no.email@nospam.invalid> - 2015-12-04 21:13 -0800
          Re: Unfeasible? Julian Fondren <julian.fondren@gmail.com> - 2015-12-04 23:48 -0800
            Re: Unfeasible? Paul Rubin <no.email@nospam.invalid> - 2015-12-05 00:11 -0800
              Re: Unfeasible? Julian Fondren <julian.fondren@gmail.com> - 2015-12-05 00:35 -0800
                Re: Unfeasible? Paul Rubin <no.email@nospam.invalid> - 2015-12-05 00:40 -0800
    Re: Unfeasible? hughaguilar96@gmail.com - 2015-12-04 20:53 -0800
  Was: Unfeasible? Is: Infeasible rickman <gnuarm@gmail.com> - 2015-12-03 19:18 -0500
  Re: Unfeasible? "WJ" <w_a_x_man@yahoo.com> - 2015-12-04 01:11 +0000
    Re: Unfeasible? rickman <gnuarm@gmail.com> - 2015-12-03 20:50 -0500
  Re: Unfeasible? Bernd Paysan <bernd.paysan@gmx.de> - 2015-12-04 03:23 +0100
  Re: Unfeasible? "WJ" <w_a_x_man@yahoo.com> - 2015-12-04 05:55 +0000
  Re: Unfeasible? Melzzzzz <mel@zzzzz.com> - 2015-12-06 01:01 +0100

csiph-web