Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Newfags can't Bruteforce

Name: Anonymous 2010-08-22 21:39

    for(i=2;i<max;i++) {
        for(j=2;j<i;j++) {
            if((i%j)==0) { tmp=1;}
        }
        if(tmp==0) { primes++; }
        tmp=0;
    }

Name: Anonymous 2010-08-22 21:47

That is terrible code. You should feel ashamed.

Name: ???????????????????????? 2010-08-22 21:48

polecat.c:1:error: ‘i’ undeclared (first use in this function)
polecat.c:1:error: ‘max’ undeclared (first use in this function)
polecat.c:2:error: ‘j’ undeclared (first use in this function)
polecat.c:3:error: ‘tmp’ undeclared (first use in this function)
polecat.c:5:error: ‘primes’ undeclared (first use in this function)

Name: ???????????????????????? 2010-08-22 21:58

????????????????????????

Name: fags up in 2010-08-22 22:38

Name: Anonymous 2010-08-23 0:12

lol bump

Name: Anonymous 2010-08-23 2:10

>>1
9.6/10
I mean, It's nearly impossible for me not to rewrite that code.  You are truly one of the greats, >>1.

Name: Anonymous 2010-08-23 5:16

fibs = loeb $ 0 : 1 : map (flip (!!) + (flip (!!) . succ)) [0..]

Name: Anonymous 2010-08-25 4:58

Here's an APL dialect, "J".

  pr=:(1&p:#[)@i.
  pr 30
2 3 5 7 11 13 17 19 23 29]


Let's take a look at (1&p:#[)@i.
n&f = monadic g where g p = n f p.
f@g = monadic h where h n = f (g n).
(f g h) n = (f n) g (h n) (called a "monadic fork"), so
((f g h) @ i) n = (f (i n)) g (h (i n)).
So that means pr y is ((1&p:) (i. y)) # ([ (i. y)).
1 p: y returns 1 only if y is prime. i. y returns the first y non-negative integers. [ is the identity function. # is "copy", but with 0 and 1 it can be "filter"]]
  1 2 3#4 5 6
4 5 5 6 6 6
  1 0 1 0 1#1 2 3 4 5
1 3 5

1&p: is applied to all of i. y, returning 1's for all primes. [ i. y is just i. y, so for each 1 in the left list an element of the right list is returned]

Have you read your Learning J today, /prog/?

Name: >>9 2010-08-25 4:59

>>9 The lack of BBCode tags in the explanation is due to the [ function causing mismatching brackets.  Fuck you, Shitchan.

Name: Anonymous 2010-08-25 5:34

Name: Anonymous 2010-08-25 6:30


for(i=2;i<max;i++) {
 for(j=2;j<i;j++) {
   if((i%j)==0) {
    tmp=1;
    }
   }
   if(tmp==0) {
    primes++;
   }
   tmp=0;
 }

Name: Anonymous 2010-08-25 6:32

/polecat kebabs/

Name: Anonymous 2010-08-25 6:36

primes=1;
i=1;
while((i+=2)<max){
 j=2,tmp=0;
 while(j++<i)tmp+=!(i%j);
 if(!tmp)primes++;
}

FV would be proud.

Name: Anonymous 2010-08-25 6:48

>>14
That should be if(tmp) or tmp+=i%j; of course.

Name: foff``faggot''guy 2010-08-25 12:45

>>11,13
It's an obvious troll, why are you even responding? I doubt a /g/ (or /b/) denizen would know what "bruteforce" means and would be able to design a working algorithm[1].
_________________________
1 Not actually tested.[sub]

Name: >>16 2010-08-25 12:47

I'll never understand Shiichan.

:/

Name: Anonymous 2010-08-25 13:13


#lang r5rs
(define-syntax scons
  (syntax-rules ()
    ((_ a b) (cons a (delay b)))))

(define scar car)

(define scdr (lambda (stream) (force (cdr stream))))

(define enumerate-integers
  (lambda(from)
    (scons from (enumerate-integers (+ 1 from)))))

(define stream-filter
  (lambda(p? stream)
    (if (p? (scar stream))
        (scons (scar stream) (stream-filter p? (scdr stream)))
        (stream-filter p? (scdr stream)))))

(define stream-map
  (lambda(p stream)
    (scons (p (scar stream)) (stream-map p (scdr stream)))))

(define multiples-of
  (lambda(n)
    (stream-map (lambda(x) (* x n)) (enumerate-integers 1))))

(define wheel-filter
  (lambda(wheels stream)
    (let ((v (scar stream)))
      (if (memq v (map scar wheels))
          (wheel-filter (rotate-wheels v wheels) (scdr stream))
          (scons (scar stream) (wheel-filter (cons (scdr (multiples-of v)) wheels) (scdr stream)))))))

(define rotate-wheels
  (lambda(value wheels)
    (cond ((null? wheels) '())
          ((eq? value (scar (car wheels))) (cons (scdr (car wheels)) (rotate-wheels value (cdr wheels))))
          (else (cons (car wheels) (rotate-wheels value (cdr wheels)))))))

(define primes
  (wheel-filter (list (scdr (multiples-of 2))) (enumerate-integers 2)))

Name: Anonymous 2010-08-25 15:47

/trapezoid/

Name: Anonymous 2010-08-25 15:48

>>18
scons
( ≖‿≖)

Name: Anonymous 2010-08-25 16:50

/parallelogram\

Name: Anonymous 2010-08-25 17:09

>>16
Actually, being imageboard patrons, they will no doubt have felt the urge to (find tripcodes|"crack" some encryption somewhere|partake in some "raid" or other|anything else where passwords are involved), all of which involve brute force attacks.

Name: Anonymous 2010-11-28 9:28

Name: Anonymous 2011-02-03 5:32

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List