2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,5 +1,10 @@
|
|||
{{basic data operation}} [[Category:Simple]]
|
||||
{{basic data operation}}
|
||||
[[Category:Simple]]
|
||||
|
||||
;Task:
|
||||
Write a function that takes two logical (boolean) values, and outputs the result of "and" and "or" on both arguments as well as "not" on the first arguments.
|
||||
|
||||
If the programming language doesn't provide a separate type for logical values, use the type most commonly used for that purpose.
|
||||
|
||||
If the language supports additional logical operations on booleans such as XOR, list them as well.
|
||||
<br><br>
|
||||
|
|
|
|||
1
Task/Logical-operations/APL/logical-operations.apl
Normal file
1
Task/Logical-operations/APL/logical-operations.apl
Normal file
|
|
@ -0,0 +1 @@
|
|||
LOGICALOPS←{(⍺∧⍵)(⍺∨⍵)(~⍺)(⍺⍲⍵)(⍺⍱⍵)(⍺≠⍵)}
|
||||
|
|
@ -1,4 +1 @@
|
|||
logical(true, true)
|
||||
logical(true, false)
|
||||
logical(false, false)
|
||||
logical(false, true)
|
||||
[true, false].each { a -> [true, false].each { b-> logical(a, b) } }
|
||||
|
|
|
|||
|
|
@ -1,31 +1,27 @@
|
|||
/*REXX program to show some binary (AKA bit or logical) operations. */
|
||||
x=1; y=0
|
||||
/*═════════════════════════════════════════════════echo X,Y values*/
|
||||
call TT 'name', "value"
|
||||
call TT 'x' , x
|
||||
call TT 'y' , y
|
||||
/*═════════════════════════════════════════════════negate X,Y values*/
|
||||
call TT 'name', "negated"
|
||||
call TT 'x' , \x /*some REXXes support the ¬ char.*/
|
||||
call TT 'y' , \y
|
||||
/*═════════════════════════════════════════════════AND X,Y values*/
|
||||
call TT 'value','value',"AND"; do x=0 to 1
|
||||
do y=0 to 1; call TT x,y, x & y; end
|
||||
end
|
||||
/*═════════════════════════════════════════════════OR X,Y values*/
|
||||
call TT 'value','value',"OR"; do x=0 to 1
|
||||
do y=0 to 1; call TT x,y, x | y; end
|
||||
end
|
||||
/*═════════════════════════════════════════════════XOR X,Y values*/
|
||||
call TT 'value','value',"XOR"; do x=0 for 2
|
||||
do y=0 for 2; call TT x,y, x && y; end
|
||||
end
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────TT subroutine───────────────────────*/
|
||||
TT: parse arg a.1,a.2,a.3,a.4; hdr=length(a.1)\==1; if hdr then say; w=7
|
||||
do TT=0 to hdr; _=
|
||||
do k=1 for arg(); _=_ center(a.k,w); end /*k*/
|
||||
say _
|
||||
a.=copies('─',w)
|
||||
end /*TT*/
|
||||
return
|
||||
/*REXX program demonstrates some binary (also known as bit or logical) operations.*/
|
||||
x=1; y=0; @v= 'value' /*set initial values of X & Y; literal.*/
|
||||
/* [↓] echo the X and Y values.*/
|
||||
call TT 'name', "value" /*display the header (title) line. */
|
||||
call TT 'x' , x /*display "x" and then the value of X.*/
|
||||
call TT 'y' , y /* " "y" " " " " " Y */
|
||||
/* [↓] negate the X; then the Y value.*/
|
||||
call TT 'name', "negated" /*some REXXes support the ¬ character*/
|
||||
call TT 'x' , \x /*display "x" and then the value of ¬X*/
|
||||
call TT 'y' , \y /* " "y" " " " " " ¬Y*/
|
||||
/*both DO loops use 0 and 1 for values.*/
|
||||
call TT @v, @v, 'AND'; do x=0 for 2; do y=0 for 2; call TT x, y, x & y; end /*y*/
|
||||
end /*x*/
|
||||
|
||||
call TT @v, @v, 'OR'; do x=0 for 2; do y=0 for 2; call TT x, y, x | y; end /*y*/
|
||||
end /*x*/
|
||||
|
||||
call TT @v, @v, 'XOR'; do x=0 for 2; do y=0 for 2; call TT x, y, x && y; end /*y*/
|
||||
end /*x*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
TT: parse arg @.1,@.2,@.3,@.4; hdr=length(@.1)\==1; if hdr then say; w=7
|
||||
do j=0 to hdr; _=; do k=1 for arg(); _=_ center(@.k,w); end /*k*/
|
||||
say _
|
||||
@.=copies('═', w) /*define the header separator line. */
|
||||
end /*j*/ /*W: is used for the width of a column*/
|
||||
return
|
||||
|
|
|
|||
14
Task/Logical-operations/Vala/logical-operations.vala
Normal file
14
Task/Logical-operations/Vala/logical-operations.vala
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
public class Program {
|
||||
private static void print_logic (bool a, bool b) {
|
||||
print ("a and b is %s\n", (a && b).to_string ());
|
||||
print ("a or b is %s\n", (a || b).to_string ());
|
||||
print ("not a %s\n", (!a).to_string ());
|
||||
}
|
||||
public static int main (string[] args) {
|
||||
if (args.length < 3) error ("Provide 2 arguments!");
|
||||
bool a = bool.parse (args[1]);
|
||||
bool b = bool.parse (args[2]);
|
||||
print_logic (a, b);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue