Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Exponentiation-operator/GAP/exponentiation-operator.gap
Normal file
20
Task/Exponentiation-operator/GAP/exponentiation-operator.gap
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
expon := function(a, n, one, mul)
|
||||
local p;
|
||||
p := one;
|
||||
while n > 0 do
|
||||
if IsOddInt(n) then
|
||||
p := mul(a, p);
|
||||
fi;
|
||||
a := mul(a, a);
|
||||
n := QuoInt(n, 2);
|
||||
od;
|
||||
return p;
|
||||
end;
|
||||
|
||||
expon(2, 10, 1, \*);
|
||||
# 1024
|
||||
|
||||
# a more creative use of exponentiation
|
||||
List([0 .. 31], n -> (1 - expon(0, n, 1, \-))/2);
|
||||
# [ 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
# 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue