Jow Forums Interview

Congrats Mr. user on making it to the third stage in our interview process. Let's see how you handle this problem.

Write a recursive function "pow" that takes in 2 numbers X and Y and calculates X^Y.

You should know how to do this user.

Attached: download.jpg (286x176, 8K)

Other urls found in this thread:

lmgtfy.com/?q=0 ^ 0
twitter.com/SFWRedditVideos

Ops back at it again!

public float pow(float x, float y, float result = 1) {
if(y==0) {
return result;
}
else {
return pow(x, y-1, x*result)
}
}

Then you call the function like this:
pow(x, y), the third parameter is optional and defaults to one.

This was easy, I typed this up on my phone in 5 minutes which is why the formatting sucks.
If this is hard for you, you should get off Jow Forums.

>Thank you for your time. While you were the quickest candidate to solve the function, we went with another candidate because our HR told us we do not have employees employees from that diversity group.

cool code user! u got the job!
now write some python shiet plugint assfuck fuck fukign why do I have to write retarded code fukkk

Python is for faggots. Learn C# or Java so you can actually get a job.

I said 2 parameters, not 3. Sorry user, it seems like you can't follow directions.

Thanks for taking the time to interview, we wish you good luck on your job search.

It's an optional parameter retard. You can't write a recursive function to do exponents without a third variable to hold the result.
You never said to only use 2 parameters, you said write a function that takes in 2 numbers.

is that Y xor Y or X to the white, er, Yth power?

You just went full retard. Get off Jow Forums and learn recursion, script kiddie.

Maybe you shouldn't use a shit language and you wouldn't need to habe three parameters

>Yth power

Racist.

x to the power of y

Lol, okay retard, go ahead and show the class your function in Python that calls the math library.

def pow(x,y): # suck my dick faggot
if y==0:
return 1
elif y%2==0:
return pow(x*x, y/2)
else:
return (x * pow(x * x, (y-1)/2))

(defun pow (x y)
(if (zerop y)
1
(* x (pow x (1- y)))))

or tail recursive
(defun pow (x y &optional (acc 1))
(if (zerop y)
acc
(pow x (1- y) (* x acc))))

cuteness is justice

var powerOf = function(x, y){

if(y === 0){
return x;
}
return powerOf(x + x, y - 1);

}

Your function sucks dick nig nog. That elif is unnecessary.

public float pow(float x, float y) {
if(y < 1)
return 1;
else
return x * pow( x, y-1);
}

Learn how to code pleb.

Ladies and gentlemen, we have a web developer.

dipshit my code is O(log y) and yours is O(y)

template
constexpr INT pow(INT X, INT Y, INT result=1) {
if(Y

Recursion sucks, just give me the job, boss

x^0 == 1
You failed.

>Your code
Top kek

>not implementing with TMP

Dickskin this won't work for y>=6 are u high

>if(y === 0)

#include
#include

double pow(double base, double exponent) {
if(exponent < 0) {
return 1 / pow(base, -exponent);
}

if(exponent == 0) {
return 1;
}

if(exponent == 1) {
return base;
}

return base * pow(base, exponent - 1);
}

int main() {
for(double a = -3; a

Attached: 1520888289684.jpg (412x430, 24K)

this seems to work
int power(int x, int y)
{
return x * (y < 3 ? x : power(x, y - 1));
}

oh shit

Attached: 2018-04-07-014044_1024x768_scrot.png (1024x768, 98K)

In [8]: pow(6,20)
Out[8]: 3656158440062976


Please enjoy a coupon for the autism ward on the way out.

This is correct but doesn't work for negative exponents.

>TMP

constexpr is more readable and does the same thing. See

>not engaging interviewer with a discussion about potential big-o complexities, argument types and negative exponents

faggots

>(You)'d again
teach me the secrets of constexpr senpai

Attached: 2018-04-07-014516_1024x768_scrot.png (1024x768, 86K)

Python let’s you get an easy overpaid “””days scientist””” meme job

Java gets you jobs for Pajeet

function pow(x, y) {
return y ? x * pow(x, y - 1) : 1;
}


JavaScript master race.

pow x = x * y

haskel man

that's exactly what i tried in c but for some reason it was giving me weird results. i had to mangle it into this
before it would work right.

it appears to me that Jow Forums can't into coding

Nope, how many people on Jow Forums are actually in CS related majors/fields?

lol

cs majors can't code either

Lol wut? There are literally 10 examples in this thread.

I hate to derail but this is relevant and didn't want to make a new thread:

I have a second interview coming up. I'm slowly learning things you do NOT say (admitting weaknesses without asking, saying you're bad at something, being too honest, etc)

Anyone have some to add to the list?

your desired salary

Unless they ask, right? What about mentioning other interviews you've had or other companies you've been looking into

Don't. Ever. Tell. Them.

You always wait for their offer first, always always always. If their offer is low, you can tell them about your competing offers.

If you tell them your desired salary first, you might be going lower than they're willing to offer.

Rule of thumb is whoever puts out a number first loses.

This fucking proves that the majority of Jow Forums can't code for shit. Seriously, my little brother in fucking middle school can probably write this with only two parameters. You don't need 3 parameters for taking x to the power of y recursively.
public static int XToY(int x, int y)
{
if (y == 0)
{
return 1;
}
else
{
return x * XToY(x, y - 1);
}
}

It is as simple as that. Now go learn to code.

be a black lesbian
your skills as a programmer don't matter half as much as the tax breaks the company can get for hiring you

your third base case is pointless, user

One post proves the majority? You're literally retarded.

int pow (int base,int exp)
{
if(exp = 0) return base*pow(base,exp)
}

he said the function is "pow", which means your code would not run when called by them and you failed the interview, listen to directions. you can feel free to apply for one of our call center support jobs though

pow(int x, int y) {
if (x==0)
return 0;
elseif (y==0)
return x;
elseif (y>=1)
return x*x;
else
return x * pow(x, y-1);
}

x^0 is always 1 you fucking mong

What is 0 ^ 0 ?

lmgtfy.com/?q=0 ^ 0

>can't even post code properly
lurk moar faggot

Note that this will never terminate if y is not an integer

This is wrong in every case except x=0

Do you fuckers even test your code?
Brainlets everywhere

{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}

data Zero
data Succ n

class Add x y t | x y -> t
instance Add Zero y y
instance (Add x y t) => Add (Succ x) y (Succ t)

class Mul x y t | x y -> t
instance Mul Zero y Zero
instance (Mul x y t, Add y t s) => Mul (Succ x) y s

class Pow x y t | x y -> t
instance Pow n Zero (Succ Zero)
instance (Pow x y t, Mul x t s) => Pow x (Succ y) s


*Main> :set -XFlexibleContexts
*Main> :t undefined :: (Pow (Succ (Succ Zero)) (Succ (Succ Zero)) r) => r
undefined :: (Pow (Succ (Succ Zero)) (Succ (Succ Zero)) r) => r
:: Succ (Succ (Succ (Succ Zero)))

how about now?
pow(int x,int y) {
if (x == 0 && y ==0)
return 1;
elseif (y == 0)
return 1;
elseif (x == 0)
return 0;
else
return x * pow(x, y-1);
}

Reminder that being able to do these little kiddie problems doesn't make you a good programmer.

You must be able to work with others, including women.

Attached: 47b.jpg (665x574, 25K)

def pow (x,y):
return 1 if y==0 else x*pow(x,y-1)

>implying there's more than 1 in hundred famales that aren't diversity hires

True, never neglect good communication skills anons, even if you're autistic and hate everyone

Diversity hires or not. You still have to work with them.

const pow = (x, y) => x ** y

or if the company sucks and doesn't use babel-env:
const pow => (x, y) => Math.pow(x, y)

>implying diversity hires do anything that qualifies as "actual work"

If a diversity hire tries to take credit for something I do and I call them out on it, do I get fired?

Depends, are they sjw?

take a wild guess

>1. diversity hire tries to take credit for others' work
>2. "is she sjw?"
if she's got the moral integrity to do 1), she'd have to be retarded to not use 2)

If they do diversity hiring they're probably sjw.

Diversity hiring is required by law in some locations.

>required by law in some locations
and by the diversity racketeers in most remaining ones
>that's a nice company you got there, fellow cishet white male. Sure would be a shame if someone were to call it...
>sexist

Not all tech females are diversity hires. Our company employs two women - one is a true diversity hire, because it takes her 2 weeks to implement single editable field, but she has double D tits, other one is an exceptional data scientist and clearly knows her shit.

sweet

>2 waman
out of how many meatbags?

Imagine sucking on double D's monster bust, popping your mouth off each one in alternating fashion MMMMWUH *pop* MMMMWUH *pop* MMMMWUH *pop* as she moans like crazy

>You can't write a recursive function to do exponents without a third variable to hold the result.
Yes you can. You just can't write tail-recursive functions.

#include

int recr_pow();

int main(int argc, char* argv[])
{
int result = recr_pow(argv[1], argv[2]);
printf("%d", result);

return 0;
}

int recr_pow(int x, int y)
{
if ( y == 0 )
{
return( 1 );
}
else if ( y == 1 )
{
return( x );
}
else
{
return( x * recr_pow( x, y-1 ));
}
}

Compile it as an executable:
gcc program.c -o program.exe

Execute format:
./filename x y

e.g./program 5 2

it's not satisfying unless you bite so hard you sink your teeth into them and there's blood everywhere.

Even then it's not as satisfying as biting the nipples clean off.

What's the point of not being tail recursive? You're basically asking for a stack overflow.

Fucking kek

function pow (x, y) {
if (y == 1) return x
return x * pow(x, y - 1)
}

function pow (x, y) {
if (y == 1) return x
if (y == 0) return 1
if (y < 0) return 1 / (x * pow(x, (-y) - 1))
return x * pow(x, y - 1)
}

fixed

Of course it's stupid to calculate exponentials by recursion, but that's true whether it's tail-recursive or not.

>Function calculating x raised to the power of the exponent y
>Not wanting exponential runtime

template
constexpr T pow(T a, int b)
{
return b == 0? 1 : a * pow(a, b-1);
}

>thinking the majority of Jow Forums can actually code and understand technology
That's really funny, user. lurk moar

Why the fuck is everyone coding this with base case y=0 and y =1. For god's sake, y=0 is all you need. Ya'll a bunch of fucking retards.

If you don't have y == 1 accounted for you'll get x^2 as a result using the Alg that most people in this thread are using

def pow(a, b):
return a ** b

Attached: 1515212955528.png (485x608, 413K)

def pow(x, y):
if y < 0:
return pow(1 / x, -y)
elif y == 0:
return 1
elif y == 1:
return x
elif y % 2 == 0:
return pow(x * x, y // 2)
else:
return x * pow(x * x, y // 2)


Negatives powers accounted for

nice recursion