[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 27 KB, 470x427, umirin.jpg [View same] [iqdb] [saucenao] [google]
4223803 No.4223803 [Reply] [Original]

#include <iostream>
using namespace std;

///////World's smallest prime number generator (u jelly? u mirin? lol deal with it homo)
int main() {
int count,n = 0;
cout << "\t>that feel when prime number generator\n\nEnter the number at which you want to stop checking primes--go!\n";
cin >> n;
cout << "\n\n";
for(int i=2;i<=n;++i) {
for(int b=2;b<i;++b) {
if((i%b)==0 && i!=b) ++count;
}
if(count==0) cout << i << " is a prime\n";
count=0;
}
return 0;
}

>> No.4223812

> smallest
> SEPPLES
Lies.

Also pretty sure I saw this on Hacker News. Repost of a repost etc.

>> No.4223844

There is some kind of old inside joke I'm missing here, right.

>> No.4223850 [DELETED] 

>>4223812
>>4223844
naw, i coded this myself right now

>> No.4223856

>>4223850
Go show your mom. I'm sure she'll be so proud and even put it on the refrigerator for you.

>> No.4223886

>>4223856
>checking up to i-1 for divisors and not sqrt(i) or at least i/2

reported for highschool

>> No.4224346

bump for glorious justice

>> No.4224355

The worst C++ code I have seen in my life.

>> No.4224364
File: 26 KB, 425x315, sippin-03.jpg [View same] [iqdb] [saucenao] [google]
4224364

>>4224355
> mfw someone thinks all C++ code isn't equally horrible, that some might actually be more horrible than others

>> No.4224366
File: 9 KB, 308x264, faggot.jpg [View same] [iqdb] [saucenao] [google]
4224366

At least this troll thread is /sci/ related.

>> No.4224367 [DELETED] 

>>4224355
stay jelly

nice dubs tho

>> No.4224383

#include <iostream>
int main() { std::cout << 2 << std::endl; }

Mine is smaller. And it only generates the smallest prime number, hence making it the smallest smallest prime number generator.

>> No.4224388

>>4224383
> implying you can prove that this program is indeed the smallest program for printing the smallest prime number.

>> No.4224387
File: 16 KB, 1003x154, sshot_2012-01-06_14:45:54.png [View same] [iqdb] [saucenao] [google]
4224387

Shorter.

<span class="math">\mathrm{Prime /@ Range@100}[/spoiler]

>> No.4224399

>>4224388
I can write something shorter, but I have to use shell scripting.

#!/bin/sh
echo 2

>> No.4224419

Common Lisp begin code

2

end code

>> No.4224438
File: 41 KB, 460x500, 1253930-this_thread_again_super.jpg [View same] [iqdb] [saucenao] [google]
4224438

Can't we all just get along?

>> No.4224655

>>4223886

Also, why "&& i!=b"? If b goes from 2 to i-1, of course i!=b...

>> No.4224657

print "2"

>> No.4224694

perl -E 'for(2..shift){say if (1x$_)!~/^1?$|^(11+?)\1+$/}' 100

>> No.4224715

>>4224694
Seriously, what fucktard came up with the syntax for this language.

>> No.4224756

>>4224694
>dat perl code

I cannot decipher it, but I'm too scared to run it. Maybe there's some malicious hacker shit hidden inside.

>> No.4224772

Prelude> let isPrime n = and [ mod n x /= 0 | x <- [2..n-1] ]
Prelude> let primes n = [ x | x <- [2..n], isPrime x ]
Prelude> primes 100
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47&#4
4;53,59,61,67,71,73,79,83,89,97]

I'd take sqrt(n) but ghci was bitching about ambiguous type lol

>> No.4224803

bool isPrime(unsigned long long n){
if((n==0)||n==1)
return false;
if((n==2)||(n==3)||(n==5)||(n==7))
return true;
if( ((n%2)==0) || ((n%3)==0) || ((n%5)==0) || ((n%7)==0) )
return false;
unsigned long int root=static_cast<unsigned long int>(root2(n));
if((n%root)==0)
return false;
#if timing
int tim2=(int)time(0);
#endif
unsigned long long int bound=root-211;
unsigned long long int i=11;
if (root>211)
{
for(;bound>i;i+=210)
{
if ( ((n%(i+0))==0) || ((n%(i+2))==0) || ((n%(i+6))==0) || ((n%(i+8))==0) || ((n%(i+12))==0) || ((n%(i+18))==0)
|| ((n%(i+20))==0) || ((n%(i+26))==0) || ((n%(i+30))==0) || ((n%(i+32))==0) || ((n%(i+36))==0) || ((n%(i+42))==0)
|| ((n%(i+48))==0) || ((n%(i+50))==0) || ((n%(i+56))==0) || ((n%(i+60))==0) || ((n%(i+62))==0) || ((n%(i+68))==0)
|| ((n%(i+72))==0) || ((n%(i+78))==0) || ((n%(i+86))==0) || ((n%(i+90))==0) || ((n%(i+92))==0) || ((n%(i+96))==0)
|| ((n%(i+98))==0) || ((n%(i+102))==0) || ((n%(i+110))==0) || ((n%(i+116))==0) || ((n%(i+120))==0) || ((n%(i+126))==0)
|| ((n%(i+128))==0) || ((n%(i+132))==0) || ((n%(i+138))==0) || ((n%(i+140))==0) || ((n%(i+146))==0) || ((n%(i+152))==0)
|| ((n%(i+156))==0) || ((n%(i+158))==0) || ((n%(i+162))==0) || ((n%(i+168))==0) || ((n%(i+170))==0) || ((n%(i+176))==0)
|| ((n%(i+180))==0) || ((n%(i+182))==0) || ((n%(i+186))==0) || ((n%(i+188))==0) || ((n%(i+198))==0) || ((n%(i+200))==0) )
{
return false;
}
}
}
for(;root>i;i+=2)
{
if((n%i)==0)
return false;
}
#if timing
cout<<" time "<<time(0)-tim2<<" \n";
#endif
return true;
}

>> No.4224804

>>4224387
gay

>> No.4224806

>>4224803
unsigned long long int root2(unsigned long long int n) {
if(n==0)
return 0;
if(n==1)
return 1;

unsigned long long int i=0,f=(static_cast<unsigned long long>(1)<<32);
unsigned long long int j=(static_cast<unsigned long long>(1)<<31);
while(1)
{
if((n/j==j)||(n/j==(j+1))||(i==f)){
return j;
}
if((n/j==(j-1)))
return j-1;
else if(n/j>j)
{
i=j;
}
else
{
f=j;
}
j=(i+f)/2;
}
return j;
}

>> No.4224817

>>4224806
>fag.cpp:12: error: ‘root2’ was not declared in this scope

>> No.4224827

>>4224806
>>4224803
Makes me wonder what kind of asswhipe out there would actually find amusement in writing such a horrible piece of code.. Whether it does what it's supposed to is irrelevant.

>> No.4224833
File: 47 KB, 438x400, orly.jpg [View same] [iqdb] [saucenao] [google]
4224833

>>4224827
>Whether it does what it's supposed to is irrelevant

>> No.4224841

>>4224817

move root2 above isPrime and both of them above main function if you can't into function prototyping...

>> No.4224846

>>4224841
>function prototyping
>not forward declaration

idiot

>> No.4224873

>>4224827
I wonder why fags care about compact code more than they do about efficient code...

>>4224846
>implying there's a meaningful difference

>> No.4224882
File: 11 KB, 251x226, laughingwhores.jpg [View same] [iqdb] [saucenao] [google]
4224882

>>4224873
>he thinks his crappy c code is efficient

>> No.4224885

>>4223803
>show off generating primes
>16bit/32bit ints everywhere
>2002

ISHYDDT

>> No.4225784

>>4223803

>using namespace std
>2012

ISHYGDDT

>> No.4226244
File: 36 KB, 587x679, asdasf.jpg [View same] [iqdb] [saucenao] [google]
4226244

public class sadface
{
public static void main(String[] args)
{

System.out.println("son, im dissapoint");
}
}

>> No.4226266

you posted this on /prog/ OP and we all made fun of your shitty solution

(defun prime (n i)
(cond ((zerop (mod n i)) -1)
((< i (isqrt n)) (prime n (1+ i))

(defun primes (l h)
(if (plusp (prime l)) (print l))
(if (< l h) (primes (1+ l) h))