Bedah Website #8: Mencari gapful numbers - MZAINI30

Sabtu, 02 Mei 2020

Bedah Website #8: Mencari gapful numbers

Gapful numbers adalah suatu bilangan minimal tiga digit yang apabila bilangan tersebut dibagi dengan suatu angka yang merupakan gabungan dari angka pertama dan angka terakhir dari bilangan tersebut, maka tidak bersisa.

Contohnya aja bilangan 120 merupakan gapful number karena 120 dibagi 10 tidak menyisakan angka berapapun.

Nah, sekarang angka berapa aja sih dari 100 hingga 9.999 yang gapful numbers? Ini skripnya:

dari = 100
ke = 9999

gapful = []
for x in [dari..ke]
  pertama = x.toString()[...1]
  terakhir = x.toString()[-1...]
  dibagi = Number pertama + terakhir
  if x % dibagi is 0
    gapful.push x
console.log gapful

Dan ini adalah hasilnya:

[100,105,108,110,120,121,130,132,135,140,143,150,154,160,165,170,176,180,187,190,192,195,198,200,220,225,231,240,242,253,260,264,275,280,286,297,300,315,330,341,352,360,363,374,385,390,396,400,405,440,451,462,473,480,484,495,500,550,561,572,583,594,600,660,671,682,693,700,770,781,792,800,880,891,900,990,1000,1001,1005,1008,1010,1020,1030,1032,1035,1037,1040,1050,1053,1056,1060,1064,1065,1070,1080,1090,1092,1095,1098,1100,1110,1111,1120,1125,1130,1134,1136,1140,1150,1152,1155,1159,1160,1170,1180,1183,1185,1188,1190,1200,1204,1207,1210,1212,1215,1216,1220,1221,1230,1240,1245,1250,1260,1270,1272,1274,1275,1278,1280,1290,1296,1300,1305,1310,1313,1320,1330,1331,1332,1335,1340,1344,1349,1350,1360,1365,1368,1370,1376,1377,1380,1390,1392,1395,1400,1410,1414,1420,1425,1430,1440,1441,1443,1450,1452,1455,1456,1458,1460,1470,1480,1484,1485,1490,1500,1510,1512,1515,1520,1530,1536,1539,1540,1545,1547,1548,1550,1551,1554,1560,1570,1572,1573,1575,1580,1590,1600,1605,1610,1616,1620,1624,1630,1632,1635,1638,1640,1650,1660,1661,1665,1670,1680,1690,1692,1694,1695,1696,1700,1703,1710,1717,1720,1725,1728,1729,1730,1740,1750,1752,1755,1760,1764,1770,1771,1776,1780,1785,1790,1800,1810,1812,1815,1818,1820,1830,1833,1834,1840,1845,1850,1856,1860,1870,1872,1875,1880,1881,1887,1890,1900,1904,1905,1908,1910,1919,1920,1930,1932,1935,1936,1940,1950,1960,1963,1965,1970,1974,1980,1990,1991,1992,1995,1998,2000,2002,2020,2025,2040,2059,2060,2064,2075,2080,2093,2100,2106,2112,2120,2121,2125,2128,2140,2160,2175,2180,2184,2187,2200,2220,2222,2225,2236,2240,2260,2268,2275,2280,2300,2304,2320,2323,2325,2331,2332,2340,2349,2360,2366,2375,2380,2400,2408,2420,2424,2425,2440,2442,2457,2460,2475,2480,2496,2500,2520,2525,2540,2541,2544,2548,2552,2553,2560,2575,2580,2600,2620,2625,2626,2639,2640,2660,2662,2664,2675,2680,2688,2700,2720,2725,2727,2740,2751,2756,2760,2772,2775,2780,2783,2784,2800,2820,2825,2828,2840,2860,2875,2880,2882,2886,2900,2904,2920,2925,2929,2940,2960,2961,2968,2975,2980,2992,2997,3000,3003,3030,3045,3060,3072,3078,3090,3094,3096,3115,3120,3131,3150,3159,3180,3185,3210,3232,3240,3255,3264,3268,3270,3276,3300,3325,3330,3333,3360,3367,3390,3392,3395,3420,3434,3441,3450,3456,3458,3465,3480,3510,3535,3540,3549,3552,3570,3600,3604,3605,3630,3636,3648,3660,3663,3675,3690,3712,3720,3737,3745,3750,3751,3774,3780,3810,3815,3816,3838,3840,3870,3872,3885,3900,3930,3939,3944,3955,3960,3990,3993,3996,4000,4004,4005,4032,4040,4080,4095,4120,4128,4141,4160,4185,4186,4200,4224,4240,4242,4275,4277,4280,4320,4343,4360,4365,4368,4400,4416,4440,4444,4452,4455,4459,4480,4520,4545,4551,4560,4600,4608,4635,4640,4646,4662,4664,4680,4720,4725,4747,4760,4773,4800,4815,4840,4848,4872,4876,4880,4884,4905,4920,4949,4960,4961,4995,5000,5005,5050,5096,5100,5115,5150,5151,5184,5187,5200,5225,5250,5252,5278,5300,5335,5350,5353,5369,5376,5400,5445,5450,5454,5500,5512,5550,5555,5568,5600,5650,5656,5661,5665,5700,5724,5750,5757,5772,5775,5800,5850,5858,5883,5885,5900,5936,5950,5959,5994,5995,6000,6006,6045,6060,6097,6120,6144,6161,6175,6180,6188,6240,6262,6279,6300,6305,6336,6360,6363,6420,6435,6464,6480,6528,6540,6565,6572,6600,6660,6666,6695,6720,6767,6771,6780,6784,6825,6840,6868,6882,6900,6955,6960,6969,6993,6996,7000,7007,7070,7098,7104,7125,7140,7171,7189,7210,7272,7275,7280,7296,7350,7373,7420,7425,7474,7488,7490,7560,7575,7630,7632,7676,7700,7725,7770,7777,7840,7844,7875,7878,7881,7910,7979,7980,7992,8000,8008,8064,8075,8080,8099,8160,8181,8240,8245,8256,8282,8320,8383,8400,8415,8448,8480,8484,8560,8585,8640,8686,8692,8720,8755,8787,8800,8880,8888,8904,8925,8960,8989,8991,9000,9009,9024,9025,9090,9180,9191,9215,9216,9270,9292,9360,9393,9405,9408,9450,9494,9540,9595,9630,9696,9720,9752,9785,9797,9810,9898,9900,9964,9975,9990,9999]

Logika pemrograman

Pertama, kita ambil dulu semua angka dari 100 hingga 9999. Kemudian, ambil angka pertamanya dan angka terakhirnya. Jika angkanya adalah 287, maka gabungan dari angka pertama dan angka terakhirnya adalah 27. Lalu, rentang bilangan yang dari 100 hingga 9999 itu dibagi dengan gabungan angka pertama dan angka terakhir. Jika tidak menyisakan sisa, berarti gapful.

Share with your friends

2 komentar

Maskot Pelarang Adblock

Hallo Kak, Perkenalkan saya Zen. Untuk bisa mengakses situs kami, terlebih dahulu matikan atau non-aktifkan ekstensi AdBlock nya yaaa...

Ok , Saya Mengerti