Skip to content

Instantly share code, notes, and snippets.

@yelinaung
Last active August 29, 2015 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yelinaung/97a4d23504fee9d58e0b to your computer and use it in GitHub Desktop.
Save yelinaung/97a4d23504fee9d58e0b to your computer and use it in GitHub Desktop.
λ Lambda Camp (Responses). Event url : https://www.facebook.com/events/1498733757081658
function power(base,expo) {
switch(expo) {
case 0: return 1;
case 1: return base;
default: expo--;return base*power(base,expo);
}
}
power = lambda do |b,p| return p > 1 ? power.call(b+b, p-1) : b; end; power.call(2,8)
def power a,b
a**b
end
power 2,8
def power(m:Int,n:Int):Int = if (x>0) x*power(x,n-1) else 1
power(2,8)
int compute(int input) {
if (input == 1) return 2;
if (input == 0) return 1;
return compute(input - 1) + compute(input - 1);
}
int a = 2;
int c = 0;
int pow(int pow) {
if (pow > c) {
a += a;
pow(++c);
}
}
System.out.println(pow(8));
function expo(b, e) {
var result;
if (e == 1) {
return b;
}
if (e == 2) {
return b * b;
}
if (e % 2 == 1) {
return b * expo(b, e - 1);
} else {
result = expo(b, e / 2);
return result * result;
}
}
expo(2, 8);
product [2,2,2,2,2,2,2,2]
public static void main(String[] args) {
int a = 2;
if (a < 300) {
a = a + a;
}
System.out.print(a);
}
public static void main(String args[]) {
int a = 2;
int b, c, d, e, f, g, h;
b = a + a;
c = b + b;
d = c + c;
e = d + d;
f = e + e;
g = f + f;
h = g + g;
System.out.print(a + b + c + d + e + f + g);
}
public static void main(String[] args) {
int ans = 2;
int count = 2;
while (count <= 8) {
ans = ans + ans;
count++;
}
System.out.print(ans);
}
// Javascript Version of 2 power 8 using only '+' operator and functions.
var add = function(a, b) {
return a + b
};
var add2 = function(a) {
return add(2, a);
};
var mul2 = function(n) {
if (n === 0) {
return 0;
} else if (n === 1) {
return 2;
} else return add2(mul2(n - 1));
};
var twoPowerN = function(n) {
if (n === 0) {
return 1;
} else {
return mul2(twoPowerN(n - 1));
}
};
var twoPower8 = function() {
return twoPowerN(8);
}
function TestTwoPowerEightEqualsTwoFiveSix() {
var result = twoPower8();
if (result === 256) {
console.log(""
The test passes "");
} else {
console.log(""
The test fails.
"" + result + ""
not equals 256.
"");
}
}
TestTwoPowerEightEqualsTwoFiveSix();
public class NewDecimal {
static int sum = 0;
static int base;
static int exp;
static double temp;
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean checkExp, checkBase;
String baseText, expText;
Scanner scan = new Scanner(System.in);
do {
System.out.println("Enter base number : ");
baseText = scan.next();
temp = base;
CheckIfNumber c = new CheckIfNumber();
checkBase = c.CheckIfNumber(baseText);
System.out.println("Enter exponential number : ");
expText = scan.next();
CheckIfNumber b = new CheckIfNumber();
checkExp = b.CheckIfNumber(expText);
if (checkExp == false) {
System.out.println("Please enter Exponent in number.");
}
if (checkBase == false) {
System.out.println("Please enter Base in number");
}
} while (checkExp == false || checkBase == false);
base = Integer.parseInt(baseText);
exp = Integer.parseInt(expText);
temp = base;
// /////////////////////////////////////////////////////
if (exp == 0) {
sum += 1;
System.out.println("The result is " + sum);
} else if (exp == 1) {
sum += base;
System.out.println("The result is " + sum);
}
if (exp > 1) {
Exp(exp, base, temp);
}
if (exp < 1) {
ExpMinus(exp, base, temp);
}
}
private static void ExpMinus(int exp2, int base2, double temp2) {
// TODO Auto-generated method stub
exp2 = Math.abs(exp2);
double result = 0.0;
if (exp2 > 1) {
temp2 = Power(base2, temp2);
ExpMinus(exp2 - 1, base2, temp2);
} else {
result = 1 / temp2;
System.out.println("The result in Decimal " + result);
int t = (int) temp2;
System.out.println("The result in Fraction " + 1 + "/" + t);
}
}
public static double Power(int b, double temp2) {
double sumBase = 0;
if (b > 0) {
sumBase = Power(b - 1, temp2) + temp2;
}
return sumBase;
}
public static void Exp(int exp, int base, double temp2) {
if (exp > 1) {
temp2 = Power(base, temp2);
Exp(exp - 1, base, temp2);
} else {
int t = (int) temp2;
System.out.println("The result is " + t);
}
}
}
public class CheckIfNumber {
public boolean CheckIfNumber(String text) {
try {
double hopnum = Double.parseDouble(text);
return true;
} catch (NumberFormatException e) {
return false;
}
}
}
//Java
import java.text.*;
import java.util.*;
public class ATalk {
static int power;
static int ans;
static int base;
static int sum = 0;
static int times;
static boolean isNegativeBase = false;
static boolean isNegativePower = false;
static String answer = """";
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println(""Enter base: "");
base = scan.nextInt();
sum = base;
System.out.println(""Enter exponential power for your base: "");
power = scan.nextInt();
ans = Power(base,1);
if(isNegativeBase){
if(power%2 != 0){
int a = ans * (-1);
answer += a;
}
else
answer += ans;
}
if(isNegativePower){
answer = ""1/"" + ans + ""\t"";
double a = 1/(double) ans;
answer += a;
}
System.out.println(""Answer is "" + answer);
}
public static int Power(int num,int pow){
if(base < 0){
isNegativeBase = true;
base = Math.abs(num);
num = base;
System.out.println(""isNegativeBase "" + num);
}
if(power < 0){
isNegativePower = true;
power = Math.abs(power);
System.out.println(""isNegativePower "" + power);
}
if(base == 0){
return 0;
}
else if(power == 0){
return 1;
}
else if(power == 1){
return base;
}
else if(pow == power){
return sum;
}
else{
times = 1;
sum = Addition(num,times,num);
pow++;
return Power(sum,pow);
}
}
public static int Addition(int repeatedSum, int t, int number){
if(t == base){
return repeatedSum;
}
else{
repeatedSum += number;
t++;
return Addition(repeatedSum, t, number);
}
}
}
function power(number, power) {
result = 1;
for (var i = 1; i <= power; i++) {
result *= number;
}
return number;
}
power(2, 8);
int Recursive(int base, int power) {
if (power == 0) return 1;
return (base * Recursive(base, (power - 1)));
}
-module (exp).
-export ([exponential/2]).
exponential(Num, 0) ->
Num;
exponential(Num, Exp) ->
exponential(Num * 2, Exp - 1).
exp:exponential(2, 8). %512
let rec pow a = function
| 0 -> 1
| 1 -> a
| n ->
let b = pow a (n / 2) in
b * b * (if n mod 2 = 0 then 1 else a)
func power(b int, p int) int {
if p == 1 {
return b
}
return power(b+b, p-1)
}
<?php
$num = 2;
power($num);
function power($num, $count=1, $power=8) {
$sum = $num+$num;
if($count == $power-1)
echo $sum;
else
power($sum, ++$count);
}
?>
mypower :: (Num a1, Num a, Eq a1, Eq a) => a1 -> a -> a1
mypower b e = powerMulti b e b
powerMulti :: (Num a2, Num a1, Num a, Eq a2, Eq a) => a1 -> a -> a2 -> a1
powerMulti b 0 _ = 1
powerMulti b 1 _ = b
powerMulti b e count = powerMulti (multi b count) (e-1) count
multi :: (Num a1, Num a, Eq a) => a1 -> a -> a1
multi b 0 = 0
multi b n = b + multi b (n-1)
main = do
print . mypower 2 $ 8
class Test {
static int a = 2;
static int b = 8;
static int c = 0;
public static void main(String[] args) {
System.out.println("Hello World");
int d = sun(a);
System.out.println(d);
}
private static int sun(int a) {
if (b != 0) {
--b;
c = a + c;
sun(c);
}
return c;
}
}
console.log(((i) => Math.pow(2,i))(8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment