panjang(S,P).supaya P memberi nilai panjang elemen yang dimasukkan ke dalam senarai S.
contoh :
panjang([b,a,c,k], P). -> P = 4.Penyelesaian:
panjang([], 0).
panjang([Head | Tail], X) :-
panjang(Tail, Y),
X is Y + 1.Muaturun
panjang(S,P).panjang([b,a,c,k], P). -> P = 4.panjang([], 0).
panjang([Head | Tail], X) :-
panjang(Tail, Y),
X is Y + 1.elemen(X,[S],T).elemen(c, [b,a,c,k], [b,a,k]).elemen(Head, [Head | Tail], Tail).
elemen(Remove_Elemen, [Head | Tail], [Head | New_Tail]):-
elemen(Remove_Elemen, Tail, New_Tail).
Solusi: Anda boleh dapatkan salinan jawapan daripada
http://code.google.com/p/fuzzy-refrigerator/
svn checkout http://fuzzy-refrigerator.googlecode.com/svn/trunk/ fuzzy-refrigerator
"The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions."
X1 X2 Y
0 0 0
0 1 1
1 0 1
1 1 0
%XOR function using McCulloch-Pitts neuron
clear;
clc;
%Getting weights and threshold value
disp('Enter Weights');
w11 = input('Weight w11 = ');
w12 = input('Weight w12 = ');
w21 = input('Weight w21 = ');
w22 = input('Weight w22 = ');
v1 = input('Weight v1 = ');
v2 = input('Weight v2 = ');
disp('Enter Threshold Value');
theta = input('theta = ');
x1 = [0 0 1 1];
x2 = [0 1 0 1];
z = [0 1 1 0];
con = 1;
while con
zin1 = x1 * w11 + x2 * w21;
zin2 = x1 * w21 + x2 * w22;
for i = 1:4
if zin1(i) >= theta
y1(i) = 1;
else
y1(i) = 0;
end
if zin2(i) >= theta
y2(i) = 1;
else
y2(i) = 0;
end
end
yin = y1 * v1 + y2 * v2;
for i = 1:4
if yin(i) >= theta
y(i) = 1;
else
y(i) = 0;
end
end
disp('Output of Net');
disp(y);
if y == z
con = 0;
else
disp('Net is not learning enter another set of weights and Threhold value');
w11 = input('Weight w11 = ');
w12 = input('Weight w12 = ');
w21 = input('Weight w21 = ');
w22 = input('Weight w22 = ');
v1 = input('Weight v1 = ');
v2 = input('Weight v2 = ');
theta = input('theta = ');
end
end
disp('McCulloch-Pitts Net for XOR function');
disp('Weights of Neuron Z1');
disp(w11);
disp(w21);
disp('Weights of Neuron Z2');
disp(w12);
disp(w22);
disp('Weights of Neuron Y');
disp(v1);
disp(v2);
disp('Threshold value');
disp(theta);
X1 X2 Y
0 0 0
0 1 0
1 0 1
1 1 0
%ANDNOT function using Mcculloch-Pitts neuron
clear;
clc;
%Getting weights and threshold value
disp('Enter weights');
w1 = input('Weight w1 = ');
w2 = input('Weight w2 = ');
disp('Enter Threshold Value');
theta = input('thete = ');
y = [0 0 0 0];
x1 = [0 0 1 1];
x2 = [0 1 0 1];
z = [0 0 1 0];
con = 1;
while con
zin = x1 * w1 + x2 * w2;
for i = 1:4
if zin(i) >= theta
y(i) = 1;
else
y(i) = 0;
end
end
disp('Output of Net');
disp(y);
if y == z
con = 0;
else
disp('Net is not learning enter another set of weights and threshold value');
w1 = input('Weight w1 = ');
w2 = input('Weight w2 = ');
theta = input('thete = ');
end
end
disp('Mcculloch-Pitts Net for ANDNOT function');
disp('Weights of Neuron');
disp(w1);
disp(w2);
disp('Threshold value');
disp(theta);
%Illustration of various activation function used in NN's
x = -10:0.1:10;
tmp = exp(-x);
y1 = 1 ./ (1 + tmp);
y2 = (1 - tmp) ./ (1 + tmp);
y3 = x;
subplot(231); plot(x, y1); grid on;
axis([min(x) max(x) -2 2]);
title('Logistic Function');
xlabel('(a)');
axis('square');
subplot(232); plot(x, y2); grid on;
axis([min(x) max(x) -2 2]);
title('Hyperbolic Tangent Function');
xlabel('(b)');
axis('square');
subplot(233); plot(x, y3); grid on;
axis([min(x) max(x) min(x) max(x)]);
title('Identity Function');
xlabel('(c)');
axis('square');
/** Converts from inches to centimeters */public static double inchToCentimeter(double in)/** Converts from centimeters to inches */public static double centimeterToInch(double cm)
Inches Centimeters Centimeters Inches
1.0 2.54 5.0 1.96
2.0 5.08 10.0 3.93
...
9.0 22.86 45.0 17.71
10.0 25.4 50.0 19.68
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package conversionbetweeninchesandcentimeters;
/**
*
* @author dekwan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
sop("Inches Centimeters Centimeters Inches\n");
// SOP Inches to Centimeters
for (int i = 1; i <= 10; i++)
{
sop("" + i);
sop(" " + inchToCentimeter(i));
sop(" " + i * 5);
sop(" " + centimeterToInch(i * 5) + "\n");
}
}
/** Converts from inches to centimeters */
public static double inchToCentimeter(double in)
{
return in * 2.54;
}
/** Converts from centimeters to inches */
public static double centimeterToInch(double cm)
{
return cm / 2.54;
}
private static void sop(String string)
{
System.out.print(string);
}
}
CCCCCCCCC ++ ++
CC ++ ++
CC ++++++++++++++ ++++++++++++++
CC ++++++++++++++ ++++++++++++++
CC ++ ++
CCCCCCCCC ++ ++
#include<iostream>
using namespace std;
int main()
{
cout << "CCCCCCCCC ++ ++" << endl;
cout << "CC ++ ++" << endl;
cout << "CC ++++++++++++++ ++++++++++++++" << endl;
cout << "CC ++++++++++++++ ++++++++++++++" << endl;
cout << "CC ++ ++" << endl;
cout << "CCCCCCCCC ++ ++" << endl;
return 0;
}
****************************************
* Programming Assignment 1 *
* Computer Programming I *
* Author: Dek Wan *
* Due Date: Wednesday, Nov 10 *
****************************************
#include<iostream>
using namespace std;
int main()
{
cout << "****************************************" << endl;
cout << "* Programming Assignment 1 *" << endl;
cout << "* Computer Programming I *" << endl;
cout << "* Author: Dek Wan *" << endl;
cout << "* Due Date: Thursday, Nov 10 *" << endl;
cout << "****************************************" << endl;
return 0;
}
1
2 1
3 2 1
...
n n-1 ... 3 2 1
public static void displayPattern(int n)
9
1
21
321
4321
54321
654321
7654321
87654321
987654321
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package displayingpatterns;
import java.util.Scanner;
/**
*
* @author dekwan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner scan = new Scanner(System.in);
displayPattern(scan.nextInt());
}
public static void displayPattern(int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = n; j > i; j--)
{
sop(" ");
}
for (int j = i; j > 0; j--)
{
sop("" + j);
}
sop("\n");
}
}
public static void sop(String str)
{
System.out.print(str);
}
}
public static void displaySortedNumbers(double num1, double num2, double num3)
5678 1234 6789
6789.0
5678.0
1234.0
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sortingthreenumbers;
import java.util.Scanner;
/**
*
* @author dekwan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner scan = new Scanner(System.in);
double num1 = scan.nextDouble();
double num2 = scan.nextDouble();
double num3 = scan.nextDouble();
displaySortedNumbers(num1, num2, num3);
}
public static void displaySortedNumbers(double num1, double num2, double num3)
{
double temp;
while (num1 < num2 || num2 < num3)
{
temp = num1;
num1 = num2;
num2 = temp;
while (num2 < num3)
{
temp = num2;
num2 = num3;
num3 = temp;
}
}
sopl("");
sopl("" + num1);
sopl("" + num2);
sopl("" + num3);
}
public static void sopl(String str)
{
System.out.println(str);
}
}
public static int sumDigits(long n)
234
9
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package summingthedigitsinaninterger;
import java.util.Scanner;
/**
*
* @author dekwan
*/
public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner scan = new Scanner(System.in);
long number = scan.nextInt();
sopl(sumDigits(number) + "\n");
}
public static void sopl(String str)
{
System.out.println(str);
}
public static int sumDigits(long digit)
{
int num;
int sum = 0;
while (digit != 0)
{
num = (int) digit % 10;
digit = digit / 10;
sum = sum + num;
}
return sum;
}
}
public static int getTriangularNumber(int n)
100
1 3 6 10 15 21 28 36 45 55
66 78 91 105 120 136 153 171 190 210
231 253 276 300 325 351 378 406 435 465
496 528 561 595 630 666 703 741 780 820
861 903 946 990 1035 1081 1128 1176 1225 1275
1326 1378 1431 1485 1540 1596 1653 1711 1770 1830
1891 1953 2016 2080 2145 2211 2278 2346 2415 2485
2556 2628 2701 2775 2850 2926 3003 3081 3160 3240
3321 3403 3486 3570 3655 3741 3828 3916 4005 4095
4186 4278 4371 4465 4560 4656 4753 4851 4950 5050
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package triangularnumbers;
import java.util.Scanner;
/**
*
* @author dekwan
*/
public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner scan = new Scanner(System.in);
int number = scan.nextInt();
sop("\n");
for (int i = 0; i < number; i += 10)
{
for (int j = 1; j <= 10; j++)
{
sop(getTriangularNumber(i + j) + " ");
}
sop("\n");
}
}
public static int getTriangularNumber(int n)
{
return (n * (n + 1)) / 2;
}
public static void sop(String str)
{
System.out.print(str);
}
}
./configure make make check sudo make installatau anda boleh menggunakan arahan yang telah diberikan dalam setiap pekej perisian yang telah anda muat turun. Setelah semuanya selesai, anda boleh memasang Doxygen dengan arahan;
./configure make sudo make installSenarai "platform-type" anda boleh perolehi dari folder kod sumber Doxygen yang telah anda muat turun.