Scheme 鸡方案中的拓扑排序错误?
以这种方式对子列表进行排序可以更清楚地了解正确的输出应该是什么:Scheme 鸡方案中的拓扑排序错误?,scheme,topological-sort,chicken-scheme,Scheme,Topological Sort,Chicken Scheme,以这种方式对子列表进行排序可以更清楚地了解正确的输出应该是什么: #;2> (topological-sort '((i am) (not trying) (confuse the) (am trying) (trying to) (am not) (trying the) (to confuse) (the issue)) eqv?) (not i am trying to confuse the issue) 看来命令应该是:
#;2> (topological-sort
'((i am)
(not trying)
(confuse the)
(am trying)
(trying to)
(am not)
(trying the)
(to confuse)
(the issue))
eqv?)
(not i am trying to confuse the issue)
看来命令应该是:
(i am)
(am not)
(not trying)
(trying to)
(to confuse)
(am trying)
(confuse the)
(trying the)
(the issue)
这是一个错误,还是我遗漏了什么
----编辑:----
将子列表与公共头相结合:
i am not trying to confuse the issue
因此,似乎正确的方法是对输入进行预处理
以确保没有两个子列表共享同一标头
解决Rosetta代码拓扑排序问题:
(topological-sort
'((i am)
(not trying)
(confuse the)
(am trying not)
(trying to the)
(to confuse)
(the issue))
eqv?)
(i am not trying to confuse the issue)
一个可能的结果(因为哈希表是无序的,所以
每次都不一样):
正在尝试验证答案:
(std ieee dware dw05 dw06 dw07 ramlib std_cell_lib gtech synopsys
dw02 dw01 des_system_lib dw03 dw04)
这似乎是正确的。是的,这是一个已知的错误:
是的,这是一个已知的错误:
2年前开放#sadpandaAlthough,OP文本听起来像是2年前开放的#sadpandaAlthough,OP文本听起来像是拖拉
(std ieee dware dw05 dw06 dw07 ramlib std_cell_lib gtech synopsys
dw02 dw01 des_system_lib dw03 dw04)
(any
(lambda (tail)
(any
(lambda (key)
(and (hash-table-exists? table key)
(member (car tail) (hash-table-ref table key))))
(cdr tail)))
(reverse (pair-fold cons '() answer)))
#f