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
ascbefore
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
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
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.
thanks, it succeed to run,
how do you know whether it is efficient?
is there any guide to investigate whether it is efficient?
That's very inefficient. [(input1!!i) | i <- [0..((length input1)-1)]]
is just a very complex and slow way to write input1.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 54:50:14 |
Calls: | 6,650 |
Calls today: | 2 |
Files: | 12,200 |
Messages: | 5,330,746 |