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.
import math def F(n): return math.pow(2, math.ceil(math.log(n, 2)))
Luke Bailey
Hello pajeet
Luke Foster
Take a base 2 log, return 2 to the next largest integer
Ian Ward
Ok you win. I was hoping faggots who couldn't into basic maths would whip out their loops.
That's a neat website.
Nolan Ward
I hadn't read the thread, but This user implemented what I said
Joseph King
>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?
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.
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
Liam Ross
woops, pic should have first term after the sigma as (1-p) not (1-)
Luis Cruz
int nextLargest(double n){ return Math.pow(2,Math.ceil(Math.log(n)/Math.log(2)); }
TRUE PAJEET LANGUAGE JAVA
Lucas Brown
did you notice how I typed int and not double as the return type?
Alexander Hughes
How the fuck do you think logarithms are claculated dumbass?
Dylan Long
>first solution >pajeet damn it, Sup Forums
John Flores
int nextlargestpowerof2(int n) { int largestpowerof2; largestpowerof2 = 1; while(largestpowerof2
Levi Torres
>I was hoping faggots who couldn't into basic maths would whip out their loops.
and then this happens
Dylan Harris
And how the fuck do you think logarithms are calculated dumbass?
Christopher Rogers
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.
Ethan Campbell
I'm a pajeet explain this to me
Nolan Ward
>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.
Nathan Edwards
>logs are implemented as loops
Are you mentally challenged?
Ethan Hughes
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.
Brody Taylor
So how are they implemented then?
Adrian Richardson
So how are they implemented?
Anthony Myers
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'.
Landon Brooks
You were right. I was the ignorant one.
Adam Campbell
Well that was an unexpected reply for Sup Forums
Hudson Gonzalez
This guy's right. OP is a faggot, as usual.
Noah Smith
not the same pajeet, but what if the Log returns a fixed value, say 7? What's ceiling(n) gonna do then?
Easton Fisher
F(unsigned int n): --n n |= n >> 1 n |= n >> 2 n |= n >> 4 n |= n >> 8 n |= n >> 16 return ++n
Jayden Bell
ceiling will just return n, if n is an integer. Integer as in the type of number, not the primitive data type.
Caleb Thompson
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.
Brody King
That should be evident given my description of ceiling.
Isaac Howard
unsigned next_power_of_2(unsigned n) { return n ? 1
Benjamin Edwards
return (n+1)
Landon Flores
Couldn't you just convert the number to binary, add a 1 in front and make the remaining digits zero?
Eli White
I just did that for a prefix sums algorithm in MPI.. Come on, you gotta have something better to do?
Lincoln Russell
What happens when n is negative? 0 for lim x -> -∞ (2^x)?
Henry Jackson
Well, shit. You saying that makes you much more emotionally stable and employable than most of Sup Forums so don't feel too bad.
Levi Morgan
Oh, forgot about 0 cases.
n= (n+1)
Tyler Adams
He's onto something...
That is one big ass street sign.
Jaxon Hernandez
This
Evan Fisher
> 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.
Levi Collins
It'll be less efficient in most cases.
Jaxson Wright
Exactly what I thought.
Carter Lee
#include int f (int n) { int powOf2 = log(n) / log(2); return pow(2, powOf2 + 1); }
youre test failed!
Owen Hernandez
> which are programmers.
programmers are lower than niggers
Josiah Martinez
>Not knowing that C has log2 >pow(2, x) instead of 1 Can't even indent code You're shit.
Oliver Parker
sry i am an engineer, i dont program much in anything but matlab and couldnt be shitted to look that up
William Hill
>image L O N D O N O N D O N
Brody Wilson
I'm a half-breed nignog. Where do I stand on the totem pole?