Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
53
Task/Ternary-logic/Phix/ternary-logic.phix
Normal file
53
Task/Ternary-logic/Phix/ternary-logic.phix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
enum type ternary T, M, F end type
|
||||
|
||||
function t_not(ternary a)
|
||||
return F+1-a
|
||||
end function
|
||||
|
||||
function t_and(ternary a, ternary b)
|
||||
return iff(a=T and b=T?T:iff(a=F or b=F?F:M))
|
||||
end function
|
||||
|
||||
function t_or(ternary a, ternary b)
|
||||
return iff(a=T or b=T?T:iff(a=F and b=F?F:M))
|
||||
end function
|
||||
|
||||
function t_xor(ternary a, ternary b)
|
||||
return iff(a=M or b=M?M:iff(a=b?F:T))
|
||||
end function
|
||||
|
||||
function t_implies(ternary a, ternary b)
|
||||
return iff(a=F or b=T?T:iff(a=T and b=F?F:M))
|
||||
end function
|
||||
|
||||
function t_equal(ternary a, ternary b)
|
||||
return iff(a=M or b=M?M:iff(a=b?T:F))
|
||||
end function
|
||||
|
||||
function t_string(ternary a)
|
||||
return iff(a=T?"T":iff(a=M?"?":"F"))
|
||||
end function
|
||||
|
||||
procedure show_truth_table(integer rid, integer unary, string name)
|
||||
printf(1,"%-3s |%s\n",{name,iff(unary?"":" T | ? | F")})
|
||||
printf(1,"----+---%s\n",{iff(unary?"":"+---+---")})
|
||||
for x=T to F do
|
||||
printf(1," %s ",{t_string(x)})
|
||||
if unary then
|
||||
printf(1," | %s",{t_string(call_func(rid,{x}))})
|
||||
else
|
||||
for y=T to F do
|
||||
printf(1," | %s",{t_string(call_func(rid,{x,y}))})
|
||||
end for
|
||||
end if
|
||||
printf(1,"\n")
|
||||
end for
|
||||
printf(1,"\n")
|
||||
end procedure
|
||||
|
||||
show_truth_table(routine_id("t_not"),1,"not")
|
||||
show_truth_table(routine_id("t_and"),0,"and")
|
||||
show_truth_table(routine_id("t_or"),0,"or")
|
||||
show_truth_table(routine_id("t_xor"),0,"xor")
|
||||
show_truth_table(routine_id("t_implies"),0,"imp")
|
||||
show_truth_table(routine_id("t_equal"),0,"eq")
|
||||
Loading…
Add table
Add a link
Reference in a new issue