1
Name:
Anonymous
2012-01-06 11:59
#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;
}
23
Name:
Anonymous
2012-01-06 17:29
>>19
>>17
>>16
>>15
They all look like shit and are slower than the iterative version
25
Name:
Anonymous
2012-01-06 18:32
No,
>>23- san, they are the iterative version.
26
Name:
Anonymous
2012-01-06 19:41
$o=1;{(grep!($o%$_),2..$o++)||print$o;redo}
27
Name:
Anonymous
2012-01-06 19:46
>>22
>>19
>>18
>>17 '
>zerop
>plusp
why would you write more characters when (= 0 (...)) is much easier to write.
28
Name:
Anonymous
2012-01-06 19:49
>>27
This is what morons actually believe!
29
Name:
Anonymous
2012-01-06 19:52
>>28
would you like to explain your elitism rather than act like it's something special rather than just a more verbose way of saying it.
30
Name:
Anonymous
2012-01-06 21:08
>>27
If I were designing a Lisp dialect, I'd use
0? and
>0?.
31
Name:
Anonymous
2012-01-06 21:41
>>30
designing a language with numbers?, of course.
it's simple and more consistent with the rest of the system.
32
Name:
Anonymous
2012-01-06 23:28
>>31
That actually works in a lot of the schemes I've used.
(define (0? n) (= n 0))
#<unspecified>
(0? 4)
#f
(0? 0)
#t
33
Name:
Anonymous
2012-01-07 18:07
struct nil;
template<typename x, typename xs>
struct Cons {
typedef x car;
typedef xs cdr;
};
template<int n>
struct Constant {
enum { value = n };
};
template<int n>
struct isPrime {
template<int p, bool acc>
struct f {
template<bool presult, bool accresult>
struct predicate {
enum { result = (n % p != 0) && f<p + 1, accresult>::result };
};
template<bool accresult>
struct predicate<false, accresult> {
enum { result = accresult };
};
enum { result = predicate<(p * p <= n), acc>::result };
};
enum { result = f<2, n>::result };
};
template<>
struct isPrime<2> {
enum { result = true };
};
template<>
struct isPrime<1> {
enum { result = false };
};
template<int from, int to>
struct primesInRange {
template<bool presult, typename dummy_>
struct predicate;
template<typename dummy_>
struct predicate<true, dummy_> {
typedef Cons<Constant<from>, typename primesInRange<from + 1, to>::result> result;
};
template<typename dummy_>
struct predicate<false, dummy_> {
typedef typename primesInRange<from + 1, to>::result result;
};
typedef typename predicate<isPrime<from>::result, void>::result result;
};
template<int n>
struct primesInRange<n, n> {
typedef nil result;
};
template<typename xs>
struct printList {
static void execute() {
printf("%d\n", xs::car::value);
printList<typename xs::cdr>::execute();
};
};
template<>
struct printList<nil> {
static void execute() { };
};
#include <stdio.h>
int main() {
typedef primesInRange<2, 200>::result myPrimes;
printList<myPrimes>::execute();
}
34
Name:
Anonymous
2012-01-07 18:10
I'm puking, thanks /prog/ you just ruined my day
35
Name:
saging slowly
2012-01-07 18:12
def isPrime(n):
for x in range(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
36
Name:
Anonymous
2012-01-07 18:44
require "prime"
1.upto(1000000){|x|puts x if x.prime?}
You all can suck my dick. Why do you keep making shit people have done for you in a more efficient way?
Fuck you all.
37
Name:
Anonymous
2012-01-07 18:53
>>36
Most languages do not have built in utilities for prime numbers. I personally did not know they extended the Fixnum class to check for prime numbers. Thank you for this wisdom.
39
Name:
Anonymous
2012-01-07 18:59
The classic APL solution:
(∼R∊R∘.×R)/R←1↓⍳R←1000
41
Name:
Anonymous
2012-01-07 19:46
>>36
Go scrub another toilet you stupid shit mental midget.
42
Name:
Anonymous
2012-01-08 1:01
>>41
Go scrub another midget you stupid shit mental toilet.