Hello, Sup Forums

Hello, Sup Forums.
I have devised a simple pajeet test:
>Produce a function F(n) returning, for some integer n, the next largest integer power of two after n.

Remember, no cheating. It will be clear which of you are street shitters, and which are programmers.

Other urls found in this thread:

codility.com/programmers/challenges/
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=997
twitter.com/SFWRedditVideos

poo

Codility is already full of these challenges, and it's score leaderboard is full of pajeets codility.com/programmers/challenges/

2^(n % 2) +1

import math
def F(n):
return math.pow(2, math.ceil(math.log(n, 2)))

Hello pajeet

Take a base 2 log, return 2 to the next largest integer

Ok you win.
I was hoping faggots who couldn't into basic maths would whip out their loops.

That's a neat website.

I hadn't read the thread, but
This user implemented what I said

>I was hoping faggots who couldn't into basic maths would whip out their loops.
Just 1 week of algorithm complexity studies should make anyone aware of log(x, 2)

What noise does a theoretical computer scientist make when they drown?

log log log log log

kek what a shitty ass question. Here is a better one
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=997

def F(n : int):
return (n + 2) ** 2

working on this (amateur programmer), here's where I am after 15 minutes. am i on the right track?

(1-p)^(n-1)p returns the probability that the nth attempt will be the first success (it didn't happen n-1 times, it did happen once).

asking the odds it will happen to Serial 7 out of N=10 is like asking the odds it will happen on the 7th attempt, the 17th attempt, the 27th attempt, the 37th...

more generally Serial S's Ith attempt occurs on trial (N*(I-1))+S
So for i=0, n=10, S=7.

I=1: (10*(1-1))+7=7
I=2 (10*(2-1))+7 = 17

etc

Then the probability that S will get the first success is the sum of the chance it will happen on every ith attempt to infinity. I think it's pretty obvious this function should converge so I should get an answer out of it.

sum(i=1->inf) (1-p)^((N*(I-1))+S)-1)p (pic related)

I used some variables in two ways here but I think the general idea is clear.

next step is to examine the sum more carefully and turn it into a non garbage function that I can easily calc

woops, pic should have first term after the sigma as (1-p) not (1-)

int nextLargest(double n){
return Math.pow(2,Math.ceil(Math.log(n)/Math.log(2));
}

TRUE PAJEET LANGUAGE JAVA

did you notice how I typed int and not double as the return type?

How the fuck do you think logarithms are claculated dumbass?

>first solution
>pajeet
damn it, Sup Forums

int nextlargestpowerof2(int n) {
int largestpowerof2;
largestpowerof2 = 1;
while(largestpowerof2

>I was hoping faggots who couldn't into basic maths would whip out their loops.

and then this happens

And how the fuck do you think logarithms are calculated dumbass?

It depends on the language, but I'm willing to wager that fyl2x() or any other language's implementation is faster than implementing your own shit.

I'm a pajeet explain this to me

>casting to floating point, doing a bunch of floating point operations in a for loop, and casting back is fasther than just doing bit shifts in a for loop
Pajeet detected.

>logs are implemented as loops

Are you mentally challenged?

You have some number n.

Lets say it's 72.

You want the next highest integer power of 2, so some number 2^n > 72

A logarithm of a number returns the power that you have to raise the base of the logarithm to in order to get it

So Log base 2 of 8 is 3 (2*2*2 = 8).

Log base 2 of 72 is 6.169925

We need a bigger number than 72, so we need to raise 2 to a higher power than 6.169925.

What's the next highest integer after 6.169925? It's 7.

ceiling(n) does the same thing I just did, it rounds up.

2^7 is the next highest integer power of 2.

do you get it now.

So how are they implemented then?

So how are they implemented?

Somebody else, but I simply would have asked the tester questions. This would be under the guises of 'trying to get him to communicate his idea more thoroughly'.

You were right. I was the ignorant one.

Well that was an unexpected reply for Sup Forums

This guy's right. OP is a faggot, as usual.

not the same pajeet, but what if the Log returns a fixed value, say 7? What's ceiling(n) gonna do then?

F(unsigned int n):
--n
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
return ++n

ceiling will just return n, if n is an integer. Integer as in the type of number, not the primitive data type.

Problem is if you pass a power of two in, F(n) will return n. So it should be floor(n) + 1 to get the next largest integer power of 2 after n.

That should be evident given my description of ceiling.

unsigned next_power_of_2(unsigned n)
{
return n ? 1

return (n+1)

Couldn't you just convert the number to binary, add a 1 in front and make the remaining digits zero?

I just did that for a prefix sums algorithm in MPI.. Come on, you gotta have something better to do?

What happens when n is negative? 0 for lim x -> -∞ (2^x)?

Well, shit. You saying that makes you much more emotionally stable and employable than most of Sup Forums so don't feel too bad.

Oh, forgot about 0 cases.

n= (n+1)

He's onto something...

That is one big ass street sign.

This

> Clever girl.

Besides, I was about to ask if we were allowed to use the math methods.
Logarithms are the best way to inversely verify power value.

It'll be less efficient in most cases.

Exactly what I thought.

#include
int f (int n) {
int powOf2 = log(n) / log(2);
return pow(2, powOf2 + 1);
}

youre test failed!

> which are programmers.

programmers are lower than niggers

>Not knowing that C has log2
>pow(2, x) instead of 1 Can't even indent code
You're shit.

sry i am an engineer, i dont program much in anything but matlab and couldnt be shitted to look that up

>image
L O N D O N
O
N
D
O
N

I'm a half-breed nignog. Where do I stand on the totem pole?