User talk:Gaaijz: Difference between revisions

From Rosetta Code
Content added Content deleted
 
(5 intermediate revisions by 3 users not shown)
Line 12: Line 12:
== Zigzag ==
== Zigzag ==
Two different approaches with Haskell for the zigzag task.
Two different approaches with Haskell for the zigzag task.
zigzag m n = take m .transp_wof $ zipWith id (cycle [reverse,id]) antiDiags where
flist = map (:[])
mmn = min m n
elist = flip replicate []
antiDiags = unfoldr (\((c:cs),xs) -> if null xs then Nothing else Just (take c xs,(cs,drop c xs)))
revNrev True = cycle [reverse,id]
([1..mmn-1]++(replicate (succ.abs $ m-n) mmn)++[mmn-1,mmn-2..0], [0..m*n-1])
revNrev _ = cycle [id,reverse]
transp_wof = unfoldr (\xs -> if null xs then Nothing else Just $ next xs)
transpN True = id
next xs = (,) (concatMap (take 1) ks) ((map (drop 1) $ drop 1 ks) ++ ts)
transpN _ = transpose
where (ks,ts) = splitAt n xs
:Slower version, almost complete emulation of the J-solution
zigzag m n = (transpN rev).map concat. transpose
. uncurry ((.(map (liftM2 (++) (elist.(dl-).length) flist))).(++).(map (liftM2 (++) flist (elist.(dl-).length))))
$ splitAt k revcs
where
k = truncate . sqrt . fromIntegral $ (m*n)
dl = min m n
nd = abs (m-n)
rev = m<n
pseudoAntiDiags = unfoldr (\((c:cs),xs) -> if null xs then Nothing else Just (take c xs,(cs,drop c xs)))
([1..dl]++(replicate nd dl)++[dl-1,dl-2..0],[0..m*n-1])
revcs = zipWith id (revNrev rev) pseudoAntiDiags
-- slower, almost complete emulation of the J-solution
groupon f x y= f x == f y
groupon f x y= f x == f y
tab n = fst . until (null.snd) (\(xs,ys)-> (xs++[take n ys], drop n ys)) . (,) []
tab n = fst . until (null.snd) (\(xs,ys)-> (xs++[take n ys], drop n ys)) . (,) []
Line 39: Line 28:
where fdiag = map (map snd). groupBy (groupon fst).sortBy (comparing fst)
where fdiag = map (map snd). groupBy (groupon fst).sortBy (comparing fst)
$ zip (map sum $ sequence [[0..m-1],[0..n-1]] ) [0..]
$ zip (map sum $ sequence [[0..m-1],[0..n-1]] ) [0..]

*Main> sum.map sum $ zigzag 500 500
*Main> sum.map sum $ zigzag 500 500
1185103928
1185103928
Line 47: Line 36:
31249875000
31249875000
(4.55 secs, 575802084 bytes)
(4.55 secs, 575802084 bytes)

== Words Of Equal Characters ==
Hi, Could you add some sample output to your Haskell implementation? Thanks. --[[User:Paddy3118|Paddy3118]] 18:47, 26 September 2008 (UTC)


== [[Generic swap]] ==

Hello again. I've [http://rosettacode.org/w/index.php?title=User_talk%3ADanBron&diff=17957&oldid=17947 responded] to your [http://rosettacode.org/w/index.php?title=User_talk%3ADanBron&diff=17947&oldid=17600 question] re: [[Generic swap]].

--[[User:DanBron|DanBron]] 16:05, 29 September 2008 (UTC)

== [[User_talk:DanBron#J_alphabet_gaps|J alphabet gaps]] ==

Hey. I've [http://rosettacode.org/w/index.php?title=User_talk:DanBron&diff=21027&oldid=20969 responded] to your [http://rosettacode.org/w/index.php?title=User_talk:DanBron&diff=20969&oldid=17957 inquiry] about alphabetic gaps in J's task coverage on RC.

--[[User:DanBron|DanBron]] 20:26, 23 January 2009 (UTC)

==Miller Rabin: 946 prime?==
Hi Gaaijz, I was doing the left truncatable prime task and started by improving the Miller Rabin primality test for Python after finding what turns out to be one of the references you cite on your [[Miller-Rabin_primality_test#Haskell|Haskell version]]. On testing 901 to 1000 for primality in my Python I noticed that the Haskell version says 946 is prime on the page? I checked the page history and found that you had the 946 from the beginning - i.e. it is not a malicious edit so I thought I'd give you a chance to look into the Haskell code rather than me just removing the 946 from your output, which was my first thought. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 05:36, 23 July 2013 (UTC)

Latest revision as of 05:36, 23 July 2013

welcome!

Welcome to Rosetta Code! If you have any questions, drop them in the appropriate talk page, and someone will get back to you. If you have a more general question, try Mwn3d's or my talk pages. --Short Circuit 04:10, 2 September 2008 (UTC)

Jers

Hey Arie. This is Dan Bron from the J forums. Tracy Harms is here too. It's good to have J representation on RosettaCode. I'm glad you posted a J solution to the Pyramid of Numbers, that was near the top of my to do list. Have you considered posting a task along the lines of your Rabbit Sequence?

Oh, by the way, I linkified your user page. I hope you don't mind. Go ahead and revert it if you like it better the other way.

DanBron 13:48, 2 September 2008 (UTC)

Zigzag

Two different approaches with Haskell for the zigzag task.

zigzag m n = take m .transp_wof $ zipWith id (cycle [reverse,id]) antiDiags where
  mmn        = min m n
  antiDiags  = unfoldr (\((c:cs),xs) -> if null xs then Nothing else Just (take c xs,(cs,drop c xs)))
               ([1..mmn-1]++(replicate (succ.abs $ m-n) mmn)++[mmn-1,mmn-2..0], [0..m*n-1])
  transp_wof = unfoldr (\xs -> if null xs then Nothing else Just $ next xs)
  next xs    =  (,) (concatMap (take 1) ks) ((map (drop 1) $ drop 1 ks) ++ ts)
       where (ks,ts) = splitAt n xs

Slower version, almost complete emulation of the J-solution
groupon f x y= f x == f y
tab n = fst . until (null.snd) (\(xs,ys)-> (xs++[take n ys], drop n ys)) . (,) []
grade xs = map snd. sort $ zip xs [0..] 

zigzagJ m n = tab n. grade .concat $ zipWith id (cycle [reverse,id]) fdiag
  where fdiag = map (map snd). groupBy (groupon fst).sortBy (comparing fst)
                $ zip (map sum $ sequence [[0..m-1],[0..n-1]] ) [0..]
*Main> sum.map sum $ zigzag  500 500
1185103928
(0.69 secs, 103908376 bytes) 

*Main> sum.map sum $ zigzagJ 500 500
31249875000
(4.55 secs, 575802084 bytes)

Words Of Equal Characters

Hi, Could you add some sample output to your Haskell implementation? Thanks. --Paddy3118 18:47, 26 September 2008 (UTC)


Generic swap

Hello again. I've responded to your question re: Generic swap.

--DanBron 16:05, 29 September 2008 (UTC)

J alphabet gaps

Hey. I've responded to your inquiry about alphabetic gaps in J's task coverage on RC.

--DanBron 20:26, 23 January 2009 (UTC)

Miller Rabin: 946 prime?

Hi Gaaijz, I was doing the left truncatable prime task and started by improving the Miller Rabin primality test for Python after finding what turns out to be one of the references you cite on your Haskell version. On testing 901 to 1000 for primality in my Python I noticed that the Haskell version says 946 is prime on the page? I checked the page history and found that you had the 946 from the beginning - i.e. it is not a malicious edit so I thought I'd give you a chance to look into the Haskell code rather than me just removing the 946 from your output, which was my first thought. --Paddy3118 (talk) 05:36, 23 July 2013 (UTC)