The AI Cookbook 3

Page 1

1 of 39 The AI Cookbook 3 By Ian Beardsley Copyright © 2016 by Ian Beardsley ISBN: 978-1-365-22018-0


2 of 39 In the AI Cookbook, we established the connection of the building blocks of AI (doped silicon) to the building blocks of organic life (Amino Acids) and, the skeletons of organic life (Arenes, Alkanes, Alkenes, Alkynes) to the skeleton of AI (scandium, a lightweight strong metal). We showed that the recipe and its ingredients are written in Nature’s AI Cookbook. We further suggest AI, is part of a natural process outside of the human endeavor to make it. 


3 of 39 Harmonic Mean

Geometric Mean

Arithmetic Mean 


4 of 39




The Golden Ratio


5 of 39 The AI Building Block






6 of 39





7 of 39





8 of 39


9 of 39 DNA and Logic Gates



10 of 39 The instructions of organic life are in the sequencing of four compounds, Adenine (A), Guanine (G), Cytosine (C), Thymine (T), where as the structure of a computer is in a series of switches that are either “on” or “off”, depending on the input. Adenine only combines with Thymine (A=T) and Guanine only combines with Cytosine (G=C). The computer switches that are either on or off are made from logic gates, such as “And” and “Or” gates. The A, G, C, T make up DNA (Deoxyribose Nucleic Acid). They are arranged in pairs of four along a twisted ladder, or “Double Helix”.


11 of 39 Adenine NH2 | = C—

—N C = || C—H C — N— —N | H

N | H_ C =

Guanine

O || C =

N —

H—N | H2N—C

C || C — —

= N

= C—H — N | H

Cytosine NH2 | C = — N C—H | || O= C || — —C—H N | H


12 of 39 Thymine

O || C — H —N | O=C —

— C — CH3 || C—H — N | H


13 of 39 An “Or” gate with one on and one off:

+1.2eV —————|>—————————> out (9.6E-20 J, or 0.6 eV) | | —————|>———| | | R | | —————————

An “And” gate: A———————<|———————————-> out | | | | | __+__ | — B ———————<|——— | | ————————————————————> out


14 of 39 cbots Ian Beardsley © 2016


15 of 39 mechanics.c #include <stdio.h> int main (void) { printf("\n"); float sh, th, hn, n, h,l, part1, part2, foot, upperarm, forearm; printf("Proportions Of Robot in hands\n"); printf("How long is the robot shin? "); scanf("%f", &sh); printf("What is the length of the neck? "); scanf("%f", &n); printf("What is the distance from chin to top of head? "); scanf("%f", &h); th=(2.0/3.0)*sh; hn=(1.0/3.0)*th; l=(sh+th); part1=l+hn; part2=2.0/3.0*(part1+n+h); foot=(1.0/3.0)*sh; upperarm=th; forearm=(3.0/2.0)*upperarm; printf("foot = %.2f ", foot); printf("shin = %.2f ", sh); printf("thigh = %.2f ", th); printf("part one = %.2f ", part1); printf("part two = %.2f\n", part2); printf("height = %.2f ", part1+part2); printf("upper arm = %.2f\n ", upperarm); printf("forearm, elbow to knuckles = %.2f ", forearm); printf("\n"); } 


16 of 39


17 of 39 cbots.c #include <stdio.h> int main (void) { printf("\n"); float height, chin, neck, nipples, navel, hips; float knees, feet, shoulders, elbow, wrist, fingertips; printf("proportions of cbot.\n"); printf("Height: "); scanf("%f", &height); chin = (7.0/8.0)*height; neck=(6.75/8.0)*height; nipples = (6.0/8.0)*height; navel = (5.0/8.0)*height; hips = (4.0/8.0)*height; knees = (2.0/8.0)*height; feet = (0.0)*height; shoulders = (6.75/8.0)*height; elbow = (5.0/8.0)*height; wrist = (4.0/8.0)*height; fingertips =(3.0/8.0)*height; printf("feet=%.2f , knees=%.2f , hips=%.2f ", feet, knees, hips); printf("\n"); printf("navel=%.2f , nipples=%.2f , neck=%.2f ", navel, nipples, neck); printf("chin=%.2f\n", chin); printf("shoulders=%.2f , elbows=%.2f , wrists=%.2f", shoulders, elbow, wrist); printf("\n"); printf("fingertips=%.2f", fingertips); printf("\n"); printf("\n"); }


18 of 39 jharvard@appliance (~): cd Dropbox jharvard@appliance (~/Dropbox): make cbots clang -ggdb3 -O0 -std=c99 -Wall -Werror cbots.c cbots jharvard@appliance (~/Dropbox): ./cbots proportions of cbot. Height: 8 feet=0.00 , knees=2.00 , hips=4.00 navel=5.00 , nipples=6.00 , neck=6.75 chin=7.00 shoulders=6.75 , elbows=5.00 , wrists=4.00 fingertips=3.00 jharvard@appliance (~/Dropbox): 

-lcs50 -lm -o


19 of 39 Computer Science At: Harvard (C) MIT (Python) University of Honk Kong (Java)


20 of 39 Compsci Homework CS50 Python Java Student: Ian Beardsley



21 of 39 Programs In C



22 of 39 Hello World #include <stdio.h> int main(void) { printf("hello, world\n"); }


23 of 39 #include <cs50.h> #include <stdio.h> #include <math.h> int main (void) { float amount=0.01; do { printf("amount owed: "); amount= GetFloat(); } while (amount<=0); float pennies = 100.0*amount; float cents = roundf(pennies); float float float float

quarter= 0; dime= 0; nickel= 0; penni= 0;

while (cents>0) if (cents>=25.0) { cents=cents-25.0; quarter=quarter+1; } else if (cents>=10.0) { cents=cents-10.0; dime=dime+1; } else if (cents>=5.0) { cents=cents-5.0; nickel=nickel+1; } else if (cents>=1.0) { cents=cents-1.0; penni=penni+1; } int sum = quarter+dime+nickel+penni; printf("%i\n", sum); }


24 of 39 #include <cs50.h> #include <stdio.h> int main (void) { printf("amount owed: "); float amount= GetFloat(); float cents= 100.0*amount; float quarter= 0; float dime= 0; float nickel= 0; float penni= 0; while (cents>0) if (cents>=25.0) { cents=cents-25.0; quarter=quarter+1; } else if (cents>=10.0) { cents=cents-10.0; dime=dime+1; } else if (cents>=5.0) { cents=cents-5.0; nickel=nickel+1; } else if (cents>=1.0) { cents=cents-1.0; penni=penni+1; } printf("%f %f %f %f %f\n",quarter,dime,nickel,penni,quarter +dime+nickel+penni); 


25 of 39 #include <cs50.h> #include <stdio.h> int main(void) { int n; do { printf("Choose a positive number less than or equal to 23: "); n=GetInt(); } while (n<=0 || n>23);

for (int j=1; j<=n;j++) { for (int i=1; i<=n;i++) { if (j>=n+1-i) { printf("#"); } else { printf(" "); } } printf("#"); printf("\n"); } } }


26 of 39 Caesar’s Cipher #include <stdio.h> #include <cs50.h> #include <string.h> int main (int argc, string argv[1]) { int k = atoi(argv[1]); if (argc>2 || argc<2) { printf("Give me a single string: "); } else { printf("Give me a word: "); } string s = GetString(); for (int i=0, n=strlen(s); i<n; i++) { printf("%c", s[i]+k); } printf("\n"); } 


27 of 39

Programs In Python



28 of 39

Hello, World! print 'hello world' print 'I like 6.00.1x' Multiply a=int(raw_input("Give me an int: ")); b=int(raw_input("Give me another int: ")); product=0 while (a>0): a=a-1; product=b+product; print("Product of a and b is: "+str(product)) Name name=raw_input('Enter your name: '); print('Are you ' +name+ '?'); answer=raw_input('Answer: '); print('Thank you');

Remainder x=int(raw_input('Enter an int: ')) if x%2 == 0: print(' ') print('even') else: print(' ') print('odd') print('Done with conditional') Square y=float(raw_input('Enter a number: ')) print('square of y: ') print(y*y) 


29 of 39 Programs In Java



30 of 39 public class Lab01 { public static void main(String[] args) { // Please code in the following area // --------------------------------System.out.println("Hello, world!"); System.out.println("Hello, beautiful"); System.out.println("Hola, amigo!");

// --------------------------------} }


31 of 39 import comp102x.IO; public class Lab02 { public static void multiply() { // Please write your code after this line System.out.print("Enter an integer, x: "); int x=IO.inputInteger(); System.out.print("Enter an integer, y: "); int y=IO.inputInteger(); int Product=x*y; IO.outputln("Answer = " + Product);

} public static void calculateTriangleArea() { // Please write your code after this line System.out.print("Enter the width of the triangle: "); float w=IO.inputFloat(); System.out.print("Enter the height of the triangle: "); float h=IO.inputFloat(); float Area=(w*h)/2; IO.outputln("The triangle area = " + Area);

} public static void solveQuadraticEquation() { // Please write your code after this line System.out.print("Enter a: "); double a=IO.inputDouble(); System.out.print("Enter b: "); double b=IO.inputDouble(); System.out.print("Enter c: "); double c=IO.inputDouble(); double square = b*b; double rootOne = (-b+(Math.sqrt(square-4*a*c)))/(2*a); double rootTwo = (-b-(Math.sqrt(square-4*a*c)))/(2*a);


32 of 39 IO.outputln("First solution for x = " + rootOne); IO.outputln("Second solution for x = " + rootTwo);

} }



33 of 39 jharvard@appliance (~): cd Dropbox jharvard@appliance (~/Dropbox): make run clang -ggdb3 -O0 -std=c99 -Wall -Werror run.c -lcs50 -lm -o run jharvard@appliance (~/Dropbox): ./run 3 Give me a word: coors frruv hello, world amount owed: 1.76 7.000000 0.000000 0.000000 1.000000 8.000000 Choose a positive number less than or equal to 23: 5 ## ### #### ##### ###### jharvard@appliance (~/Dropbox):  





34 of 39





35 of 39


36 of 39


37 of 39 #include <stdio.h> #include <cs50.h> #include <string.h> #include <math.h> int main (int argc, string argv[1]) { int k = atoi(argv[1]); if (argc>2 || argc<2) { printf("Give me a single string: "); } else { printf("Give me a word: "); } string s = GetString(); for (int i=0, n=strlen(s); i<n; i++) { printf("%c", s[i]+k); } printf("\n");

printf("hello, world\n"); { printf("amount owed: "); float amount= GetFloat(); float cents= 100.0*amount; float quarter= 0; float dime= 0; float nickel= 0; float penni= 0; while (cents>0) if (cents>=25.0) { cents=cents-25.0; quarter=quarter+1; } else if (cents>=10.0) { cents=cents-10.0; dime=dime+1;


38 of 39 } else if (cents>=5.0) { cents=cents-5.0; nickel=nickel+1; } else if (cents>=1.0) { cents=cents-1.0; penni=penni+1; } printf("%f %f %f %f %f\n",quarter,dime,nickel,penni,quarter+dime +nickel+penni); } { int n; do { printf("Choose a positive number less than or equal to 23: "); n=GetInt(); } while (n<=0 || n>23);

for (int j=1; j<=n;j++) { for (int i=1; i<=n;i++) { if (j>=n+1-i) { printf("#"); } else { printf(" "); } } printf("#"); printf("\n"); } } }


39 of 39 The Author


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.