1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
1
00:00:00,000 --> 00:00:11,952

2
00:00:11,952 --> 00:00:13,800
>> DAVID J. MALAN: So this is CS50.

3
00:00:13,800 --> 00:00:18,970
And this was CS50's own Colton Ogden,
for more of who's music you can

4
00:00:18,970 --> 00:00:22,820
download at soundcloud.com/cs50.

5
00:00:22,820 --> 00:00:26,690
>> So today we focus all the more
on the art of programming.

6
00:00:26,690 --> 00:00:28,980
And we take where we left
off last week, focusing

7
00:00:28,980 --> 00:00:31,660
on Scratch, which was this
graphical programming language.

8
00:00:31,660 --> 00:00:35,490
And take things down to a lower level,
using a more traditional programming

9
00:00:35,490 --> 00:00:38,420
language known as C. But
along the way, realizing

10
00:00:38,420 --> 00:00:40,730
that the same ideas we
talked about last Friday

11
00:00:40,730 --> 00:00:44,390
will recur not only in this
language C, but in most every other

12
00:00:44,390 --> 00:00:46,350
that we look at this semester.

13
00:00:46,350 --> 00:00:50,247
>> So we called this thing
here what last time?

14
00:00:50,247 --> 00:00:51,830
This is representative of a statement.

15
00:00:51,830 --> 00:00:53,080
So we called this a statement.

16
00:00:53,080 --> 00:00:54,100
And it does something.

17
00:00:54,100 --> 00:00:56,910
It's an instruction that a
computer or Scratch might execute.

18
00:00:56,910 --> 00:00:59,910
And henceforth, let's also start
calling something like this a function,

19
00:00:59,910 --> 00:01:02,070
for reasons we shall soon see.

20
00:01:02,070 --> 00:01:03,681
>> Meanwhile, we saw things like this.

21
00:01:03,681 --> 00:01:05,680
And these are generally
known as what construct?

22
00:01:05,680 --> 00:01:06,240
>> AUDIENCE: Loop.

23
00:01:06,240 --> 00:01:06,860
>> DAVID J. MALAN: So a loop.

24
00:01:06,860 --> 00:01:07,943
So pretty straightforward.

25
00:01:07,943 --> 00:01:09,470
It literally does what it says.

26
00:01:09,470 --> 00:01:12,210
And in Scratch, if you want to
cram more puzzle pieces in there,

27
00:01:12,210 --> 00:01:13,950
the piece will grow to fit it.

28
00:01:13,950 --> 00:01:16,790
And we'll see in C that
we can do the same thing.

29
00:01:16,790 --> 00:01:20,000
>> Another type of loop, though,
in Scratch might be forever,

30
00:01:20,000 --> 00:01:21,820
or there's any number
of other approaches.

31
00:01:21,820 --> 00:01:24,150
But let's take a more
generalist look, with a face

32
00:01:24,150 --> 00:01:27,402
that's likely quite familiar,
at loops more generally.

33
00:01:27,402 --> 00:01:29,110
MARK ZUCKERBERG: One
thing that computers

34
00:01:29,110 --> 00:01:31,860
are really good at is
repeating commands.

35
00:01:31,860 --> 00:01:33,910
As a person, you'd get
really bored if you

36
00:01:33,910 --> 00:01:36,730
had to do the same thing
lots of times in a row.

37
00:01:36,730 --> 00:01:40,530
But a computer can do the same thing
millions or even billions of times,

38
00:01:40,530 --> 00:01:43,290
and not get bored, and be able
to carry that out really well.

39
00:01:43,290 --> 00:01:45,650
>> So for example, if I
wanted to wish everyone

40
00:01:45,650 --> 00:01:48,840
on Facebook a happy birthday
by sending them an email,

41
00:01:48,840 --> 00:01:51,550
it might take me more than a
century to actually write out

42
00:01:51,550 --> 00:01:53,000
all of those emails to everyone.

43
00:01:53,000 --> 00:01:57,780
But with just a few lines of code, I can
have a system send an email to everyone

44
00:01:57,780 --> 00:01:59,930
on Facebook wishing
them a happy birthday.

45
00:01:59,930 --> 00:02:02,730
So that's what loops are and why
they're valuable and something

46
00:02:02,730 --> 00:02:04,740
that computers can do very well.

47
00:02:04,740 --> 00:02:05,630
>> DAVID J. MALAN: So if
you've been the recipient

48
00:02:05,630 --> 00:02:07,820
of some of CS50's and
Dropbox's space of late,

49
00:02:07,820 --> 00:02:10,590
that's actually precisely what we
do, using code quite like that.

50
00:02:10,590 --> 00:02:12,600
We essentially have a big
spreadsheet into which

51
00:02:12,600 --> 00:02:15,016
folks have been inputting their
names and email addresses.

52
00:02:15,016 --> 00:02:18,160
And we wrote a tiny bit of code that
can iterate over those addresses

53
00:02:18,160 --> 00:02:21,860
and spit out unique addresses in
case anyone submitted multiple times.

54
00:02:21,860 --> 00:02:25,120
And thereafter, we send an
automated email from CS50's bot,

55
00:02:25,120 --> 00:02:27,190
including the coupon code.

56
00:02:27,190 --> 00:02:29,290
>> Now we also looked at
this construct last time.

57
00:02:29,290 --> 00:02:33,100
And this is a particular
example of what?

58
00:02:33,100 --> 00:02:35,050
So, yeah, a Boolean expression.

59
00:02:35,050 --> 00:02:37,050
And the shape is meant
to capture that as well.

60
00:02:37,050 --> 00:02:39,966
All such questions of the
form true or false in Scratch

61
00:02:39,966 --> 00:02:41,590
will look a little something like this.

62
00:02:41,590 --> 00:02:43,200
And we call this a Boolean expression.

63
00:02:43,200 --> 00:02:46,170
That's indeed true or false, yes or no.

64
00:02:46,170 --> 00:02:49,150
It's a way of answering a question.

65
00:02:49,150 --> 00:02:52,420
>> And Meanwhile you can use these Boolean
expressions inside of constructs

66
00:02:52,420 --> 00:02:54,720
like these, which of
course are conditions

67
00:02:54,720 --> 00:02:57,259
or branches, proverbial
forks in the road.

68
00:02:57,259 --> 00:02:59,550
And they can look not only
like this, but they can also

69
00:02:59,550 --> 00:03:02,080
have elses associated with them.

70
00:03:02,080 --> 00:03:05,820
And you can actually have a three way
fork in the road or a four way fork

71
00:03:05,820 --> 00:03:08,340
in the road, simply by
nesting these things,

72
00:03:08,340 --> 00:03:10,510
as you'll see in Scratch
if you haven't already.

73
00:03:10,510 --> 00:03:13,550
And as you can do in C as well.

74
00:03:13,550 --> 00:03:16,810
>> Let's take another generalist
look at an alumnist, as well, who

75
00:03:16,810 --> 00:03:21,490
might present a different approach
to these things called conditions.

76
00:03:21,490 --> 00:03:24,060
>> BILL GATES: People make
decisions every day.

77
00:03:24,060 --> 00:03:27,530
For example, before you go outside you
kind of have an if statement that says,

78
00:03:27,530 --> 00:03:31,480
if it's raining then I
need to get my jacket.

79
00:03:31,480 --> 00:03:36,820
And computers are amazing once you
decide those kinds of statements,

80
00:03:36,820 --> 00:03:42,280
that they can reliably execute
those things at unbelievable speed.

81
00:03:42,280 --> 00:03:48,240
And so a computer program really
is a little bit of math and some

82
00:03:48,240 --> 00:03:53,050
if statements where
the decision gets made.

83
00:03:53,050 --> 00:03:55,020
>> DAVID J. MALAN: So as
you may know, it was

84
00:03:55,020 --> 00:03:57,880
folks like Bill Gates,
Paul Allen, and others

85
00:03:57,880 --> 00:04:00,240
that truly kicked off the
so-called personal computer

86
00:04:00,240 --> 00:04:01,990
revolution some years ago.

87
00:04:01,990 --> 00:04:04,140
I thought, before we dive
into some administrivia,

88
00:04:04,140 --> 00:04:09,920
we'd relate a tale from the Albuquerque,
New Mexico museum of Natural History

89
00:04:09,920 --> 00:04:13,650
and science where some of Bill Gates'
and Paul Allen's earliest stories

90
00:04:13,650 --> 00:04:17,470
are recounted how we have now
today's PCs and Macs and more.

91
00:04:17,470 --> 00:04:22,390
For this, though, we need two volunteers
who have very good narration voices

92
00:04:22,390 --> 00:04:23,735
to read a script aloud.

93
00:04:23,735 --> 00:04:25,530
>> All right, how about in back there.

94
00:04:25,530 --> 00:04:26,120
Come on up.

95
00:04:26,120 --> 00:04:27,770
And how about in front here.

96
00:04:27,770 --> 00:04:28,340
Come on down.

97
00:04:28,340 --> 00:04:29,600
Take your places here.

98
00:04:29,600 --> 00:04:32,444
As you guys come up, a couple
of administrative announcements.

99
00:04:32,444 --> 00:04:34,360
sectioning, the process
of choosing a section,

100
00:04:34,360 --> 00:04:36,068
will start this
Wednesday through Friday.

101
00:04:36,068 --> 00:04:38,400
More on that this coming
Wednesday in lecture.

102
00:04:38,400 --> 00:04:41,770
>> Super sections, meanwhile, are
something that we offer next week

103
00:04:41,770 --> 00:04:45,310
whereby the entire class is invited
to participate in fairly large scale

104
00:04:45,310 --> 00:04:47,690
sections, one more comfy,
one less comfortable.

105
00:04:47,690 --> 00:04:51,340
And we will announce the particulars
of that, as well, later this week.

106
00:04:51,340 --> 00:04:53,310
>> Meanwhile sections,
themselves, will start

107
00:04:53,310 --> 00:04:57,241
in week three of the course, zero index,
which means those are a couple of weeks

108
00:04:57,241 --> 00:04:57,740
out.

109
00:04:57,740 --> 00:04:58,450
So not to worry.

110
00:04:58,450 --> 00:05:01,014
You have not yet missed
anything along those lines.

111
00:05:01,014 --> 00:05:03,930
Meanwhile in the meantime, if you
have any questions administratively,

112
00:05:03,930 --> 00:05:08,120
email myself and Devon and Gabe
and Rob at this address here.

113
00:05:08,120 --> 00:05:10,320
>> Lastly, problem set
0 is, of course, out.

114
00:05:10,320 --> 00:05:12,320
You may have noticed it
on the course's website.

115
00:05:12,320 --> 00:05:14,840
It should provide you with
all answers to questions

116
00:05:14,840 --> 00:05:18,250
you might have along the way for
getting started with the problem set.

117
00:05:18,250 --> 00:05:21,430
But if you find yourself
in need of a helping hand,

118
00:05:21,430 --> 00:05:25,020
by all means attend office hours,
Monday, Tuesday, Wednesday, Thursday

119
00:05:25,020 --> 00:05:27,290
of this week in the evening
in four dining halls.

120
00:05:27,290 --> 00:05:31,650
See that URL there for the particulars
of where office hours shall be.

121
00:05:31,650 --> 00:05:34,000
>> Now Let's meet our
two guests here today.

122
00:05:34,000 --> 00:05:34,740
What's your name?

123
00:05:34,740 --> 00:05:35,290
>> JAY PAUL: Jay Paul.

124
00:05:35,290 --> 00:05:36,880
>> DAVID J. MALAN: Jay
Paul, nice to meet you.

125
00:05:36,880 --> 00:05:37,330
>> HIKARI: Hikari.

126
00:05:37,330 --> 00:05:37,975
>> DAVID J. MALAN: Hikari?

127
00:05:37,975 --> 00:05:38,250
>> HIKARI: Hikari.

128
00:05:38,250 --> 00:05:38,810
>> DAVID J. MALAN: Hikari.

129
00:05:38,810 --> 00:05:39,790
Nice to meet you as well.

130
00:05:39,790 --> 00:05:42,123
Jay Paul and Hikari have in
front of them on these music

131
00:05:42,123 --> 00:05:45,100
stands two scripts that I printed
out this morning from the New Mexico

132
00:05:45,100 --> 00:05:46,692
museum of Natural History and Science.

133
00:05:46,692 --> 00:05:48,400
And what I thought
I'd do on the overhead

134
00:05:48,400 --> 00:05:52,830
is accompany your recitation
of the script and this history

135
00:05:52,830 --> 00:05:54,700
with some visual images, no surprises.

136
00:05:54,700 --> 00:05:57,512
>> And what I've done in advance
is prehighlight on your script

137
00:05:57,512 --> 00:05:59,470
what you should read,
and what you should read.

138
00:05:59,470 --> 00:06:00,920
And we'll essentially
just alternate paragraphs.

139
00:06:00,920 --> 00:06:03,211
So it's much like you might
have done in English class.

140
00:06:03,211 --> 00:06:06,875
That's really compel the audience
to believe in your tale here.

141
00:06:06,875 --> 00:06:07,600
Shall we?

142
00:06:07,600 --> 00:06:13,272
So the story here is, we have a
BASIC, and it begins in Cambridge.

143
00:06:13,272 --> 00:06:18,750
>> JAY PAUL: It was winter, 1974,
in Cambridge, Massachusetts

144
00:06:18,750 --> 00:06:20,240
where winters can be cold.

145
00:06:20,240 --> 00:06:22,800
A bearded, long haired
college dropout named

146
00:06:22,800 --> 00:06:27,280
Paul Allen was drudging across Harvard
Square, absorbed in his thoughts.

147
00:06:27,280 --> 00:06:31,050
His main preoccupation in those days
was how to get his friend, Bill Gates,

148
00:06:31,050 --> 00:06:34,974
to quit school and go
into business with him.

149
00:06:34,974 --> 00:06:37,890
HIKARI: The two had already gone
through a number of business ventures

150
00:06:37,890 --> 00:06:40,850
together, beginning at Lakeside
school in Seattle where

151
00:06:40,850 --> 00:06:45,220
they were paid in free computer time to
test a PDP-10 computer at a local time

152
00:06:45,220 --> 00:06:46,580
sharing company.

153
00:06:46,580 --> 00:06:50,930
The most recent plan had been to quit
school and form a software company.

154
00:06:50,930 --> 00:06:53,440
Allen had left Washington
State University.

155
00:06:53,440 --> 00:06:58,380
But at the last minute, Gates
decided to stick with Harvard.

156
00:06:58,380 --> 00:07:02,080
>> JAY PAUL: That day, crossing Harvard
Square, Allen spotted the January,

157
00:07:02,080 --> 00:07:07,530
1975 issue of Popular Electronics
with the earth stopping headline,

158
00:07:07,530 --> 00:07:11,900
World's First Minicomputer Kit
to Rival Commercial Models.

159
00:07:11,900 --> 00:07:14,430
Beneath the headline was
a picture of a small box

160
00:07:14,430 --> 00:07:16,160
adorned with lights and switches.

161
00:07:16,160 --> 00:07:19,770
It was called the MITS Altair 8800.

162
00:07:19,770 --> 00:07:24,100
And Allen knew this was what
he had been looking for.

163
00:07:24,100 --> 00:07:26,350
>> HIKARI: Days of discussion followed.

164
00:07:26,350 --> 00:07:30,170
Allen and Gates understood the
significance of the Altair.

165
00:07:30,170 --> 00:07:32,480
They had talked often
about microprocessors

166
00:07:32,480 --> 00:07:35,250
and were waiting to see what
would be done with them.

167
00:07:35,250 --> 00:07:39,770
Now there was a minicomputer kit on
the cover of Popular Electronics.

168
00:07:39,770 --> 00:07:42,830
It apparently had no software yet.

169
00:07:42,830 --> 00:07:46,830
They imagined a nation of
programmers descending on MITS.

170
00:07:46,830 --> 00:07:49,590
And so they called Ed Roberts,
the head of the company,

171
00:07:49,590 --> 00:07:53,330
claiming to have a version of the
BASIC programming language almost ready

172
00:07:53,330 --> 00:07:54,710
for the Altair.

173
00:07:54,710 --> 00:07:55,570
They didn't.

174
00:07:55,570 --> 00:07:58,910
And Roberts must have known they didn't.

175
00:07:58,910 --> 00:08:03,170
He was getting 10 calls a day from
people who had a BASIC almost ready.

176
00:08:03,170 --> 00:08:05,570
And his stock response
was, "The first person

177
00:08:05,570 --> 00:08:11,090
who shows up with a working
BASIC gets the contract."

178
00:08:11,090 --> 00:08:13,910
>> JAY PAUL: Gates and Allen
had never seen an Altair.

179
00:08:13,910 --> 00:08:17,600
They had never even seen the
Intel 8080 microprocessor

180
00:08:17,600 --> 00:08:19,060
at the heart of the Altair.

181
00:08:19,060 --> 00:08:21,470
But a couple of years earlier
Allen had written a program

182
00:08:21,470 --> 00:08:25,220
on a mainframe computer that emulated
the operation of a previous Intel

183
00:08:25,220 --> 00:08:26,217
microprocessor.

184
00:08:26,217 --> 00:08:28,300
And this time around they
would do the same thing.

185
00:08:28,300 --> 00:08:31,530

186
00:08:31,530 --> 00:08:34,380
>> HIKARI: With an Intel
8080 manual at his side,

187
00:08:34,380 --> 00:08:37,770
Allen sat down at a
Harvard PDP-10 computer

188
00:08:37,770 --> 00:08:42,010
and wrote the emulator and software
tools necessary to do the programming.

189
00:08:42,010 --> 00:08:45,820
Meanwhile Gates stopped going
to classes and devoted himself

190
00:08:45,820 --> 00:08:48,120
to designing the BASIC,
using every trick

191
00:08:48,120 --> 00:08:53,130
he knew to get the size
down below 4 kilobytes.

192
00:08:53,130 --> 00:08:55,870
>> JAY PAUL: Out in Albuquerque,
Ed Roberts got a call from Gates

193
00:08:55,870 --> 00:08:59,754
asking for details about how the
Altair handled specific routines.

194
00:08:59,754 --> 00:09:01,170
No one had ever asked that before.

195
00:09:01,170 --> 00:09:02,670
And Roberts began to get interested.

196
00:09:02,670 --> 00:09:05,240

197
00:09:05,240 --> 00:09:07,970
>> HIKARI: With the development
tools and the design ready,

198
00:09:07,970 --> 00:09:10,780
Gates and Allen wrote
the code on the PDP-10,

199
00:09:10,780 --> 00:09:16,060
enlisting another Harvard student,
Monte Davidoff, to write math routines.

200
00:09:16,060 --> 00:09:19,450
After a final night of
programming, Allen got on a plane

201
00:09:19,450 --> 00:09:22,970
to deliver their BASIC to MITS.

202
00:09:22,970 --> 00:09:25,800
He spent the plane ride out worrying.

203
00:09:25,800 --> 00:09:28,490
And back in Cambridge
Gates was worrying.

204
00:09:28,490 --> 00:09:32,100
They had tested their BASIC and
it had worked on the emulator.

205
00:09:32,100 --> 00:09:35,444
But what if the emulator was wrong?

206
00:09:35,444 --> 00:09:37,360
JAY PAUL: As the plane
approached Albuquerque,

207
00:09:37,360 --> 00:09:40,070
Allen realized that their
BASIC, now neatly contained

208
00:09:40,070 --> 00:09:42,460
on a small roll of
punched paper tape, would

209
00:09:42,460 --> 00:09:44,970
be useless without a separate
program, called a loader, that

210
00:09:44,970 --> 00:09:47,550
would tell the Altair how
to read the paper tape being

211
00:09:47,550 --> 00:09:49,620
fed into the teletype machine.

212
00:09:49,620 --> 00:09:52,970
He took out his notebook and quickly
scribbled down a loader program

213
00:09:52,970 --> 00:09:56,819
in Assembly language, then manually
translated that into the 1s and 0s

214
00:09:56,819 --> 00:09:57,985
the Altair would understand.

215
00:09:57,985 --> 00:10:00,530

216
00:10:00,530 --> 00:10:03,830
>> HIKARI: Allen was expecting a
clean, little, high tech company

217
00:10:03,830 --> 00:10:05,470
run by men in business suits.

218
00:10:05,470 --> 00:10:09,210
So he was surprised when Roberts met
him at the airport looking like a ranch

219
00:10:09,210 --> 00:10:10,270
hand.

220
00:10:10,270 --> 00:10:12,070
Roberts was also surprised.

221
00:10:12,070 --> 00:10:16,340
When he dropped the Harvard
programmer at an expensive hotel,

222
00:10:16,340 --> 00:10:20,790
Allen had to confess that
he couldn't afford the room.

223
00:10:20,790 --> 00:10:24,510
>> JAY PAUL: MITS, itself, was
located in a dusty strip mall.

224
00:10:24,510 --> 00:10:27,040
Inside on a cluttered
workbench was an Altair

225
00:10:27,040 --> 00:10:30,390
loaded up with 5 kilobytes of
memory and connected by a cable

226
00:10:30,390 --> 00:10:32,030
to a teletype machine.

227
00:10:32,030 --> 00:10:37,200
Roberts and Chief Engineer,
Bill Yates, waited expectantly

228
00:10:37,200 --> 00:10:40,660
as Allen toggled his loader
program into the Altair.

229
00:10:40,660 --> 00:10:44,980
The teletype began chugging as it pulled
the paper tape through the tape reader.

230
00:10:44,980 --> 00:10:47,215
It took perhaps 15 minutes
to load the program.

231
00:10:47,215 --> 00:10:52,110
Then the teletype abruptly printed a
memory prompt, then a ready prompt,

232
00:10:52,110 --> 00:10:55,340
and Allen began typing
a few test commands.

233
00:10:55,340 --> 00:10:57,400
To everyone's amazement,
the software worked.

234
00:10:57,400 --> 00:10:58,525
There were bugs, of course.

235
00:10:58,525 --> 00:11:02,070
But the main thing was it worked.

236
00:11:02,070 --> 00:11:06,570
>> HIKARI: Later, on their way to a
$3.00 lunch at Pancho's, a wasp flew

237
00:11:06,570 --> 00:11:10,470
in the window of the pickup
truck and stung Allen on the arm.

238
00:11:10,470 --> 00:11:13,070
But at that point nothing
could spoil the mood.

239
00:11:13,070 --> 00:11:17,210
The Altair now had its BASIC, the
first commercial software for a home

240
00:11:17,210 --> 00:11:23,260
computer, made by Paul Allen and Bill
Gates, doing business as Microsoft.

241
00:11:23,260 --> 00:11:25,336
>> DAVID J. MALAN: Many
thanks to our two readers.

242
00:11:25,336 --> 00:11:30,690
>> [APPLAUSE]

243
00:11:30,690 --> 00:11:32,520
>> DAVID J. MALAN: Now
you have your choice,

244
00:11:32,520 --> 00:11:35,880
before you leave, of a sparkly
or a glow in the dark-- oh,

245
00:11:35,880 --> 00:11:40,810
wait one sec, wait-- sparkly
and a glow in the dark elephant

246
00:11:40,810 --> 00:11:42,534
from CS50's own Cheng Gong.

247
00:11:42,534 --> 00:11:43,450
HIKARI: Aw, thank you.

248
00:11:43,450 --> 00:11:45,324
DAVID J. MALAN: All
right, thank you so much.

249
00:11:45,324 --> 00:11:49,855
[APPLAUSE]

250
00:11:49,855 --> 00:11:51,105
DAVID J. MALAN: So true story.

251
00:11:51,105 --> 00:11:54,380
This is to say that all of these
machines and the ease with which we

252
00:11:54,380 --> 00:11:56,270
use them now and take
for granted, really

253
00:11:56,270 --> 00:12:00,070
started here, just a few paces
from this actual theater.

254
00:12:00,070 --> 00:12:03,930
And now today, if you've not been,
this is Maxwell Dworkin, the computer

255
00:12:03,930 --> 00:12:05,810
sciences building,
also around the corner.

256
00:12:05,810 --> 00:12:09,760
And on the second floor of this
building does hang three pages

257
00:12:09,760 --> 00:12:12,740
from the original source code that
Bill Gates and Paul Allen wrote.

258
00:12:12,740 --> 00:12:14,770
In fact, if use you zoom
in you can see not only

259
00:12:14,770 --> 00:12:17,350
their names in the
original type, but also

260
00:12:17,350 --> 00:12:22,100
their signatures that they adorned a
few years back when they last visited.

261
00:12:22,100 --> 00:12:25,800
>> But what was particularly compelling
about this is what they set out to do

262
00:12:25,800 --> 00:12:29,760
was to write a program that would
enable other people to write

263
00:12:29,760 --> 00:12:30,950
their own programs.

264
00:12:30,950 --> 00:12:34,280
At the time all there was with
this Altair machine made by MITS.

265
00:12:34,280 --> 00:12:40,020
And all they needed was some way of
making it easy for hobbyists and people

266
00:12:40,020 --> 00:12:45,300
like us in this room to actually program
that without necessarily understanding

267
00:12:45,300 --> 00:12:49,060
Assembly code, or machine
code, or God forbid, 0s and 1s.

268
00:12:49,060 --> 00:12:51,190
We programmers, like
those in this room, we

269
00:12:51,190 --> 00:12:54,070
want to be able to express
ourselves much more like pseudo code

270
00:12:54,070 --> 00:12:57,330
even if it's a bit more nit
picky than we talked last week.

271
00:12:57,330 --> 00:13:00,970
We don't want to write code like this,
which Paul Allen and Bill Gates did.

272
00:13:00,970 --> 00:13:04,850
We, instead, want to write code that
looks a little more user friendly.

273
00:13:04,850 --> 00:13:07,150
>> Now this is a language known as BASIC.

274
00:13:07,150 --> 00:13:11,497
And the line numbers there are what you
use to simply number the lines of code

275
00:13:11,497 --> 00:13:12,330
that you're writing.

276
00:13:12,330 --> 00:13:14,038
We don't even have to
do that these days.

277
00:13:14,038 --> 00:13:16,060
But you can see here
how PRINT "hello, world"

278
00:13:16,060 --> 00:13:18,660
would indeed presumably print just that.

279
00:13:18,660 --> 00:13:22,710
And so what Bill and Paul did was
empower people to write code like this

280
00:13:22,710 --> 00:13:27,240
instead of-- if you take a look at the
computer science wall-- code like this.

281
00:13:27,240 --> 00:13:29,290
>> In fact, CS50 recently
had an opportunity

282
00:13:29,290 --> 00:13:32,540
to sit down with Professor Harry Lewis
in the Computer Science department, who

283
00:13:32,540 --> 00:13:34,640
actually taught Bill
Gates some years ago,

284
00:13:34,640 --> 00:13:38,460
and is standing here before
those three pages of excerpts.

285
00:13:38,460 --> 00:13:39,560
Let's take a look.

286
00:13:39,560 --> 00:13:45,520
>> HARRY LEWIS: What you have here is a
listing of an early piece of software

287
00:13:45,520 --> 00:13:50,240
written by Bill Gates and Paul
Allen, the founders of Microsoft.

288
00:13:50,240 --> 00:13:52,570
So the code is interesting
for two reasons.

289
00:13:52,570 --> 00:13:55,480
First of all, it became
Microsoft's first product,

290
00:13:55,480 --> 00:14:01,810
which was an interpreter for
the BASIC programming language.

291
00:14:01,810 --> 00:14:04,940
And secondly, this was
one of the first attempts

292
00:14:04,940 --> 00:14:10,580
to create an interpreter so ordinary
people could use personal computers.

293
00:14:10,580 --> 00:14:12,670
>> So Bill Gates was an
undergraduate at Harvard.

294
00:14:12,670 --> 00:14:14,820
I started teaching at Harvard in 1974.

295
00:14:14,820 --> 00:14:16,560
This was done in 1975.

296
00:14:16,560 --> 00:14:20,180
So it was early in his career
and early in my career.

297
00:14:20,180 --> 00:14:23,790
I actually taught Bill in
a course around this time.

298
00:14:23,790 --> 00:14:27,130
Paul Allen was not a
Harvard student, but he

299
00:14:27,130 --> 00:14:31,020
had been a high school
classmate of Bill Gates.

300
00:14:31,020 --> 00:14:33,740
If you come and look
at the listing, you'll

301
00:14:33,740 --> 00:14:36,230
actually find a third
name, Monte Davidoff,

302
00:14:36,230 --> 00:14:39,260
who was Gates's classmate
here at Harvard.

303
00:14:39,260 --> 00:14:41,340
>> OK, so here's an
interesting comment up here.

304
00:14:41,340 --> 00:14:47,150
It says "In 4K can delete square root
but for loops should still work."

305
00:14:47,150 --> 00:14:53,080
OK, so what that means is that there
were two ways to compile this program.

306
00:14:53,080 --> 00:14:57,860
One was to run on a version
of this Altair computer

307
00:14:57,860 --> 00:15:04,310
that only had 4K words of
memory, 4,096 words of memory.

308
00:15:04,310 --> 00:15:07,050
But the big version had 8K.

309
00:15:07,050 --> 00:15:09,770
And so what this says is
that in the 4K version

310
00:15:09,770 --> 00:15:12,770
you had to delete some
code to make it fit.

311
00:15:12,770 --> 00:15:14,790
And one of the things
that would be deleted

312
00:15:14,790 --> 00:15:16,290
would be the square root routine.

313
00:15:16,290 --> 00:15:20,360
But apparently the
for loops should still

314
00:15:20,360 --> 00:15:26,392
work even when you're compiling down
for just the 4K version of the computer.

315
00:15:26,392 --> 00:15:29,350
DAVID J. MALAN: So one of the themes,
as we'll see in computer science,

316
00:15:29,350 --> 00:15:31,430
is this notion of
layering and abstraction,

317
00:15:31,430 --> 00:15:34,670
and really standing on the shoulders
of folks who have come before us, not

318
00:15:34,670 --> 00:15:37,890
unlike some of the Bill Gates
and Paul Allen narrative here.

319
00:15:37,890 --> 00:15:40,080
And what this means is
that today we can take for

320
00:15:40,080 --> 00:15:43,490
granted that things are actually
easier for us to write code.

321
00:15:43,490 --> 00:15:47,170
Indeed code, as we said on Friday, is
more technically known as source code.

322
00:15:47,170 --> 00:15:52,210
And it's this English like syntax
that's more proper and more well defined

323
00:15:52,210 --> 00:15:55,480
than something like pseudo code, for
which there is no formal definition.

324
00:15:55,480 --> 00:15:58,320
>> And today what we're going
to focus on is source code

325
00:15:58,320 --> 00:16:01,010
that looks like this, which
admittedly at first glance

326
00:16:01,010 --> 00:16:02,690
looks completely cryptic.

327
00:16:02,690 --> 00:16:08,540
And frankly, it's way more aesthetically
complex than the underlying program is.

328
00:16:08,540 --> 00:16:13,300
All this program does,
recall, is what did we say?

329
00:16:13,300 --> 00:16:14,990
It just prints "hello world."

330
00:16:14,990 --> 00:16:19,600
And yet look at all of the stuff we need
to wrap around that very simple phrase.

331
00:16:19,600 --> 00:16:21,750
But before long all of
these lines and more

332
00:16:21,750 --> 00:16:24,800
will make much better sense to you.

333
00:16:24,800 --> 00:16:26,940
>> And the flow is as follows.

334
00:16:26,940 --> 00:16:31,220
What we need at our disposal
is to take code, like source

335
00:16:31,220 --> 00:16:32,340
code that we just saw.

336
00:16:32,340 --> 00:16:35,060
And we need a new program
to run it through.

337
00:16:35,060 --> 00:16:39,130
We need algorithms that can
convert source code, like this,

338
00:16:39,130 --> 00:16:41,932
into object code, 0s and 1s.

339
00:16:41,932 --> 00:16:43,890
In other words, what
we're going to learn today

340
00:16:43,890 --> 00:16:46,620
is how to do this, write
source code up top,

341
00:16:46,620 --> 00:16:49,930
pass it as input to a special
program known as a compiler,

342
00:16:49,930 --> 00:16:52,140
and we're going to produce object code.

343
00:16:52,140 --> 00:16:54,600
Which is just a fancy way of
saying we will take something

344
00:16:54,600 --> 00:16:58,350
that looks like this, pass it
into a program called a compiler,

345
00:16:58,350 --> 00:17:01,210
producing object code
that looks like this.

346
00:17:01,210 --> 00:17:04,720
>> So these are literally
the patterns of 0s and 1s

347
00:17:04,720 --> 00:17:08,550
that are understood by an
Intel computer these days,

348
00:17:08,550 --> 00:17:12,480
that if interpreted by the CPU,
the brains inside of a computer,

349
00:17:12,480 --> 00:17:16,130
will literally print out,
quite simply, "hello world."

350
00:17:16,130 --> 00:17:19,670
Now there's way more 0s and 1s than you
would hope might be necessary for that.

351
00:17:19,670 --> 00:17:22,520
But that's because we're building
on a good deal of complexity

352
00:17:22,520 --> 00:17:24,270
that we can henceforth take for granted.

353
00:17:24,270 --> 00:17:27,869
In other words, a lot of smart people
have given us a lot of cool tools

354
00:17:27,869 --> 00:17:32,480
and powerful software with which we
can now make projects of our own.

355
00:17:32,480 --> 00:17:33,400
>> So let's get started.

356
00:17:33,400 --> 00:17:36,640
Whereas last Friday, and
for Problem Set 0 this week,

357
00:17:36,640 --> 00:17:39,000
you'll be playing in a
world that looks like this.

358
00:17:39,000 --> 00:17:42,180
Starting today and for Problem
Set 1 next week, the code

359
00:17:42,180 --> 00:17:45,410
is going to look a little more
cryptic, but functionally is

360
00:17:45,410 --> 00:17:46,940
going to be the same.

361
00:17:46,940 --> 00:17:50,770
So notice, top is Scratch,
bottom is C. Frankly Scratch

362
00:17:50,770 --> 00:17:52,780
is a lot more user
friendly and accessible.

363
00:17:52,780 --> 00:17:56,890
But if you now compare visually top to
bottom, there's kind of a one to one

364
00:17:56,890 --> 00:17:59,690
correspondence between the
puzzle pieces and the language

365
00:17:59,690 --> 00:18:00,870
we're about to play with.

366
00:18:00,870 --> 00:18:04,420
In particular, say, the
blue puzzle piece up top,

367
00:18:04,420 --> 00:18:08,370
is apparently equivalent to what keyword
or special phrase in this language

368
00:18:08,370 --> 00:18:09,062
called C?

369
00:18:09,062 --> 00:18:09,770
AUDIENCE: Printf.

370
00:18:09,770 --> 00:18:10,728
DAVID J. MALAN: Printf.

371
00:18:10,728 --> 00:18:12,140
That means formatted printing.

372
00:18:12,140 --> 00:18:15,240
And that's just a fancy
way of saying printf in C

373
00:18:15,240 --> 00:18:18,615
is going to be a statement or a function
that prints something to the screen.

374
00:18:18,615 --> 00:18:19,990
What does it print to the screen?

375
00:18:19,990 --> 00:18:23,627
Whatever you tell it to inside
of quotes, inside of parentheses.

376
00:18:23,627 --> 00:18:25,460
So again, admittedly,
there's a lot of stuff

377
00:18:25,460 --> 00:18:27,990
that you have to keep in mind,
parentheses, quotes, semicolons,

378
00:18:27,990 --> 00:18:28,656
and all of this.

379
00:18:28,656 --> 00:18:30,600
But all of that is sort
of beside the point.

380
00:18:30,600 --> 00:18:33,660
The interesting takeaway for now
is that the say block in Scratch

381
00:18:33,660 --> 00:18:37,520
is pretty much equivalent to
the printf statement in C.

382
00:18:37,520 --> 00:18:41,390
>> Meanwhile, the yellow puzzle piece
up top, when green flag clicked,

383
00:18:41,390 --> 00:18:44,736
is probably equivalent
to what keyword here?

384
00:18:44,736 --> 00:18:45,360
AUDIENCE: Main.

385
00:18:45,360 --> 00:18:46,359
DAVID J. MALAN: So main.

386
00:18:46,359 --> 00:18:47,410
Maybe int, maybe void.

387
00:18:47,410 --> 00:18:51,280
But main kind of sounds like
it's important, and indeed it is.

388
00:18:51,280 --> 00:18:54,080
So when green flag clicked
is, again, the puzzle piece

389
00:18:54,080 --> 00:18:56,390
that kicks off an
entire Scratch program.

390
00:18:56,390 --> 00:19:02,140
But we are going to now start calling
that main, this function known as main.

391
00:19:02,140 --> 00:19:06,410
>> Now meanwhile we'll
generalize this as follows.

392
00:19:06,410 --> 00:19:08,780
We might call say a function.

393
00:19:08,780 --> 00:19:10,580
And it might look
specifically like this.

394
00:19:10,580 --> 00:19:11,770
Well, what about loops?

395
00:19:11,770 --> 00:19:16,540
If we want to start converting or
translating more in Scratch to C,

396
00:19:16,540 --> 00:19:19,400
this thing here apparently just
says "hello world" forever.

397
00:19:19,400 --> 00:19:23,060
So if you associate these
scripts with a cat in Scratch,

398
00:19:23,060 --> 00:19:26,560
it's just going to keep saying
in some kind of cartoon bubble,

399
00:19:26,560 --> 00:19:29,922
"hello world, hello world, hello
world," ad nauseum, forever.

400
00:19:29,922 --> 00:19:33,130
If we want to do something similar in
C, it's going to look a little cryptic.

401
00:19:33,130 --> 00:19:35,463
But we can achieve the same
results, as we'll eventually

402
00:19:35,463 --> 00:19:36,861
find out, with syntax like this.

403
00:19:36,861 --> 00:19:39,360
I'm going to use printf again,
because at the end of the day

404
00:19:39,360 --> 00:19:42,040
I want to print "hello world."

405
00:19:42,040 --> 00:19:45,610
And I'm apparently using a
keyword that isn't forever.

406
00:19:45,610 --> 00:19:47,320
It's instead the word while.

407
00:19:47,320 --> 00:19:49,650
But just semantically in
English, while kind of

408
00:19:49,650 --> 00:19:52,120
suggests some kind of loop or cycle.

409
00:19:52,120 --> 00:19:55,070
>> So that happens to be
the keyword that C uses.

410
00:19:55,070 --> 00:20:00,700
And while true, why does while
true effectively mean forever?

411
00:20:00,700 --> 00:20:04,240
Well, while, as we'll soon
appreciate all the more,

412
00:20:04,240 --> 00:20:08,140
has this parenthetical next to it
where you can put a Boolean expression.

413
00:20:08,140 --> 00:20:11,360
And so long as that
expression is true, this code,

414
00:20:11,360 --> 00:20:14,750
as denoted between these two
curly braces as we'll call them,

415
00:20:14,750 --> 00:20:16,880
will just keep running again and again.

416
00:20:16,880 --> 00:20:18,410
>> So true is true.

417
00:20:18,410 --> 00:20:20,900
So while true means
just do this forever.

418
00:20:20,900 --> 00:20:23,480
It's almost a stupid
construct to express yourself.

419
00:20:23,480 --> 00:20:26,590
But there was no forever
keyword in C. There was while.

420
00:20:26,590 --> 00:20:29,390
And there was a very simple
Boolean expression like true.

421
00:20:29,390 --> 00:20:32,210
And so this, we'll see,
achieves the same result.

422
00:20:32,210 --> 00:20:33,890
>> How else might you implement a loop?

423
00:20:33,890 --> 00:20:36,980
Well, in Scratch you might
hard code a specific number

424
00:20:36,980 --> 00:20:39,430
of iterations in the loop here.

425
00:20:39,430 --> 00:20:43,210
And so that's exactly what we
might do in this version of C,

426
00:20:43,210 --> 00:20:46,140
whereby we have a so-called for loop.

427
00:20:46,140 --> 00:20:49,850
And the for loop here is going
to iterate, somewhat cryptically,

428
00:20:49,850 --> 00:20:54,100
from the value 0 on up
to but less than 10.

429
00:20:54,100 --> 00:20:55,955
>> Now variables in Scratch.

430
00:20:55,955 --> 00:20:57,830
You might not have had
occasion to use these.

431
00:20:57,830 --> 00:21:02,516
But what's the point, in general,
of a variable did we say last week?

432
00:21:02,516 --> 00:21:03,015
What's that?

433
00:21:03,015 --> 00:21:03,780
>> AUDIENCE: Points.

434
00:21:03,780 --> 00:21:05,200
>> DAVID J. MALAN: To point?

435
00:21:05,200 --> 00:21:05,700
Oh, points.

436
00:21:05,700 --> 00:21:07,620
OK, keeping track of points,
for instance, in a game.

437
00:21:07,620 --> 00:21:09,510
Or more generally doing
what with the variable?

438
00:21:09,510 --> 00:21:10,450
What's the utility of them?

439
00:21:10,450 --> 00:21:10,825
>> AUDIENCE: Memory.

440
00:21:10,825 --> 00:21:11,750
>> DAVID J. MALAN: Yeah, so memory.

441
00:21:11,750 --> 00:21:13,000
It's for storing something.

442
00:21:13,000 --> 00:21:17,336
And the sort of silly visual I used
last time was like this glass bowl.

443
00:21:17,336 --> 00:21:19,710
And if we wanted to store
something inside of a variable,

444
00:21:19,710 --> 00:21:21,918
for instance right now the
value is six because there

445
00:21:21,918 --> 00:21:23,450
are six ping pong balls in here.

446
00:21:23,450 --> 00:21:26,158
It's just some kind of storage
container that underneath the hood

447
00:21:26,158 --> 00:21:30,030
is implemented with bits, 0s and 1s,
however a computer happens to do that.

448
00:21:30,030 --> 00:21:32,900
>> So in Scratch, if we
want to have a variable,

449
00:21:32,900 --> 00:21:34,840
we can use an orange block like this.

450
00:21:34,840 --> 00:21:37,050
We'll call that counter
in this particular case.

451
00:21:37,050 --> 00:21:38,890
I initialized it to 0.

452
00:21:38,890 --> 00:21:41,080
And what it I then do?

453
00:21:41,080 --> 00:21:44,780
Forever, say counter, which if
you play with that in Scratch,

454
00:21:44,780 --> 00:21:45,780
you'll just see Scratch.

455
00:21:45,780 --> 00:21:49,920
The cat or whatever costume you put on
him will speak the number in question.

456
00:21:49,920 --> 00:21:52,840
>> Change counter by 1 is
like incrementing by 1.

457
00:21:52,840 --> 00:21:56,580
And so this is going to
count from what so what?

458
00:21:56,580 --> 00:21:59,114
From 0 til infinity, or
until Scratch breaks,

459
00:21:59,114 --> 00:22:01,030
or until you sort of
lose interest in watching

460
00:22:01,030 --> 00:22:02,650
how high he can actually count.

461
00:22:02,650 --> 00:22:04,800
>> So how might we convert this to C?

462
00:22:04,800 --> 00:22:06,480
It's going to look a little cryptic.

463
00:22:06,480 --> 00:22:08,896
But again, if you look at each
of these lines individually

464
00:22:08,896 --> 00:22:10,410
they kind of lineup generally.

465
00:22:10,410 --> 00:22:13,526
So apparently int is going to
have some special meaning in C.

466
00:22:13,526 --> 00:22:14,400
We'll see that again.

467
00:22:14,400 --> 00:22:15,810
As an aside it means integer.

468
00:22:15,810 --> 00:22:16,990
So it just means number.

469
00:22:16,990 --> 00:22:18,920
So that's the type of
glass bowl I want, one

470
00:22:18,920 --> 00:22:21,120
that can store numbers,
not ping pong balls.

471
00:22:21,120 --> 00:22:25,520
And I'm going to use the equal sign
there to assign it a value of 0.

472
00:22:25,520 --> 00:22:29,440
So that's quite like set
counter to 0, but in C.

473
00:22:29,440 --> 00:22:32,840
>> Meanwhile, while true, that was
equivalent, of course, to forever,

474
00:22:32,840 --> 00:22:35,980
even though it's a little cryptic,
and then inside of the curly braces.

475
00:22:35,980 --> 00:22:39,188
And you can think of these curly braces,
which you can type on your keyboard,

476
00:22:39,188 --> 00:22:43,110
as really being like the curvature in
these yellow loop blocks in Scratch.

477
00:22:43,110 --> 00:22:45,700
It embraces multiple lines of code.

478
00:22:45,700 --> 00:22:48,120
>> Printf is getting a
little scary now because I

479
00:22:48,120 --> 00:22:51,120
see not only quotes in parentheses.

480
00:22:51,120 --> 00:22:55,160
But what else is new
syntactically in this example?

481
00:22:55,160 --> 00:22:57,300
There's a percent d.

482
00:22:57,300 --> 00:22:58,551
And then backslash n is there.

483
00:22:58,551 --> 00:23:00,883
We did see that before, even
though I didn't mention it.

484
00:23:00,883 --> 00:23:01,886
Then there's a comma.

485
00:23:01,886 --> 00:23:03,010
And then there's a counter.

486
00:23:03,010 --> 00:23:05,010
>> But we'll see in just a
moment that this is just

487
00:23:05,010 --> 00:23:09,080
a standard way of saying print a
"decimal number," quote, unquote,

488
00:23:09,080 --> 00:23:10,500
some decimal number.

489
00:23:10,500 --> 00:23:13,370
But I'm going to tell you later
what that decimal number is.

490
00:23:13,370 --> 00:23:16,835
So the fact that there's a comma
in this line saying printf,

491
00:23:16,835 --> 00:23:18,710
means go ahead and print
some decimal number.

492
00:23:18,710 --> 00:23:23,110
Oh, and by the way, the number is
whatever the value of this variable is.

493
00:23:23,110 --> 00:23:25,880
And so to make this more
clear, we'll see an example

494
00:23:25,880 --> 00:23:30,930
before long involving exactly printf
in the context of real C programs.

495
00:23:30,930 --> 00:23:33,472
>> Now just to wrap up some
of these constructs.

496
00:23:33,472 --> 00:23:36,680
Boolean expressions, you might not have
occasion to use these in your program

497
00:23:36,680 --> 00:23:39,450
but you might very well,
especially if using conditions.

498
00:23:39,450 --> 00:23:43,460
And so these two examples from
Scratch mean if x is less than y,

499
00:23:43,460 --> 00:23:48,770
or if x is less than y and y is less
than z, how might we translate that?

500
00:23:48,770 --> 00:23:50,810
>> Well, in C it's just
going to look like this.

501
00:23:50,810 --> 00:23:55,300
A little cryptic, more parentheses,
some weird ampersands, but fundamentally

502
00:23:55,300 --> 00:23:59,160
the ideas are as simple as they
are in the puzzle piece world.

503
00:23:59,160 --> 00:24:02,690
We're simply checking if something
is less than something else.

504
00:24:02,690 --> 00:24:03,910
>> How about conditions?

505
00:24:03,910 --> 00:24:09,710
In a nutshell in English, what does this
chunk of Scratch code do would you say?

506
00:24:09,710 --> 00:24:11,050
>> AUDIENCE: Compares two numbers.

507
00:24:11,050 --> 00:24:13,760
>> DAVID J. MALAN: Compares two
numbers, and if x is less than y

508
00:24:13,760 --> 00:24:14,860
it says as much.

509
00:24:14,860 --> 00:24:18,080
If x is greater than y
it says as much, else

510
00:24:18,080 --> 00:24:20,740
if x is equal to y it says as much.

511
00:24:20,740 --> 00:24:22,180
Now where did x and y come from?

512
00:24:22,180 --> 00:24:22,680
Who knows.

513
00:24:22,680 --> 00:24:25,380
This chunk of Scratch
code is out of context.

514
00:24:25,380 --> 00:24:29,050
But what we want to do now is translate
this for just a moment to see.

515
00:24:29,050 --> 00:24:31,660
>> So as you get comfortable
this week in Problem Set

516
00:24:31,660 --> 00:24:34,190
0 playing in this world
on the left, realize

517
00:24:34,190 --> 00:24:36,940
that the ideas aren't changing
this week or next or beyond.

518
00:24:36,940 --> 00:24:38,690
We're simply going to
start writing things

519
00:24:38,690 --> 00:24:41,240
in a different way with our
keyboard instead of our mouse.

520
00:24:41,240 --> 00:24:44,577
>> So if x is less than y, and
there's some parentheses there,

521
00:24:44,577 --> 00:24:47,160
then there's some curly braces
again to kind of encapsulate it

522
00:24:47,160 --> 00:24:48,970
just like the yellow puzzle pieces do.

523
00:24:48,970 --> 00:24:53,000
And I'm going to printf x
is less than y and so forth.

524
00:24:53,000 --> 00:24:56,540
>> What is nice about C,
as you can see here,

525
00:24:56,540 --> 00:25:00,480
is that you don't get this nesting,
nesting, nesting that's necessarily

526
00:25:00,480 --> 00:25:02,220
going to push your code to the right.

527
00:25:02,220 --> 00:25:04,990
You can instead have everything
lineup neatly like this.

528
00:25:04,990 --> 00:25:08,960
But that's just an aesthetic
detail we'll see again before long.

529
00:25:08,960 --> 00:25:09,660
>> All right.

530
00:25:09,660 --> 00:25:13,290
So that brings us back to
this cryptic looking program.

531
00:25:13,290 --> 00:25:15,180
Let's actually write some code.

532
00:25:15,180 --> 00:25:16,830
Now how do you go about writing code?

533
00:25:16,830 --> 00:25:21,310
All these years that you've owned
a Mac or PC, desktop or laptop,

534
00:25:21,310 --> 00:25:24,520
you've actually had the capability
to start writing programming code.

535
00:25:24,520 --> 00:25:27,050
But you're probably missing
a special type of program.

536
00:25:27,050 --> 00:25:28,470
You can certainly write code.

537
00:25:28,470 --> 00:25:30,740
But you can't necessarily,
out of the box,

538
00:25:30,740 --> 00:25:34,210
convert that source code
into object code, 0s and 1s

539
00:25:34,210 --> 00:25:35,619
without what on your computer?

540
00:25:35,619 --> 00:25:36,410
AUDIENCE: Compiler.

541
00:25:36,410 --> 00:25:37,630
DAVID J. MALAN: So a compiler, right.

542
00:25:37,630 --> 00:25:39,730
Now most of you probably
don't own a compiler,

543
00:25:39,730 --> 00:25:41,259
have never downloaded a compiler.

544
00:25:41,259 --> 00:25:44,300
But you'll see you can download it
like most any other piece of software.

545
00:25:44,300 --> 00:25:47,470
In the world of Mac OS, you might
download or have downloaded already

546
00:25:47,470 --> 00:25:50,437
something called Xcode or GCC or Clang.

547
00:25:50,437 --> 00:25:52,270
If you come from the
Windows world you might

548
00:25:52,270 --> 00:25:56,190
have downloaded Visual Studio,
Visual Basic, environments like that.

549
00:25:56,190 --> 00:25:59,200
There's dozens of compilers
these days that you might use.

550
00:25:59,200 --> 00:26:01,940
But the short of it here
is that it would be a pain

551
00:26:01,940 --> 00:26:04,480
and, frankly, a technological
nightmare for hundreds

552
00:26:04,480 --> 00:26:07,680
of people with different
computer configurations to all

553
00:26:07,680 --> 00:26:09,800
configure their machines
in exactly the same way

554
00:26:09,800 --> 00:26:11,700
so that we can all be on the same page.

555
00:26:11,700 --> 00:26:15,240
>> So what we, instead, do
in CS50 is we give you

556
00:26:15,240 --> 00:26:18,349
a standard environment, a
Linux environment that's

557
00:26:18,349 --> 00:26:20,140
going to look a little
something like this.

558
00:26:20,140 --> 00:26:22,980
You'll see more of this in the
Problem Set 1 specification which

559
00:26:22,980 --> 00:26:25,330
will go online this Friday night.

560
00:26:25,330 --> 00:26:28,360
>> And what this means
is that you henceforth

561
00:26:28,360 --> 00:26:32,060
are going to be able to
download and install a program

562
00:26:32,060 --> 00:26:33,650
called the CS50 Appliance.

563
00:26:33,650 --> 00:26:36,275
And you're going to download and
install another program called

564
00:26:36,275 --> 00:26:40,300
a hypervisor, which is just a
fancy way of achieving this.

565
00:26:40,300 --> 00:26:44,600
Whether you own a Mac or PC or a
Linux computer or a Solaris computer,

566
00:26:44,600 --> 00:26:46,830
or whatever crazy operating
system you're running,

567
00:26:46,830 --> 00:26:49,820
you're going to download a program
called the hypervisor that's

568
00:26:49,820 --> 00:26:53,350
going to run the CS50
Appliance on your computer

569
00:26:53,350 --> 00:26:55,430
no matter what your operating system is.

570
00:26:55,430 --> 00:27:00,640
A hypervisor in other words converts
our stuff to whatever language,

571
00:27:00,640 --> 00:27:03,850
whatever instructions your
own computer understands.

572
00:27:03,850 --> 00:27:04,962
>> So this is a layering.

573
00:27:04,962 --> 00:27:06,920
And again, this is kind
of thematic in computer

574
00:27:06,920 --> 00:27:08,722
science, the building on top of things.

575
00:27:08,722 --> 00:27:09,680
You might have Windows.

576
00:27:09,680 --> 00:27:10,710
You might have Mac OS.

577
00:27:10,710 --> 00:27:12,960
But starting next week you're
going to have downloaded

578
00:27:12,960 --> 00:27:14,980
a free piece of software
called the hypervisor.

579
00:27:14,980 --> 00:27:17,800
You're going to have downloaded a piece
of software called the CS50 Appliance.

580
00:27:17,800 --> 00:27:21,050
>> That's going to run in the hypervisor,
which is going to run on your computer.

581
00:27:21,050 --> 00:27:23,030
And the end result is
that all of us will

582
00:27:23,030 --> 00:27:26,220
have a simple window like
this on your Mac or PC

583
00:27:26,220 --> 00:27:30,160
that gives us the illusion of all
running the same operating system,

584
00:27:30,160 --> 00:27:32,800
without any other
impact on your computer.

585
00:27:32,800 --> 00:27:34,870
And you can full screen
it and essentially behave

586
00:27:34,870 --> 00:27:37,550
as though you are running an
operating system called Linux,

587
00:27:37,550 --> 00:27:40,270
which is what the CS50
Appliance is based on.

588
00:27:40,270 --> 00:27:42,930
>> So let's actually use this
now to write a program.

589
00:27:42,930 --> 00:27:45,450
You can write a program
using Microsoft Word.

590
00:27:45,450 --> 00:27:48,160
You can write a program
using TextEdit, or Notepad,

591
00:27:48,160 --> 00:27:51,880
or WordPad, or pretty much any word
processing program you've ever used.

592
00:27:51,880 --> 00:27:55,174
But the reality is you shouldn't
use really any of those programs.

593
00:27:55,174 --> 00:27:57,840
You certainly shouldn't use
something like Microsoft Word, which

594
00:27:57,840 --> 00:28:01,120
has bold facing and italics, and
bigger fonts and smaller fonts,

595
00:28:01,120 --> 00:28:03,560
because the computer doesn't
care about any of that.

596
00:28:03,560 --> 00:28:05,600
All the computer is
going to care about is

597
00:28:05,600 --> 00:28:09,040
English like instructions written in C.

598
00:28:09,040 --> 00:28:12,050
>> So what we'll do inside
of the CS50 Appliance

599
00:28:12,050 --> 00:28:14,290
is use a program freely
available, and it's

600
00:28:14,290 --> 00:28:17,360
pre-installed in this
appliance, called Gedit.

601
00:28:17,360 --> 00:28:22,280
And Gedit is just a super simple
text editor like Mac OS's TextEdit,

602
00:28:22,280 --> 00:28:26,200
like Windows Notepad that's going to
look a little something like this.

603
00:28:26,200 --> 00:28:28,910
>> So let's actually not
look at slides of this.

604
00:28:28,910 --> 00:28:32,580
But let's actually go into
the environment itself.

605
00:28:32,580 --> 00:28:36,090
I'm going to go ahead and
log in, in this other window,

606
00:28:36,090 --> 00:28:40,910
to my CS50 Appliance, which I've
pre-installed on my laptop here.

607
00:28:40,910 --> 00:28:43,771
>> Notice that, like Windows and
Mac OS, it's got some menus.

608
00:28:43,771 --> 00:28:45,520
Like Windows it puts
it down there instead

609
00:28:45,520 --> 00:28:47,020
of Mac OS, which puts it down there.

610
00:28:47,020 --> 00:28:48,930
But the reality is it's
all kind of the same.

611
00:28:48,930 --> 00:28:50,770
And in here is a whole
bunch of software.

612
00:28:50,770 --> 00:28:51,770
There's Dropbox.

613
00:28:51,770 --> 00:28:54,780
There's a whole bunch of accessories,
graphical programs that we'll

614
00:28:54,780 --> 00:28:56,430
use later in the term for problem sets.

615
00:28:56,430 --> 00:28:59,650
There's a web browser built in so
that this is a full fledged computer

616
00:28:59,650 --> 00:29:01,240
inside of a computer.

617
00:29:01,240 --> 00:29:04,170
>> But I'm going to click this
leftmost white icon here,

618
00:29:04,170 --> 00:29:05,890
which is the icon for Gedit.

619
00:29:05,890 --> 00:29:09,650
And it's going to open a window
that has three panels to it,

620
00:29:09,650 --> 00:29:12,590
a left one, a top one, and a bottom one.

621
00:29:12,590 --> 00:29:16,071
>> Now it's in this top right one that
I'm going to actually write some code.

622
00:29:16,071 --> 00:29:16,820
So let's do this,.

623
00:29:16,820 --> 00:29:19,040
I'm going to go to File, Save.

624
00:29:19,040 --> 00:29:22,100
And you might not ever have seen
this particular window before.

625
00:29:22,100 --> 00:29:23,620
But this is like Mac OS or Windows.

626
00:29:23,620 --> 00:29:25,490
It's just a window
with all of the folders

627
00:29:25,490 --> 00:29:27,290
that I have inside of this computer.

628
00:29:27,290 --> 00:29:30,320
>> And I'm going to save
the file as hello.c.

629
00:29:30,320 --> 00:29:32,690
And I'm going to go
ahead and click Save.

630
00:29:32,690 --> 00:29:36,364
And now notice I have a tab
at top left called hello.c.

631
00:29:36,364 --> 00:29:38,280
So probably pretty
familiar even if you've not

632
00:29:38,280 --> 00:29:40,240
used this particular program before.

633
00:29:40,240 --> 00:29:44,890
>> And now I'm going to type in those
fairly cryptic sequence of commands

634
00:29:44,890 --> 00:29:46,360
that we saw a moment ago.

635
00:29:46,360 --> 00:29:49,330
Include, standard I/O.h.

636
00:29:49,330 --> 00:29:50,600
More on that soon.

637
00:29:50,600 --> 00:29:55,670
Int main void, open curly
brace, closed curly brace.

638
00:29:55,670 --> 00:30:01,570
And then inside of there I think is
where we had "hello world," semicolon.

639
00:30:01,570 --> 00:30:03,100
And now save.

640
00:30:03,100 --> 00:30:08,780
>> So this is a program written in C,
written, therefore, in source code.

641
00:30:08,780 --> 00:30:10,720
But I can't just run this program.

642
00:30:10,720 --> 00:30:13,390
I kind of want to double
click on an icon somewhere,

643
00:30:13,390 --> 00:30:16,390
but no icon exists other
than the source code file.

644
00:30:16,390 --> 00:30:20,359
What, again, is the process now that
I need to run this file through?

645
00:30:20,359 --> 00:30:21,150
AUDIENCE: Compiler.

646
00:30:21,150 --> 00:30:22,399
DAVID J. MALAN: So a compiler.

647
00:30:22,399 --> 00:30:24,890
So in different computers you
do this in different ways.

648
00:30:24,890 --> 00:30:27,480
But what we've done here in
the CS50 Appliance that's

649
00:30:27,480 --> 00:30:31,260
representative of how you might
do this on many different systems,

650
00:30:31,260 --> 00:30:34,036
is I'm simply going to
run a command called make.

651
00:30:34,036 --> 00:30:35,660
And make is literally going to do that.

652
00:30:35,660 --> 00:30:36,640
Make me a program.

653
00:30:36,640 --> 00:30:39,060
>> So make is going to
run a compiler for me.

654
00:30:39,060 --> 00:30:42,160
And the name of the program
I want to make is hello.

655
00:30:42,160 --> 00:30:43,510
Now make is a program.

656
00:30:43,510 --> 00:30:47,170
And make is smart enough to
realize that if I say make hello,

657
00:30:47,170 --> 00:30:50,980
it's going to look automatically
for a file called hello.c

658
00:30:50,980 --> 00:30:53,420
just because that's the
way it's configured.

659
00:30:53,420 --> 00:31:00,300
>> So when I now hit Enter here, this
crazy cryptic line just got executed.

660
00:31:00,300 --> 00:31:02,720
And trust me, before
long, within just days,

661
00:31:02,720 --> 00:31:05,590
you'll understand what all
of that nonsense means.

662
00:31:05,590 --> 00:31:11,150
But for now, just know that make
triggered execution of a compiler.

663
00:31:11,150 --> 00:31:13,290
In other words, it found
a compiler on my computer

664
00:31:13,290 --> 00:31:14,820
that's pre-installed
on the CS50 Appliance

665
00:31:14,820 --> 00:31:16,560
that we'll hand to you in Problem Set 1.

666
00:31:16,560 --> 00:31:20,990
And it then took hello.c as
input, and produced apparently

667
00:31:20,990 --> 00:31:23,040
0s and 1s as output.

668
00:31:23,040 --> 00:31:29,410
>> And by default what it does is it saves
those 0s and 1s in a file called hello.

669
00:31:29,410 --> 00:31:33,180
And though this syntax too might
be new to you, simply by saying dot

670
00:31:33,180 --> 00:31:37,110
slash hello is going to be the
means by which I run this program.

671
00:31:37,110 --> 00:31:40,360
>> For now and for at least a couple
of weeks, almost all of the programs

672
00:31:40,360 --> 00:31:44,230
we write are going to be in
black and white text windows.

673
00:31:44,230 --> 00:31:47,006
No mice, no clicking,
no windows, no icons.

674
00:31:47,006 --> 00:31:49,630
We're going to keep it simple
and focus on the underlying ideas

675
00:31:49,630 --> 00:31:52,490
initially before we get to something
higher level, for instance,

676
00:31:52,490 --> 00:31:56,410
like the break out game that we talked
about in the first lecture last week.

677
00:31:56,410 --> 00:32:00,820
>> So when I hit Enter here, it's
equivalent in a text only environment

678
00:32:00,820 --> 00:32:03,272
to double clicking an icon called hello.

679
00:32:03,272 --> 00:32:05,480
What do you expect will
happen when I hit Enter then?

680
00:32:05,480 --> 00:32:07,120
>> AUDIENCE: It'll print "hello world."

681
00:32:07,120 --> 00:32:10,000
>> DAVID J. MALAN: Hopefully
it will print "hello world."

682
00:32:10,000 --> 00:32:11,370
And indeed it did.

683
00:32:11,370 --> 00:32:13,690
Now there's been some
cryptic syntax here.

684
00:32:13,690 --> 00:32:15,950
Let's rewind for just
a moment and see if we

685
00:32:15,950 --> 00:32:19,530
can't start inferring just by
tinkering, trying and failing,

686
00:32:19,530 --> 00:32:21,130
as to what's going on here.

687
00:32:21,130 --> 00:32:23,609
What if I get rid of the backslash n?

688
00:32:23,609 --> 00:32:25,650
Now some of you who've
programmed before probably

689
00:32:25,650 --> 00:32:27,054
know instantly what that means.

690
00:32:27,054 --> 00:32:29,220
But for those of you who've
never programmed before,

691
00:32:29,220 --> 00:32:34,052
at least think to yourself what is going
to change when I rerun this program?

692
00:32:34,052 --> 00:32:37,010
So I'm going to go back down to my
little black and white window, which

693
00:32:37,010 --> 00:32:39,290
is the window in which
I can compile this.

694
00:32:39,290 --> 00:32:41,130
I'm going to recompile hello.

695
00:32:41,130 --> 00:32:43,520
We're going to see the same
cryptic sequence of commands.

696
00:32:43,520 --> 00:32:45,719
And I'm going to do dot slash hello.

697
00:32:45,719 --> 00:32:48,260
And now someone, if you would,
who's never programmed before,

698
00:32:48,260 --> 00:32:49,770
what might be different this time?

699
00:32:49,770 --> 00:32:50,020
Yeah.

700
00:32:50,020 --> 00:32:51,840
>> AUDIENCE: It won't stop
printing "hello world."

701
00:32:51,840 --> 00:32:52,660
>> DAVID J. MALAN: It's going to-- sorry?

702
00:32:52,660 --> 00:32:54,210
>> AUDIENCE: It won't stop printing it?

703
00:32:54,210 --> 00:32:55,810
>> DAVID J. MALAN: It won't
stop printing "hello world."

704
00:32:55,810 --> 00:32:56,560
So not a bad idea.

705
00:32:56,560 --> 00:32:58,633
Other ideas?

706
00:32:58,633 --> 00:32:59,132
Yeah.

707
00:32:59,132 --> 00:33:00,060
>> AUDIENCE: Error message?

708
00:33:00,060 --> 00:33:01,750
>> DAVID J. MALAN: Error
message, OK, could be.

709
00:33:01,750 --> 00:33:02,250
What else?

710
00:33:02,250 --> 00:33:05,479
AUDIENCE: It might print the
bracket with the semicolon as well?

711
00:33:05,479 --> 00:33:08,270
DAVID J. MALAN: Might print the
bracket with the semicolon as well.

712
00:33:08,270 --> 00:33:11,950
So maybe that backslash then is some
kind of terminous that's important.

713
00:33:11,950 --> 00:33:14,860
Any other thoughts?

714
00:33:14,860 --> 00:33:16,412
>> So all good ideas.

715
00:33:16,412 --> 00:33:18,370
And in fact, it's going
to be an error message.

716
00:33:18,370 --> 00:33:20,400
That's probably most likely
to be the answer in general

717
00:33:20,400 --> 00:33:22,420
for the next few weeks
as we learn to code here.

718
00:33:22,420 --> 00:33:27,680
>> But for now remember that computers
only do what you tell them to do.

719
00:33:27,680 --> 00:33:30,400
Much like the ridiculous peanut
butter and jelly example.

720
00:33:30,400 --> 00:33:33,860
Our human computers were only supposed
to do what you told them to do.

721
00:33:33,860 --> 00:33:36,250
So in this case, if you
don't tell the computer

722
00:33:36,250 --> 00:33:41,190
to move that blinking cursor to the
next line, it's not going to do it.

723
00:33:41,190 --> 00:33:45,390
So when I run this program
now, notice the difference.

724
00:33:45,390 --> 00:33:46,900
>> Looks like a bug.

725
00:33:46,900 --> 00:33:49,190
It's an aesthetic bug, perhaps.

726
00:33:49,190 --> 00:33:53,310
But what is different about this
output versus the last one obviously?

727
00:33:53,310 --> 00:33:53,810
Yeah.

728
00:33:53,810 --> 00:33:54,920
>> AUDIENCE: It didn't do a new line.

729
00:33:54,920 --> 00:33:56,586
>> DAVID J. MALAN: It didn't do a new line.

730
00:33:56,586 --> 00:33:58,740
Now those of you who
have maybe made web pages

731
00:33:58,740 --> 00:34:01,910
before, you might know of the
BR tag or the paragraph tag,

732
00:34:01,910 --> 00:34:03,120
very similar in spirit.

733
00:34:03,120 --> 00:34:06,680
A web browser will ignore you until
you tell it exactly what to do.

734
00:34:06,680 --> 00:34:10,020
Similarly, is a language like C only
going to do what you tell it to do.

735
00:34:10,020 --> 00:34:12,730
>> So the reason that
all of these examples,

736
00:34:12,730 --> 00:34:15,350
thus far, have kind of
casually had this backslash

737
00:34:15,350 --> 00:34:18,560
in there, that's the means
by which you express yourself

738
00:34:18,560 --> 00:34:21,380
as a new line character, so to speak.

739
00:34:21,380 --> 00:34:26,219
And you can kind of appreciate, perhaps,
that this would look kind of stupid

740
00:34:26,219 --> 00:34:27,070
if nothing else.

741
00:34:27,070 --> 00:34:29,150
If I wanted a new line, just
hitting Enter and then kind

742
00:34:29,150 --> 00:34:32,219
of butchering the code like that
shouldn't really rub you the right way.

743
00:34:32,219 --> 00:34:33,830
And even if you don't
really care at this point,

744
00:34:33,830 --> 00:34:35,830
you will realize that
this is not a particularly

745
00:34:35,830 --> 00:34:37,870
good looking piece of code.

746
00:34:37,870 --> 00:34:39,969
>> And so what the world
decided years ago is

747
00:34:39,969 --> 00:34:43,420
that when you want to put the
cursor onto a new line explicitly,

748
00:34:43,420 --> 00:34:46,332
you must explicitly say
new line, backslash n.

749
00:34:46,332 --> 00:34:48,040
And there's some other
symbols like that.

750
00:34:48,040 --> 00:34:50,719
But for now we'll just
focus on backslash n.

751
00:34:50,719 --> 00:34:53,790
>> Now let's make the program
a little more interesting.

752
00:34:53,790 --> 00:34:59,200
I'm going to go ahead and
this time open up a new file.

753
00:34:59,200 --> 00:35:02,520
I'm going to save this as hello-1.c.

754
00:35:02,520 --> 00:35:05,540
And just for kicks, I'm going to
go put it into my Dropbox folder.

755
00:35:05,540 --> 00:35:09,030
>> As you'll see in the CS50
documentation for the appliance,

756
00:35:09,030 --> 00:35:11,210
later this week for Problem
Set 1, we'll encourage

757
00:35:11,210 --> 00:35:13,230
you to use Dropbox or
some equivalent service,

758
00:35:13,230 --> 00:35:15,430
because then all of your code's
going to be backed up automatically.

759
00:35:15,430 --> 00:35:17,830
And so that's why I've
gone into this folder here.

760
00:35:17,830 --> 00:35:20,230
>> And now I'm going to write a
slightly different program.

761
00:35:20,230 --> 00:35:24,740
Include, standard I/O.h, int main void.

762
00:35:24,740 --> 00:35:29,660
And then in here printf, hello world,
which is exactly the same as before.

763
00:35:29,660 --> 00:35:32,450
>> But now I want to print something
that's a little different.

764
00:35:32,450 --> 00:35:34,800
I want to print out,
say, "Hello, David."

765
00:35:34,800 --> 00:35:37,590
All right, so obviously,
it should hopefully

766
00:35:37,590 --> 00:35:40,360
be the case that if I recompile
this program, rerun it,

767
00:35:40,360 --> 00:35:41,840
it's going to say "hello, David."

768
00:35:41,840 --> 00:35:45,160
>> But what if I want to introduce
this sort of variable,

769
00:35:45,160 --> 00:35:49,240
the notion of a container that's going
to store D-a-v-i-d and not hard code it

770
00:35:49,240 --> 00:35:50,600
into my program.

771
00:35:50,600 --> 00:35:53,430
Well what if I start
doing something like this?

772
00:35:53,430 --> 00:35:57,120
>> String s, so this is a variable.

773
00:35:57,120 --> 00:36:00,250
If you want a string,
a.k.a. a word or a phrase.

774
00:36:00,250 --> 00:36:03,485
A sequence of characters is what
we in programming call a string.

775
00:36:03,485 --> 00:36:06,610
We're just going to generically call
it s, because it's a nice simple name.

776
00:36:06,610 --> 00:36:08,010
But I could call it anything.

777
00:36:08,010 --> 00:36:12,920
>> I'm going to say string s equals
quote unquote, "David," semicolon.

778
00:36:12,920 --> 00:36:18,330
And now I want to insert
D-a-v-i-d into what I'm printing.

779
00:36:18,330 --> 00:36:23,720
And before we saw a teaser on
the screen of some special syntax

780
00:36:23,720 --> 00:36:26,050
that allowed us to
substitute in a value.

781
00:36:26,050 --> 00:36:29,250
What was the special
symbol a few slides ago?

782
00:36:29,250 --> 00:36:30,040
>> So percent.

783
00:36:30,040 --> 00:36:33,830
At the time it was percent
d for decimal number.

784
00:36:33,830 --> 00:36:35,850
That doesn't really seem relevant here.

785
00:36:35,850 --> 00:36:38,650
Turns out there's
another percent symbol,

786
00:36:38,650 --> 00:36:42,810
which is percent s, which stands
for a placeholder for a string.

787
00:36:42,810 --> 00:36:49,350
>> So now, very simply, I'm
going to go make hello-1,

788
00:36:49,350 --> 00:36:54,210
because this file's called
hello-1.c, and hit Enter.

789
00:36:54,210 --> 00:36:56,230
And I screwed up.

790
00:36:56,230 --> 00:36:57,394
What's going on?

791
00:36:57,394 --> 00:37:00,560
Well, here's where we have to begin to
appreciate that we're in this command

792
00:37:00,560 --> 00:37:02,810
line environment, this
text only environment.

793
00:37:02,810 --> 00:37:06,114
There's no clicking on icons
like folders right now.

794
00:37:06,114 --> 00:37:07,280
And think back a moment ago.

795
00:37:07,280 --> 00:37:10,740
In what folder did I say
I was saving my code?

796
00:37:10,740 --> 00:37:11,657
So the Dropbox folder.

797
00:37:11,657 --> 00:37:12,989
Could have been called anything.

798
00:37:12,989 --> 00:37:14,530
But it happens to be called Dropbox.

799
00:37:14,530 --> 00:37:18,380
So I somehow need to double click on
that Dropbox folder in order to get

800
00:37:18,380 --> 00:37:21,657
into it and get at my
code called hello-1.c.

801
00:37:21,657 --> 00:37:24,490
In fact, let me go ahead and minimize
this window for just a moment.

802
00:37:24,490 --> 00:37:27,560
Just like Windows and Mac OS,
there are folders in Linux.

803
00:37:27,560 --> 00:37:29,410
There are folders in the CS50 Appliance.

804
00:37:29,410 --> 00:37:32,380
It's just right now we're confining
ourselves to this text environment.

805
00:37:32,380 --> 00:37:34,700
>> But if I double click
on Dropbox, notice there

806
00:37:34,700 --> 00:37:37,210
is the file that I want to compile.

807
00:37:37,210 --> 00:37:41,430
But I need this black and white
terminal window, so to speak.

808
00:37:41,430 --> 00:37:45,750
But I need, therefore, to move
into that folder or directory.

809
00:37:45,750 --> 00:37:48,290
So slightly arcane, but
you'll get used to this too.

810
00:37:48,290 --> 00:37:50,430
>> In the world of Linux,
which again is the operating

811
00:37:50,430 --> 00:37:54,860
system we're running inside of the CS50
Appliance, there's a command called CD.

812
00:37:54,860 --> 00:37:58,310
Which means I can do CD, space, Dropbox.

813
00:37:58,310 --> 00:37:59,900
CD, change directory.

814
00:37:59,900 --> 00:38:00,400
Right.

815
00:38:00,400 --> 00:38:02,890
Back in the day when people were
inventing computers and operating

816
00:38:02,890 --> 00:38:05,806
systems like this, they wanted to
type the fewest keystrokes possible.

817
00:38:05,806 --> 00:38:08,760
So the easiest way to say
change directory was CD.

818
00:38:08,760 --> 00:38:13,910
>> So if I hit CD, space Dropbox,
notice what has changed here.

819
00:38:13,910 --> 00:38:16,480
Inside of parentheses
the appliance is kind

820
00:38:16,480 --> 00:38:19,360
of humoring me and
reminding me where I am.

821
00:38:19,360 --> 00:38:21,480
So the open folder is Dropbox.

822
00:38:21,480 --> 00:38:24,950
If I now type ls for
list, again succinct,

823
00:38:24,950 --> 00:38:27,540
because people didn't want to
type back in the day l-i-s-t.

824
00:38:27,540 --> 00:38:29,300
So they instead made it ls.

825
00:38:29,300 --> 00:38:30,110
>> Enter.

826
00:38:30,110 --> 00:38:35,740
Notice I see two things, hello-1.c,
and then this cryptic thing, source 1m.

827
00:38:35,740 --> 00:38:38,310
That's just my way of saying
source code for week 1 Monday.

828
00:38:38,310 --> 00:38:42,020
That's a folder I downloaded from
CS50's website that I made earlier today

829
00:38:42,020 --> 00:38:43,990
and just put it into the
appliance in advance.

830
00:38:43,990 --> 00:38:47,550
>> But for now the only thing we
care about is making this program.

831
00:38:47,550 --> 00:38:50,440
So when I type make hello-1, Enter.

832
00:38:50,440 --> 00:38:51,320
Damn it.

833
00:38:51,320 --> 00:38:53,060
Something went wrong.

834
00:38:53,060 --> 00:38:54,580
So let's tease this apart.

835
00:38:54,580 --> 00:38:58,489
And unfortunately this is where things
get a little stressful at first,

836
00:38:58,489 --> 00:39:00,280
at least if you've
never programmed before.

837
00:39:00,280 --> 00:39:00,980
>> My god.

838
00:39:00,980 --> 00:39:04,990
I wrote a two line program and
I have four lines of errors.

839
00:39:04,990 --> 00:39:07,180
So what's going on here.

840
00:39:07,180 --> 00:39:11,370
First and foremost always scroll back
up and find the first error message,

841
00:39:11,370 --> 00:39:15,730
because oftentimes compilers just
get confused by what you and I do.

842
00:39:15,730 --> 00:39:17,000
Compilers are pretty dumb.

843
00:39:17,000 --> 00:39:18,360
They'll only do what
you tell them to do.

844
00:39:18,360 --> 00:39:21,484
And if you confuse them, they're just
going to kind of throw up their hands

845
00:39:21,484 --> 00:39:25,010
and maybe throw more error messages
than are actually relevant.

846
00:39:25,010 --> 00:39:26,380
>> So let's look at the first.

847
00:39:26,380 --> 00:39:27,540
Super cryptic at first.

848
00:39:27,540 --> 00:39:31,050
But notice, here's the name of the
file in which I screwed up apparently.

849
00:39:31,050 --> 00:39:36,570
Colon 5, colon 5 just means on
line 5 at the fifth character.

850
00:39:36,570 --> 00:39:39,760
So fifth column of characters,
if you will, error.

851
00:39:39,760 --> 00:39:41,870
Use of undeclared identifier string.

852
00:39:41,870 --> 00:39:43,120
Did you mean standard n?

853
00:39:43,120 --> 00:39:44,850
>> No, I meant string.

854
00:39:44,850 --> 00:39:47,640
And then it's kind of
copying and pasting

855
00:39:47,640 --> 00:39:50,700
what I typed to really draw my
attention to where I screwed up.

856
00:39:50,700 --> 00:39:54,260
So for some reason C,
or at least the compiler

857
00:39:54,260 --> 00:39:56,470
does not understand the word string.

858
00:39:56,470 --> 00:39:57,890
And that's because we made it up.

859
00:39:57,890 --> 00:40:01,440
So string does not exist
in C. What CS50 does,

860
00:40:01,440 --> 00:40:03,380
for the first few weeks
only of the class,

861
00:40:03,380 --> 00:40:05,700
is we provide some training
wheels, so to speak.

862
00:40:05,700 --> 00:40:11,160
And we put these training wheels
inside of a special file called CS50.h.

863
00:40:11,160 --> 00:40:14,970
>> So this is the second of two file
names that apparently end in dot h.

864
00:40:14,970 --> 00:40:16,300
Let's rewind.

865
00:40:16,300 --> 00:40:19,360
Printf is a statement or function
that apparently prints something

866
00:40:19,360 --> 00:40:20,580
to the screen.

867
00:40:20,580 --> 00:40:23,470
But you didn't see me
implement printf, right.

868
00:40:23,470 --> 00:40:26,360
Someone years ago implemented printf.

869
00:40:26,360 --> 00:40:30,420
In what file would you wager he
or she put the implementation

870
00:40:30,420 --> 00:40:34,270
for printf, the code for printf?

871
00:40:34,270 --> 00:40:36,860
>> In a file called standard I/O.h.

872
00:40:36,860 --> 00:40:39,930
In fact, it's probably in
two files, standard I/O.h,

873
00:40:39,930 --> 00:40:42,650
which stands for header
file, and standard I/O.c,

874
00:40:42,650 --> 00:40:44,060
which stands for C source code.

875
00:40:44,060 --> 00:40:48,220
So he or she some years ago plopped
the code that they wrote into that file

876
00:40:48,220 --> 00:40:51,240
so that people like us
years later can include it,

877
00:40:51,240 --> 00:40:53,040
so to speak, in our own programs.

878
00:40:53,040 --> 00:40:56,320
>> And indeed, that's what the pound sign
followed by the word include does.

879
00:40:56,320 --> 00:41:00,250
It looks on the local hard drive,
finds the file called standard I/O.h,

880
00:41:00,250 --> 00:41:03,840
and then effectively copies and
pastes it inside of my own file.

881
00:41:03,840 --> 00:41:07,210
So now my program knows
how to print to the screen.

882
00:41:07,210 --> 00:41:11,120
>> So by that logic, where
is string defined?

883
00:41:11,120 --> 00:41:12,260
>> AUDIENCE: CS50.h.

884
00:41:12,260 --> 00:41:13,290
>> DAVID J. MALAN: CS50.h.

885
00:41:13,290 --> 00:41:15,540
And indeed, that's what we,
the core staff, have done.

886
00:41:15,540 --> 00:41:19,590
We've invented a few data types,
so to speak, like a string,

887
00:41:19,590 --> 00:41:22,370
in addition to ones you
get for free, like an int.

888
00:41:22,370 --> 00:41:26,010
And we'll see others like a char
for a character and a few more.

889
00:41:26,010 --> 00:41:30,670
Inside of CS50.h apparently is
at least some mention of string.

890
00:41:30,670 --> 00:41:34,980
>> So now let me go ahead
and rerun make hello-1.

891
00:41:34,980 --> 00:41:37,100
I'll zoom in again and cross my fingers.

892
00:41:37,100 --> 00:41:41,370
Now by having made one
change I fixed most things.

893
00:41:41,370 --> 00:41:42,100
But damn it.

894
00:41:42,100 --> 00:41:44,290
More percents than data arguments.

895
00:41:44,290 --> 00:41:45,980
What did I do wrong this time?

896
00:41:45,980 --> 00:41:47,420
>> So it's still pretty cryptic.

897
00:41:47,420 --> 00:41:51,560
But this error is on
line 7 and character 21.

898
00:41:51,560 --> 00:41:53,880
So let's go look up here.

899
00:41:53,880 --> 00:41:55,350
It's a little subtle.

900
00:41:55,350 --> 00:41:59,167
But if you think about what
the fundamental ideas here are,

901
00:41:59,167 --> 00:42:00,500
perhaps we can tease this apart.

902
00:42:00,500 --> 00:42:02,300
>> So printf is the name of the function.

903
00:42:02,300 --> 00:42:04,960
Parentheses, thus far, is
just like what we put around

904
00:42:04,960 --> 00:42:07,005
the stuff we're passing
as inputs to a function.

905
00:42:07,005 --> 00:42:08,921
All right, just an
arbitrary human convention.

906
00:42:08,921 --> 00:42:09,919
Use parentheses.

907
00:42:09,919 --> 00:42:12,460
Inside of those parentheses
we've been putting double quotes,

908
00:42:12,460 --> 00:42:14,810
and then a string like "hello world."

909
00:42:14,810 --> 00:42:18,160
>> But in that earlier example very
briefly did we look at with Scratch.

910
00:42:18,160 --> 00:42:22,590
And we had the percent d, what else
was inside of those parentheses

911
00:42:22,590 --> 00:42:23,730
that I called out verbally?

912
00:42:23,730 --> 00:42:24,230
Yeah.

913
00:42:24,230 --> 00:42:28,166
>> AUDIENCE: So it's what you're taking
[INAUDIBLE] from within [INAUDIBLE]

914
00:42:28,166 --> 00:42:30,200
what these [INAUDIBLE]?

915
00:42:30,200 --> 00:42:31,200
DAVID J. MALAN: Exactly.

916
00:42:31,200 --> 00:42:32,700
So we had the percent d.

917
00:42:32,700 --> 00:42:36,620
But then we had close
quote, comma, counter.

918
00:42:36,620 --> 00:42:37,120
Right.

919
00:42:37,120 --> 00:42:40,680
We specified what we want
to do as the placeholder.

920
00:42:40,680 --> 00:42:44,621
So what I'm going to do here is
comma, what do you want me to put?

921
00:42:44,621 --> 00:42:45,120
AUDIENCE: S.

922
00:42:45,120 --> 00:42:46,828
DAVID J. MALAN: S,
because s in this case

923
00:42:46,828 --> 00:42:48,700
is the name of the storage container.

924
00:42:48,700 --> 00:42:50,180
It's the name of that glass bowl.

925
00:42:50,180 --> 00:42:53,610
Whereas before it was counter in that
simple Scratch example we looked at.

926
00:42:53,610 --> 00:42:56,630
So now having made two
changes, let me zoom in

927
00:42:56,630 --> 00:42:59,800
and try once more to
compile this program.

928
00:42:59,800 --> 00:43:01,596
>> Now I see that cryptic line.

929
00:43:01,596 --> 00:43:03,470
But that's actually the
name of the compiler.

930
00:43:03,470 --> 00:43:04,886
Clang is the name of the compiler.

931
00:43:04,886 --> 00:43:07,100
Make is just saving me
the headache of ever

932
00:43:07,100 --> 00:43:09,830
typing that long crazy command out.

933
00:43:09,830 --> 00:43:14,900
So now if I do dot slash hello-1,
I should see "hello, David."

934
00:43:14,900 --> 00:43:16,450
>> Pretty underwhelming, though, right?

935
00:43:16,450 --> 00:43:18,158
We could have done
this a lot more simply

936
00:43:18,158 --> 00:43:20,940
without talking about variables
and CS50.h and all of that.

937
00:43:20,940 --> 00:43:23,080
So let's make it a
little more interesting.

938
00:43:23,080 --> 00:43:31,010
>> In addition to CS50.h,
having things like string

939
00:43:31,010 --> 00:43:34,550
declared, the CS50 library
also has a few functions.

940
00:43:34,550 --> 00:43:38,520
So just like years ago, someone wrote
printf and put it in standard I/O.h

941
00:43:38,520 --> 00:43:39,530
and some other file.

942
00:43:39,530 --> 00:43:44,010
>> We, the CS50 staff, wrote a function
called GetChar, GetDouble, GetFloat,

943
00:43:44,010 --> 00:43:47,610
GetInt, GetLongLong, GetString,
and we put those inside a file

944
00:43:47,610 --> 00:43:49,890
called CS50.h and CS50.c.

945
00:43:49,890 --> 00:43:51,880
And we put them inside
of the CS50 Appliance.

946
00:43:51,880 --> 00:43:53,880
And people can also
download them online if they

947
00:43:53,880 --> 00:43:55,880
want to put them on their
own computers as well.

948
00:43:55,880 --> 00:44:00,880
Which is to say that we have created
functions that get input from the user.

949
00:44:00,880 --> 00:44:02,930
I don't know what all
of these data types are.

950
00:44:02,930 --> 00:44:06,490
GetInt is kind of straightforward, like
get an integer somehow from the user.

951
00:44:06,490 --> 00:44:09,980
And GetString is probably like get
a word or a sentence from the user.

952
00:44:09,980 --> 00:44:11,770
>> So let's focus on that.

953
00:44:11,770 --> 00:44:14,710
And I'm going to go back into the
appliance and I'm going to go ahead

954
00:44:14,710 --> 00:44:20,790
and save this file as, let's call
it hello-2.c as my second version.

955
00:44:20,790 --> 00:44:23,030
And let's make a couple of changes.

956
00:44:23,030 --> 00:44:25,800
>> This time instead of
hard coding David, which

957
00:44:25,800 --> 00:44:29,120
makes an incredibly consistent
but underwhelming program,

958
00:44:29,120 --> 00:44:32,640
what if I instead do GetString?

959
00:44:32,640 --> 00:44:35,660
Now notice GetString
has an open parenthesis,

960
00:44:35,660 --> 00:44:38,500
closed parenthesis, because
it doesn't need any input.

961
00:44:38,500 --> 00:44:40,850
It's just going to go get
a string from the user.

962
00:44:40,850 --> 00:44:42,460
>> And now a word on other syntax.

963
00:44:42,460 --> 00:44:45,439
Semicolons just end a line of code.

964
00:44:45,439 --> 00:44:46,730
You don't need them everywhere.

965
00:44:46,730 --> 00:44:48,896
But that just means I'm
done with this line of code.

966
00:44:48,896 --> 00:44:51,080
Let me move onto another
statement or function.

967
00:44:51,080 --> 00:44:53,010
String declares a variable.

968
00:44:53,010 --> 00:44:55,920
String is like saying
give me a bowl, please.

969
00:44:55,920 --> 00:44:57,940
And let me put a string in it.

970
00:44:57,940 --> 00:44:59,430
>> And now the equal sign.

971
00:44:59,430 --> 00:45:03,510
What is the equal sign
essentially equivalent to?

972
00:45:03,510 --> 00:45:04,500
>> AUDIENCE: Assign.

973
00:45:04,500 --> 00:45:06,190
>> DAVID J. MALAN: Yeah, assigning a value.

974
00:45:06,190 --> 00:45:09,872
So if I, for instance, call
this function GetString,

975
00:45:09,872 --> 00:45:12,830
and we'll see in a moment that's
going to prompt the user for a string.

976
00:45:12,830 --> 00:45:17,810
This is like letting me then write
D-a-v-i-d on a piece of paper.

977
00:45:17,810 --> 00:45:21,060
And when I say string
s equals GetString,

978
00:45:21,060 --> 00:45:24,140
equal doesn't really mean
equal in C programming.

979
00:45:24,140 --> 00:45:27,880
It means assign from the right
hand side to the left hand side.

980
00:45:27,880 --> 00:45:29,510
>> So I've gotten a string.

981
00:45:29,510 --> 00:45:32,785
And the equal sign means put it
in the storage container called s.

982
00:45:32,785 --> 00:45:36,730
And Then pass this off to
printf to actually do its thing.

983
00:45:36,730 --> 00:45:39,790
>> So the end result then is going
to look a little different.

984
00:45:39,790 --> 00:45:40,840
Let's do make hello-2.

985
00:45:40,840 --> 00:45:43,940

986
00:45:43,940 --> 00:45:45,260
Either could work.

987
00:45:45,260 --> 00:45:46,450
You're following along.

988
00:45:46,450 --> 00:45:47,940
Make hello-2 worked.

989
00:45:47,940 --> 00:45:52,640
Dot slash hello-2, Enter.

990
00:45:52,640 --> 00:45:54,620
>> I seem to have an infinite
loop or something.

991
00:45:54,620 --> 00:45:55,453
Nothing's happening.

992
00:45:55,453 --> 00:45:56,134
Why?

993
00:45:56,134 --> 00:45:57,805
>> AUDIENCE: It's making an infinite loop.

994
00:45:57,805 --> 00:45:59,430
DAVID J. MALAN: It is an infinite loop.

995
00:45:59,430 --> 00:46:02,710
It's kind of waiting for me to
actually provide it with some input.

996
00:46:02,710 --> 00:46:05,800
So let me go ahead and type
in David, and hit Enter.

997
00:46:05,800 --> 00:46:07,230
And now it says "hello, David."

998
00:46:07,230 --> 00:46:09,040
If I run it again.

999
00:46:09,040 --> 00:46:11,530
Let's type in Rob, "hello, Rob."

1000
00:46:11,530 --> 00:46:13,900
>> Now this is the worst
user interface ever.

1001
00:46:13,900 --> 00:46:16,110
The user's apparently
supposed to know what to do.

1002
00:46:16,110 --> 00:46:17,120
But no matter.

1003
00:46:17,120 --> 00:46:19,570
Using these same building
blocks just like in Scratch,

1004
00:46:19,570 --> 00:46:24,980
we can solve that problem and say
something like your name please, colon,

1005
00:46:24,980 --> 00:46:27,820
space, closed quote, close
parenthesis, semicolon.

1006
00:46:27,820 --> 00:46:30,680
So a lot of again
silliness with the syntax.

1007
00:46:30,680 --> 00:46:34,040
>> But notice I've just added a
puzzle piece above this one

1008
00:46:34,040 --> 00:46:35,280
and above this one.

1009
00:46:35,280 --> 00:46:38,870
So now if I rerun this, hello-2, Enter.

1010
00:46:38,870 --> 00:46:41,180
Wait a minute.

1011
00:46:41,180 --> 00:46:41,830
What's wrong?

1012
00:46:41,830 --> 00:46:43,570
It's not behaving any differently.

1013
00:46:43,570 --> 00:46:44,200
Yeah.

1014
00:46:44,200 --> 00:46:46,010
>> AUDIENCE: You didn't run make again.

1015
00:46:46,010 --> 00:46:47,968
>> DAVID J. MALAN: I didn't
run make again, right.

1016
00:46:47,968 --> 00:46:49,430
So I've changed my source code.

1017
00:46:49,430 --> 00:46:50,638
But again, there's that flow.

1018
00:46:50,638 --> 00:46:54,530
Source code through the compiler gives
you new object code, or 0s and 1s.

1019
00:46:54,530 --> 00:47:00,209
So I need to actually
rerun make hello-2 Enter.

1020
00:47:00,209 --> 00:47:01,750
OK, something seems to have happened.

1021
00:47:01,750 --> 00:47:04,220
Dot slash hello-2.

1022
00:47:04,220 --> 00:47:05,390
Your name please.

1023
00:47:05,390 --> 00:47:09,990
And to be clear now, why is
the cursor on the same line?

1024
00:47:09,990 --> 00:47:10,490
Exactly.

1025
00:47:10,490 --> 00:47:13,020
I didn't put the backslash
n up here in my code.

1026
00:47:13,020 --> 00:47:16,110
So now I can write
something like Daven, Enter.

1027
00:47:16,110 --> 00:47:18,710
I can run it again and type
something like Gabe, Enter,

1028
00:47:18,710 --> 00:47:22,250
and we get a different program
again and again and again.

1029
00:47:22,250 --> 00:47:28,940
>> Now ultimately we're going to need
to use a few different capabilities.

1030
00:47:28,940 --> 00:47:32,860
We need to introduce ultimately some
conditions to do things conditionally.

1031
00:47:32,860 --> 00:47:35,550
Maybe loops so we can do
things again and again.

1032
00:47:35,550 --> 00:47:38,220
>> Maybe it would be nice if we
could implement our own functions,

1033
00:47:38,220 --> 00:47:41,355
like we could implement our own
printf or our own version of GetString

1034
00:47:41,355 --> 00:47:45,870
and GetFlow, because ultimately even
using this command line environment

1035
00:47:45,870 --> 00:47:49,780
can we do even the most
visually interesting of things.

1036
00:47:49,780 --> 00:47:51,950
>> Indeed in conclusion let me do this.

1037
00:47:51,950 --> 00:47:54,020
I'm going to go ahead
and close these windows

1038
00:47:54,020 --> 00:47:57,400
and open this icon here,
which is just a bigger

1039
00:47:57,400 --> 00:48:00,020
version of that embedded
terminal window.

1040
00:48:00,020 --> 00:48:02,329
So Gedit has not only
the place for my code,

1041
00:48:02,329 --> 00:48:05,620
but also a built in terminal window, the
black and white window where I can run

1042
00:48:05,620 --> 00:48:06,230
commands.

1043
00:48:06,230 --> 00:48:08,600
>> I just happened to open
a bigger version of this.

1044
00:48:08,600 --> 00:48:11,170
And now I'm going to go into
the folder that I've already

1045
00:48:11,170 --> 00:48:13,150
put in advance on the course's website.

1046
00:48:13,150 --> 00:48:16,720
And I'm going to go ahead and
open a file called thadgavin.c,

1047
00:48:16,720 --> 00:48:18,710
which was written by someone else.

1048
00:48:18,710 --> 00:48:21,220
>> And if we look at this,
this is not the kind of code

1049
00:48:21,220 --> 00:48:24,370
we'll be writing since
the goal of this code

1050
00:48:24,370 --> 00:48:28,450
was to write the prettiest
looking code that he or she could,

1051
00:48:28,450 --> 00:48:31,290
irrespective of whether or not
another human being could ever

1052
00:48:31,290 --> 00:48:33,660
understand this code.

1053
00:48:33,660 --> 00:48:37,050
>> Indeed, every year there's what's
called an obfuscated C contest, which

1054
00:48:37,050 --> 00:48:39,570
is for real geeks who write
code that no one else can read,

1055
00:48:39,570 --> 00:48:42,050
but that does something either
really simple or really amazing.

1056
00:48:42,050 --> 00:48:43,890
And we thought we'd
conclude with this look

1057
00:48:43,890 --> 00:48:48,300
at something that's pretty amazing
you might have seen once before.

1058
00:48:48,300 --> 00:48:52,650
But we'll end on this
note, dot slash, thadgavin.

1059
00:48:52,650 --> 00:48:53,860
This then is what awaits.

1060
00:48:53,860 --> 00:48:57,140

1061
00:48:57,140 --> 00:48:58,500
>> That's it for CS50.

1062
00:48:58,500 --> 00:48:59,935
We will see you on Wednesday.

1063
00:48:59,935 --> 00:49:04,284

1064
00:49:04,284 --> 00:49:10,016
>> [MUSIC PLAYING]

1065
00:49:10,016 --> 00:53:31,883