File size: 226,775 Bytes
d5bfab8 |
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 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 |
#[cfg(test)]
mod tests {
use crate::arc::arc_json_model::{Task, ImagePair};
use crate::arc::arc_work_model::{self, PairType};
use crate::arc::{ActionLabel, convolution3x3, ImageCollect, ImageSize, ImageLayout, ImageLayoutMode};
use crate::arc::{RunWithProgram, RunWithProgramResult, SolutionSimple, SolutionSimpleData, AnalyzeAndSolve, ImageRepeat, ImagePeriodicity};
use crate::arc::{ImageOverlay, ImageNoiseColor, ImageGrid, ImageExtractRowColumn, ConnectedComponent, PixelConnectivity, ConnectedComponentItem, ImageMask, Histogram};
use crate::arc::{ImageFind, ImageOutline, ImageRotate90, ImageBorder, ImageCompare, ImageCrop, ImageResize};
use crate::arc::{Image, PopularObjects, ImageNeighbour, ImageNeighbourDirection, ImageRepairPattern, ImageFill};
use crate::arc::{ObjectsMeasureMass, ObjectsUniqueColorCount, ObjectWithSmallestValue, ObjectWithDifferentColor};
use crate::arc::{ObjectsToGrid, ObjectsToGridMode, SubstitutionRule, ReverseColorPopularity, ObjectsAndMass};
use crate::arc::{ImageTrim, ImageRemoveDuplicates, ImageStack, ImageMaskCount, ImageSetPixelWhere, GridPattern};
use crate::arc::{ImageReplaceColor, ImageSymmetry, ImageOffset, ImageColorProfile, ImageCreatePalette, ImageDrawLineWhere};
use crate::arc::{ImageHistogram, ImageDenoise, ImageDetectHole, ImageTile, ImagePadding, Rectangle, ImageObjectEnumerate};
use crate::arc::{ImageReplaceRegex, ImageReplaceRegexToColor, ImagePosition, ImageMaskBoolean, ImageCountUniqueColors};
use crate::arc::{ImageDrawRect, SingleColorObject, SingleColorObjectClusterContainer, ObjectsAndGravity, ObjectsAndGravityDirection};
use crate::arc::{MixMode, ImageMix, GravityDirection, ImageGravity, ImageSort, ImageSortMode, Color};
use std::collections::HashMap;
use regex::Regex;
#[allow(unused_imports)]
use crate::arc::{HtmlLog, ImageToHTML};
trait RunWithTestdata {
fn run(self, task_name: &str) -> anyhow::Result<String>;
}
impl RunWithTestdata for SolutionSimple {
fn run(self, task_name: &str) -> anyhow::Result<String> {
let json_task: Task = Task::load_testdata(task_name)?;
let task = arc_work_model::Task::try_from(&json_task)?;
let instance: RunWithProgram = RunWithProgram::new(task, true);
let result: RunWithProgramResult = instance.run_solution(self)?;
let mut string: String = format!("{} {}", result.count_train_correct(), result.count_test_correct());
let messages: String = result.messages();
if !messages.is_empty() {
string = format!("{} - {}", string, messages);
}
Ok(string)
}
}
#[allow(dead_code)]
pub fn run_analyze_and_solve(
task_name: &str,
analyze_and_solve: &mut dyn AnalyzeAndSolve,
) -> anyhow::Result<String> {
let json_task: Task = Task::load_testdata(task_name)?;
let task = arc_work_model::Task::try_from(&json_task)?;
let instance: RunWithProgram = RunWithProgram::new(task, true);
let result: RunWithProgramResult = instance.run_analyze_and_solve(analyze_and_solve)?;
let mut string: String = format!("{} {}", result.count_train_correct(), result.count_test_correct());
let messages: String = result.messages();
if !messages.is_empty() {
string = format!("{} - {}", string, messages);
}
Ok(string)
}
fn run_simple(task_name: &str, program: &str) -> anyhow::Result<String> {
let json_task: Task = Task::load_testdata(task_name)?;
let task = arc_work_model::Task::try_from(&json_task)?;
let instance: RunWithProgram = RunWithProgram::new(task, true);
let result: RunWithProgramResult = instance.run_simple(program)?;
let mut string: String = format!("{} {}", result.count_train_correct(), result.count_test_correct());
let messages: String = result.messages();
if !messages.is_empty() {
string = format!("{} - {}", string, messages);
}
Ok(string)
}
fn run_advanced(task_name: &str, program: &str) -> anyhow::Result<String> {
let json_task: Task = Task::load_testdata(task_name)?;
let task = arc_work_model::Task::try_from(&json_task)?;
let instance: RunWithProgram = RunWithProgram::new(task, true);
let result: RunWithProgramResult = instance.run_advanced(program)?;
let mut string: String = format!("{} {}", result.count_train_correct(), result.count_test_correct());
let messages: String = result.messages();
if !messages.is_empty() {
string = format!("{} - {}", string, messages);
}
Ok(string)
}
#[test]
fn test_10000_puzzle_4258a5f9() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_pixel_color: u8 = input.most_popular_color().expect("pixel");
let result_image: Image = input.outline_type1(1, background_pixel_color).expect("image");
Ok(result_image)
};
let result: String = solution.run("4258a5f9").expect("String");
assert_eq!(result, "2 1");
}
const ADVANCED_PROGRAM_4258A5F9: &'static str = r#"
mov $40,0 ; outline color
; process "train" vector
mov $80,$97 ; set iteration counter = length of "train" vector
mov $81,100 ; address of first training data train[0].input
mov $82,101 ; address of first training data train[0].output
lps $80
mov $0,$$81 ; load train[x].input image
mov $1,$$82 ; load train[x].output image
; analyze the output images
f12 $1,101070 ; least popular colors
mov $40,$2 ; get the outline color
; next iteration
add $81,100 ; jump to address of next training input image
add $82,100 ; jump to address of next training output image
lpe
; process "train"+"test" vectors
mov $80,$99 ; set iteration counter = length of "train"+"test" vectors
mov $81,100 ; address of vector[0].input
mov $82,102 ; address of vector[0].computed_output
lps $80
mov $0,$$81 ; load vector[x].input image
mov $5,$0
f11 $5,101060 ; most popular color
mov $1,$40 ; outline color
mov $2,$5 ; background color
f31 $0,101080 ; draw outline
mov $$82,$0 ; save vector[x].computed_output image
; next iteration
add $81,100 ; jump to address of next input image
add $82,100 ; jump to address of next computed_output image
lpe
"#;
#[test]
fn test_10001_puzzle_4258a5f9_loda() {
let result: String = run_advanced("4258a5f9", ADVANCED_PROGRAM_4258A5F9).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_20000_puzzle_5614dbcf() {
let solution: SolutionSimple = |data| {
let image_denoised: Image = data.image.denoise_type3(3).expect("image");
let result_image: Image = image_denoised.remove_duplicates().expect("image");
Ok(result_image)
};
let result: String = solution.run("5614dbcf").expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_5614DBCF: &'static str = "
mov $1,3 ; number of noise colors to remove
f21 $0,101092 ; denoise type 3
f11 $0,101140 ; remove duplicates
";
#[test]
fn test_20001_puzzle_5614dbcf_loda() {
let result: String = run_simple("5614dbcf", PROGRAM_5614DBCF).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_30000_puzzle_2013d3e2() {
let solution: SolutionSimple = |data| {
let input_trimmed: Image = data.image.trim().expect("image");
// Extract top/left corner
let top_rows: Image = input_trimmed.top_rows(input_trimmed.height() / 2).expect("image");
let result_image: Image = top_rows.left_columns(input_trimmed.height() / 2).expect("image");
Ok(result_image)
};
let result: String = solution.run("2013d3e2").expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_2013D3E2: &'static str = "
f11 $0,101160 ; trim
mov $4,$0
mov $5,$0
f11 $4,101000 ; get width
f11 $5,101001 ; get height
div $4,2
div $5,2
mov $1,$4
f21 $0,101220 ; get top rows
mov $1,$5
f21 $0,101222 ; get left columns
";
#[test]
fn test_30001_puzzle_2013d3e2_loda() {
let result: String = run_simple("2013d3e2", PROGRAM_2013D3E2).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_40000_puzzle_90c28cc7_manual() {
let solution: SolutionSimple = |data| {
let input = data.image;
let input_trimmed: Image = input.trim().expect("image");
let result_image: Image = input_trimmed.remove_duplicates().expect("image");
Ok(result_image)
};
let result: String = solution.run("90c28cc7").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_90C28CC7: &'static str = "
f11 $0,101160 ; trim
f11 $0,101140 ; remove duplicates
";
#[test]
fn test_40001_puzzle_90c28cc7_loda() {
let result: String = run_simple("90c28cc7", PROGRAM_90C28CC7).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_50000_puzzle_7468f01a_manual() {
let solution: SolutionSimple = |data| {
let input = data.image;
let input_trimmed: Image = input.trim().expect("image");
let result_image: Image = input_trimmed.flip_x().expect("image");
Ok(result_image)
};
let result: String = solution.run("7468f01a").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_7468F01A: &'static str = "
f11 $0,101160 ; trim
f11 $0,101190 ; flip x
";
#[test]
fn test_50001_puzzle_7468f01a_loda() {
let result: String = run_simple("7468f01a", PROGRAM_7468F01A).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_60000_puzzle_63613498() {
let solution: SolutionSimple = |data| {
let input = data.image;
// Extract needle
let mut needle: Image = Image::zero(3, 3);
let center_pixel_color: u8 = input.get(1, 1).unwrap_or(255);
for y in 0..3i32 {
for x in 0..3i32 {
let pixel_value: u8 = input.get(x, y).unwrap_or(255);
let mut mask_value: u8 = 0;
if pixel_value == center_pixel_color {
mask_value = 1;
}
match needle.set(x, y, mask_value) {
Some(()) => {},
None => {
return Err(anyhow::anyhow!("Unable to set pixel ({}, {}) inside the needle bitmap", x, y));
}
}
}
}
// Clear the needle area from the search area
let mut search_area: Image = input.clone();
for y in 0..4i32 {
for x in 0..4i32 {
match search_area.set(x, y, 0) {
Some(()) => {},
None => {
return Err(anyhow::anyhow!("Unable to set pixel ({}, {}) inside the search area", x, y));
}
}
}
}
// println!("needle: {:?}", needle);
// println!("search area: {:?}", search_area);
// Find the pattern
let mut optional_position: Option<(u8, u8)> = None;
for color in 1..=255u8 {
let needle_with_color: Image = needle.replace_color(1, color)?;
optional_position = search_area.find_first(&needle_with_color).expect("some position");
if optional_position == None {
continue;
}
break;
}
let position: (u8, u8) = match optional_position {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Didn't find needle inside the search area"));
}
};
// println!("position: {:?}", position);
// Clear color of the found pattern
let mut result_bitmap: Image = input.clone();
for y in 0..3i32 {
for x in 0..3i32 {
let xx = x + (position.0 as i32);
let yy = y + (position.1 as i32);
let pixel_value: u8 = needle.get(x, y).unwrap_or(255);
if pixel_value == 0 {
continue;
}
match result_bitmap.set(xx, yy, 5) {
Some(()) => {},
None => {
return Err(anyhow::anyhow!("Unable to set pixel ({}, {}) in the result_bitmap", x, y));
}
}
}
}
Ok(result_bitmap)
};
let result: String = solution.run("63613498").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_70000_puzzle_cdecee7f() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.most_popular_color().expect("pixel");
// Collect pixels by traversing columns
let rotated: Image = input.rotate_cw()?;
let mask: Image = rotated.to_mask_where_color_is_different(background_color);
let pixels: Image = rotated.collect_pixels_as_image(&mask)?;
// Layout the collected pixels in a 3x3 image
let size = ImageSize { width: 3, height: 3 };
let result_image: Image = pixels.layout(size, 0, ImageLayoutMode::ReverseOddRows).expect("ok");
Ok(result_image)
};
let result: String = solution.run("cdecee7f").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_CDECEE7F: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,103 ; address of vector[0].PredictedOutputWidth
mov $84,104 ; address of vector[0].PredictedOutputHeight
mov $85,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $1,$$85 ; most popular color across inputs
; rotate input by 90 degrees clockwise
mov $3,$0
mov $4,1
f21 $3,101170 ; rotate cw
; $3 is the rotated input image
; extract mask
mov $5,$3
mov $6,$1
f21 $5,101251 ; where color is different than background color
; $5 is the mask
; collect pixels
mov $7,$3 ; the rotated input image
mov $8,$5 ; mask
f21 $7,102230 ; collect pixels
; $7 is a single row with the collected pixels
; change layout of the pixels
mov $9,$7 ; pixels to be re-layouted
mov $10,$$83 ; width = predicted width
mov $11,$$84 ; height = predicted height
mov $12,$1 ; background = most popular color
f41 $9,102241 ; layout pixels with ReverseOddRows
mov $0,$9
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
add $85,100
lpe
";
#[test]
fn test_70001_puzzle_cdecee7f_loda() {
let result: String = run_advanced("cdecee7f", PROGRAM_CDECEE7F).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_80000_puzzle_007bbfb7() {
let solution: SolutionSimple = |data| {
let input = data.image;
let mut image: Image = Image::zero(9, 9);
for y in 0..input.height() {
for x in 0..input.width() {
let mask_value: u8 = input.get(x as i32, y as i32).unwrap_or(255);
if mask_value == 0 {
continue;
}
image = image.overlay_with_position(&input, (x * 3) as i32, (y * 3) as i32)?;
}
}
Ok(image)
};
let result: String = solution.run("007bbfb7").expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_007BBFB7: &'static str = "
; tile_width
mov $2,$0
f11 $2,101000 ; Get width of image
; tile_height
mov $3,$0
f11 $3,101001 ; Get height of image
; tile
mov $7,0 ; color
mov $6,$3 ; height
mov $5,$2 ; width
f31 $5,101010 ; Create new image with size (x, y) and filled with color z
; mask
mov $10,$0 ; image
mov $11,$1 ; color
f21 $10,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
mov $11,$5 ; tile0
mov $12,$0 ; tile1
f31 $10,102110 ; Create a big composition of tiles.
mov $0,$10
";
#[test]
fn test_80001_puzzle_007bbfb7_loda() {
let result: String = run_simple("007bbfb7", PROGRAM_007BBFB7).expect("String");
assert_eq!(result, "5 1");
}
#[test]
fn test_90000_puzzle_b9b7f026_manual() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.most_popular_color().expect("color");
// Detect corners / holes
let corner_image: Image = input.detect_hole_type1(background_color).expect("image");
// println!("input: {:?}", input);
// println!("corner_image: {:?}", corner_image);
// Extract color of the corner
let corner_color: u8 = corner_image.least_popular_color().expect("color");
let result_image: Image = Image::color(1, 1, corner_color);
Ok(result_image)
};
let result: String = solution.run("b9b7f026").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_B9B7F026: &'static str = "
mov $1,$0
f11 $1,101060 ; most popular color
; $1 is background color
f21 $0,101110 ; detect holes
mov $2,$0
f11 $2,101070 ; least popular color
; $2 is the corner color
mov $0,1 ; width=1
mov $1,1 ; height=1
f31 $0,101010 ; create image with color
";
#[test]
fn test_90001_puzzle_b9b7f026_loda() {
let result: String = run_simple("b9b7f026", PROGRAM_B9B7F026).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_100000_puzzle_a79310a0_manual() {
let solution: SolutionSimple = |data| {
let image_with_offset: Image = data.image.offset_wrap(0, 1).expect("image");
let result_image: Image = image_with_offset.replace_color(8, 2).expect("image");
Ok(result_image)
};
let result: String = solution.run("a79310a0").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_A79310A0: &'static str = "
mov $1,0
mov $2,1
f31 $0,101180 ; offset dx,dy
";
#[test]
fn test_100001_puzzle_a79310a0_loda() {
let result: String = run_simple("a79310a0", PROGRAM_A79310A0).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_100002_puzzle_a79310a0_manual_without_hardcoded_colors() -> anyhow::Result<()> {
// Pseudo code for a LODA program:
// Loop through training input/output images.
// Extract color palette from image. Nx2 where N is the number of histogram entries. Top row is the color, bottom row the count.
// Merge color palette images. hstack images.
// Remove duplicates from palette images.
// Use color palette images for replacement.
let model: Task = Task::load_testdata("a79310a0").expect("model");
// These images contain 2 colors. Build a mapping from source color to target color
let train_pairs: Vec<ImagePair> = model.images_train().expect("pairs");
let mut color_replacements = HashMap::<u8, u8>::new();
for (index, pair) in train_pairs.iter().enumerate() {
let input_histogram = pair.input.histogram_all();
if input_histogram.number_of_counters_greater_than_zero() != 2 {
return Err(anyhow::anyhow!("input[{}] Expected exactly 2 colors", index));
}
let output_histogram = pair.output.histogram_all();
if output_histogram.number_of_counters_greater_than_zero() != 2 {
return Err(anyhow::anyhow!("output[{}] Expected exactly 2 colors", index));
}
let in_color0: u8 = input_histogram.most_popular_color().expect("u8");
let out_color0: u8 = output_histogram.most_popular_color().expect("u8");
color_replacements.insert(in_color0, out_color0);
let in_color1: u8 = input_histogram.least_popular_color().expect("u8");
let out_color1: u8 = output_histogram.least_popular_color().expect("u8");
color_replacements.insert(in_color1, out_color1);
}
let pairs: Vec<ImagePair> = model.images_all().expect("pairs");
let mut count = 0;
for (index, pair) in pairs.iter().enumerate() {
let mut image: Image = pair.input.offset_wrap(0, 1).expect("image");
image = image.replace_colors_with_hashmap(&color_replacements).expect("image");
assert_eq!(image, pair.output, "pair: {}", index);
count += 1;
}
assert_eq!(count, 4);
Ok(())
}
#[test]
fn test_100003_puzzle_a79310a0_manual_without_hashmap() {
let model: Task = Task::load_testdata("a79310a0").expect("model");
// These images contain 2 colors. Build a mapping from source color to target color
let train_pairs: Vec<ImagePair> = model.images_train().expect("pairs");
let mut palette_image = Image::empty();
for pair in &train_pairs {
let image: Image = pair.input.palette_using_histogram(&pair.output, false).expect("image");
palette_image = palette_image.hjoin(image).expect("image");
}
let pairs: Vec<ImagePair> = model.images_all().expect("pairs");
let mut count = 0;
for (index, pair) in pairs.iter().enumerate() {
let mut image: Image = pair.input.offset_wrap(0, 1).expect("image");
image = image.replace_colors_with_palette_image(&palette_image).expect("image");
assert_eq!(image, pair.output, "pair: {}", index);
count += 1;
}
assert_eq!(count, 4);
}
const ADVANCED_PROGRAM_A79310A0: &'static str = r#"
mov $40,0 ; palette image accumulated
; process "train" vector
mov $80,$97 ; set iteration counter = length of "train" vector
mov $81,100 ; address of first training data train[0].input
mov $82,101 ; address of first training data train[0].output
lps $80
mov $0,$$81 ; load train[x].input image
mov $1,$$82 ; load train[x].output image
; analyze the images
f21 $0,101130 ; build palette image with color mapping from input to output
mov $41,$0
f21 $40,101030 ; hstack of the palette images
; next iteration
add $81,100 ; jump to address of next training input image
add $82,100 ; jump to address of next training output image
lpe
; process "train"+"test" vectors
mov $80,$99 ; set iteration counter = length of "train"+"test" vectors
mov $81,100 ; address of vector[0].input
mov $82,102 ; address of vector[0].computed_output
lps $80
mov $0,$$81 ; load vector[x].input image
; change offset of the image
mov $1,0 ; offset x=0
mov $2,1 ; offset y=+1
f31 $0,101180 ; offset x, y
; replace colors of the image using the palette image
mov $1,$40 ; palette image
f21 $0,101052 ; replace colors using palette image
mov $$82,$0 ; save vector[x].computed_output image
; next iteration
add $81,100 ; jump to address of next input image
add $82,100 ; jump to address of next computed_output image
lpe
"#;
#[test]
fn test_100004_puzzle_a79310a0_loop_over_images_in_loda() {
let result: String = run_advanced("a79310a0", ADVANCED_PROGRAM_A79310A0).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_110000_puzzle_0dfd9992() {
let solution: SolutionSimple = |data| {
let input = data.image;
let repair_color: u8 = 0;
let result_image: Image = input.repair_pattern_with_color(repair_color).expect("image");
Ok(result_image)
};
let result: String = solution.run("0dfd9992").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_0DFD9992: &'static str = "
; $0 is the image that is to be repaired
mov $1,0 ; repair color
f21 $0,102151 ; Repair damaged pixels and recreate big repeating patterns such as mosaics.
";
#[test]
fn test_110001_puzzle_0dfd9992_loda() {
let result: String = run_simple("0dfd9992", PROGRAM_0DFD9992).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_120000_puzzle_3bdb4ada() {
let solution: SolutionSimple = |data| {
let input = data.image;
let mut image = input.clone();
for yy in 0..((image.height() as i32) - 2) {
for xx in 0..((image.width() as i32) - 2) {
let top_left_pixel_value: u8 = image.get(xx, yy).unwrap_or(255);
let mut same_count = 1;
for y in 0..3 {
for x in 0..3 {
if x == 1 && y == 1 {
continue;
}
if x == 0 && y == 0 {
continue;
}
let pixel_value: u8 = image.get(xx + x, yy + y).unwrap_or(255);
if pixel_value == top_left_pixel_value {
same_count += 1;
}
}
}
if same_count == 8 {
match image.set(xx + 1, yy + 1, 0) {
Some(()) => {},
None => {
return Err(anyhow::anyhow!("Unable to set pixel inside the result bitmap"));
}
}
}
}
}
Ok(image)
};
let result: String = solution.run("3bdb4ada").expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_130000_puzzle_7fe24cdd() {
let solution: SolutionSimple = |data| {
let input = data.image;
let row0: Image = Image::hstack(vec![input.clone(), input.rotate(1).expect("image")]).expect("image");
let row1: Image = Image::hstack(vec![input.rotate(3).expect("image"), input.rotate(2).expect("image")]).expect("image");
let result_image = Image::vstack(vec![row0.clone(), row1.clone()]).expect("image");
Ok(result_image)
};
let result: String = solution.run("7fe24cdd").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_7FE24CDD: &'static str = "
mov $5,$0 ; original corner
; construct top half
mov $1,$0
mov $2,1
f21 $1,101170 ; rotate cw
f21 $0,101030 ; hstack
; $0 is top half
; construct bottom half
mov $6,2
f21 $5,101170 ; rotate cw cw
mov $1,$5
mov $2,1
f21 $1,101170 ; rotate cw
mov $2,$5
f21 $1,101030 ; hstack
; $1 is bottom half
; join top half and bottom half
f21 $0,101040 ; vstack
";
#[test]
fn test_130001_puzzle_7fe24cdd_loda() {
let result: String = run_simple("7fe24cdd", PROGRAM_7FE24CDD).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_140000_puzzle_9565186b() {
let solution: SolutionSimple = |data| {
let input = data.image;
let pixel_color: u8 = input.most_popular_color().expect("color");
let result_image: Image = input.replace_colors_other_than(pixel_color, 5).expect("image");
Ok(result_image)
};
let result: String = solution.run("9565186b").expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_9565186B: &'static str = "
mov $1,$0
f11 $1,101060 ; most popular color
mov $2,5
f31 $0,101051 ; replace colors other than color
";
#[test]
fn test_140001_puzzle_9565186b_loda() {
let result: String = run_simple("9565186b", PROGRAM_9565186B).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_150000_puzzle_3af2c5a8() {
let solution: SolutionSimple = |data| {
let input = data.image;
let row0: Image = Image::hstack(vec![input.clone(), input.flip_x().expect("image")]).expect("image");
let row1: Image = row0.flip_y().expect("image");
let result_image = Image::vstack(vec![row0.clone(), row1.clone()]).expect("image");
Ok(result_image)
};
let result: String = solution.run("3af2c5a8").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_3AF2C5A8: &'static str = "
mov $1,$0
f11 $1,101190 ; flip x
f21 $0,101030 ; hstack
mov $1,$0
f11 $1,101191 ; flip y
f21 $0,101040 ; vstack
";
#[test]
fn test_150001_puzzle_3af2c5a8_loda() {
let result: String = run_simple("3af2c5a8", PROGRAM_3AF2C5A8).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_44F52BB0: &'static str = "
mov $1,$0
f11 $1,101190 ; flip x
cmp $0,$1
mov $2,1 ; color when there is symmetry
mul $2,$0
cmp $0,0
mul $0,7 ; color when there is no symmetry
add $2,$0
mov $0,1 ; output image width
mov $1,1 ; output image height
f31 $0,101010 ; create image
";
#[test]
fn test_160000_puzzle_44f52bb0_loda() {
let result: String = run_simple("44f52bb0", PROGRAM_44F52BB0).expect("String");
assert_eq!(result, "6 2");
}
#[test]
fn test_170000_puzzle_496994bd() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_pixel_color: u8 = input.most_popular_color().expect("color");
let flipped_image: Image = input.flip_y().expect("image");
let result_image: Image = input.overlay_with_mask_color(
&flipped_image,
background_pixel_color
).expect("image");
Ok(result_image)
};
let result: String = solution.run("496994bd").expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_496994BD: &'static str = "
mov $1,$0
mov $2,$0
f11 $2,101060 ; most popular color
f11 $1,101191 ; flip y
f31 $0,101150 ; overlay
";
#[test]
fn test_170001_puzzle_496994bd_loda() {
let result: String = run_simple("496994bd", PROGRAM_496994BD).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_180000_puzzle_31aa019c() {
let solution: SolutionSimple = |data| {
let input = data.image;
let pixel_color: u8 = input.least_popular_color().expect("color");
let image: Image = input.replace_colors_other_than(pixel_color, 0).expect("image");
let outline_color: u8 = 2;
let background_color: u8 = 0;
let result_image: Image = image.outline_type1(outline_color, background_color).expect("image");
Ok(result_image)
};
let result: String = solution.run("31aa019c").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_31AA019C: &'static str = "
mov $1,$0
f11 $1,101070 ; most unpopular color
mov $2,0 ; background color
f31 $0,101051 ; replace colors other than
mov $1,2 ; outline color
mov $2,0 ; background color
f31 $0,101080 ; draw outline
";
#[test]
fn test_180001_puzzle_31aa019c_loda() {
let result: String = run_simple("31aa019c", PROGRAM_31AA019C).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_190000_puzzle_5ad4f10b() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.most_popular_color().expect("color");
let denoised_image: Image = input.denoise_type1(background_color).expect("image");
// println!("denoised: {:?}", denoised_image);
// Pick the most popular noise color
let noise_color_vec: Vec<u8> = input.noise_color_vec(&denoised_image).expect("vec with colors");
let noise_color: u8 = *noise_color_vec.first().expect("1 or more colors");
// println!("noise color: {}", noise_color);
// Remove background around the object
let trimmed_image: Image = denoised_image.trim().expect("image");
// Remove duplicate rows/columns
let image_without_duplicates: Image = trimmed_image.remove_duplicates().expect("image");
// Change color of the object
let result_image: Image = image_without_duplicates.replace_colors_other_than(background_color, noise_color).expect("image");
Ok(result_image)
};
let result: String = solution.run("5ad4f10b").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_5AD4F10B: &'static str = "
mov $1,$0
mov $2,$0
mov $3,$0
mov $9,$0
f11 $3,101060 ; most popular color
; $3 is background_color
mov $5,$0 ; noisy image
mov $6,$3 ; background_color
f21 $5,101090 ; denoise image
; $5 is denoised image
; $9 is noisy image
mov $10,$5 ; denoised image
f21 $9,101100 ; extract 1 noise color
; $9 is the most popular noise color
mov $12,$5 ; denoised image
f11 $12,101160 ; trim
f11 $12,101140 ; remove duplicates
mov $0,$12
mov $1,$3 ; background color
mov $2,$9 ; noise color
f31 $0,101051 ; replace colors other than
";
#[test]
fn test_190001_puzzle_5ad4f10b_loda() {
let result: String = run_simple("5ad4f10b", PROGRAM_5AD4F10B).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_200000_puzzle_1190e5a7() {
let solution: SolutionSimple = |data| {
let without_duplicates: Image = data.image.remove_duplicates().expect("image");
let result_image: Image = without_duplicates.remove_grid().expect("image");
Ok(result_image)
};
let result: String = solution.run("1190e5a7").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_1190E5A7: &'static str = "
f11 $0,101140 ; remove duplicates
f11 $0,101120 ; remove grid
";
#[test]
fn test_200001_puzzle_1190e5a7_loda() {
let result: String = run_simple("1190e5a7", PROGRAM_1190E5A7).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_210000_puzzle_39a8645d() {
let solution: SolutionSimple = |data| {
let result_image: Image = PopularObjects::most_popular_object(&data.image).expect("image");
Ok(result_image)
};
let result: String = solution.run("39a8645d").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_39A8645D: &'static str = "
f11 $0,102000 ; most popular object
";
#[test]
fn test_210001_puzzle_39a8645d_loda() {
let result: String = run_simple("39a8645d", PROGRAM_39A8645D).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_220000_puzzle_88a62173() {
let solution: SolutionSimple = |data| {
let result_image: Image = PopularObjects::least_popular_object(&data.image).expect("image");
Ok(result_image)
};
let result: String = solution.run("88a62173").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_88A62173: &'static str = "
f11 $0,102001 ; least popular object
";
#[test]
fn test_220001_puzzle_88a62173_loda() {
let result: String = run_simple("88a62173", PROGRAM_88A62173).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_230000_puzzle_bbc9ae5d() {
let solution: SolutionSimple = |data| {
let input = data.image;
let repeat_count: u8 = input.width() / 2;
let mut result_image: Image = Image::empty();
for i in 0..repeat_count {
let m = input.clone();
let j = m.offset_clamp(i as i32, 0).expect("image");
result_image = result_image.vjoin(j).expect("image");
}
Ok(result_image)
};
let result: String = solution.run("bbc9ae5d").expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_BBC9AE5D: &'static str = "
mov $10,$0
f11 $10,101000 ; get image width
div $10,2
; $10 is the height of the final image
mov $2,0
mov $7,0
lps $10
; clone the input image, and offset it
mov $4,$7
mov $5,0
mov $3,$0
f31 $3,101181 ; offset clamp
; glue onto the bottom of the result image
f21 $2,101040 ; vstack
add $7,1
lpe
mov $0,$2
";
#[test]
fn test_230001_puzzle_bbc9ae5d_loda() {
let result: String = run_simple("bbc9ae5d", PROGRAM_BBC9AE5D).expect("String");
assert_eq!(result, "5 1");
}
#[test]
fn test_240000_puzzle_ea32f347() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.most_popular_color().expect("color");
let background_ignore_mask: Image = input.to_mask_where_color_is(background_color);
// println!("background_ignore_mask: {:?}", background_ignore_mask);
// Objects that is not the background
let object_mask_vec: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &input, &background_ignore_mask)
.expect("find_objects_with_ignore_mask");
// Count the number of pixels in each object
let f = |image: &Image| -> (Image, u32) {
let count: u32 = image.mask_count_one() as u32;
(image.clone(), count)
};
let mut object_count_vec: Vec<(Image, u32)> = object_mask_vec.iter().map(f).collect();
// Sort objects by their number of pixels
object_count_vec.sort_unstable_by_key(|item| (item.1));
object_count_vec.reverse();
// Object size to color value
let mut color_mapping = HashMap::<usize, u8>::new();
color_mapping.insert(0, 1); // biggest object
color_mapping.insert(1, 4); // medium object
color_mapping.insert(2, 2); // smallest object
// Build the result image
let mut result_image: Image = Image::color(input.width(), input.height(), background_color);
for (index, item) in object_count_vec.iter().enumerate() {
let mask_image: Image = item.0.clone();
// Obtain color for the object size
let mut assign_color: u8 = 255;
if let Some(color) = color_mapping.get(&index) {
assign_color = *color;
}
// Change color of the object
let colored_object_image: Image = mask_image.replace_color(1, assign_color).expect("Image");
// Overlay each object onto the result image
result_image = mask_image.select_from_images(&result_image, &colored_object_image).expect("image");
}
Ok(result_image)
};
let result: String = solution.run("ea32f347").expect("String");
assert_eq!(result, "4 1");
}
mod solve_ea32f347 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("no enumerated_objects"));
}
};
Ok(enumerated_objects.clone())
}
}
}
#[test]
fn test_240001_puzzle_ea32f347() {
let mut instance = solve_ea32f347::MySolution {};
let result: String = run_analyze_and_solve("ea32f347", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_ENUMERATED_OBJECTS: &'static str = "
mov $80,$99
mov $81,110 ; address of vector[0].EnumeratedObjects
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $$82,$$81
add $81,100
add $82,100
lpe
";
#[test]
fn test_240002_puzzle_ea32f347_loda() {
let result: String = run_advanced("ea32f347", PROGRAM_ENUMERATED_OBJECTS).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_250000_puzzle_7bb29440() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.histogram_border().most_popular_color().expect("color");
let object_mask: Image = input.to_mask_where_color_is(background_color);
// Objects that is not the background
let object_mask_vec: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &object_mask, &object_mask)
.expect("find_objects_with_ignore_mask");
// Traverse each object, and count holes in each object
let mut object_count_vec = Vec::<(Image, u32)>::new();
for mask_image in &object_mask_vec {
let histogram: Histogram = input.histogram_with_mask(&mask_image).expect("histogram");
let mut pairs: Vec<(u32,u8)> = histogram.pairs_ascending();
// Remove the background color of the rectangle
pairs.pop();
// Number of holes inside the rectangle
let mut pixel_count: u32 = 0;
for pair in &pairs {
pixel_count += pair.0;
}
object_count_vec.push((mask_image.clone(), pixel_count));
}
// Sort objects by their number of pixels
object_count_vec.sort_unstable_by_key(|item| (item.1));
// Pick the first the object with lowest pixel count
let (mask_image, _pixel_count) = object_count_vec.first().expect("first object");
// Extract pixels from input image, just for the object
let image: Image = mask_image.select_from_color_and_image(background_color, &input).expect("image");
let result_image = image.trim().expect("image");
Ok(result_image)
};
let result: String = solution.run("7bb29440").expect("String");
assert_eq!(result, "5 1");
}
#[test]
fn test_260000_puzzle_5521c0d9() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.histogram_border().most_popular_color().expect("color");
let object_mask: Image = input.to_mask_where_color_is(background_color);
// Objects that is not the background
let object_mask_vec: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &object_mask, &object_mask)
.expect("find_objects_with_ignore_mask");
// Adjust offsets for all objects
let mut result_image: Image = Image::color(input.width(), input.height(), background_color);
for mask_image in &object_mask_vec {
// Bounding box of object
let rect: Rectangle = match mask_image.bounding_box() {
Some(value) => value,
None => {
continue;
}
};
// Determine how much to adjust offset
let distance_from_bottom: i32 = (input.height() as i32) - (rect.y() as i32);
let offset_y: i32 = -distance_from_bottom;
// Adjust offset
let mask_with_offset: Image = mask_image.offset_wrap(0, offset_y).expect("image");
let image_with_offset: Image = input.offset_wrap(0, offset_y).expect("image");
result_image = mask_with_offset.select_from_images(&result_image, &image_with_offset).expect("image");
}
Ok(result_image)
};
let result: String = solution.run("5521c0d9").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_270000_puzzle_7f4411dc() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.histogram_border().most_popular_color().expect("color");
let result_image: Image = input.denoise_type1(background_color).expect("image");
Ok(result_image)
};
let result: String = solution.run("7f4411dc").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_7F4411DC: &'static str = "
mov $1,$0
f11 $1,101060 ; most popular color
; $0 is noisy image
; $1 is background_color
f21 $0,101090 ; denoise type 1
; $0 is denoised image
";
#[test]
fn test_270001_puzzle_7f4411dc_loda() {
let result: String = run_simple("7f4411dc", PROGRAM_7F4411DC).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_280000_puzzle_aabf363d() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.histogram_border().most_popular_color().expect("color");
let object_mask: Image = input.to_mask_where_color_is(background_color);
// Objects that is not the background
let object_mask_vec: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &object_mask, &object_mask)
.expect("find_objects_with_ignore_mask");
// Traverse each object, and measure object size
let mut object_count_vec = Vec::<(Image, u32)>::new();
for mask_image in &object_mask_vec {
let histogram: Histogram = input.histogram_with_mask(&mask_image).expect("histogram");
let pairs: Vec<(u32,u8)> = histogram.pairs_ascending();
// Measure size of the object
let mut pixel_count: u32 = 0;
for pair in &pairs {
if pair.1 == background_color {
continue;
}
pixel_count += pair.0;
}
object_count_vec.push((mask_image.clone(), pixel_count));
}
// Sort objects by their number of pixels
object_count_vec.sort_unstable_by_key(|item| (item.1));
// Pick the first the object with lowest pixel count
let (mask_image_biggest, _pixel_count) = object_count_vec.last().expect("first object");
let (mask_image_smallest, _pixel_count) = object_count_vec.first().expect("first object");
let histogram_smallest: Histogram = input.histogram_with_mask(&mask_image_smallest).expect("histogram");
let fill_color: u8 = histogram_smallest.most_popular_color().expect("color");
let mut result_image: Image = mask_image_biggest.clone();
result_image = result_image.replace_color(0, background_color).expect("image");
result_image = result_image.replace_color(1, fill_color).expect("image");
Ok(result_image)
};
let result: String = solution.run("aabf363d").expect("String");
assert_eq!(result, "2 1");
}
mod solve_aabf363d {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_most_popular_color.expect("color");
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mut result_image: Image = input.replace_color(noise_color, background_color)?;
result_image = result_image.replace_colors_other_than(background_color, noise_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_280001_puzzle_aabf363d() {
let mut instance = solve_aabf363d::MySolution {};
let result: String = run_analyze_and_solve("aabf363d", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_AABF363D: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
mov $84,115 ; address of vector[0].InputSinglePixelNoiseColor
lps $80
mov $0,$$81 ; input image
mov $1,$$84 ; noise color
mov $2,$$83 ; background color
f31 $0,101050 ; Replace noise pixels with background color
mov $3,$1
mov $1,$2 ; background color
mov $2,$3 ; noise color
f31 $0,101051 ; Replace non-background-pixels with noise color
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_280002_puzzle_aabf363d_loda() {
let result: String = run_advanced("aabf363d", PROGRAM_AABF363D).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_290000_puzzle_00d62c1b() {
let solution: SolutionSimple = |data| {
let input = data.image;
let replacement_color: u8 = 4;
let background_color: u8 = input.histogram_border().most_popular_color().expect("color");
let border_mask_image: Image = Image::border_inside(input.width(), input.height(), 0, 1, 1).expect("image");
// Objects that is not the background
let object_mask_vec: Vec<Image> = ConnectedComponent::find_objects(PixelConnectivity::Connectivity4, &input).expect("find_objects");
// Traverse the interior objects. Replace color for the interior object.
let mut result_image: Image = input.clone();
for mask_image in &object_mask_vec {
let mask_image_border_overlap: Image = border_mask_image.select_from_color_and_image(0, mask_image).expect("image");
let border_histogram: Histogram = input.histogram_with_mask(&mask_image_border_overlap).expect("histogram");
if let Some(border_color) = border_histogram.most_popular_color() {
if border_color == background_color {
// println!("skip background object: {:?}", mask_image);
continue;
}
}
let mask_neighbour: Image = mask_image.outline_mask_neighbour().expect("image");
// println!("mask_image: {:?}", mask_image);
// println!("mask_neighbour: {:?}", mask_neighbour);
let histogram: Histogram = input.histogram_with_mask(&mask_neighbour).expect("histogram");
let pairs: Vec<(u32,u8)> = histogram.pairs_ascending();
if pairs.len() != 1 {
println!("expected 1 color in the histogram, but got: {:?}", pairs);
continue;
}
let outline_color: u8 = histogram.most_popular_color().expect("expected 1 color");
if outline_color == background_color {
// Ignore non-interior objects
continue;
}
// println!("outline_color: {:?}", outline_color);
// println!("mask_image: {:?}", mask_image);
// println!("mask_neighbour: {:?}", mask_neighbour);
// Replace color only for the interior objects
let mask_inverted: Image = mask_image.invert_mask();
result_image = mask_inverted.select_from_color_and_image(replacement_color, &result_image).expect("image");
}
Ok(result_image)
};
let result: String = solution.run("00d62c1b").expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_00D62C1B: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; from_color = most popular color
mov $2,255 ; to_color = auto assign color
f31 $0,102180 ; Flood fill at every pixel along the border, connectivity-4.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_290001_puzzle_00d62c1b_loda() {
let result: String = run_advanced("00d62c1b", PROGRAM_00D62C1B).expect("String");
assert_eq!(result, "5 1");
}
#[test]
fn test_300000_puzzle_ae3edfdc() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.histogram_all().most_popular_color().expect("color");
let ignore_mask = input.to_mask_where_color_is(background_color);
let color_when_there_is_no_neighbour: u8 = 255;
let neighbour_up: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Up, color_when_there_is_no_neighbour).expect("image");
let neighbour_left: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Left, color_when_there_is_no_neighbour).expect("image");
let neighbour_right: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Right, color_when_there_is_no_neighbour).expect("image");
let neighbour_down: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Down, color_when_there_is_no_neighbour).expect("image");
let mut result_image: Image = Image::color(input.width(), input.height(), background_color);
for y in 0..(input.height() as i32) {
for x in 0..(input.width() as i32) {
let mask_value: u8 = ignore_mask.get(x, y).unwrap_or(255);
if mask_value == 1 {
continue;
}
let color_up: u8 = neighbour_up.get(x, y).unwrap_or(255);
let color_down: u8 = neighbour_down.get(x, y).unwrap_or(255);
let color_left: u8 = neighbour_left.get(x, y).unwrap_or(255);
let color_right: u8 = neighbour_right.get(x, y).unwrap_or(255);
let mut histogram = Histogram::new();
if color_up != color_when_there_is_no_neighbour {
histogram.increment(color_up);
}
if color_down != color_when_there_is_no_neighbour {
histogram.increment(color_down);
}
if color_left != color_when_there_is_no_neighbour {
histogram.increment(color_left);
}
if color_right != color_when_there_is_no_neighbour {
histogram.increment(color_right);
}
if let Some(count) = histogram.most_popular_count() {
if count < 2 {
continue;
}
} else {
continue;
}
let color_value: u8 = input.get(x, y).unwrap_or(255);
let _ = result_image.set(x, y, color_value);
if color_up != color_when_there_is_no_neighbour {
let _ = result_image.set(x, y - 1, color_up);
}
if color_down != color_when_there_is_no_neighbour {
let _ = result_image.set(x, y + 1, color_down);
}
if color_left != color_when_there_is_no_neighbour {
let _ = result_image.set(x - 1, y, color_left);
}
if color_right != color_when_there_is_no_neighbour {
let _ = result_image.set(x + 1, y, color_right);
}
}
}
Ok(result_image)
};
let result: String = solution.run("ae3edfdc").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_310000_puzzle_1f876c06() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.histogram_all().most_popular_color().expect("color");
let ignore_mask = input.to_mask_where_color_is(background_color);
let color_when_there_is_no_neighbour: u8 = 255;
let neighbour_up_left: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::UpLeft, color_when_there_is_no_neighbour).expect("image");
let neighbour_up_right: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::UpRight, color_when_there_is_no_neighbour).expect("image");
let neighbour_down_left: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::DownLeft, color_when_there_is_no_neighbour).expect("image");
let neighbour_down_right: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::DownRight, color_when_there_is_no_neighbour).expect("image");
let mut output: Image = input.clone();
output.set_pixel_where_two_images_agree(&neighbour_down_left, &neighbour_up_right, color_when_there_is_no_neighbour).expect("ok");
output.set_pixel_where_two_images_agree(&neighbour_up_left, &neighbour_down_right, color_when_there_is_no_neighbour).expect("ok");
Ok(output)
};
let result: String = solution.run("1f876c06").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_1F876C06: &'static str = "
mov $20,255 ; color when there is no neighbour
; ignore mask
mov $1,$0
mov $2,$0
f11 $2,101060 ; most popular color
f21 $1,101250 ; mask where color is
; $2 is most popular color
; $1 is the ignore mask
; neighbour_up_left
mov $10,$0
mov $11,$1
mov $12,$20
f31 $10,102064 ; neighbour 'UpLeft'
mov $3,$10
; neighbour_up_right
mov $10,$0
mov $11,$1
mov $13,$20
f31 $10,102065 ; neighbour 'UpRight'
mov $4,$10
; neighbour_down_left
mov $10,$0
mov $11,$1
mov $13,$20
f31 $10,102066 ; neighbour 'DownLeft'
mov $5,$10
; neighbour_down_right
mov $10,$0
mov $11,$1
mov $13,$20
f31 $10,102067 ; neighbour 'DownRight'
mov $6,$10
; prepare the output image
mov $14,$0 ; clone input image
; set pixel where the two images agree
mov $17,$20 ; color to ignore
mov $16,$5 ; neighbour_down_left
mov $15,$4 ; neighbour_up_right
f41 $14,102100 ; set pixel where two images agree
; set pixel where the two images agree
mov $17,$20 ; color to ignore
mov $16,$6 ; neighbour_down_right
mov $15,$3 ; neighbour_up_left
f41 $14,102100 ; set pixel where two images agree
mov $0,$14
";
#[test]
fn test_310001_puzzle_1f876c06_loda() {
let result: String = run_simple("1f876c06", PROGRAM_1F876C06).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_320000_puzzle_623ea044() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let background_color: u8 = input.histogram_all().most_popular_color().expect("color");
let ignore_mask = input.to_mask_where_color_is(background_color);
let color_when_there_is_no_neighbour: u8 = 255;
let neighbour_up_left: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::UpLeft, color_when_there_is_no_neighbour).expect("image");
let neighbour_up_right: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::UpRight, color_when_there_is_no_neighbour).expect("image");
let neighbour_down_left: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::DownLeft, color_when_there_is_no_neighbour).expect("image");
let neighbour_down_right: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::DownRight, color_when_there_is_no_neighbour).expect("image");
let mut result_image: Image = input.clone();
result_image.set_pixel_where_image_has_different_color(&neighbour_up_left, color_when_there_is_no_neighbour)?;
result_image.set_pixel_where_image_has_different_color(&neighbour_up_right, color_when_there_is_no_neighbour)?;
result_image.set_pixel_where_image_has_different_color(&neighbour_down_left, color_when_there_is_no_neighbour)?;
result_image.set_pixel_where_image_has_different_color(&neighbour_down_right, color_when_there_is_no_neighbour)?;
Ok(result_image)
};
let result: String = solution.run("623ea044").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_623EA044: &'static str = "
mov $20,255 ; color when there is no neighbour
; ignore mask
mov $1,$0
mov $2,$0
f11 $2,101060 ; most popular color
f21 $1,101250 ; mask where color is
; $2 is most popular color
; $1 is the ignore mask
; neighbour_up_left
mov $10,$0
mov $11,$1
mov $12,$20
f31 $10,102064 ; neighbour 'UpLeft'
mov $3,$10
; neighbour_up_right
mov $10,$0
mov $11,$1
mov $13,$20
f31 $10,102065 ; neighbour 'UpRight'
mov $4,$10
; neighbour_down_left
mov $10,$0
mov $11,$1
mov $13,$20
f31 $10,102066 ; neighbour 'DownLeft'
mov $5,$10
; neighbour_down_right
mov $10,$0
mov $11,$1
mov $13,$20
f31 $10,102067 ; neighbour 'DownRight'
mov $6,$10
; prepare the output image
mov $14,$0 ; clone input image
; draw diagonal line - down right
mov $15,$3 ; neighbour_up_left
mov $16,$20
f31 $14,102101 ; Set pixel where the image has a pixel value different than the color parameter.
; draw diagonal line - down left
mov $15,$4 ; neighbour_up_right
mov $16,$20
f31 $14,102101 ; Set pixel where the image has a pixel value different than the color parameter.
; draw diagonal line - up right
mov $15,$5 ; neighbour_down_left
mov $16,$20
f31 $14,102101 ; Set pixel where the image has a pixel value different than the color parameter.
; draw diagonal line - up left
mov $15,$6 ; neighbour_down_right
mov $16,$20
f31 $14,102101 ; Set pixel where the image has a pixel value different than the color parameter.
mov $0,$14
";
#[test]
fn test_320001_puzzle_623ea044_loda() {
let result: String = run_simple("623ea044", PROGRAM_623EA044).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_330000_puzzle_f8b3ba0a() {
let solution: SolutionSimple = |data| {
let histogram: Histogram = data.image.histogram_all();
let histogram_image: Image = histogram.to_image().expect("image");
// Take the row with the colors, discard the row with the counters
let colors = histogram_image.bottom_rows(1).expect("image");
// Discard the 2 most popular colors
let trimmed = colors.remove_left_columns(2).expect("image");
let output = trimmed.rotate(1).expect("image");
Ok(output)
};
let result: String = solution.run("f8b3ba0a").expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_340000_puzzle_f8ff0b80() {
let solution: SolutionSimple = |data| {
let histogram: Histogram = data.image.histogram_all();
let histogram_image: Image = histogram.to_image().expect("image");
// Take the row with the colors, discard the row with the counters
let colors = histogram_image.bottom_rows(1).expect("image");
// Discard the 1 most popular color
let trimmed = colors.remove_left_columns(1).expect("image");
let output = trimmed.rotate(1).expect("image");
Ok(output)
};
let result: String = solution.run("f8ff0b80").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_F8FF0B80: &'static str = "
f11 $0,101230 ; Histogram of image. The most popular to the left, least popular to the right. The top row is the counters. The bottom row is the colors.
mov $1,1
f21 $0,101224 ; remove top-most row
; $1 is 1
f21 $0,101226 ; remove left-most column
";
#[test]
fn test_340001_puzzle_f8ff0b80_loda() {
let result: String = run_simple("f8ff0b80", PROGRAM_F8FF0B80).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_350000_puzzle_a68b268e() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let histogram: Histogram = input.histogram_all();
let background_color: u8 = histogram.most_popular_color().expect("color");
let top: Image = input.top_rows(4).expect("image");
let top_left: Image = top.left_columns(4).expect("image");
let top_right: Image = top.right_columns(4).expect("image");
let bottom: Image = input.bottom_rows(4).expect("image");
let bottom_left: Image = bottom.left_columns(4).expect("image");
let bottom_right: Image = bottom.right_columns(4).expect("image");
let mut output: Image = bottom_right;
output = output.overlay_with_mask_color(&bottom_left, background_color).expect("image");
output = output.overlay_with_mask_color(&top_right, background_color).expect("image");
output = output.overlay_with_mask_color(&top_left, background_color).expect("image");
Ok(output)
};
let result: String = solution.run("a68b268e").expect("String");
assert_eq!(result, "6 1");
}
const PROGRAM_A68B268E: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $20,$$83 ; most popular color across inputs
mov $21,1 ; pixel spacing = 1
mov $10,$$81 ; input image
mov $11,$21 ; spacing
f22 $10,102261 ; split into 2 rows
; $10..$11 are the 2 rows
mov $15,$10
mov $16,$21 ; spacing
f22 $15,102260 ; split into 2 columns
; $15..$16 are the 2 columns
mov $17,$11
mov $18,$21 ; spacing
f22 $17,102260 ; split into 2 columns
; $17..$18 are the 2 columns
; $15 = cell top left
; $16 = cell top right
; $17 = cell bottom left
; $18 = cell bottom right
mov $0,$20 ; transparent color
mov $1,$18 ; layer 0 lowest layer
mov $2,$17 ; layer 1
mov $3,$16 ; layer 2
mov $4,$15 ; layer 3 top
f51 $0,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_350001_puzzle_a68b268e_loda() {
let result: String = run_advanced("a68b268e", PROGRAM_A68B268E).expect("String");
assert_eq!(result, "6 1");
}
#[test]
fn test_360000_puzzle_6b9890af() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let histogram: Histogram = input.histogram_all();
let background_color: u8 = histogram.most_popular_color().expect("color");
let ignore_mask: Image = input.to_mask_where_color_is(background_color);
let mut objects: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &input, &ignore_mask).expect("images");
if objects.len() != 2 {
return Err(anyhow::anyhow!("Expected exactly 2 objects, but got a different count"));
}
objects.sort_unstable_by(|lhs, rhs| {
let a = lhs.mask_count_one();
let b = rhs.mask_count_one();
a.cmp(&b)
});
let smallest_object: Image = match objects.first() {
Some(image) => image.clone(),
None => {
return Err(anyhow::anyhow!("Expected an object, but got none"));
}
};
let biggest_object: Image = match objects.last() {
Some(image) => image.clone(),
None => {
return Err(anyhow::anyhow!("Expected an object, but got none"));
}
};
// Extract the biggest object
let biggest_image_full: Image = biggest_object.select_from_color_and_image(background_color, &input).expect("image");
let biggest_image: Image = biggest_image_full.trim().expect("image");
// Extract the smallest object
let smallest_image_full: Image = smallest_object.select_from_color_and_image(background_color, &input).expect("image");
let smallest_image: Image = smallest_image_full.trim().expect("image");
let width: u8 = biggest_image.width();
let x_ratio = width / smallest_image.width();
let x_ratio_remain = width % smallest_image.width();
// println!("x_ratio: {} {}", x_ratio, x_ratio_remain);
let height: u8 = biggest_image.height();
let y_ratio = height / smallest_image.height();
let y_ratio_remain = height % smallest_image.height();
// println!("y_ratio: {} {}", y_ratio, y_ratio_remain);
if x_ratio != y_ratio {
return Err(anyhow::anyhow!("Expected same ratio, but different x y ratio: {} {}", x_ratio, y_ratio));
}
// Scale up the smallest object so it fits inside the biggest object
let new_width: u8 = smallest_image.width() * x_ratio;
let new_height: u8 = smallest_image.height() * y_ratio;
let fit_image: Image = smallest_image.resize(new_width, new_height).expect("image");
// Overlay the smallest object on top of the biggest object
let mut output: Image = biggest_image;
let x = (x_ratio_remain / 2) as i32;
let y = (y_ratio_remain / 2) as i32;
output = output.overlay_with_position(&fit_image, x, y).expect("image");
Ok(output)
};
let result: String = solution.run("6b9890af").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_370000_puzzle_2281f1f4() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let background_color: u8 = 0;
let set_value: u8 = 2;
let row: Image = input.top_rows(1).expect("image");
let column: Image = input.right_columns(1).expect("image");
let mut output: Image = input.clone();
for y in 0..output.height() {
for x in 0..output.width() {
if y == 0 {
continue;
}
if x + 1 == output.width() {
continue;
}
let value0: u8 = row.get(x as i32, 0).unwrap_or(255);
let value1: u8 = column.get(0, y as i32).unwrap_or(255);
if value0 > background_color && value1 > background_color {
_ = output.set(x as i32, y as i32, set_value);
}
}
}
Ok(output)
};
let result: String = solution.run("2281f1f4").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_380000_puzzle_d687bc17_manual() {
let solution: SolutionSimple = |data| {
let input = data.image;
let mut area: Image = input.remove_left_columns(1).expect("image");
area = area.remove_right_columns(1).expect("image");
area = area.remove_top_rows(1).expect("image");
area = area.remove_bottom_rows(1).expect("image");
let histogram_rows: Vec<Histogram> = area.histogram_rows();
let histogram_columns: Vec<Histogram> = area.histogram_columns();
// Empty overlay image with the most popular color
let most_popular_color: u8 = area.most_popular_color().expect("color");
let mut overlay: Image = Image::color(area.width(), area.height(), most_popular_color);
// Draw pixels for histogram_rows
for (y, histogram_row) in histogram_rows.iter().enumerate() {
let y1: i32 = (y + 1) as i32;
let counters: &[u32; 256] = histogram_row.counters();
{
let color: u8 = input.get(0, y1).unwrap_or(255);
let count: u32 = counters[color as usize];
for i in 0..count {
_ = overlay.set(i as i32, y as i32, color);
}
}
{
let color: u8 = input.get((input.width() as i32) - 1, y1).unwrap_or(255);
let count: u32 = counters[color as usize];
for i in 0..count {
_ = overlay.set((overlay.width() as i32) - (i + 1) as i32, y as i32, color);
}
}
}
// Draw pixels for histogram_columns
for (x, histogram_column) in histogram_columns.iter().enumerate() {
let x1: i32 = (x + 1) as i32;
let counters: &[u32; 256] = histogram_column.counters();
{
let color: u8 = input.get(x1, 0).unwrap_or(255);
let count: u32 = counters[color as usize];
for i in 0..count {
_ = overlay.set(x as i32, i as i32, color);
}
}
{
let color: u8 = input.get(x1, (input.height() as i32) - 1).unwrap_or(255);
let count: u32 = counters[color as usize];
for i in 0..count {
_ = overlay.set(x as i32, (overlay.height() as i32) - (i + 1) as i32, color);
}
}
}
let output: Image = input.overlay_with_position(&overlay, 1, 1).expect("image");
Ok(output)
};
let result: String = solution.run("d687bc17").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_390000_puzzle_5b6cbef5() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = 0;
let mask: Image = input.to_mask_where_color_is_different(background_color);
let tile1: Image = input.clone();
let tile0: Image = Image::color(tile1.width(), tile1.height(), background_color);
let output: Image = mask.select_two_tiles(&tile0, &tile1)?;
Ok(output)
};
let result: String = solution.run("5b6cbef5").expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_5B6CBEF5: &'static str = "
; tile_width
mov $2,$0
f11 $2,101000 ; Get width of image
; tile_height
mov $3,$0
f11 $3,101001 ; Get height of image
; tile
mov $7,0 ; color
mov $6,$3 ; height
mov $5,$2 ; width
f31 $5,101010 ; Create new image with size (x, y) and filled with color z
; mask
mov $10,$0 ; image
mov $11,$1 ; color
f21 $10,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
mov $11,$5 ; tile0
mov $12,$0 ; tile1
f31 $10,102110 ; Create a big composition of tiles.
mov $0,$10
";
#[test]
fn test_390001_puzzle_5b6cbef5_loda() {
let result: String = run_simple("5b6cbef5", PROGRAM_5B6CBEF5).expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_CCD554AC: &'static str = "
mov $1,$0
f11 $1,101000 ; Get width of image
mov $2,$0
f11 $2,101001 ; Get height of image
; $1 is count x = width of the image
; $2 is count y = height of the image
f31 $0,102120 ; Make a big image by repeating the current image.
";
#[test]
fn test_400001_puzzle_ccd554ac_loda() {
let result: String = run_simple("ccd554ac", PROGRAM_CCD554AC).expect("String");
assert_eq!(result, "6 1");
}
const PROGRAM_27F8CE4F: &'static str = "
mov $1,$0
f11 $1,101060 ; most popular color
; tile_width
mov $2,$0
f11 $2,101000 ; Get width of image
; tile_height
mov $3,$0
f11 $3,101001 ; Get height of image
; tile
mov $7,0 ; color
mov $6,$3 ; height
mov $5,$2 ; width
f31 $5,101010 ; Create new image with size (x, y) and filled with color z
; mask
mov $10,$0 ; image
mov $11,$1 ; color
f21 $10,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
mov $11,$0 ; tile0
mov $12,$5 ; tile1
f31 $10,102110 ; Create a big composition of tiles.
mov $0,$10
";
#[test]
fn test_410000_puzzle_27f8ce4f_loda() {
let result: String = run_simple("27f8ce4f", PROGRAM_27F8CE4F).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_1F85A75F: &'static str = "
mov $3,$0
f11 $3,101060 ; most popular color
; $3 is background_color
; remove noisy pixels
mov $4,$0
mov $5,3 ; number of noise colors to remove
f21 $4,101092 ; denoise type 3
;mov $0,$4
; mask
mov $6,$4 ; image
mov $7,$3 ; color
f21 $6,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
;mov $0,$6
; multiply input image by mask
mov $8,$6
mov $9,$3
mov $10,$0
f31 $8,102130 ; Pick pixels from one image.
mov $0,$8
; remove space around the object
f11 $0,101160 ; trim
";
#[test]
fn test_420000_puzzle_1f85a75f_loda() {
let result: String = run_simple("1f85a75f", PROGRAM_1F85A75F).expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_80AF3007: &'static str = "
mov $3,$0
f11 $3,101060 ; most popular color
; $3 is background_color
; remove space around the object
mov $5,$0
f11 $5,101160 ; trim
; scaled down to 3x3
mov $8,$5
mov $9,3
mov $10,3
f31 $8,101200 ; resize
; mask
mov $10,$8 ; image
mov $11,$3 ; color
f21 $10,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
; an empty tile
mov $14,$3 ; color
mov $13,3 ; height
mov $12,3 ; width
f31 $12,101010 ; Create new image with size (x, y) and filled with color z
; Layout tiles
mov $15,$10
mov $16,$12 ; tile0
mov $17,$8 ; tile1
f31 $15,102110 ; Create a big composition of tiles.
mov $0,$15
";
#[test]
fn test_430000_puzzle_80af3007_loda() {
let result: String = run_simple("80af3007", PROGRAM_80AF3007).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_440000_puzzle_73ccf9c2() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.most_popular_color().expect("pixel");
let ignore_mask: Image = input.to_mask_where_color_is(background_color);
let objects: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &input, &ignore_mask).expect("images");
// Identify the asymmetric objects
let mut asymmetric_objects: Vec<Image> = vec!();
for object in &objects {
let trimmed: Image = object.trim_color(background_color)?;
if !trimmed.is_symmetric_x()? {
asymmetric_objects.push(object.clone());
}
}
let mut output: Image = Image::empty();
for object in &asymmetric_objects {
// Obtain original colors from the input image
let extracted_object: Image = object.select_from_color_and_image(background_color, &input)?;
// Trim borders
let image: Image = extracted_object.trim_color(background_color)?;
output = image;
break;
}
Ok(output)
};
let result: String = solution.run("73ccf9c2").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_440001_puzzle_73ccf9c2() {
let mut instance = solve_crop_first_object::MySolution {};
let result: String = run_analyze_and_solve("73ccf9c2", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_440002_puzzle_73ccf9c2_loda() {
let result: String = run_advanced("73ccf9c2", PROGRAM_CROP_FIRST_OBJECT).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_450000_puzzle_72ca375d() {
let solution: SolutionSimple = |data| {
let input = data.image;
let background_color: u8 = input.most_popular_color().expect("pixel");
let ignore_mask: Image = input.to_mask_where_color_is(background_color);
let objects: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &input, &ignore_mask).expect("images");
// Identify the symmetric objects
let mut symmetric_objects: Vec<Image> = vec!();
for object in &objects {
let trimmed: Image = object.trim_color(background_color)?;
if trimmed.is_symmetric_x()? {
symmetric_objects.push(object.clone());
}
}
let mut output: Image = Image::empty();
for object in &symmetric_objects {
// Obtain original colors from the input image
let extracted_object: Image = object.select_from_color_and_image(background_color, &input)?;
// Trim borders
let image: Image = extracted_object.trim_color(background_color)?;
output = image;
break;
}
Ok(output)
};
let result: String = solution.run("72ca375d").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_450001_puzzle_72ca375d() {
let mut instance = solve_crop_first_object::MySolution {};
let result: String = run_analyze_and_solve("72ca375d", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_450002_puzzle_72ca375d_loda() {
let result: String = run_advanced("72ca375d", PROGRAM_CROP_FIRST_OBJECT).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_460000_puzzle_dbc1a6ce() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let background_color: u8 = input.histogram_all().most_popular_color().expect("color");
let ignore_mask = input.to_mask_where_color_is(background_color);
let color_when_there_is_no_neighbour: u8 = 255;
let neighbour_up: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Up, color_when_there_is_no_neighbour).expect("image");
let neighbour_down: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Down, color_when_there_is_no_neighbour).expect("image");
let neighbour_left: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Left, color_when_there_is_no_neighbour).expect("image");
let neighbour_right: Image = input.neighbour_color(&ignore_mask, ImageNeighbourDirection::Right, color_when_there_is_no_neighbour).expect("image");
let mut lines: Image = input.clone();
lines.set_pixel_where_two_images_agree(&neighbour_up, &neighbour_down, color_when_there_is_no_neighbour).expect("ok");
lines.set_pixel_where_two_images_agree(&neighbour_left, &neighbour_right, color_when_there_is_no_neighbour).expect("ok");
lines = lines.replace_color(1, 8)?;
let result_image: Image = ignore_mask.select_from_images(&input, &lines)?;
Ok(result_image)
};
let result: String = solution.run("dbc1a6ce").expect("String");
assert_eq!(result, "4 1");
}
mod solve_dbc1a6ce {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mut result_image: Image = input.clone();
_ = result_image.draw_line_connecting_two_colors(noise_color, noise_color, 255)?;
Ok(result_image)
}
}
}
#[test]
fn test_460001_puzzle_dbc1a6ce() {
let mut instance = solve_dbc1a6ce::MySolution {};
let result: String = run_analyze_and_solve("dbc1a6ce", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_DBC1A6CE: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,115 ; address of vector[0].InputSinglePixelNoiseColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; noise color
; $1 is color0 = noise color
mov $2,$1 ; color1 = noise color
mov $3,255 ; line color = 255 auto fill in
f41 $0,102210 ; Draw lines between the `color0` pixels and `color1` pixels when both occur in the same column/row.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_460002_puzzle_dbc1a6ce_loda() {
let result: String = run_advanced("dbc1a6ce", PROGRAM_DBC1A6CE).expect("String");
assert_eq!(result, "4 1");
}
mod solve_ea959feb {
use super::*;
pub struct MySolution {
repair_color: u8,
}
impl MySolution {
pub fn new() -> Self {
Self {
repair_color: 255
}
}
}
impl AnalyzeAndSolve for MySolution {
fn analyze(&mut self, task: &arc_work_model::Task) -> anyhow::Result<()> {
// Obtain the color is used for damaged pixels
let mut found_color: Option<u8> = None;
for label in &task.action_label_set_intersection {
match label {
ActionLabel::OutputImageIsInputImageWithChangesLimitedToPixelsWithColor { color } => {
found_color = Some(*color);
break;
},
_ => {}
};
}
let color: u8 = match found_color {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Expected a repair color"));
}
};
self.repair_color = color;
Ok(())
}
fn solve(&self, data: &SolutionSimpleData, _task: &arc_work_model::Task) -> anyhow::Result<Image> {
let input: &Image = &data.image;
let result_image: Image = input.repair_pattern_with_color(self.repair_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_470000_puzzle_1d0a4b61() {
let mut instance = solve_ea959feb::MySolution::new();
let result: String = run_analyze_and_solve("1d0a4b61", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_470001_puzzle_29ec7d0e() {
let mut instance = solve_ea959feb::MySolution::new();
let result: String = run_analyze_and_solve("29ec7d0e", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_470002_puzzle_ca8f78db() {
let mut instance = solve_ea959feb::MySolution::new();
let result: String = run_analyze_and_solve("ca8f78db", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_470003_puzzle_e95e3d8e() {
let mut instance = solve_ea959feb::MySolution::new();
let result: String = run_analyze_and_solve("e95e3d8e", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_470004_puzzle_ea959feb() {
let mut instance = solve_ea959feb::MySolution::new();
let result: String = run_analyze_and_solve("ea959feb", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const ADVANCED_PROGRAM_EA959FEB: &'static str = r#"
mov $80,$99
mov $81,100
mov $82,102
mov $83,105 ; address of vector[0].OutputImageIsInputImageWithChangesLimitedToPixelsWithColor
lps $80
mov $0,$$81
mov $1,$$83
f21 $0,102151 ; Repair damaged pixels and recreate big repeating patterns such as mosaics.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
"#;
#[test]
fn test_470005_puzzle_ea959feb_loda() {
let result: String = run_advanced("ea959feb", ADVANCED_PROGRAM_EA959FEB).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_520000_puzzle_49d1d64f() {
let solution: SolutionSimple = |data| {
data.image.border_grow(1, 0)
};
let result: String = solution.run("49d1d64f").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_49D1D64F: &'static str = "
mov $1,1
mov $2,0
f31 $0,102160 ; Expand by repeating the outer-most pixel border
";
#[test]
fn test_520001_puzzle_49d1d64f_loda() {
let result: String = run_simple("49d1d64f", PROGRAM_49D1D64F).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_530000_puzzle_780d0b14() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let mask: Image = input.mask_for_gridcells(Some(0))?;
let objects: Vec<Image> = ConnectedComponent::find_objects(PixelConnectivity::Connectivity4, &mask)?;
let mut result_image = Image::zero(input.width(), input.height());
for object in &objects {
let histogram: Histogram = input.histogram_with_mask(object)?;
let color: u8 = histogram.most_popular_color().expect("color");
result_image = object.select_from_image_and_color(&result_image, color)?;
}
result_image = result_image.remove_grid()?;
result_image = result_image.remove_duplicates()?;
Ok(result_image)
};
let result: String = solution.run("780d0b14").expect("String");
assert_eq!(result, "3 1");
}
mod solve_a699fb00 {
use super::*;
type Dict = HashMap<Image, Image>;
pub struct MySolution {
dict_outer: Dict,
}
impl MySolution {
pub fn new() -> Self {
Self {
dict_outer: Dict::new(),
}
}
}
impl AnalyzeAndSolve for MySolution {
fn analyze(&mut self, task: &arc_work_model::Task) -> anyhow::Result<()> {
let mut dict_inner = Dict::new();
for pair in &task.pairs {
if pair.pair_type != PairType::Train {
continue;
}
let diff_mask: Image = pair.input.image.diff(&pair.output.image)?;
let width: u8 = pair.input.image.width();
let height: u8 = pair.input.image.height();
for y in 0..height {
for x in 0..width {
let get_x: i32 = x as i32;
let get_y: i32 = y as i32;
let is_different0: u8 = diff_mask.get(get_x, get_y).unwrap_or(255);
let is_different1: u8 = diff_mask.get(get_x+1, get_y).unwrap_or(255);
let is_different2: u8 = diff_mask.get(get_x+2, get_y).unwrap_or(255);
let should_replace_horizontal = is_different0 == 0 && is_different1 == 1 && is_different2 == 0;
if !should_replace_horizontal {
continue;
}
let rect = Rectangle::new(x, y, 3, 1);
let replace_source: Image = pair.input.image.crop(rect)?;
let replace_target: Image = pair.output.image.crop(rect)?;
if let Some(value) = dict_inner.get(&replace_source) {
if *value != replace_target {
return Err(anyhow::anyhow!("No consensus on what replacements are to be done"));
}
}
dict_inner.insert(replace_source, replace_target);
// let pixel_value0: u8 = pair.input.image.get(get_x, get_y).unwrap_or(255);
// let pixel_value1: u8 = pair.output.image.get(get_x, get_y).unwrap_or(255);
// println!("replace from {} to {}", pixel_value0, pixel_value1);
}
}
}
// println!("number of items in dict: {}", dict_inner.len());
self.dict_outer = dict_inner;
Ok(())
}
fn solve(&self, data: &SolutionSimpleData, _task: &arc_work_model::Task) -> anyhow::Result<Image> {
let input: &Image = &data.image;
let mut result_image: Image = input.clone();
// Do substitutions from the dictionary
for _ in 0..100 {
let mut stop = true;
for (key, value) in &self.dict_outer {
let position = result_image.find_first(key)?;
if let Some((x, y)) = position {
result_image = result_image.overlay_with_position(value, x as i32, y as i32)?;
stop = false;
}
}
if stop {
break;
}
}
Ok(result_image)
}
}
}
#[test]
fn test_540000_puzzle_a699fb00() {
let mut instance = solve_a699fb00::MySolution::new();
let result: String = run_analyze_and_solve("a699fb00", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_540001_puzzle_a699fb00() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let background_color: u8 = match input.most_popular_color() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("unclear what is the most popular color"));
}
};
let image_padded: Image = input.padding_with_color(1, background_color)?;
let result_image: Image = convolution3x3(&image_padded, |bm| {
let left: u8 = bm.get(0, 1).unwrap_or(255);
let center: u8 = bm.get(1, 1).unwrap_or(255);
let right: u8 = bm.get(2, 1).unwrap_or(255);
let result_color: u8;
// flag the pixel when it have 2 neighbors with same color, but different center pixel.
if left != background_color && left != center && left == right {
result_color = 255;
} else {
result_color = center;
}
Ok(result_color)
})?;
Ok(result_image)
};
let result: String = solution.run("a699fb00").expect("String");
assert_eq!(result, "3 1");
}
mod solve_a699fb00_version2 {
use super::*;
pub struct MySolution {
substitution_rule: Option<SubstitutionRule>,
}
impl MySolution {
pub fn new() -> Self {
Self {
substitution_rule: None,
}
}
}
impl AnalyzeAndSolve for MySolution {
fn analyze(&mut self, task: &arc_work_model::Task) -> anyhow::Result<()> {
let mut image_pairs = Vec::<(Image, Image)>::new();
for pair in &task.pairs {
if pair.pair_type != PairType::Train {
continue;
}
image_pairs.push((pair.input.image.clone(), pair.output.image.clone()));
}
let rule: SubstitutionRule = SubstitutionRule::find_rule(image_pairs)?;
// println!("substitution_rule.source: {:?}", rule.source);
// println!("substitution_rule.destination: {:?}", rule.destination);
self.substitution_rule = Some(rule);
Ok(())
}
fn solve(&self, data: &SolutionSimpleData, _task: &arc_work_model::Task) -> anyhow::Result<Image> {
let rule: &SubstitutionRule = match &self.substitution_rule {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("expected some substitution_rule"));
}
};
rule.apply(&data.image)
}
}
}
const PROGRAM_SUBSTITUTION_RULE_APPLIED: &'static str = "
mov $80,$99
mov $81,111 ; address of vector[0].SubstitutionRuleApplied
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $$82,$$81
add $81,100
add $82,100
lpe
";
#[test]
fn test_540002_puzzle_a699fb00() {
let mut instance = solve_a699fb00_version2::MySolution::new();
let result: String = run_analyze_and_solve("a699fb00", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_540003_puzzle_a699fb00_loda() {
let result: String = run_advanced("a699fb00", PROGRAM_SUBSTITUTION_RULE_APPLIED).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_541000_puzzle_b60334d2() {
let mut instance = solve_a699fb00_version2::MySolution::new();
let result: String = run_analyze_and_solve("b60334d2", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_541001_puzzle_b60334d2_loda() {
let result: String = run_advanced("b60334d2", PROGRAM_SUBSTITUTION_RULE_APPLIED).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_542000_puzzle_d364b489() {
let mut instance = solve_a699fb00_version2::MySolution::new();
let result: String = run_analyze_and_solve("d364b489", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_542001_puzzle_d364b489_loda() {
let result: String = run_advanced("d364b489", PROGRAM_SUBSTITUTION_RULE_APPLIED).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_543000_puzzle_6c434453() {
let mut instance = solve_a699fb00_version2::MySolution::new();
let result: String = run_analyze_and_solve("6c434453", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_543001_puzzle_6c434453_loda() {
let result: String = run_advanced("6c434453", PROGRAM_SUBSTITUTION_RULE_APPLIED).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_544000_puzzle_95990924() {
let mut instance = solve_a699fb00_version2::MySolution::new();
let result: String = run_analyze_and_solve("95990924", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_544001_puzzle_95990924_loda() {
let result: String = run_advanced("95990924", PROGRAM_SUBSTITUTION_RULE_APPLIED).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_550000_puzzle_94f9d214() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let height: u8 = input.height() / 2;
let input_top: Image = input.top_rows(height)?;
let input_bottom: Image = input.bottom_rows(height)?;
let mask_top: Image = input_top.to_mask_where_color_is_different(0);
let mask_bottom: Image = input_bottom.to_mask_where_color_is_different(0);
let mut result_image: Image = mask_top.clone();
result_image = result_image.overlay_with_mask_color(&mask_bottom, 0)?;
result_image = result_image.replace_color(0, 2)?;
result_image = result_image.replace_color(1, 0)?;
Ok(result_image)
};
let result: String = solution.run("94f9d214").expect("String");
assert_eq!(result, "4 1");
}
mod solve_5c0a986e_regex_manual {
use super::*;
pub struct MySolution;
impl MySolution {
pub fn new() -> Self {
Self {}
}
}
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, _task: &arc_work_model::Task) -> anyhow::Result<Image> {
let input: &Image = &data.image;
let pattern1a: &str =
"^\\d+,\\d+,\\d+,\\d+,\\d+,\
\\d+,\\d+,\\d+,\\d+,\\d+,\
\\d+,\\d+,0,\\d+,\\d+,\
\\d+,\\d+,\\d+,1,1,\
\\d+,\\d+,\\d+,1,1$";
let pattern1b: &str =
"^\\d+,\\d+,\\d+,\\d+,\\d+,\
\\d+,\\d+,\\d+,\\d+,\\d+,\
\\d+,\\d+,0,\\d+,\\d+,\
\\d+,\\d+,\\d+,1,0,\
\\d+,\\d+,\\d+,0,1$";
let pattern2a: &str =
"^2,2,\\d+,\\d+,\\d+,\
2,2,\\d+,\\d+,\\d+,\
\\d+,\\d+,0,\\d+,\\d+,\
\\d+,\\d+,\\d+,\\d+,\\d+,\
\\d+,\\d+,\\d+,\\d+,\\d+$";
let pattern2b: &str =
"^2,0,\\d+,\\d+,\\d+,\
0,2,\\d+,\\d+,\\d+,\
\\d+,\\d+,0,\\d+,\\d+,\
\\d+,\\d+,\\d+,\\d+,\\d+,\
\\d+,\\d+,\\d+,\\d+,\\d+$";
let replacements: Vec<ImageReplaceRegexToColor> = vec![
ImageReplaceRegexToColor {
regex: Regex::new(pattern1a).expect("regex"),
color: 1,
},
ImageReplaceRegexToColor {
regex: Regex::new(pattern1b).expect("regex"),
color: 1,
},
ImageReplaceRegexToColor {
regex: Regex::new(pattern2a).expect("regex"),
color: 2,
},
ImageReplaceRegexToColor {
regex: Regex::new(pattern2b).expect("regex"),
color: 2,
}
];
let mut result_image: Image = input.padding_with_color(2, 0)?;
let _count: usize = result_image.replace_5x5_regex(&replacements, 14, 14)?;
// println!("replace_5x5_regex. count: {}", count);
let rect = Rectangle::new(2, 2, input.width(), input.height());
let result_image_cropped: Image = result_image.crop(rect)?;
Ok(result_image_cropped)
}
}
}
#[test]
fn test_560003_puzzle_5c0a986e_using_regex_manual() {
let mut instance = solve_5c0a986e_regex_manual::MySolution::new();
let result: String = run_analyze_and_solve("5c0a986e", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod solve_5c0a986e_regex_advanced {
use super::*;
pub struct MySolution {
replacements: Vec<ImageReplaceRegexToColor>,
}
impl MySolution {
pub fn new() -> Self {
Self {
replacements: vec!()
}
}
fn similarity_of_two5x5(source_image: &Image, target_image: &Image, ignore_color: u8) -> anyhow::Result<(u8, u8)> {
if source_image.width() != 5 || source_image.height() != 5 || target_image.width() != 5 || target_image.height() != 5 {
return Err(anyhow::anyhow!("both images must have the exact size 5x5"));
}
let target_pixel_value: u8 = target_image.get(2, 2).unwrap_or(255);
let mut count_same_as_target: u8 = 0;
let mut count_same: u8 = 0;
let mut count_different: u8 = 0;
for y in 0..5 {
for x in 0..5 {
if y == 2 && x == 2 {
// Ignore the center pixel of the 5x5
continue;
}
let pixel_value0: u8 = source_image.get(x as i32, y as i32).unwrap_or(255);
let pixel_value1: u8 = target_image.get(x as i32, y as i32).unwrap_or(255);
if pixel_value0 == ignore_color && pixel_value1 == ignore_color {
continue;
}
if pixel_value0 != pixel_value1 {
count_different += 1;
continue;
}
// Idea, use distance from the center pixel to assign more weight to pixels near center
if pixel_value0 == target_pixel_value {
count_same_as_target += 1;
} else {
count_same += 1;
}
}
}
count_same += count_same_as_target * 10;
Ok((count_same, count_different))
}
fn pattern_of_two5x5(source_image: &Image, target_image: &Image, ignore_color: u8) -> anyhow::Result<String> {
if source_image.width() != 5 || source_image.height() != 5 || target_image.width() != 5 || target_image.height() != 5 {
return Err(anyhow::anyhow!("both images must have the exact size 5x5"));
}
let target_center_pixel_value: u8 = target_image.get(2, 2).unwrap_or(255);
let mut pattern_parts = Vec::<String>::new();
for y in 0..5 {
for x in 0..5 {
let pixel_value0: u8 = source_image.get(x as i32, y as i32).unwrap_or(255);
if y == 2 && x == 2 {
// Special treatment for the center pixel of the 5x5
pattern_parts.push(format!("{}", pixel_value0));
continue;
}
let pixel_value1: u8 = target_image.get(x as i32, y as i32).unwrap_or(255);
if pixel_value0 == ignore_color && pixel_value1 == ignore_color {
pattern_parts.push("\\d+".into());
continue;
}
if pixel_value0 == target_center_pixel_value {
pattern_parts.push(format!("{}", pixel_value0));
continue;
}
pattern_parts.push("\\d+".into());
}
}
let pattern: String = format!("^{}$", pattern_parts.join(","));
Ok(pattern)
}
fn analyze_train_pair(pair: &arc_work_model::Pair) -> anyhow::Result<Vec<ImageReplaceRegexToColor>> {
let background_color: u8 = 0;
let mut input_image: Image = pair.input.image.padding_with_color(2, background_color)?;
let output_image: Image = pair.output.image.padding_with_color(2, background_color)?;
// HtmlLog::text("analyze train pair");
let mut replacements = Vec::<ImageReplaceRegexToColor>::new();
for _iteration in 0..20 {
// HtmlLog::text(format!("iteration: {}", iteration));
let rect = Rectangle::new(2, 2, pair.input.image.width(), pair.input.image.height());
let current_input: Image = input_image.crop(rect)?;
let diff_mask: Image = current_input.diff(&pair.output.image)?;
// HtmlLog::image(&diff_mask);
let positions: Vec<(u8, u8)> = diff_mask.positions_where_color_is(1);
// println!("positions: {:?}", positions);
if positions.is_empty() {
break;
}
let mut found_x: u8 = 0;
let mut found_y: u8 = 0;
let mut found_score: u8 = 0;
for (x, y) in &positions {
let rect = Rectangle::new(*x, *y, 5, 5);
let input_crop: Image = input_image.crop(rect)?;
let output_crop: Image = output_image.crop(rect)?;
// Compare input_crop with output_crop, ignoring the center pixel
// If they are nearly identical, then we know that it's only the center pixel that has changed.
// And that we can establish a pattern at this position.
let (count_same, _count_diff) = Self::similarity_of_two5x5(&input_crop, &output_crop, background_color)?;
// println!("position: {},{} same: {} diff: {}", x, y, count_same, count_diff);
if count_same > found_score {
found_x = *x;
found_y = *y;
found_score = count_same;
}
}
if found_score == 0 {
break;
}
// println!("found position: {},{}", found_x, found_y);
let x: u8 = found_x;
let y: u8 = found_y;
let rect = Rectangle::new(x, y, 5, 5);
let input_crop: Image = input_image.crop(rect)?;
let output_crop: Image = output_image.crop(rect)?;
let pattern: String = Self::pattern_of_two5x5(&input_crop, &output_crop, background_color)?;
// println!("pattern: {}", pattern);
let target_color: u8 = output_crop.get(2, 2).unwrap_or(255);
// println!("target_color: {}", target_color);
let item = ImageReplaceRegexToColor {
regex: Regex::new(&pattern)?,
color: target_color,
};
replacements.push(item);
let _replace_count: usize = input_image.replace_5x5_regex(&replacements, 14, 14)?;
// println!("replace_count: {}", replace_count);
// HtmlLog::image(&input_image);
}
// HtmlLog::text("separator");
Ok(replacements)
}
fn intersection(items0: &Vec<ImageReplaceRegexToColor>, items1: &Vec<ImageReplaceRegexToColor>) -> Vec<ImageReplaceRegexToColor> {
let mut result_items = Vec::<ImageReplaceRegexToColor>::new();
for item0 in items0 {
for item1 in items1 {
if *item0.regex.as_str() != *item1.regex.as_str() {
continue;
}
if item0.color != item1.color {
continue;
}
result_items.push(item0.clone());
}
}
result_items
}
}
impl AnalyzeAndSolve for MySolution {
fn analyze(&mut self, task: &arc_work_model::Task) -> anyhow::Result<()> {
let mut is_first = true;
let mut replacements_intersection = Vec::<ImageReplaceRegexToColor>::new();
for pair in &task.pairs {
if pair.pair_type != PairType::Train {
continue;
}
let replacements: Vec<ImageReplaceRegexToColor> = Self::analyze_train_pair(pair)?;
if is_first {
is_first = false;
replacements_intersection = replacements;
} else {
replacements_intersection = Self::intersection(&replacements_intersection, &replacements);
}
if replacements_intersection.is_empty() {
break;
}
}
// println!("rules.len: {}", replacements_intersection.len());
// println!("rules: {:?}", replacements_intersection);
self.replacements = replacements_intersection;
Ok(())
}
fn solve(&self, data: &SolutionSimpleData, _task: &arc_work_model::Task) -> anyhow::Result<Image> {
let input: &Image = &data.image;
let mut result_image: Image = input.padding_with_color(2, 0)?;
let _count: usize = result_image.replace_5x5_regex(&self.replacements, 14, 14)?;
// println!("replace_5x5_regex. count: {}", count);
let rect = Rectangle::new(2, 2, input.width(), input.height());
let result_image_cropped: Image = result_image.crop(rect)?;
Ok(result_image_cropped)
}
}
}
#[test]
fn test_560004_puzzle_5c0a986e_using_regex_advanced() {
let mut instance = solve_5c0a986e_regex_advanced::MySolution::new();
let result: String = run_analyze_and_solve("5c0a986e", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_570000_puzzle_3428a4f5() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let half_height: u8 = input.height() / 2;
let a: Image = input.top_rows(half_height)?;
let b: Image = input.bottom_rows(half_height)?;
let result_image: Image = a.mask_xor(&b)?;
Ok(result_image)
};
let result: String = solution.run("3428a4f5").expect("String");
assert_eq!(result, "4 2");
}
const PROGRAM_3428A4F5: &'static str = "
mov $1,$0
f11 $1,101001 ; get height
mod $1,2 ; spacing between the columns
f22 $0,102261 ; split into 2 rows
; $0..$1 are the 2 rows
f21 $0,101254 ; xor
";
#[test]
fn test_570001_puzzle_3428a4f5_loda() {
let result: String = run_simple("3428a4f5", PROGRAM_3428A4F5).expect("String");
assert_eq!(result, "4 2");
}
#[test]
fn test_580000_puzzle_25d8a9c8() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let mut result_image: Image = input.count_unique_colors_per_row()?;
result_image = result_image.to_mask_where_color_is_different(1);
result_image = result_image.repeat_by_count(input.width(), 1)?;
Ok(result_image)
};
let result: String = solution.run("25d8a9c8").expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_25D8A9C8: &'static str = "
mov $1,$0
f11 $1,101000 ; get width
; $1 is the width of the input image
f11 $0,101241 ; count unique colors per row
; $1 is the width of the input image
mov $2,1
f31 $0,102120 ; repeat image
";
#[test]
fn test_580001_puzzle_25d8a9c8_loda() {
let result: String = run_simple("25d8a9c8", PROGRAM_25D8A9C8).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_590000_puzzle_50cb2852() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let color_count: Image = input.count_duplicate_pixels_in_3x3()?;
let count_mask: Image = color_count.to_mask_where_color_is_equal_or_greater_than(8);
let object_mask: Image = input.to_mask_where_color_is_different(0);
let mask: Image = count_mask.mask_and(&object_mask)?;
let result_image: Image = mask.select_from_image_and_color(&input, 42)?;
Ok(result_image)
};
let result: String = solution.run("50cb2852").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_50CB2852: &'static str = "
mov $1,$0
f11 $1,102140 ; Traverse all pixels in the 3x3 convolution and count how many have the same color as the center.
mov $2,8
f21 $1,101253 ; Convert to a mask image by converting `pixel_color >= threshold_color` to 1 and converting anything else to to 0.
mov $2,$0
mov $3,0
f21 $2,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
f21 $1,101255 ; AND between two masks
mov $3,42
mov $2,$0
f31 $1,102131 ; Pick pixels from image and color. When the mask is 0 then pick from the image. When the mask is [1..255] then use the `default_color`.
mov $0,$1
";
#[test]
fn test_590001_puzzle_50cb2852_loda() {
let result: String = run_simple("50cb2852", PROGRAM_50CB2852).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_600000_puzzle_c1d99e64() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let mask: Image = input.mask_for_gridcells(None)?;
let result_image: Image = mask.select_from_color_and_image(42, &input)?;
Ok(result_image)
};
let result: String = solution.run("c1d99e64").expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_C1D99E64: &'static str = "
mov $2,$0
f11 $0,102270 ; Mask, where the cells are the value is 1 and where the grid lines are the value is 0. Don't care about the color of the grid lines.
mov $1,42
f31 $0,102130 ; Pick pixels from color and image. When the mask is 0 then pick the `default_color`. When the mask is [1..255] then pick from the image.
";
#[test]
fn test_600001_puzzle_c1d99e64_loda() {
let result: String = run_simple("c1d99e64", PROGRAM_C1D99E64).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_610000_puzzle_f2829549() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let half_width: u8 = input.width() / 2;
let a: Image = input.left_columns(half_width)?;
let b: Image = input.right_columns(half_width)?;
let result_image: Image = a.mask_or(&b)?;
Ok(result_image)
};
let result: String = solution.run("f2829549").expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_F2829549: &'static str = "
mov $1,$0
f11 $1,101000 ; get width
mod $1,2 ; spacing between the columns
f22 $0,102260 ; split into 2 columns
; $0..$1 are the 2 columns
f21 $0,101256 ; or
";
#[test]
fn test_610001_puzzle_f2829549_loda() {
let result: String = run_simple("f2829549", PROGRAM_F2829549).expect("String");
assert_eq!(result, "5 1");
}
#[test]
fn test_620000_puzzle_662c240a() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let height: u8 = input.height() / 3;
let mut images = Vec::<Image>::new();
for i in 0..3 {
let y: i32 = (height as i32) * i;
if y > (u8::MAX as i32) {
return Err(anyhow::anyhow!("cannot split image"));
}
let rect = Rectangle::new(0, y as u8, input.width(), height);
let image: Image = input.crop(rect)?;
images.push(image);
}
for image in &images {
if image.is_symmetric_any_diagonal()? {
continue;
}
return Ok(image.clone());
}
Err(anyhow::anyhow!("no non-symmetric image found"))
};
let result: String = solution.run("662c240a").expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_630000_puzzle_b6afb2da() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let color_count: Image = input.count_duplicate_pixels_in_3x3()?;
let object_mask: Image = input.to_mask_where_color_is_different(0);
let result_image: Image = object_mask.select_from_color_and_image(42, &color_count)?;
Ok(result_image)
};
let result: String = solution.run("b6afb2da").expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_B6AFB2DA: &'static str = "
mov $80,$99
mov $81,100
mov $82,102
mov $83,105 ; address of vector[0].OutputImageIsInputImageWithChangesLimitedToPixelsWithColor
lps $80
mov $0,$$81
mov $4,$0
f11 $4,102140 ; Traverse all pixels in the 3x3 convolution and count how many have the same color as the center.
mov $5,$0
mov $6,$$83
f21 $5,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
mov $8,42
mov $7,$4
mov $6,$5
f31 $6,102131 ; Pick pixels from color and image. When the mask is 0 then pick the `default_color`. When the mask is [1..255] then pick from the image.
mov $$82,$6
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_630001_puzzle_b6afb2da_loda() {
let result: String = run_advanced("b6afb2da", PROGRAM_B6AFB2DA).expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_640000_puzzle_c444b776() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
// Objects from the grid
let cell_mask: Image = input.mask_for_gridcells(Some(4))?;
let ignore_mask: Image = cell_mask.invert_mask();
let objects: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity4, &cell_mask, &ignore_mask)?;
// Identify the single template image
let mut image_to_insert: Option<Image> = None;
let mut number_of_images_found: usize = 0;
for object in &objects {
let rect: Rectangle = match object.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("expected all objects to have a bounding box"));
}
};
let image: Image = input.crop(rect)?;
let count: u16 = image.histogram_all().number_of_counters_greater_than_zero();
if count == 1 {
continue;
}
image_to_insert = Some(image);
number_of_images_found += 1;
}
if number_of_images_found >= 2 {
return Err(anyhow::anyhow!("Found 2 or more patterns to insert"));
}
let template_image: Image = match image_to_insert {
Some(image) => image,
None => {
return Err(anyhow::anyhow!("Didn't find any pattern for insertion"));
}
};
// Insert the template image into all the empty cells
let mut result_image: Image = input.clone();
for object in &objects {
let rect: Rectangle = match object.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("expected all objects to have a bounding box"));
}
};
let image: Image = input.crop(rect)?;
let count: u16 = image.histogram_all().number_of_counters_greater_than_zero();
if count != 1 {
continue;
}
result_image = result_image.overlay_with_position(&template_image, rect.x() as i32, rect.y() as i32)?;
}
Ok(result_image)
};
let result: String = solution.run("c444b776").expect("String");
assert_eq!(result, "2 1");
}
#[test]
fn test_650000_puzzle_017c7c7b() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let ignore_mask = Image::zero(input.width(), input.height());
let periodicity_optional: Option<u8> = input.periodicity_y(&ignore_mask)?;
let periodicity: u8 = periodicity_optional.expect("u8");
if periodicity < 1 {
return Err(anyhow::anyhow!("expected periodicity to be 1 or more"));
}
let repeat_count: u8 = (9 / periodicity) + 1;
let pattern: Image = input.top_rows(periodicity)?;
let mut result_image: Image = pattern.repeat_by_count(1, repeat_count)?;
let rect = Rectangle::new(0, 0, input.width(), 9);
result_image = result_image.crop(rect)?;
Ok(result_image)
};
let result: String = solution.run("017c7c7b").expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_660000_puzzle_6f8cd79b() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let rect = Rectangle::new(1, 1, input.width() - 2, input.height() - 2);
let cropped: Image = input.crop(rect)?;
let result_image: Image = cropped.padding_with_color(1, 42)?;
Ok(result_image)
};
let result: String = solution.run("6f8cd79b").expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_670000_puzzle_cf98881b() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let width: u8 = (input.width() - 2) / 3;
let mut images = Vec::<Image>::new();
for i in 0..3 {
let x: i32 = (width as i32 + 1) * i;
if x > (u8::MAX as i32) {
return Err(anyhow::anyhow!("cannot split image"));
}
let rect = Rectangle::new(x as u8, 0, width, input.height());
let image: Image = input.crop(rect)?;
images.push(image);
}
images.reverse();
let mut result_image = Image::empty();
for (index, image) in images.iter().enumerate() {
if index == 0 {
result_image = image.clone();
continue;
}
let mask: Image = image.to_mask_where_color_is_different(0);
result_image = mask.select_from_images(&result_image, &image)?;
}
Ok(result_image)
};
let result: String = solution.run("cf98881b").expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_CF98881B: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $20,$$83 ; most popular color across inputs
mov $10,$$81 ; input image
mov $11,1 ; 1 pixel spacing
f23 $10,102260 ; split into 3 columns
; $10..$12 are the 3 columns
mov $0,$20 ; transparent color
mov $1,$12 ; layer 0 lowest layer
mov $2,$11 ; layer 1
mov $3,$10 ; layer 2 top
f41 $0,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_670001_puzzle_cf98881b_loda() {
let result: String = run_advanced("cf98881b", PROGRAM_CF98881B).expect("String");
assert_eq!(result, "5 1");
}
#[test]
fn test_680000_puzzle_8731374e() {
let solution: SolutionSimple = |data| {
let input: Image = data.image;
let color_count: Image = input.count_duplicate_pixels_in_3x3()?;
let ignore_mask: Image = color_count.to_mask_where_color_is_equal_or_less_than(3);
let mut objects: Vec<ConnectedComponentItem> = ConnectedComponent::find_objects_with_ignore_mask_inner(PixelConnectivity::Connectivity4, &input, &ignore_mask)?;
objects.sort_unstable_by_key(|item| (item.mass, item.x, item.y));
objects.reverse();
let biggest_object: ConnectedComponentItem = match objects.first() {
Some(value) => value.clone(),
None => {
return Err(anyhow::anyhow!("biggest object"));
}
};
let color_to_be_trimmed: u8 = 0;
// Idea, with the actionlabel, check the size of the masked area correspond to the output size
let rect: Rectangle = biggest_object.mask.inner_bounding_box_after_trim_with_color(color_to_be_trimmed)?;
if rect.is_empty() {
return Err(anyhow::anyhow!("bounding box is empty"));
}
// Idea, save the bounding box as a mask and provide it to the .asm program
// let mut the_mask = Image::zero(input.width(), input.height());
// the_mask = the_mask.fill_inside_rect(rect, 1)?;
// Crop out the strongly-connected-object from input image
let cropped_input: Image = input.crop(rect)?;
let histogram_all: Histogram = cropped_input.histogram_all();
if histogram_all.number_of_counters_greater_than_zero() != 2 {
return Err(anyhow::anyhow!("expected 2 colors in the cropped area"));
}
let least_popular_color: u8 = match histogram_all.least_popular_color_disallow_ambiguous() {
Some(color) => color,
None => {
return Err(anyhow::anyhow!("expected a least popular colors in the cropped area"));
}
};
let line_color: u8 = least_popular_color;
let mut result_image: Image = cropped_input.clone();
let mask: Image = cropped_input.to_mask_where_color_is(least_popular_color);
_ = result_image.draw_line_where_mask_is_nonzero(&mask, line_color)?;
Ok(result_image)
};
let result: String = solution.run("8731374e").expect("String");
assert_eq!(result, "3 1");
}
mod solve_f9012d9b {
use super::*;
pub struct MySolution;
impl MySolution {
pub fn new() -> Self {
Self {}
}
}
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let input: &Image = &data.image;
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let repair_mask: Image = match &pair.input.repair_mask {
Some(value) => value.clone(),
None => {
return Err(anyhow::anyhow!("Expected a repair mask"));
}
};
let rect: Rectangle = match repair_mask.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Unable to determine bounding box of repair mask"));
}
};
let mut result_image: Image = input.repair_pattern_with_mask(&repair_mask)?;
result_image = result_image.crop(rect)?;
Ok(result_image)
}
}
}
#[test]
fn test_690000_puzzle_f9012d9b() {
let mut instance = solve_f9012d9b::MySolution::new();
let result: String = run_analyze_and_solve("f9012d9b", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod repair_symmetry_crop {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let repair_mask: Image = match &pair.input.repair_mask {
Some(value) => value.clone(),
None => {
return Err(anyhow::anyhow!("Expected a repair mask"));
}
};
let repair_mask_bounding_box: Rectangle = match repair_mask.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Unable to determine bounding box of repair mask"));
}
};
let repaired_image: Image = match &pair.input.repaired_image {
Some(value) => value.clone(),
None => {
return Err(anyhow::anyhow!("Expected repaired_image"));
}
};
let result_image: Image = repaired_image.crop(repair_mask_bounding_box)?;
Ok(result_image)
}
}
}
#[test]
fn test_700000_puzzle_de493100() {
let mut instance = repair_symmetry_crop::MySolution {};
let result: String = run_analyze_and_solve("de493100", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_700001_puzzle_dc0a314f() {
let mut instance = repair_symmetry_crop::MySolution {};
let result: String = run_analyze_and_solve("dc0a314f", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_700002_puzzle_ff805c23() {
let mut instance = repair_symmetry_crop::MySolution {};
let result: String = run_analyze_and_solve("ff805c23", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_FF805C23: &'static str = "
mov $80,$99
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,106 ; address of vector[0].RepairMask
mov $84,107 ; address of vector[0].RepairedImage
lps $80
; replace what is outside the repair mask with the color 255
mov $0,$$83 ; repair mask
mov $1,255 ; color for what to be removed
mov $2,$$84 ; repaired image
f31 $0,102130 ; Pick pixels from color and image. When the mask is 0 then pick the `default_color`. When the mask is [1..255] then pick from the image.
; crop out the repair mask
mov $1,255
f21 $0,101161 ; trim with color
mov $$82,$0
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_700002_puzzle_ff805c23_loda() {
let result: String = run_advanced("ff805c23", PROGRAM_FF805C23).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_700003_puzzle_67b4a34d() {
let mut instance = repair_symmetry_crop::MySolution {};
let result: String = run_analyze_and_solve("67b4a34d", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_700004_puzzle_9ecd008a() {
// Predicts the correct size of the output, but for the wrong reasons.
// It doesn't detect that it's a strongly connected area of 3x3 pixels, and that it's colored black.
let mut instance = repair_symmetry_crop::MySolution {};
let result: String = run_analyze_and_solve("9ecd008a", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod repair_symmetry {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let repaired_image: Image = match &pair.input.repaired_image {
Some(value) => value.clone(),
None => {
return Err(anyhow::anyhow!("Expected repaired_image"));
}
};
Ok(repaired_image)
}
}
}
#[test]
fn test_710000_puzzle_af22c60d() {
let mut instance = repair_symmetry::MySolution {};
let result: String = run_analyze_and_solve("af22c60d", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_710001_puzzle_b8825c91() {
let mut instance = repair_symmetry::MySolution {};
let result: String = run_analyze_and_solve("b8825c91", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_710002_puzzle_3631a71a() {
let mut instance = repair_symmetry::MySolution {};
let result: String = run_analyze_and_solve("3631a71a", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_710003_puzzle_929ab4e9() {
let mut instance = repair_symmetry::MySolution {};
let result: String = run_analyze_and_solve("929ab4e9", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
#[test]
fn test_710004_puzzle_47996f11() {
let mut instance = repair_symmetry::MySolution {};
let result: String = run_analyze_and_solve("47996f11", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_47996F11: &'static str = "
mov $80,$99
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,107 ; address of vector[0].RepairedImage
lps $80
mov $$82,$$83
add $82,100
add $83,100
lpe
";
#[test]
fn test_710004_puzzle_47996f11_loda() {
let result: String = run_advanced("47996f11", PROGRAM_47996F11).expect("String");
assert_eq!(result, "4 1");
}
#[allow(dead_code)]
mod inspect_grid {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
println!("grid: {:?}", pair.input.image_meta.grid);
let result_image: Image = pair.input.image.clone();
Ok(result_image)
}
}
}
#[allow(dead_code)]
// #[test]
fn test_720000_puzzle_95a58926() {
let mut instance = inspect_grid::MySolution {};
let result: String = run_analyze_and_solve("95a58926", &mut instance).expect("String");
assert_eq!(result, "5 1");
}
mod solve_0b148d64 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let grid_pattern: &GridPattern = match &pair.input.grid_pattern {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Missing grid_pattern for input"));
}
};
let grid_color: u8 = grid_pattern.color;
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Missing enumerated_objects for input"));
}
};
let mut ignore_colors = Histogram::new();
ignore_colors.increment(grid_color);
// Find the cell with the unusual color
let mask: Image = ObjectWithDifferentColor::run(&input, &enumerated_objects, Some(&ignore_colors))?;
// crop out the cell
let crop_rect: Rectangle = match mask.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("cannot determine bounding box"));
}
};
let result_image: Image = input.crop(crop_rect)?;
Ok(result_image)
}
}
}
#[test]
fn test_730000_puzzle_0b148d64() {
let mut instance = solve_0b148d64::MySolution {};
let result: String = run_analyze_and_solve("0b148d64", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_0B148D64: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,109 ; address of vector[0].GridColor
mov $84,110 ; address of vector[0].EnumeratedObjects
lps $80
mov $0,$$81
mov $1,$$84 ; enumerated objects
mov $2,$$83 ; grid color
f31 $0,104111 ; Find the single object that has different colors than the other objects. With 1 ignore color.
mov $1,255 ; color for the area to be trimmed
mov $2,$$81
f31 $0,102130 ; Pick pixels from color and image
; $1 is the color to be trimmed
f21 $0,101161 ; trim with color
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_730001_puzzle_0b148d64_loda() {
let result: String = run_advanced("0b148d64", PROGRAM_0B148D64).expect("String");
assert_eq!(result, "3 1");
}
mod solve_c3202e5a {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Missing enumerated_objects for input"));
}
};
// Number of unique colors inside each object
let unique_colors: Image = ObjectsUniqueColorCount::run(input, &enumerated_objects, None)?;
// Pick the object with the lowest number of unique colors
let mask: Image = ObjectWithSmallestValue::run(&unique_colors, &enumerated_objects)?;
// crop out the cell
let crop_rect: Rectangle = match mask.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("cannot determine bounding box"));
}
};
let result_image: Image = input.crop(crop_rect)?;
Ok(result_image)
}
}
}
#[test]
fn test_740000_puzzle_c3202e5a() {
let mut instance = solve_c3202e5a::MySolution {};
let result: String = run_analyze_and_solve("c3202e5a", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_C3202E5A: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,110 ; address of vector[0].EnumeratedObjects
lps $80
mov $0,$$81
mov $1,$$83 ; enumerated objects
f21 $0,104000 ; Count unique colors in each object
; $1 is the enumerated objects
f21 $0,104100 ; Pick object with the smallest value
mov $1,255 ; color for the area to be trimmed
mov $2,$$81
f31 $0,102130 ; Pick pixels from color and image
; $1 is the color to be trimmed
f21 $0,101161 ; trim with color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_740001_puzzle_c3202e5a_loda() {
let result: String = run_advanced("c3202e5a", PROGRAM_C3202E5A).expect("String");
assert_eq!(result, "3 1");
}
mod solve_1c0d0a4b {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let grid_pattern: &GridPattern = match &pair.input.grid_pattern {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Missing grid_pattern for input"));
}
};
let grid_mask: &Image = &grid_pattern.line_mask;
let grid_color: u8 = grid_pattern.color;
let cell_content: Image = input.to_mask_where_color_is_different(grid_color);
let result_image: Image = cell_content.mask_xor(&grid_mask)?;
Ok(result_image)
}
}
}
#[test]
fn test_750000_puzzle_1c0d0a4b() {
let mut instance = solve_1c0d0a4b::MySolution {};
let result: String = run_analyze_and_solve("1c0d0a4b", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_1C0D0A4B: &'static str = "
mov $80,$99
mov $81,100
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,108 ; address of vector[0].GridMask
mov $84,109 ; address of vector[0].GridColor
lps $80
mov $0,$$81
mov $1,$$84 ; grid color
f21 $0,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
mov $1,$$83 ; grid mask
f21 $0,101254 ; xor
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_750001_puzzle_1c0d0a4b_loda() {
let result: String = run_advanced("1c0d0a4b", PROGRAM_1C0D0A4B).expect("String");
assert_eq!(result, "3 1");
}
mod solve_6773b310 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let grid_pattern: &GridPattern = match &pair.input.grid_pattern {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Missing grid_pattern for input"));
}
};
let grid_mask: &Image = &grid_pattern.line_mask;
let grid_color: u8 = grid_pattern.color;
let background_color: u8;
{
let mut histogram: Histogram = pair.input.image_meta.histogram_all.clone();
histogram.set_counter_to_zero(grid_color);
background_color = match histogram.most_popular_color_disallow_ambiguous() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("ambiguous what the background color is"));
}
};
}
// Segment the image into cells
let blank: Image = Image::zero(input.width(), input.height());
let cells: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity4, &blank, grid_mask)?;
if cells.is_empty() {
return Err(anyhow::anyhow!("Expected 1 or more cells"));
}
let enumerated_cells: Image = Image::object_enumerate(&cells).expect("image");
let mut ignore_colors = Histogram::new();
ignore_colors.increment(background_color);
ignore_colors.increment(grid_color);
let mass_of_objects: Image = ObjectsMeasureMass::run(input, &enumerated_cells, Some(&ignore_colors))?;
// Layout the objects in a grid
let grid_width: u8 = grid_pattern.horizontal_cell_count;
let grid_height: u8 = grid_pattern.vertical_cell_count;
if grid_width < 1 || grid_height < 1 {
return Err(anyhow::anyhow!("Too small grid. Must be 1x1 or bigger"));
}
let result_image: Image = ObjectsToGrid::run(
&mass_of_objects,
&enumerated_cells,
grid_width,
grid_height,
ObjectsToGridMode::MostPopularColor,
)?;
Ok(result_image)
}
}
}
#[test]
fn test_760000_puzzle_6773b310() {
let mut instance = solve_6773b310::MySolution {};
let result: String = run_analyze_and_solve("6773b310", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
mod solve_crop_first_object {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Missing enumerated_objects for input"));
}
};
let mask: Image = enumerated_objects.to_mask_where_color_is(1);
let crop_rect: Rectangle = match mask.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Cannot determine crop_rect for mask"));
}
};
let result_image = input.crop(crop_rect)?;
Ok(result_image)
}
}
}
#[test]
fn test_770000_puzzle_be94b721() {
let mut instance = solve_crop_first_object::MySolution {};
let result: String = run_analyze_and_solve("be94b721", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_CROP_FIRST_OBJECT: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,110 ; address of vector[0].EnumeratedObjects
lps $80
; extract the background image
mov $1,$$83 ; enumerated objects
mov $2,0 ; the 0th object is the background object
f21 $1,101250 ; where color is the mask of the 0th object
; histogram of the background image
mov $0,$$81 ; input image
f21 $0,101231 ; histogram with mask
; get pixel at x=0, y=1, this is the most popular color
mov $1,0
mov $2,1
f31 $0,101002 ; get pixel of the most popular color
mov $10,$0
; extract object 1, the biggest object
mov $0,$$83 ; enumerated objects
mov $1,1 ; the 1st object is the biggest object
f21 $0,101250 ; where color is the mask of the 1st object
; surround the object with the background-color
mov $1,$10 ; color for the area to be trimmed
mov $2,$$81
f31 $0,102130 ; Pick pixels from color and image
; $1 is the color to be trimmed
f21 $0,101161 ; trim with color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_770001_puzzle_be94b721_loda() {
let result: String = run_advanced("be94b721", PROGRAM_CROP_FIRST_OBJECT).expect("String");
assert_eq!(result, "4 1");
}
mod solve_cd3c21df {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8;
{
let histogram: Histogram = pair.input.image_meta.histogram_all.clone();
background_color = match histogram.most_popular_color_disallow_ambiguous() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("ambiguous what the background color is"));
}
};
}
// Segment the image into objects
let non_background_mask: Image = input.to_mask_where_color_is(background_color);
let blank: Image = Image::zero(input.width(), input.height());
let objects: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity4, &blank, &non_background_mask)?;
if objects.is_empty() {
return Err(anyhow::anyhow!("Expected 1 or more cells"));
}
let mut object_histogram = HashMap::<Image, Item>::new();
for (object_index, object) in objects.iter().enumerate() {
let key_with_padding: Image = object.select_from_color_and_image(255, input)?;
let key: Image = key_with_padding.trim_color(255)?;
if let Some(item) = object_histogram.get_mut(&key) {
item.count += 1;
item.object_indexes.push(object_index);
} else {
let item = Item {
count: 1,
object_indexes: vec![object_index]
};
object_histogram.insert(key, item);
}
}
// println!("object_histogram: {:?}", object_histogram);
let mut found_item: Option<&Item> = None;
let mut ambiguity_count: usize = 0;
for (_key, value) in &object_histogram {
if value.count == 1 {
found_item = Some(value);
ambiguity_count += 1;
}
}
if ambiguity_count > 1 {
return Err(anyhow::anyhow!("Found multiple objects that occur once. Ambiguous which one to pick"));
}
let item: &Item = match found_item {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Didn't find any object that occur exactly once."));
}
};
// println!("found: {:?}", item);
let object_index: usize = match item.object_indexes.first() {
Some(value) => *value,
None => {
return Err(anyhow::anyhow!("There is supposed to be exactly 1 object_index, but got none."));
}
};
let object_mask: Image = match objects.get(object_index) {
Some(value) => value.clone(),
None => {
return Err(anyhow::anyhow!("Unable to lookup the object_index between the objects."));
}
};
let crop_rect: Rectangle = match object_mask.bounding_box() {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("Cannot determine crop_rect for mask"));
}
};
let result_image = input.crop(crop_rect)?;
Ok(result_image)
}
}
#[derive(Debug)]
struct Item {
count: usize,
object_indexes: Vec<usize>,
}
}
#[test]
fn test_780000_puzzle_cd3c21df() {
let mut instance = solve_cd3c21df::MySolution {};
let result: String = run_analyze_and_solve("cd3c21df", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod solve_45737921 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("missing enumerated_object"));
}
};
let result_image: Image = ReverseColorPopularity::apply_to_objects(&input, enumerated_objects)?;
Ok(result_image)
}
}
}
#[test]
fn test_790000_puzzle_45737921() {
let mut instance = solve_45737921::MySolution {};
let result: String = run_analyze_and_solve("45737921", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_45737921: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,110 ; address of vector[0].EnumeratedObjects
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; enumerated objects
f21 $0,102171 ; Takes 2 parameters: Image, EnumeratedObjects. Reorder the color palette, so that the `most popular color` changes place with the `least popular color`
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_790001_puzzle_45737921_loda() {
let result: String = run_advanced("45737921", PROGRAM_45737921).expect("String");
assert_eq!(result, "3 1");
}
mod solve_6e82a1ae {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("missing enumerated_object"));
}
};
let oam: ObjectsAndMass = ObjectsAndMass::new(enumerated_objects)?;
let result_image: Image = oam.group3_small_medium_big(false)?;
Ok(result_image)
}
}
}
#[test]
fn test_800000_puzzle_6e82a1ae() {
let mut instance = solve_6e82a1ae::MySolution {};
let result: String = run_analyze_and_solve("6e82a1ae", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_6E82A1AE: &'static str = "
mov $80,$99
mov $81,110 ; address of vector[0].EnumeratedObjects
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; enumerated objects
mov $1,0 ; reverse = false
f21 $0,104200 ; Group the objects into 3 bins based on mass: small=1, medium=2, big=3.
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_800001_puzzle_6e82a1ae_loda() {
let result: String = run_advanced("6e82a1ae", PROGRAM_6E82A1AE).expect("String");
assert_eq!(result, "3 1");
}
mod solve_d2abd087 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let enumerated_objects: &Image = match &pair.input.enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("missing enumerated_object"));
}
};
let oam: ObjectsAndMass = ObjectsAndMass::new(enumerated_objects)?;
let result_image: Image = oam.group2_mass_different(6, false)?;
Ok(result_image)
}
}
}
#[test]
fn test_810000_puzzle_d2abd087() {
let mut instance = solve_d2abd087::MySolution {};
let result: String = run_analyze_and_solve("d2abd087", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_D2ABD087: &'static str = "
mov $80,$99
mov $81,110 ; address of vector[0].EnumeratedObjects
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; enumerated objects
mov $1,6 ; objects with 'mass = 6'
mov $2,0 ; reverse = false
f31 $0,104201 ; Group the objects into 2 bins based on mass: objects that has the matching mass=1, objects that have a different mass=2.
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_810000_puzzle_d2abd087_loda() {
let result: String = run_advanced("d2abd087", PROGRAM_D2ABD087).expect("String");
assert_eq!(result, "3 1");
}
mod solve_d631b094 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let image: &Image = match &pair.input.predicted_single_color_image {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("missing enumerated_object"));
}
};
let result_image: Image = image.clone();
Ok(result_image)
}
}
}
#[test]
fn test_820000_puzzle_d631b094() {
let mut instance = solve_d631b094::MySolution {};
let result: String = run_analyze_and_solve("d631b094", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
mod solve_810b9b61 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = input.most_popular_color().expect("color");
let background_ignore_mask: Image = input.to_mask_where_color_is(background_color);
// Objects that is not the background
let object_mask_vec: Vec<Image> = ConnectedComponent::find_objects_with_ignore_mask(PixelConnectivity::Connectivity8, &input, &background_ignore_mask)?;
let mut result_image: Image = Image::zero(input.width(), input.height());
for object in &object_mask_vec {
let rect: Rectangle = object.bounding_box().expect("some");
// flood fill at every border pixel around the object
let mut object_image: Image = object.crop(rect)?;
object_image.border_flood_fill(0, 1, PixelConnectivity::Connectivity4);
// if there are unfilled areas, then it's because there is one or more holes
let count: u16 = object_image.mask_count_zero();
if count > 0 {
// object with one or more holes
result_image = object.select_from_image_and_color(&result_image, 1)?;
} else {
// object without any holes
result_image = object.select_from_image_and_color(&result_image, 2)?;
}
}
Ok(result_image)
}
}
}
#[test]
fn test_830000_puzzle_810b9b61() {
let mut instance = solve_810b9b61::MySolution {};
let result: String = run_analyze_and_solve("810b9b61", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod solve_56ff96f3 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_most_popular_color.expect("color");
let result_image: Image = input.draw_rect_filled_foreach_color(background_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_840000_puzzle_56ff96f3() {
let mut instance = solve_56ff96f3::MySolution {};
let result: String = run_analyze_and_solve("56ff96f3", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_56FF96F3: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; background color
f21 $0,102250 ; Draw non-overlapping filled rectangles over the bounding boxes of each color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_840001_puzzle_56ff96f3_loda() {
let result: String = run_advanced("56ff96f3", PROGRAM_56FF96F3).expect("String");
assert_eq!(result, "4 1");
}
mod solve_7e0986d6 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_most_popular_color.expect("color");
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let result_image = input.denoise_type4(noise_color, background_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_850000_puzzle_7e0986d6() {
let mut instance = solve_7e0986d6::MySolution {};
let result: String = run_analyze_and_solve("7e0986d6", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_7E0986D6: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
mov $84,115 ; address of vector[0].InputSinglePixelNoiseColor
lps $80
mov $0,$$81 ; input image
mov $1,$$84 ; noise color
mov $2,$$83 ; background color
f31 $0,101093 ; Denoise type4. denoise noisy pixels.
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_850001_puzzle_7e0986d6_loda() {
let result: String = run_advanced("7e0986d6", PROGRAM_7E0986D6).expect("String");
assert_eq!(result, "2 1");
}
mod solve_ded97339 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mut result_image: Image = input.clone();
_ = result_image.draw_line_connecting_two_colors(noise_color, noise_color, noise_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_860000_puzzle_ded97339() {
let mut instance = solve_ded97339::MySolution {};
let result: String = run_analyze_and_solve("ded97339", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_DED97339: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,115 ; address of vector[0].InputSinglePixelNoiseColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; color0 = noise color
mov $2,$1 ; color1 = noise color
mov $3,$1 ; line_color = noise color
f41 $0,102210 ; Draw lines between the `color0` pixels and `color1` pixels when both occur in the same column/row.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_860001_puzzle_ded97339_loda() {
let result: String = run_advanced("ded97339", PROGRAM_DED97339).expect("String");
assert_eq!(result, "3 1");
}
mod solve_f5b8619d {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mask: Image = input.to_mask_where_color_is(noise_color);
let mut result_image: Image = input.clone();
_ = result_image.draw_line_column_where_mask_is_nonzero(&mask, 42)?;
result_image = mask.select_from_images(&result_image, input)?;
result_image = result_image.repeat_by_count(2, 2)?;
Ok(result_image)
}
}
}
#[test]
fn test_870000_puzzle_f5b8619d() {
let mut instance = solve_f5b8619d::MySolution {};
let result: String = run_analyze_and_solve("f5b8619d", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_F5B8619D: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,115 ; address of vector[0].InputSinglePixelNoiseColor
lps $80
mov $0,$$81 ; input image
mov $8,$0
mov $9,$$83 ; noise color
f21 $8,101250 ; Convert to a mask image by converting `color` to 1 and converting anything else to to 0.
; $8 is now the mask
mov $10,$0 ; image
mov $11,$8 ; mask
mov $12,42 ; line color
f31 $10,102222 ; Draw a vertical line if the `mask` contains one or more non-zero pixels.
; $10 is now the columns image
mov $13,$8 ; mask
mov $14,$10 ; the columns image
mov $15,$0 ; input image
f31 $13,102132 ; Pick pixels from two images. When the mask is 0 then pick `image_a`. When the mask is [1..255] then pick from `image_b`.
mov $0,$13
mov $1,2
mov $2,2
f31 $0,102120 ; repeat image
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_870001_puzzle_f5b8619d_loda() {
let result: String = run_advanced("f5b8619d", PROGRAM_F5B8619D).expect("String");
assert_eq!(result, "3 1");
}
mod solve_af902bf9 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mut a: Image = input.to_mask_where_color_is(noise_color);
_ = a.draw_line_connecting_two_colors(1, 1, 2)?;
_ = a.draw_line_connecting_two_colors(2, 2, 3)?;
let b: Image = a.to_mask_where_color_is(3);
let c: Image = b.select_from_image_and_color(&input, 255)?;
Ok(c)
}
}
}
#[test]
fn test_880000_puzzle_af902bf9() {
let mut instance = solve_af902bf9::MySolution {};
let result: String = run_analyze_and_solve("af902bf9", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_AF902BF9: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,115 ; address of vector[0].InputSinglePixelNoiseColor
lps $80
mov $0,$$81 ; input image
mov $1,$0
mov $2,$$83 ; noise color
f21 $1,101250 ; mask where color is noise color
; $1 = image
mov $2,1 ; color0 = 1
mov $3,1 ; color1 = 1
mov $4,2 ; line_color = 2
f41 $1,102210 ; Draw lines between the `color0` pixels and `color1` pixels when both occur in the same column/row.
; $1 = image
mov $2,2 ; color0 = 2
mov $3,2 ; color1 = 2
mov $4,3 ; line_color = 3
f41 $1,102210 ; Draw lines between the `color0` pixels and `color1` pixels when both occur in the same column/row.
mov $2,3
f21 $1,101250 ; mask where color is 3
mov $2,$0
mov $3,255
f31 $1,102131 ; Pick pixels from image and color. When the mask is 0 then pick from the image. When the mask is [1..255] then use the `default_color`.
mov $0,$1
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_880001_puzzle_af902bf9_loda() {
let result: String = run_advanced("af902bf9", PROGRAM_AF902BF9).expect("String");
assert_eq!(result, "3 1");
}
mod solve_2c608aff {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let mut found = false;
for action_label in &task.action_label_set_intersection {
match action_label {
ActionLabel::OutputImageIsInputImageWithChangesLimitedToPixelsWithMostPopularColorOfTheInputImage => {
found = true;
},
_ => {}
}
}
if !found {
return Err(anyhow::anyhow!("OutputImageIsInputImageWithChangesLimitedToPixelsWithMostPopularColorOfTheInputImage not found"));
}
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = input.most_popular_color().expect("color");
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mut histogram: Histogram = pair.input.image_meta.histogram_all.clone();
histogram.set_counter_to_zero(background_color);
histogram.set_counter_to_zero(noise_color);
if histogram.number_of_counters_greater_than_zero() != 1 {
return Err(anyhow::anyhow!("Expected exactly 1 color that is not background_color or noise_color"));
}
let sticky_color: u8 = histogram.most_popular_color_disallow_ambiguous().expect("color");
let mut result_image: Image = input.clone();
result_image.draw_line_connecting_two_colors(sticky_color, noise_color, noise_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_890000_puzzle_2c608aff() {
let mut instance = solve_2c608aff::MySolution {};
let result: String = run_analyze_and_solve("2c608aff", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
mod solve_21f83797 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let mut found = false;
for action_label in &task.action_label_set_intersection {
match action_label {
ActionLabel::OutputImageIsInputImageWithChangesLimitedToPixelsWithMostPopularColorOfTheInputImage => {
found = true;
},
_ => {}
}
}
if !found {
return Err(anyhow::anyhow!("OutputImageIsInputImageWithChangesLimitedToPixelsWithMostPopularColorOfTheInputImage not found"));
}
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let mask: Image = input.to_mask_where_color_is(noise_color);
let single_color_objects: &SingleColorObject = pair.input.image_meta.single_color_object.as_ref().expect("some");
let mut result_image: Image = input.clone();
for object in &single_color_objects.sparse_vec {
if object.color != noise_color {
continue;
}
result_image = result_image.draw_rect_filled(object.bounding_box, 42)?;
}
result_image.draw_line_where_mask_is_nonzero(&mask, noise_color)?;
Ok(result_image)
}
}
}
#[test]
fn test_900000_puzzle_21f83797() {
let mut instance = solve_21f83797::MySolution {};
let result: String = run_analyze_and_solve("21f83797", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
mod solve_1e0a9b12 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_histogram_intersection.most_popular_color_disallow_ambiguous().expect("color");
let result_image: Image = input.gravity(background_color, GravityDirection::Down)?;
Ok(result_image)
}
}
}
#[test]
fn test_910000_puzzle_1e0a9b12() {
let mut instance = solve_1e0a9b12::MySolution {};
let result: String = run_analyze_and_solve("1e0a9b12", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_1E0A9B12: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; most popular color across inputs
f21 $0,102191 ; Gravity in the down direction
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_910001_puzzle_1e0a9b12_loda() {
let result: String = run_advanced("1e0a9b12", PROGRAM_1E0A9B12).expect("String");
assert_eq!(result, "3 1");
}
mod solve_beb8660c {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_most_popular_color.expect("color");
let image_with_gravity: Image = input.gravity(background_color, GravityDirection::Right)?;
let result_image: Image = image_with_gravity.sort_by_mass(background_color, ImageSortMode::RowsAscending)?;
Ok(result_image)
}
}
}
#[test]
fn test_920000_puzzle_beb8660c() {
let mut instance = solve_beb8660c::MySolution {};
let result: String = run_analyze_and_solve("beb8660c", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_BEB8660C: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; most popular color across inputs
f21 $0,102193 ; Gravity in the right direction
; $1 holds the most popular color across inputs
f21 $0,102200 ; Sort rows-ascending by color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_920001_puzzle_beb8660c_loda() {
let result: String = run_advanced("beb8660c", PROGRAM_BEB8660C).expect("String");
assert_eq!(result, "3 1");
}
mod solve_d5d6de2d {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_histogram_intersection.most_popular_color_disallow_ambiguous().expect("color");
let single_color_objects: &SingleColorObject = pair.input.image_meta.single_color_object.as_ref().expect("some");
let mut result_image: Image = Image::zero(input.width(), input.height());
for object in &single_color_objects.sparse_vec {
if object.color == background_color {
continue;
}
let container: &SingleColorObjectClusterContainer = match &object.container4 {
Some(value) => value,
None => {
continue;
}
};
result_image = container.holes_mask_uncropped.clone();
}
Ok(result_image)
}
}
}
#[test]
fn test_930000_puzzle_d5d6de2d() {
let mut instance = solve_d5d6de2d::MySolution {};
let result: String = run_analyze_and_solve("d5d6de2d", &mut instance).expect("String");
assert_eq!(result, "3 2");
}
mod solve_84db8fc4 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let color: u8 = pair.input.removal_color.expect("color");
let mut result_image: Image = input.clone();
result_image.border_flood_fill(color, 255, PixelConnectivity::Connectivity4);
Ok(result_image)
}
}
}
#[test]
fn test_940000_puzzle_84db8fc4() {
let mut instance = solve_84db8fc4::MySolution {};
let result: String = run_analyze_and_solve("84db8fc4", &mut instance).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_84DB8FC4: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,113 ; address of vector[0].RemovalColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; set source color = removal color
mov $2,42 ; set destination color to 42
f31 $0,102180 ; Flood fill at every pixel along the border, connectivity-4.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_940001_puzzle_84db8fc4_loda() {
let result: String = run_advanced("84db8fc4", PROGRAM_84DB8FC4).expect("String");
assert_eq!(result, "4 1");
}
mod solve_e7639916 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let mut found = false;
for action_label in &task.action_label_set_intersection {
match action_label {
ActionLabel::OutputImageIsInputImageWithChangesLimitedToPixelsWithMostPopularColorOfTheInputImage => {
found = true;
},
_ => {}
}
}
if !found {
return Err(anyhow::anyhow!("OutputImageIsInputImageWithChangesLimitedToPixelsWithMostPopularColorOfTheInputImage not found"));
}
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let noise_color: u8 = pair.input.single_pixel_noise_color.expect("some");
let single_color_objects: &SingleColorObject = pair.input.image_meta.single_color_object.as_ref().expect("some");
let mut result_image: Image = input.clone();
for object in &single_color_objects.sparse_vec {
if object.color != noise_color {
continue;
}
let rect: Rectangle = object.bounding_box;
result_image = result_image.draw_rect_border(rect.min_x(), rect.min_y(), rect.max_x(), rect.max_y(), 42)?;
result_image = object.mask_uncropped.select_from_image_and_color(&result_image, object.color)?;
}
Ok(result_image)
}
}
}
#[test]
fn test_960000_puzzle_e7639916() {
let mut instance = solve_e7639916::MySolution {};
let result: String = run_analyze_and_solve("e7639916", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod solve_e0fb7511 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let mut found = false;
for action_label in &task.action_label_set_intersection {
match action_label {
ActionLabel::OutputImageHasSameStructureAsInputImage => {
found = true;
},
_ => {}
}
}
if !found {
return Err(anyhow::anyhow!("OutputImageHasSameStructureAsInputImage not found"));
}
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let single_color_objects: &SingleColorObject = pair.input.image_meta.single_color_object.as_ref().expect("some");
// Histogram of the isolated pixels
let mut isolated_pixels: Image = input.count_duplicate_pixels_in_neighbours()?;
isolated_pixels = isolated_pixels.to_mask_where_color_is(1);
let histogram: Histogram = input.histogram_with_mask(&isolated_pixels)?;
// println!("histogram: {:?}", histogram.pairs_descending());
let noise_color: u8 = histogram.most_popular_color_disallow_ambiguous().expect("color");
let mut result_image: Image = input.clone();
for object in &single_color_objects.sparse_vec {
if object.color != noise_color {
continue;
}
let container: &SingleColorObjectClusterContainer = match &object.container4 {
Some(value) => value,
None => {
continue;
}
};
let mut enumerated_objects: Image = container.enumerated_clusters_uncropped.clone();
for cluster in &container.cluster_vec {
if cluster.mass_cluster <= 1 {
continue;
}
if cluster.cluster_id > (u8::MAX as usize) {
continue;
}
let source_color: u8 = cluster.cluster_id as u8;
enumerated_objects = enumerated_objects.replace_color(source_color, 0)?;
}
let mask: Image = enumerated_objects.to_mask_where_color_is_different(0);
result_image = mask.select_from_image_and_color(&result_image, 42)?;
}
Ok(result_image)
}
}
}
#[test]
fn test_970000_puzzle_e0fb7511() {
let mut instance = solve_e0fb7511::MySolution {};
let result: String = run_analyze_and_solve("e0fb7511", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
mod solve_62ab2642 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let mut found = false;
for action_label in &task.action_label_set_intersection {
match action_label {
ActionLabel::OutputImageHasSameStructureAsInputImage => {
found = true;
},
_ => {}
}
}
if !found {
return Err(anyhow::anyhow!("OutputImageHasSameStructureAsInputImage not found"));
}
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let background_color: u8 = task.input_histogram_intersection.most_popular_color_disallow_ambiguous().expect("color");
let single_color_objects: &SingleColorObject = pair.input.image_meta.single_color_object.as_ref().expect("some");
let mut result_image: Image = input.clone();
for object in &single_color_objects.sparse_vec {
if object.color != background_color {
continue;
}
let container: &SingleColorObjectClusterContainer = match &object.container4 {
Some(value) => value,
None => {
continue;
}
};
let oam: ObjectsAndMass = ObjectsAndMass::new(&container.enumerated_clusters_uncropped)?;
let enumerated_by_mass: Image = oam.group3_small_medium_big(false)?;
result_image = result_image.mix(&enumerated_by_mass, MixMode::Plus)?;
}
Ok(result_image)
}
}
}
#[test]
fn test_980000_puzzle_62ab2642() {
let mut instance = solve_62ab2642::MySolution {};
let result: String = run_analyze_and_solve("62ab2642", &mut instance).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_3906DE3D: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $1,$$83 ; most popular color across inputs
f21 $0,102190 ; Gravity in the up direction
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_990000_puzzle_3906de3d_loda() {
let result: String = run_advanced("3906de3d", PROGRAM_3906DE3D).expect("String");
assert_eq!(result, "3 1");
}
#[test]
fn test_1000000_puzzle_75b8110e_loda() {
let result: String = run_advanced("75b8110e", PROGRAM_EA9794B1).expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_CCE03E0D: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
; tile_width
mov $2,$0
f11 $2,101000 ; Get width of image
; tile_height
mov $3,$0
f11 $3,101001 ; Get height of image
; tile
mov $7,$20 ; color
mov $6,$3 ; height
mov $5,$2 ; width
f31 $5,101010 ; Create new image with size (x, y) and filled with color z
; mask
mov $10,$0 ; image
mov $11,2 ; color
f21 $10,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
mov $11,$0 ; tile0
mov $12,$5 ; tile1
f31 $10,102110 ; Create a big composition of tiles.
mov $0,$10
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1010000_puzzle_cce03e0d_loda() {
let result: String = run_advanced("cce03e0d", PROGRAM_CCE03E0D).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_8D5021E8: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; input image
mov $1,$0
f11 $0,101190 ; flip x
f21 $0,101030 ; hstack
mov $1,$0
f11 $0,101191 ; flip y
mov $2,$0
f31 $0,101040 ; vstack
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_1020000_puzzle_8d5021e8_loda() {
let result: String = run_advanced("8d5021e8", PROGRAM_8D5021E8).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_6A11F6DA: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $20,$$83 ; most popular color across inputs
mov $10,$$81 ; input image
mov $11,0 ; no spacing
f23 $10,102261 ; split into 3 rows
; $10..$12 are the 3 columns
mov $0,$20 ; transparent color
mov $1,$11 ; layer 0 lowest layer
mov $2,$10 ; layer 1
mov $3,$12 ; layer 2 top
f41 $0,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1030000_puzzle_6a11f6da_loda() {
let result: String = run_advanced("6a11f6da", PROGRAM_6A11F6DA).expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_6F473927: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
; determine if the image needs to be flipped
mov $8,$0
mov $9,1
f21 $8,101222 ; get N left columns
mov $9,$20 ; most popular color
f21 $8,101250 ; Convert to a mask image by converting `color` to 1 and converting anything else to to 0.
f11 $8,101243 ; number of zeroes in image
mod $8,2
; $8 is 1 when the input image has its content on the right side, and needs flipping. Otherwise it's 0.
mov $9,$8
; flip the input image so it's content is on the right side
lps $8
f11 $0,101190 ; flip x
lpe
mov $1,$0
f11 $1,101190 ; flip x
f21 $1,101250 ; Convert to a mask image by converting `color` to 1 and converting anything else to to 0.
f21 $0,101030 ; hstack
; restore the x axis
lps $9
f11 $0,101190 ; flip x
lpe
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1040000_puzzle_6f473927_loda() {
let result: String = run_advanced("6f473927", PROGRAM_6F473927).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_C48954C1: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; input image
mov $1,1
mov $2,1
mov $3,1
mov $4,1
f51 $0,102122 ; Make a big image by repeating the current image and doing flip x, flip y, flip xy.
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_1050000_puzzle_c48954c1_loda() {
let result: String = run_advanced("c48954c1", PROGRAM_C48954C1).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_281123B4: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
mov $1,1 ; spacing is 1 pixel
f24 $0,102260 ; split into 4 columns
; $0..$3 are the 4 columns
mov $10,$20 ; transparent color
mov $11,$1 ; layer 0 lowest layer
mov $12,$0 ; layer 1
mov $13,$3 ; layer 2
mov $14,$2 ; layer 3 top
f51 $10,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $0,$10
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1060000_puzzle_281123b4_loda() {
let result: String = run_advanced("281123b4", PROGRAM_281123B4).expect("String");
assert_eq!(result, "6 1");
}
const PROGRAM_3D31C5B3: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $20,$$83 ; most popular color across inputs
mov $10,$$81 ; input image
mov $11,0 ; no spacing
f24 $10,102261 ; split into 4 rows
; $10..$13 are the 4 rows
mov $0,$20 ; transparent color
mov $1,$12 ; layer 0 lowest layer
mov $2,$13 ; layer 1
mov $3,$11 ; layer 2
mov $4,$10 ; layer 3 top
f51 $0,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1070000_puzzle_3d31c5b3_loda() {
let result: String = run_advanced("3d31c5b3", PROGRAM_3D31C5B3).expect("String");
assert_eq!(result, "6 1");
}
const PROGRAM_E99362F0: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $20,$$83 ; most popular color across inputs
mov $21,1 ; pixel spacing = 1
mov $10,$$81 ; input image
mov $11,$21 ; spacing
f22 $10,102261 ; split into 2 rows
; $10..$11 are the 2 rows
mov $15,$10
mov $16,$21 ; spacing
f22 $15,102260 ; split into 2 columns
; $15..$16 are the 2 columns
mov $17,$11
mov $18,$21 ; spacing
f22 $17,102260 ; split into 2 columns
; $17..$18 are the 2 columns
; $15 = cell top left
; $16 = cell top right
; $17 = cell bottom left
; $18 = cell bottom right
mov $0,$20 ; transparent color
mov $1,$17 ; layer 0 lowest layer
mov $2,$16 ; layer 1
mov $3,$15 ; layer 2
mov $4,$18 ; layer 3 top
f51 $0,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1080000_puzzle_e99362f0_loda() {
let result: String = run_advanced("e99362f0", PROGRAM_E99362F0).expect("String");
assert_eq!(result, "6 1");
}
const PROGRAM_BC4146BD: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; input image
mov $1,0
mov $2,0
mov $3,0
mov $4,4 ; grow right 4 times
f51 $0,102122 ; repeat symmetry
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_1090000_puzzle_bc4146bd_loda() {
let result: String = run_advanced("bc4146bd", PROGRAM_BC4146BD).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_8E2EDD66: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
; tile_width
mov $2,$0
f11 $2,101000 ; Get width of image
; tile_height
mov $3,$0
f11 $3,101001 ; Get height of image
; tile0
mov $7,$20 ; color
mov $6,$3 ; height
mov $5,$2 ; width
f31 $5,101010 ; Create new image with size (x, y) and filled with color z
; mask
mov $10,$0 ; image
mov $11,$20 ; color
f21 $10,101250 ; Convert to a mask image by converting `color` to 1 and converting anything else to to 0.
; tile1
f11 $0,102170 ; Reorder the color palette, so that the `most popular color` changes place with the `least popular color`
mov $11,$5 ; tile0
mov $12,$0 ; tile1
f31 $10,102110 ; Create a big composition of tiles.
mov $0,$10
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1100000_puzzle_8e2edd66_loda() {
let result: String = run_advanced("8e2edd66", PROGRAM_8E2EDD66).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_A59B95C0: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; input image
mov $1,$0
f11 $1,101240 ; Number of unique colors in image.
mov $2,$1
f31 $0,102120 ; Repeat image by the number of unique colors in image.
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_1110000_puzzle_a59b95c0_loda() {
let result: String = run_advanced("a59b95c0", PROGRAM_A59B95C0).expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_0692E18C: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
; tile_width
mov $2,$0
f11 $2,101000 ; Get width of image
; tile_height
mov $3,$0
f11 $3,101001 ; Get height of image
; tile0
mov $7,$20 ; color
mov $6,$3 ; height
mov $5,$2 ; width
f31 $5,101010 ; Create new image with size (x, y) and filled with color z
; mask
mov $10,$0 ; image
mov $11,$20 ; color
f21 $10,101251 ; Convert to a mask image by converting `color` to 0 and converting anything else to to 1.
; tile1
f11 $0,102170 ; Reorder the color palette, so that the `most popular color` changes place with the `least popular color`
mov $11,$5 ; tile0
mov $12,$0 ; tile1
f31 $10,102110 ; Create a big composition of tiles.
mov $0,$10
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1120000_puzzle_0692e18c_loda() {
let result: String = run_advanced("0692e18c", PROGRAM_0692E18C).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_48131B3C: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $0,$$81 ; input image
f11 $0,102170 ; Reorder the color palette, so that the `most popular color` changes place with the `least popular color`
mov $1,2
mov $2,2
f31 $0,102120 ; Repeat image
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_1130000_puzzle_48131b3c_loda() {
let result: String = run_advanced("48131b3c", PROGRAM_48131B3C).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_D037B0A7: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
; Construct ignore_mask based on the most popular color
mov $1,$0
mov $2,$20
f21 $1,101250 ; Convert to a mask image by converting `color` to 1 and converting anything else to to 0.
; $1 is the pixels to be ignored
; determine the nearest color in the direction 'up'
mov $3,$0
mov $4,$1 ; ignore mask
mov $5,$20 ; color_when_there_is_no_neighbour
f31 $3,102060 ; color of nearest neighbour pixel 'up'
; $3 is an image of the nearest color in the direction 'up'
; combine images based on the ignore mask
mov $6,$1
mov $7,$0
mov $8,$3
f31 $6,102132 ; Pick pixels from two images. When the mask is 0 then pick `image_a`. When the mask is [1..255] then pick from `image_b`.
; $6 is a combination of the original image and the nearest color in the direction 'up'
mov $0,$6
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1140000_puzzle_d037b0a7_loda() {
let result: String = run_advanced("d037b0a7", PROGRAM_D037B0A7).expect("String");
assert_eq!(result, "3 1");
}
const PROGRAM_EA9794B1: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
mov $21,0 ; pixel spacing = 0
mov $10,$$81 ; input image
mov $11,$21 ; spacing
f22 $10,102261 ; split into 2 rows
; $10..$11 are the 2 rows
mov $15,$10
mov $16,$21 ; spacing
f22 $15,102260 ; split into 2 columns
; $15..$16 are the 2 columns
mov $17,$11
mov $18,$21 ; spacing
f22 $17,102260 ; split into 2 columns
; $17..$18 are the 2 columns
; $15 = cell top left
; $16 = cell top right
; $17 = cell bottom left
; $18 = cell bottom right
mov $0,$20 ; transparent color
mov $1,$15 ; layer 0 lowest layer
mov $2,$18 ; layer 1
mov $3,$17 ; layer 2
mov $4,$16 ; layer 3 top
f51 $0,101152 ; Z-stack images: Overlay multiple images using a transparency color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1150000_puzzle_ea9794b1_loda() {
let result: String = run_advanced("ea9794b1", PROGRAM_EA9794B1).expect("String");
assert_eq!(result, "6 1");
}
const PROGRAM_23581191: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $0,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
mov $1,$0
mov $2,$20
f21 $1,101251 ; where color is different than the most popular color
mov $1,$1 ; mask
mov $2,255 ; overlap color
f31 $0,102223 ; Shoot out lines in all directions where mask is non-zero. Preserving the color.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1160000_puzzle_23581191_loda() {
let result: String = run_advanced("23581191", PROGRAM_23581191).expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_BA26E723: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $10,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
mov $15,$10
mov $16,$20
f21 $15,101250 ; where color is the most popular color
; $15 = mask where the pixels have the same value as the most popular color
mov $0,$10
f11 $0,101000 ; width of image
mov $1,$10
f11 $1,101001 ; height of image
; $0 = width
; $1 = height
mov $2,1 ; color0
mov $3,1 ; count0
mov $4,0 ; color1
mov $5,2 ; count1
f61 $0,101260 ; Alternating columns with two colors
mov $1,$15
f21 $0,101255 ; boolean AND
; $0 = intersection of the most popular color pixels with the alternating columns
mov $1,$10
mov $2,255
f31 $0,102131 ; Pick pixels from image and color. When the mask is 0 then pick from the image. When the mask is [1..255] then use the `default_color`.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1170000_puzzle_ba26e723_loda() {
let result: String = run_advanced("ba26e723", PROGRAM_BA26E723).expect("String");
assert_eq!(result, "5 1");
}
const PROGRAM_D406998B: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $10,$$81 ; input image
mov $20,$$83 ; most popular color across inputs
mov $15,$10
mov $16,$20
f21 $15,101251 ; where color is different than the most popular color
; $15 = mask
mov $0,$10
f11 $0,101000 ; width of image
mov $1,$10
f11 $1,101001 ; height of image
; $0 = width
; $1 = height
mov $2,1 ; color0
mov $3,1 ; count0
mov $4,0 ; color1
mov $5,1 ; count1
f61 $0,101260 ; Alternating columns with two colors
; $0 = stripes that starts from the left edge
f11 $0,101190 ; flip x
; $0 = stripes that starts from the right edge
mov $1,$15
f21 $0,101255 ; boolean AND
; $0 = intersection of the mask with the alternating columns
mov $1,$10
mov $2,255
f31 $0,102131 ; Pick pixels from image and color. When the mask is 0 then pick from the image. When the mask is [1..255] then use the `default_color`.
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1180000_puzzle_d406998b_loda() {
let result: String = run_advanced("d406998b", PROGRAM_D406998B).expect("String");
assert_eq!(result, "4 1");
}
const PROGRAM_E9AFCF9A: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
lps $80
mov $10,$$81 ; input image
f11 $10,102206 ; sort columns by pixel value
mov $11,$10
f11 $11,101191 ; flip y
mov $0,$10
f11 $0,101000 ; width of image
mov $1,$10
f11 $1,101001 ; height of image
; $0 = width
; $1 = height
mov $2,1 ; color0
mov $3,1 ; count0
mov $4,0 ; color1
mov $5,1 ; count1
f61 $0,101260 ; Alternating columns with two colors
; $0 = stripes that starts from the left edge
mov $1,$10
mov $2,$11
f31 $0,102132 ; Pick pixels from two images. When the mask is 0 then pick `image_a`. When the mask is [1..255] then pick from `image_b`.
mov $$82,$0
add $81,100
add $82,100
lpe
";
#[test]
fn test_1190000_puzzle_e9afcf9a_loda() {
let result: String = run_advanced("e9afcf9a", PROGRAM_E9AFCF9A).expect("String");
assert_eq!(result, "2 1");
}
mod solve_6a1e5592 {
use super::*;
pub struct MySolution;
impl AnalyzeAndSolve for MySolution {
fn solve(&self, data: &SolutionSimpleData, task: &arc_work_model::Task) -> anyhow::Result<Image> {
let pair: &arc_work_model::Pair = &task.pairs[data.index];
let input: &Image = &pair.input.image;
let single_color_objects: &SingleColorObject = pair.input.image_meta.single_color_object.as_ref().expect("some");
let mut found_enumerated_objects: Option<Image> = None;
for object in &single_color_objects.sparse_vec {
if object.color != Color::Grey as u8 {
continue;
}
let container: &SingleColorObjectClusterContainer = match &object.container4 {
Some(value) => value,
None => {
continue;
}
};
found_enumerated_objects = Some(container.enumerated_clusters_uncropped.clone());
break;
}
let enumerated_objects: Image = match found_enumerated_objects {
Some(value) => value,
None => {
return Err(anyhow::anyhow!("No enumerated objects found"));
}
};
let solid_mask: Image = input.to_mask_where_color_is(Color::Red as u8);
let enumerated_objects_at_new_position: Image = ObjectsAndGravity::gravity(&enumerated_objects, &solid_mask, ObjectsAndGravityDirection::GravityUp)?;
let mut result_image = enumerated_objects_at_new_position.to_mask_where_color_is_different(0);
result_image = solid_mask.select_from_images(&result_image, &input)?;
Ok(result_image)
}
}
}
#[test]
fn test_1200000_puzzle_6a1e5592() {
let mut instance = solve_6a1e5592::MySolution {};
let result: String = run_analyze_and_solve("6a1e5592", &mut instance).expect("String");
assert_eq!(result, "2 1");
}
const PROGRAM_TOPBOTTOM2D7: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,110 ; address of vector[0].EnumeratedObjects
lps $80
mov $0,$$83 ; enumerated objects
f11 $0,104210 ; mask of top-most object
; $0 = mask of top-most object
mov $1,255 ; fill color
mov $2,$$81 ; input image
f31 $0,102130 ; Pick pixels from color and image. When the mask is 0 then pick the `default_color`. When the mask is [1..255] then pick from the image.
mov $1,255 ; the color to be trimmed
f21 $0,101161 ; trim with color
mov $$82,$0
add $81,100
add $82,100
add $83,100
lpe
";
#[test]
fn test_1210000_puzzle_topbottom2d7_loda() {
let result: String = run_advanced("TopBottom2D7", PROGRAM_TOPBOTTOM2D7).expect("String");
assert_eq!(result, "5 3");
}
const PROGRAM_TOPBOTTOM2D6: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,110 ; address of vector[0].EnumeratedObjects
mov $84,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $10,$$84 ; most popular color
mov $0,$$83 ; enumerated objects
f11 $0,104211 ; mask of bottom-most object
; $0 = mask of bottom-most object
mov $1,$10 ; fill color
mov $2,$$81 ; input image
f31 $0,102130 ; Pick pixels from color and image. When the mask is 0 then pick the `default_color`. When the mask is [1..255] then pick from the image.
mov $1,$10 ; the color to be trimmed
f21 $0,101161 ; trim with color
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_1220000_puzzle_topbottom2d6_loda() {
let result: String = run_advanced("TopBottom2D6", PROGRAM_TOPBOTTOM2D6).expect("String");
assert_eq!(result, "4 3");
}
const PROGRAM_EXTRACTOBJECTS1: &'static str = "
mov $80,$99
mov $81,100 ; address of vector[0].InputImage
mov $82,102 ; address of vector[0].ComputedOutputImage
mov $83,110 ; address of vector[0].EnumeratedObjects
mov $84,114 ; address of vector[0].InputMostPopularColor
lps $80
mov $10,$$84 ; most popular color
mov $0,$$83 ; enumerated objects
f11 $0,104202 ; Object ids of the biggest objects.
; $0 = mask of bottom-most object
mov $1,$10 ; fill color
mov $2,$$81 ; input image
f31 $0,102130 ; Pick pixels from color and image. When the mask is 0 then pick the `default_color`. When the mask is [1..255] then pick from the image.
mov $1,$10 ; the color to be trimmed
f21 $0,101161 ; trim with color
mov $$82,$0
add $81,100
add $82,100
add $83,100
add $84,100
lpe
";
#[test]
fn test_1230000_puzzle_extractobjects1_loda() {
let result: String = run_advanced("ExtractObjects1", PROGRAM_EXTRACTOBJECTS1).expect("String");
// There is a problem with the last `test` pair. Here the output has 2 foreground colors and a background color. 3 colors in total.
// All the output images have a single foreground color with an optional background color.
// The `enumerated_objects` contains a multi colored object.
// where the `enumerated_objects` should be enumerating the single colored objects.
assert_eq!(result.contains("3 2 - test"), true);
}
}
|