如何进行最大值为2的额外列视图组合 [英] how to do combination for extra column view with maximum value 2

查看:98
本文介绍了如何进行最大值为2的额外列视图组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Update2 :是否有3 ^ 2,4 ^ 2,5 ^ 2,... 10 ^ 2的函数返回类型的动态数字,到目前为止我必须硬编码这个,即使加回来,
i感觉不是一个完整的组合

  comb0 :: [(Int ,Int,Int)] 
comb0 = do
a < - [0,1,2]
b < - [0,1,2]
return(a,b ,2 - max ab)

comb :: [(Int,Int,Int,Int,Int,Int,Int,Int,Int)]
comb = do
a1 < - [0]
a2 < - [0,1]
a3 < - [0]
a4 < - [0,1]
a5 < - [0,1]
a6 < - [0]
a7 < - [0]
a8 < - [0]
a9 < - [0]
return(a1,a2,a3,a4,a5,a6,a7,a8,a9)

Update1 :我认为一个愚蠢的方式,但可能有完整的组合



假设输出为[0; 1; 0]输入列1由于输入1和输入2的第一行是0,所以不必在意第一个0 [0; 0; 1]输入列2 [0; 1; 0]

输出

,然后2减去[1; 0]变成[1; 2],然后是

我们看到有两行,所以make两个循环



为我在0..1做$ /

 对于0..2中的j,

组合变为[0; 0],[0; 1] ,[0; 2],[1; 0],[1; 1],[1; 2]

加回[1; 0]变成[1 + 0; 0 + 0],[1 + 0; 0 + 1],[1 + 0; 0 + 2],[1 + 1; 0 + 1] ...等然后粘贴然后回到表格



如何以简单的方式在haskell中编写此代码?



原始问题:
如果仅返回(a,b),则输入对于逻辑表是正确的

这个问题是使用值2,可以说它是3值,
当我计算5值时,我的计算机计算速度很慢c#
等待很长一段时间,仍然没有完成,我希望增加价值
尽可能多,希望haskell可以更快在这个



期望将输出列添加到此,
i使用((a,b),max(a,b))作为起始点,然后添加一个到第三个
列,输出到达2并递归运行并保存每个组合使用F#编写的列表,输出12个组合输出,但是我觉得有一些
缺失,而不是完整的组合,希望使用haskell做同样的事情来查看完整的组合并保存到文本文件中,如果除第一行0,0以外还有输出0,那么它有很多组合




  comb :: [(Int,Int,Int)] 
comb = do
b < - [0,1,2]
a < - [0,1,2]
return( a,b,max ab)

comb2 :: [(Int,Int,Int)] - > [(Int,Int,Int)]
comb2 x = do
c < - [0,1,2]
return(fst x,fst snd x,c + snd snd x)



<1>编译Main(main.hs,main.o)

  main.hs:67:19:
无法匹配预期类型`Int'
,其实际类型为`(Int ,Int) - > (Int,Int)'
在`max'调用的返回类型中
可能的原因:`max'应用于太少的参数
在表达式中:max(a,b )
在`return'的第一个参数中,即`((a,b),max(a,b))'

comb :: [((Int,Int)), (a,b),(b),(b),(b),(b),最大(a,b))

mapM_打印梳

F# / p>

  let MakeColumn(输入:List< int>,m1:int,m2:int,numberofvalue:int):List< int> = 
let mutable zero1 = 0
for i in 0 ..(m1-1)do
for j in 0 ..(m2-1)do
input.Add( zero1)
zero1 < - zero1 + 1
if zero1> = numberofvalue then
zero1 < - 0
input

let mutable col1_3:列表与LT; INT> = new List< int>()
let mutable col2_3:List< int> = new List< int>()
let mutable col3_3:List< int> = new List< int>()
let mutable col1_2:List< int> = new List< int>()
let mutable col2_2:List< int> = new List< int>()
let mutable col3_2:List< int> = new List< int>()
let Radix = 3
let mutable totalrows = Convert.ToInt32(Math.Pow(float 2,float Radix))
col1_3 < - MakeColumn(col1_3 ,totalrows,1,2)
col2_3< - MakeColumn(col2_3,totalrows / 2,2,2)
col3_3< - MakeColumn(col3_3,totalrows / 4,4,2)
col1_2< - MakeColumn(col1_2,totalrows / 2,1,2)
col2_2< - MakeColumn(col2_2,totalrows / 4,2,2)
let debugtotalrows = totalrows
let debugcol1_3 = col1_3
让debugcol2_3 = col2_3
让debugcol3_3 = col3_3
让debugcol1_2 = col1_2
让debugcol2_2 = col2_2
让debugcol3_2 = col3_2
让mutable col1_3a :列表< int> = new List< int>()
let mutable col2_3a:List< int> = new List< int>()
let debugcol1_3a = MakeColumn(col1_3a,9/3,3,3)
let debugcol2_3a = MakeColumn(col2_3a,9,1,3)
for i在0 ..(col1_3.Count-1)do
Console.WriteLine(col1_3。[i] .ToString()+,+ col2_3。[i] .ToString())


让MinimumCovering(col1:List< int>,col2:List< int>)=
让OutputBits = new List< int>() .Count-1)do
OutputBits.Add(Math.Max(col1。[i],col2。[i]))
OutputBits

让MinimumCoveringList(col1:List< ; int>,col2:List< int>)=
let mutable OutputBits = []
for i in 0 ..(col1.Count-1)do
OutputBits< - Math。 Max(col1。[i],col2。[i]):: OutputBits
let finaloutput = List.rev OutputBits
finaloutput

let NumberOfNonMaximumForCovering(col1:List< int> )=
let mutable count = 0
for i in 0 ..(col1.Count-1)do
if col1。[i]< 2 then
count < - count + 1
count

let rec AllCombinationOfBasicOutput(NumberOfNonMaximumValue:int,MinimumCoveringOutputParam:int list,numberofloops:int,maximumvalue:int,finaloutput:Dictionary< ; int list,int list> byref)=
let mutable newoutputs = new Dictionary< int list,int list>()
if numberofloops-1> = 0 then
newoutputs< - 新的词典< int list,int list>()
for i in 0 ..(NumberOfNonMaximumValue-1)do
let mutable newoutput = []
for j in 0 ..(MinimumCoveringOutputParam。 Length-1)do //每次改变一行
if i = j then
如果MinimumCoveringOutputParam。[j] + 1 < maximumvalue then
newoutput< - MinimumCoveringOutputParam。[j] + 1 :: newoutput
else
newoutput< - MinimumCoveringOutputParam。[j] :: newoutput
else
newoutput< - MinimumCoveringOutputParam。[j] :: newoutput
let newoutput5 = List.rev newoutput
if finaloutput.ContainsKey(newoutput5)= false then
finaloutput.Add(newoutput5,newoutput5)
if numberofloops-1> = 0 then
finaloutput< - AllCombinationOfBasicOutput(NumberOfNonMaximumValue,newoutput5,numberofloops - 1,maximumvalue,& finaloutput)
finaloutput

let MinimumCoveringOutput = MinimumCovering(debugcol1_3a,debugcol2_3a)
let MinimumCoveringOutputList = MinimumCoveringList(debugcol1_3a,debugcol2_3a)
let NumberOfNonMaximum = NumberOfNonMaximumForCovering(MinimumCoveringOutput)
let mutable ne woutputs3 = new Dictionary< int list,int list>()
let comboutputs = AllCombinationOfBasicOutput(NumberOfNonMaximum,MinimumCoveringOutputList,NumberOfNonMaximum,3,& newoutputs3)
let ChangeIntListToListInt(m:int list):List< int> ; =
let result = new List< int>()
for i in 0 ..(m.Length-1)do
result.Add(m。[i])
结果

用于comboutputs中的aa。键值
let newaa = ChangeIntListToListInt(aa)
WriteTableMultipleValuedLogic(debugcol1_3a,debugcol2_3a,newaa,E:/martintonic.txt)
System.IO.File.AppendAllText(E:/martintonic.txt,***** \r\\\

期望比较下面的输出以查看下面是否是完整组合

  0,0 = 1 
0,1 = 1
0,2 = 2
1,0 = 1
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 2
0 ,1 = 1
0,2 = 2
1,0 = 1
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 2
0,1 = 2
0, 2 = 2
1,0 = 1
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 2
0,1 = 1
0,2 = 2
1,0 = 2
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 2
0,1 = 2
0,2 = 2
1,0 = 2
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 1
0,1 = 2
0,2 = 2
1,0 = 1
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 1
0,1 = 2
0,2 = 2
1,0 = 2
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0 ,0 = 1
0,1 = 1
0,2 = 2
1,0 = 2
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 0
0, 1 = 2
0,2 = 2
1,0 = 1
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 0
0,1 = 2
0,2 = 2
1,0 = 2
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 0
0,1 = 1
0,2 = 2
1,0 = 1
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****
0,0 = 0
0,1 = 1
0,2 = 2
1,0 = 2
1,1 = 1
1,2 = 2
2,0 = 2
2,1 = 2
2,2 = 2
*****


解决方案使用 max ab ,而不是 max(a,b)。前者传递两个参数,后者只传递一个参数 - 一对(a,b)


Update2 : is it possible to have dynamic number of type in return of function for 3^2, 4^2, 5^2, ... 10^2, so far i have to hard code this, and even if add back this, i feel not a full combination

comb0 :: [(Int, Int, Int)]
comb0 = do
   a <- [0,1,2]
   b <- [0,1,2]
   return (a, b, 2 - max a b)

comb :: [(Int, Int, Int, Int, Int, Int, Int, Int, Int)]
comb = do
   a1 <- [0]
   a2 <- [0,1]
   a3 <- [0]
   a4 <- [0,1] 
   a5 <- [0,1]
   a6 <- [0]
   a7 <- [0]
   a8 <- [0]
   a9 <- [0]
   return (a1,a2,a3,a4,a5,a6,a7,a8,a9)

Update1 : i thought a stupid way but may have full combination

assume output is [0;1;0] input column 1 [0;0;1] input column 2[0;1;0]

since input 1 and input 2 first row is 0, so do not care first 0 in output

and then 2 minus [1;0] become [1;2] and then

we see that there are two rows, so make two for loop

for i in 0..1 do

 for j in 0..2 do

combinations become [0;0] , [0;1], [0; 2], [1;0] , [1; 1], [1; 2]

add back to [1;0] become [1+0; 0+0], [1+0; 0+1], [1+0; 0+2], [1+1; 0+1]... etc then glue then back to the table

how to write this in simple way in haskell?

Original question: if only return (a,b), the input is correct for logic table

this problem is using value 2, you can say that it is 3 valued, when i calculated for 5 valued, my computer calculated is slow in c# waiting for long time, still not finish, i expect to increase value as many as possible, hope haskell can be faster in this

expect to add output column to this, i use ((a,b), max(a,b)) as the starting point, and then add one to third column which is output until reach 2 and recursively run and save each combination in list written in F#, output 12 combinations outputs, but i feel that there is some missing, not full combinations, expect to use haskell do the same things to see full combinations of this and save into text file and moreover counting how many combinations it have

if except first row 0, 0 keep output 0 too

comb :: [(Int, Int, Int)]
comb = do
   b <- [0,1,2]
   a <- [0,1,2]
   return (a,b, max a b)

comb2 :: [(Int, Int, Int)] -> [(Int, Int, Int)]
comb2 x = do
   c <- [0,1,2]
   return (fst x, fst snd x, c + snd snd x)

[1 of 1] Compiling Main ( main.hs, main.o )

main.hs:67:19:
    Couldn't match expected type `Int'
                with actual type `(Int, Int) -> (Int, Int)'
    In the return type of a call of `max'
    Probable cause: `max' is applied to too few arguments
    In the expression: max (a, b)
    In the first argument of `return', namely `((a, b), max (a, b))'

comb :: [((Int, Int), Int)]
comb = do
   b <- [0,1,2]
   a <- [0,1,2]
   return ((a,b), max(a,b))

  mapM_ print comb

F# code

let MakeColumn(input : List<int> , m1 : int , m2 : int, numberofvalue : int) : List<int>=
    let mutable zero1 = 0
    for i in 0..(m1-1) do
        for j in 0..(m2-1) do
            input.Add(zero1)
        zero1 <- zero1 + 1
        if zero1 >= numberofvalue then
            zero1 <- 0
    input

let mutable col1_3 : List<int> = new List<int>()
let mutable col2_3 : List<int> = new List<int>()
let mutable col3_3 : List<int> = new List<int>()
let mutable col1_2 : List<int> = new List<int>()
let mutable col2_2 : List<int> = new List<int>()
let mutable col3_2 : List<int> = new List<int>()
let Radix = 3
let mutable totalrows = Convert.ToInt32(Math.Pow(float 2, float Radix))
col1_3 <- MakeColumn(col1_3, totalrows, 1, 2)
col2_3 <- MakeColumn(col2_3, totalrows/2, 2, 2)
col3_3 <- MakeColumn(col3_3, totalrows/4, 4, 2)
col1_2 <- MakeColumn(col1_2, totalrows/2, 1, 2)
col2_2 <- MakeColumn(col2_2, totalrows/4, 2, 2)
let debugtotalrows = totalrows
let debugcol1_3 = col1_3
let debugcol2_3 = col2_3
let debugcol3_3 = col3_3
let debugcol1_2 = col1_2
let debugcol2_2 = col2_2
let debugcol3_2 = col3_2
let mutable col1_3a : List<int> = new List<int>()
let mutable col2_3a : List<int> = new List<int>()
let debugcol1_3a = MakeColumn(col1_3a, 9/3, 3, 3)
let debugcol2_3a = MakeColumn(col2_3a, 9, 1, 3)
for i in 0..(col1_3.Count-1) do
    Console.WriteLine(col1_3.[i].ToString()+","+col2_3.[i].ToString())


let MinimumCovering(col1 : List<int>, col2 : List<int>)=
    let OutputBits = new List<int>()
    for i in 0..(col1.Count-1) do
        OutputBits.Add(Math.Max(col1.[i], col2.[i]))
    OutputBits

let MinimumCoveringList(col1 : List<int>, col2 : List<int>)=
    let mutable OutputBits = []
    for i in 0..(col1.Count-1) do
        OutputBits <- Math.Max(col1.[i], col2.[i]) :: OutputBits
    let finaloutput = List.rev OutputBits
    finaloutput

let NumberOfNonMaximumForCovering(col1 : List<int>)=
    let mutable count = 0
    for i in 0..(col1.Count-1) do
        if col1.[i] <> 2 then
            count <- count + 1
    count

let rec AllCombinationOfBasicOutput(NumberOfNonMaximumValue : int, MinimumCoveringOutputParam : int list, numberofloops : int, maximumvalue : int, finaloutput : Dictionary<int list, int list> byref)=
    let mutable newoutputs = new Dictionary<int list, int list>()
    if numberofloops-1 >= 0 then
        newoutputs <- new Dictionary<int list, int list>()
    for i in 0..(NumberOfNonMaximumValue-1) do 
        let mutable newoutput = []
        for j in 0..(MinimumCoveringOutputParam.Length-1) do //change one row at each time
            if i = j then
                if MinimumCoveringOutputParam.[j] + 1 < maximumvalue then
                    newoutput <- MinimumCoveringOutputParam.[j] + 1 :: newoutput
                else
                    newoutput <- MinimumCoveringOutputParam.[j] :: newoutput
            else
                newoutput <- MinimumCoveringOutputParam.[j] :: newoutput
        let newoutput5 = List.rev newoutput
        if finaloutput.ContainsKey(newoutput5) = false then
            finaloutput.Add(newoutput5, newoutput5)            
        if numberofloops-1 >= 0 then
            finaloutput <- AllCombinationOfBasicOutput(NumberOfNonMaximumValue, newoutput5, numberofloops - 1, maximumvalue, &finaloutput)
    finaloutput

let MinimumCoveringOutput = MinimumCovering(debugcol1_3a, debugcol2_3a)
let MinimumCoveringOutputList = MinimumCoveringList(debugcol1_3a, debugcol2_3a)         
let NumberOfNonMaximum = NumberOfNonMaximumForCovering(MinimumCoveringOutput)
let mutable newoutputs3 = new Dictionary<int list, int list>()   
let comboutputs = AllCombinationOfBasicOutput(NumberOfNonMaximum, MinimumCoveringOutputList, NumberOfNonMaximum, 3, &newoutputs3)
let ChangeIntListToListInt(m : int list) : List<int> =
    let result = new List<int>()
    for i in 0..(m.Length-1) do
        result.Add(m.[i])
    result

for aa in comboutputs.Keys do
    let newaa = ChangeIntListToListInt(aa)
    WriteTableMultipleValuedLogic(debugcol1_3a, debugcol2_3a,newaa, "E:/martintonic.txt")
    System.IO.File.AppendAllText("E:/martintonic.txt", "*****\r\n")

expect to compare the output below to see whether below is full combinations

0,0=1
0,1=1
0,2=2
1,0=1
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=2
0,1=1
0,2=2
1,0=1
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=2
0,1=2
0,2=2
1,0=1
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=2
0,1=1
0,2=2
1,0=2
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=2
0,1=2
0,2=2
1,0=2
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=1
0,1=2
0,2=2
1,0=1
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=1
0,1=2
0,2=2
1,0=2
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=1
0,1=1
0,2=2
1,0=2
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=0
0,1=2
0,2=2
1,0=1
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=0
0,1=2
0,2=2
1,0=2
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=0
0,1=1
0,2=2
1,0=1
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****
0,0=0
0,1=1
0,2=2
1,0=2
1,1=1
1,2=2
2,0=2
2,1=2
2,2=2
*****

解决方案

Use max a b, not max (a,b). The former passes two arguments, the latter passes just one -- a pair (a,b).

这篇关于如何进行最大值为2的额外列视图组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆