# 函数式编程思想：耦合和组合，第1部分

import java.util.HashSet;

import java.util.Iterator;

import java.util.Set;

import static java.lang.Math.sqrt;

public class ClassifierAlpha {

private int number;

public ClassifierAlpha(int number) {

this.number = number;

}

public boolean isFactor(int potential_factor) {

return number % potential_factor == 0;

}

public Set factors() {

HashSet factors = new HashSet();

for (int i = 1; i <= sqrt(number); i++)

if (isFactor(i)) {

}

return factors;

}

static public int sum(Set factors) {

Iterator it = factors.iterator();

int sum = 0;

while (it.hasNext())

sum += (Integer) it.next();

return sum;

}

public boolean isPerfect() {

return sum(factors()) - number == number;

}

public boolean isAbundant() {

return sum(factors()) - number > number;

}

public boolean isDeficient() {

return sum(factors()) - number < number;

}

}

import java.util.HashSet;

import java.util.Set;

import static java.lang.Math.sqrt;

public class PrimeAlpha {

private int number;

public PrimeAlpha(int number) {

this.number = number;

}

public boolean isPrime() {

Set primeSet = new HashSet() {{

return number > 1 &&

factors().equals(primeSet);

}

public boolean isFactor(int potential_factor) {

return number % potential_factor == 0;

}

public Set factors() {

HashSet factors = new HashSet();

for (int i = 1; i <= sqrt(number); i++)

if (isFactor(i)) {

}

return factors;

}

}

import java.util.Set;

import static java.lang.Math.sqrt;

import java.util.HashSet;

public class FactorsBeta {

protected int number;

public FactorsBeta(int number) {

this.number = number;

}

public boolean isFactor(int potential_factor) {

return number % potential_factor == 0;

}

public Set getFactors() {

HashSet factors = new HashSet();

for (int i = 1; i <= sqrt(number); i++)

if (isFactor(i)) {

}

return factors;

}

}

import java.util.Iterator;

import java.util.Set;

public class ClassifierBeta extends FactorsBeta {

public ClassifierBeta(int number) {

super(number);

}

public int sum() {

Iterator it = getFactors().iterator();

int sum = 0;

while (it.hasNext())

sum += (Integer) it.next();

return sum;

}

public boolean isPerfect() {

return sum() - number == number;

}

public boolean isAbundant() {

return sum() - number > number;

}

public boolean isDeficient() {

return sum() - number < number;

}

}

import java.util.HashSet;

import java.util.Set;

public class PrimeBeta extends FactorsBeta {

public PrimeBeta(int number) {

super(number);

}

public boolean isPrime() {

Set primeSet = new HashSet() {{

return getFactors().equals(primeSet);

}

}

public class FClassifier {

static public boolean isFactor(int number, int potential_factor) {

return number % potential_factor == 0;

}

static public Set factors(int number) {

HashSet factors = new HashSet();

for (int i = 1; i <= sqrt(number); i++)

if (isFactor(number, i)) {

}

return factors;

}

public static int sumOfFactors(int number) {

Iterator it = factors(number).iterator();

int sum = 0;

while (it.hasNext())

sum += it.next();

return sum;

}

public static boolean isPerfect(int number) {

return sumOfFactors(number) - number == number;

}

public static boolean isAbundant(int number) {

return sumOfFactors(number) - number > number;

}

public static boolean isDeficient(int number) {

return sumOfFactors(number) - number < number;

}

}

public static boolean isPrime(int number) {

Set factors = factors(number);

return number > 1 &&

factors.size() == 2 &&

factors.contains(1) &&

factors.contains(number);

}

import java.util.HashSet;

import java.util.Set;

import static java.lang.Math.sqrt;

public class Factors {

static public boolean isFactor(int number, int potential_factor) {

return number % potential_factor == 0;

}

static public Set of(int number) {

HashSet factors = new HashSet();

for (int i = 1; i <= sqrt(number); i++)

if (isFactor(number, i)) {

}

return factors;

}

}

public class FClassifier {

public static int sumOfFactors(int number) {

Iterator it = Factors.of(number).iterator();

int sum = 0;

while (it.hasNext())

sum += it.next();

return sum;

}

public static boolean isPerfect(int number) {

return sumOfFactors(number) - number == number;

}

public static boolean isAbundant(int number) {

return sumOfFactors(number) - number > number;

}

public static boolean isDeficient(int number) {

return sumOfFactors(number) - number < number;

}

}

import java.util.Set;

public class FPrime {

public static boolean isPrime(int number) {

Set factors = Factors.of(number);

return number > 1 &&

factors.size() == 2 &&

factors.contains(1) &&

factors.contains(number);

}

}

## [技术] 谈谈编程思想

https://zhuanlan.zhihu.com/p/19736530?columnSlug=prattle 作者:陈天链接:https://zhuanlan.zhihu.com/p/19736530来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 这段时间又攒了很多答应了,但还未动手的文章.大概一两周前,有个读者留言:「程序君,能发篇文章有关编程思想的吗?我是编程初学者,对编程思想没啥概念,求传授点经验!」 今天就讲讲编程思想.编程思想是个宏大的主题,我不敢保

## js 函数式编程 浅谈

js 函数式编程 函数式的思想, 就是不断地用已有函数, 来组合出新的函数. 函数式编程具有五个鲜明的特点: 1. 函数是"第一等公民" 指的是函数与其他数据类型一样,处于平等地位 2. 只用"表达式",不用"语句" "表达式"(expression)是一个单纯的运算过程,总是有返回值: "语句"(statement)是执行某种操作,没有返回值. 3. 没有"副作用" 指的是函数内部与外