• choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a for

    From meInvent bbird@21:1/5 to All on Mon Jul 25 01:39:56 2016
    choose 2,3,4,5 can run very fast,
    but when choose 6,7 it run into a forever loop

    theoretically, the number of items will be less in the list

    why it run forever?

    let input1 = replicateM 5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)], isSorted (input1!!i)]
    writeFile "logic3layer5.txt" $ unlines ascbefore


    for example, choose 5 can run very fast, but when reach 6, it run into a forever loop

    let input1 = replicateM 6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)], isSorted (input1!!i)]
    writeFile "logic3layer6.txt" $ unlines ascbefore

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From meInvent bbird@21:1/5 to meInvent bbird on Mon Jul 25 01:48:38 2016
    i record this video when i run

    https://youtu.be/hA7PN8aRFKk


    On Monday, July 25, 2016 at 4:39:57 PM UTC+8, meInvent bbird wrote:
    choose 2,3,4,5 can run very fast,
    but when choose 6,7 it run into a forever loop

    theoretically, the number of items will be less in the list

    why it run forever?

    let input1 = replicateM 5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)], isSorted (input1!!i)]
    writeFile "logic3layer5.txt" $ unlines ascbefore


    for example, choose 5 can run very fast, but when reach 6, it run into a forever loop

    let input1 = replicateM 6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)], isSorted (input1!!i)]
    writeFile "logic3layer6.txt" $ unlines ascbefore

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From meInvent bbird@21:1/5 to meInvent bbird on Mon Jul 25 01:58:09 2016
    when i run

    ascbefore

    it looping



    On Monday, July 25, 2016 at 4:48:40 PM UTC+8, meInvent bbird wrote:
    i record this video when i run

    https://youtu.be/hA7PN8aRFKk


    On Monday, July 25, 2016 at 4:39:57 PM UTC+8, meInvent bbird wrote:
    choose 2,3,4,5 can run very fast,
    but when choose 6,7 it run into a forever loop

    theoretically, the number of items will be less in the list

    why it run forever?

    let input1 = replicateM 5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)], isSorted (input1!!i)]
    writeFile "logic3layer5.txt" $ unlines ascbefore


    for example, choose 5 can run very fast, but when reach 6, it run into a forever loop

    let input1 = replicateM 6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)], isSorted (input1!!i)]
    writeFile "logic3layer6.txt" $ unlines ascbefore

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to meInvent bbird on Mon Jul 25 13:57:32 2016
    meInvent bbird <jobmattcon@gmail.com> writes:

    choose 2,3,4,5 can run very fast,
    but when choose 6,7 it run into a forever loop

    theoretically, the number of items will be less in the list

    why it run forever?

    let input1 = replicateM 5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted
    [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)],
    isSorted (input1!!i)]
    writeFile "logic3layer5.txt" $ unlines ascbefore


    for example, choose 5 can run very fast, but when reach 6, it run into
    a forever loop

    let input1 = replicateM 6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted
    [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)],
    isSorted (input1!!i)]
    writeFile "logic3layer6.txt" $ unlines ascbefore

    That's very inefficient. [(input1!!i) | i <- [0..((length input1)-1)]]
    is just a very complex and slow way to write input1. Try

    unlines $ map show $ filter isSorted input1

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From meInvent bbird@21:1/5 to Ben Bacarisse on Mon Jul 25 19:03:07 2016
    thanks, it succeed to run,

    how do you know whether it is efficient?
    is there any guide to investigate whether it is efficient?

    On Monday, July 25, 2016 at 8:57:33 PM UTC+8, Ben Bacarisse wrote:
    meInvent bbird <jobmattcon@gmail.com> writes:

    choose 2,3,4,5 can run very fast,
    but when choose 6,7 it run into a forever loop

    theoretically, the number of items will be less in the list

    why it run forever?

    let input1 = replicateM 5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted
    [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)],
    isSorted (input1!!i)]
    writeFile "logic3layer5.txt" $ unlines ascbefore


    for example, choose 5 can run very fast, but when reach 6, it run into
    a forever loop

    let input1 = replicateM 6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
    let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted
    [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
    let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)],
    isSorted (input1!!i)]
    writeFile "logic3layer6.txt" $ unlines ascbefore

    That's very inefficient. [(input1!!i) | i <- [0..((length input1)-1)]]
    is just a very complex and slow way to write input1. Try

    unlines $ map show $ filter isSorted input1

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to meInvent bbird on Tue Jul 26 10:37:54 2016
    meInvent bbird <jobmattcon@gmail.com> writes:

    thanks, it succeed to run,

    how do you know whether it is efficient?

    It's not always easy to tell because a compiler/interpreter can be
    clever and remove some sources of inefficiency, but the essential
    problem here is that !! does not provide constant-time access
    to the elements of a list. Unless some optimisation can be done l !! i
    takes time (roughly) proportional to i, so running over all i from 0 to
    length l - 1 is a quadratic operation (it takes time proportional to
    (length l) squared).

    is there any guide to investigate whether it is efficient?

    Sorry, I'm not aware of one.

    By the way, consider interleaving your comments with what other people
    say (as I've done here) and cutting any material that is not helpful in establishing the context of your reply.

    <snip>
    That's very inefficient. [(input1!!i) | i <- [0..((length input1)-1)]]
    is just a very complex and slow way to write input1.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)