"CPSC 449 - Assignment 4, David Mitchell, 989256, 2001-4-10" "This program is meant to generate pairs of primes (numbers that are" "prime and have a difference of two). It uses some classes from primes.st" "original code is located at the bottom, in the PrimPairs method." "Class declarations, including my own primepairs." Class TrivInterval Object lower cur Class FactorFilter Object myFac gen Class Primes Object pGen lastF Class PrimePairs Object myG "TrivInterval comes from primes.st" Methods TrivInterval from: a1 lower <- a1. cur <- lower | next | t | t <- cur. cur <- cur + 1. ^t ] "FactorFilter comes from primes.st" Methods FactorFilter remove: facVal from: genVal myFac <- facVal. gen <- genVal | next | poss | [(poss <- gen next) notNil] whileTrue: [(poss \\ myFac ~= 0) ifTrue: [^ poss]]. ^ nil ] "Primes comes from primes.st, and generates primes using the previous classes" Methods Primes new pGen <- TrivInterval new; from: 2. lastF <- pGen next. | next | tmp | tmp <- lastF. pGen <- (FactorFilter new; remove: lastF from: pGen). "FactorFilter comes from primes.st" Methods FactorFilter remove: facVal from: genVal myFac <- facVal. gen <- genVal | next | poss | [(poss <- gen next) notNil] whileTrue: [(poss \\ myFac ~= 0) ifTrue: [^ poss]]. ^ nil ] "Primes comes from primes.st, and generates primes using the previous classes" Methods Primes new pGen <- TrivInterval new; from: 2. lastF <- pGen next. | next | tmp | tmp <- lastF. pGen <- (FactorFilter new; remove: lastF from: pGen). lastF <- pGen next. ^tmp ] "Here is my class - the one that generates pairs of primes. It works by using Primes to generate two new primes, and then checking if they are a pair" Methods PrimePairs new myG <- Primes new. | next | p1 p2 | p1 <- (myG next). p2 <- (myG next). "the loop goes until we find a pair of primes, getting the next highest" "prime, and checking to see if it and the last prime are a pair." [p2 - p1 ~= 2] whileTrue: [p1 <- p2. p2 <- (myG next)]. ^((p1 asString), ',', p2 asString) "return the pair." ]