Saturday, October 30, 2004

Haskell GD linking example

Demonstration of linking the GD Graphics Library (in C) with some Haskell code, using the tool C->Haskell c2hs.
begin 644 haskell-gd.tar.bz2
M0EIH.3%!629368B6U`@``X5_TLZ0`)!\]__?/^_>RO__W_H`(`$`0```"%`$
MO=CF;F-3S9J-7IX))$U,T@4;4\IYIH%'B0;4/2-I#U-`--#30T\IY0"4IHQ2
M;4>U--JC]4]0]0``]0`-&@`````D2""3U3&"GI/4&GJ`VHTT````:```-J2G
MI">*>H!IY1H'J-```!Z@&@#30`>H))3*&(F>J,TC$T:&@``!HT````!0%-OT
M.ETT6,93%8NC,D\<S(30H0/9"%*R1NF[RC5JFEB2=K=(E8]0Y6P,E+-8E5):
M$FD)R7PWC^%U.L=SXK52<?OJZ/]<DZ(D2EVYXL)7/Q"P3[)5CAUP*@\@K8#T
MN^/+)%*L1F"MDPNORCKD/<;HS_<N^:H2%62T1F-H\>1+MZP[8RVZ6NE2;XT"
MK^S5"M#>/J;1<Y+:&M*0G=<9$N\,>*%,!>ZLU9!8O#'&C<Y;4F_,PL'N4T'&
MEN!9?GJD8_"B<0+X4%:HSB)1<K6/F'7I1;IR6[>6F28Q;._&O63<D;S2^##`
MY1"N&8SHYZT)#K$#E26@VM1<3+=P<;%LM'!1C;>T>58][)EP%Z&+?&+:3)45
M=5D)&L)E9O.I9HIQ(T@7.)_1CT9>3QJ,5IB*BD/L<<?;]*/5,XGL(E$E7TUG
MLGO>F$%&Z@HNN#"1<DN.5R`(`S%")<@,AJD;7K/15"KQ>S^QSK[AA4:"Q*VU
MW8DHJ1+V62=-9NHXETZM0UEMOE*^6%82L"W#8N2<TKG952FA42G.5$7-*KG$
M%*WW'MG]'>3J0JW3V"E+K*P32<Z1B-!XP@UFHD=P@P&P>9\@Y#I@/S*:^5+%
M<ZX;CJ(I62)A?\LW4^M[?TY\NE!V6JOBD04TGLTYLV'"6T9UMM'X*&O[7D6'
M>B&LN.WI<*!J/VQ<[$@W#-TRY#'*6B=W+P4-?X+UMSR4G,'2Y(H.,6)"L$4H
M)2#S,IU2Y:G&`WBW3%D@3I95[P?T:ARVB>E2+X0+:1?EI))KQ9A*1,L"G*J`
MN8YX[#Z340S"(D#F1*YE9+K)$FM5&K.!5#E1`E**%T(5ZJK5N^]G\>8;SWPY
MP54%3"JT40LR[A>3)UCD0/D,P]*M%:CG,LQ/GL`N-,,F&3,\<*F!C*1U]/+O
M`9##-.0)50J$*1,)0M?2JE%1BT[-*,&N3GLP\<,#E:+D[)K$">JB=;9@PC6N
MG]_?FEW2M?1%6N)5ZM<9M;.<S*Z4!26J%=SD]`7H+1>\%1FF+8HF2SD*.`51
M@G?&JE/84P\*9&0'(-=*JL$3(+BB+!7U$^NPZ:1BA*PP#$A@H>^J89O0)C\2
MM*-1A[XQ(0%,`Q?P![IF%,A,A)AT35"(;"&0,9>DR6C!YB-PD92A"SKI&!GY
MV$<A;10B5D5ZXA/6K/*E<+97400%<8M+&HT$JQE`X<K,`LY/`V2M4UO(5O!>
M4+E7O/F8D*TVS.;!@K2],1'B6",4"XVHHHK,%'3%42]NR3NDKS1J`R"5/J3)
MM22?XT@52EC&5@X@MF%1T&#7'&0.0F*MT$)#2JE"2<#N-)Q;#'C>D/U:,8Q@
M\"&Q&DIC))Q,61$28D5BD,6L]%6SH5R6`>*U+(*RI\.E3)6XY"(6M':0C_%W
))%.%"0B);4"`
`
end

haskell-gd

Friday, October 29, 2004

Verhoeff Digit Checksums

As mentioned in Numerical Recipes. Here are the checksummed 1- 2- and 3-digit numbers (more at the link above): 07 19 26 34 40 51 63 72 85 98 008 010 024 036 043 051 069 072 085 097 103 116 121 134 149 155 167 178 180 192 209 214 225 231 247 250 262 273 286 298 307 311 320 335 342 356 368 379 384 393 402 415 426 430 448 454 463 477 481 499 505 512 529 537 541 553 564 570 588 596 600 618 627 632 645 659 661 676 683 694 706 713 722 738 740 757 765 774 789 791 804 819 828 833 846 852 860 871 887 895 901 917 923 939 944 958 966 975 982 990 0003 0011 0025 0032 0040 0057 0069 0076 0084 0098 0104 0116 0127 0139 0148 0155 0162 0171 0183 0190 0206 0212 0229 0231 0244 0258 0265 0273 0280 0297 0305 0318 0323 0330 0342 0356 0364 0377 0389 0391 0409 0417 0426 0434 0441 0453 0460 0478 0485 0492 0508 0514 0520 0537 0545 0552 0566 0579 0581 0593 0600 0613 0628 0635 0647 0659 0661 0672 0686 0694 0707 0710 0724 0738 0749 0751 0763 0775 0782 0796 0802 0815 0821 0833 0846 0854 0868 0870 0887 0899 0901 0919 0922 0936 0943 0950 0967 0974 0988 0995 1009 1017 1026 1034 1041 1053 1060 1078 1085 1092 1105 1118 1123 1130 1142 1156 1164 1177 1189 1191 1208 1214 1220 1237 1245 1252 1266 1279 1281 1293 1306 1312 1329 1331 1344 1358 1365 1373 1380 1397 1400 1413 1428 1435 1447 1459 1461 1472 1486 1494 1502 1515 1521 1533 1546 1554 1568 1570 1587 1599 1601 1619 1622 1636 1643 1650 1667 1674 1688 1695 1703 1711 1725 1732 1740 1757 1769 1776 1784 1798 1804 1816 1827 1839 1848 1855 1862 1871 1883 1890 1907 1910 1924 1938 1949 1951 1963 1975 1982 1996 2000 2013 2028 2035 2047 2059 2061 2072 2086 2094 2106 2112 2129 2131 2144 2158 2165 2173 2180 2197 2202 2215 2221 2233 2246 2254 2268 2270 2287 2299 2308 2314 2320 2337 2345 2352 2366 2379 2381 2393 2401 2419 2422 2436 2443 2450 2467 2474 2488 2495 2504 2516 2527 2539 2548 2555 2562 2571 2583 2590 2607 2610 2624 2638 2649 2651 2663 2675 2682 2696 2709 2717 2726 2734 2741 2753 2760 2778 2785 2792 2805 2818 2823 2830 2842 2856 2864 2877 2889 2891 2903 2911 2925 2932 2940 2957 2969 2976 2984 2998 3001 3019 3022 3036 3043 3050 3067 3074 3088 3095 3108 3114 3120 3137 3145 3152 3166 3179 3181 3193 3204 3216 3227 3239 3248 3255 3262 3271 3283 3290 3302 3315 3321 3333 3346 3354 3368 3370 3387 3399 3407 3410 3424 3438 3449 3451 3463 3475 3482 3496 3505 3518 3523 3530 3542 3556 3564 3577 3589 3591 3603 3611 3625 3632 3640 3657 3669 3676 3684 3698 3700 3713 3728 3735 3747 3759 3761 3772 3786 3794 3806 3812 3829 3831 3844 3858 3865 3873 3880 3897 3909 3917 3926 3934 3941 3953 3960 3978 3985 3992 4007 4010 4024 4038 4049 4051 4063 4075 4082 4096 4102 4115 4121 4133 4146 4154 4168 4170 4187 4199 4205 4218 4223 4230 4242 4256 4264 4277 4289 4291 4304 4316 4327 4339 4348 4355 4362 4371 4383 4390 4403 4411 4425 4432 4440 4457 4469 4476 4484 4498 4506 4512 4529 4531 4544 4558 4565 4573 4580 4597 4609 4617 4626 4634 4641 4653 4660 4678 4685 4692 4701 4719 4722 4736 4743 4750 4767 4774 4788 4795 4808 4814 4820 4837 4845 4852 4866 4879 4881 4893 4900 4913 4928 4935 4947 4959 4961 4972 4986 4994 5002 5015 5021 5033 5046 5054 5068 5070 5087 5099 5107 5110 5124 5138 5149 5151 5163 5175 5182 5196 5200 5213 5228 5235 5247 5259 5261 5272 5286 5294 5301 5319 5322 5336 5343 5350 5367 5374 5388 5395 5408 5414 5420 5437 5445 5452 5466 5479 5481 5493 5509 5517 5526 5534 5541 5553 5560 5578 5585 5592 5606 5612 5629 5631 5644 5658 5665 5673 5680 5697 5704 5716 5727 5739 5748 5755 5762 5771 5783 5790 5803 5811 5825 5832 5840 5857 5869 5876 5884 5898 5905 5918 5923 5930 5942 5956 5964 5977 5989 5991 6004 6016 6027 6039 6048 6055 6062 6071 6083 6090 6103 6111 6125 6132 6140 6157 6169 6176 6184 6198 6201 6219 6222 6236 6243 6250 6267 6274 6288 6295 6307 6310 6324 6338 6349 6351 6363 6375 6382 6396 6402 6415 6421 6433 6446 6454 6468 6470 6487 6499 6500 6513 6528 6535 6547 6559 6561 6572 6586 6594 6608 6614 6620 6637 6645 6652 6666 6679 6681 6693 6705 6718 6723 6730 6742 6756 6764 6777 6789 6791 6809 6817 6826 6834 6841 6853 6860 6878 6885 6892 6906 6912 6929 6931 6944 6958 6965 6973 6980 6997 7005 7018 7023 7030 7042 7056 7064 7077 7089 7091 7109 7117 7126 7134 7141 7153 7160 7178 7185 7192 7207 7210 7224 7238 7249 7251 7263 7275 7282 7296 7303 7311 7325 7332 7340 7357 7369 7376 7384 7398 7404 7416 7427 7439 7448 7455 7462 7471 7483 7490 7501 7519 7522 7536 7543 7550 7567 7574 7588 7595 7602 7615 7621 7633 7646 7654 7668 7670 7687 7699 7706 7712 7729 7731 7744 7758 7765 7773 7780 7797 7800 7813 7828 7835 7847 7859 7861 7872 7886 7894 7908 7914 7920 7937 7945 7952 7966 7979 7981 7993 8006 8012 8029 8031 8044 8058 8065 8073 8080 8097 8100 8113 8128 8135 8147 8159 8161 8172 8186 8194 8203 8211 8225 8232 8240 8257 8269 8276 8284 8298 8309 8317 8326 8334 8341 8353 8360 8378 8385 8392 8405 8418 8423 8430 8442 8456 8464 8477 8489 8491 8507 8510 8524 8538 8549 8551 8563 8575 8582 8596 8604 8616 8627 8639 8648 8655 8662 8671 8683 8690 8708 8714 8720 8737 8745 8752 8766 8779 8781 8793 8801 8819 8822 8836 8843 8850 8867 8874 8888 8895 8902 8915 8921 8933 8946 8954 8968 8970 8987 8999 9008 9014 9020 9037 9045 9052 9066 9079 9081 9093 9101 9119 9122 9136 9143 9150 9167 9174 9188 9195 9209 9217 9226 9234 9241 9253 9260 9278 9285 9292 9300 9313 9328 9335 9347 9359 9361 9372 9386 9394 9406 9412 9429 9431 9444 9458 9465 9473 9480 9497 9503 9511 9525 9532 9540 9557 9569 9576 9584 9598 9605 9618 9623 9630 9642 9656 9664 9677 9689 9691 9702 9715 9721 9733 9746 9754 9768 9770 9787 9799 9807 9810 9824 9838 9849 9851 9863 9875 9882 9896 9904 9916 9927 9939 9948 9955 9962 9971 9983 9990

Monday, October 25, 2004

CVS on su

Every time you use the su command (or sudo) you can make a RCS-style comment entry of what you did with the privilege. A separate idea: whatever your system's ``control panel'' is has the ability to roll back changes to a previous version (and form branches and stuff, like CVS).

Between Spreadsheet and Database

There's some area in between Spreadsheet and Relational Database that would make a good software product: something a little more smart and elegant about multiple different Tables than a spreadsheet, and a little more smart and elegant about math than a database.

Thursday, October 21, 2004

Modular Exponentiation Permutations

Consider the seqence N[1]=1, N[i+1]=g^N[i] mod P, where P is a prime and g is a generator (primitive root). For what {P,g} do the sequence of N's repeat with the maximum period length P-1?

P versus NP

It's interesting that P=NP can be proved or disproved by a single example or counterexample in either direction. It can be disproved by finding a single counterexample of a problem that is NP but not P. By the magic of computability theory, it can also be proved by finding a single example of an NP-complete problem that can by solved in deterministic polynomial time.

I know of of no other hard, unsolved, problems that have this property. Usually the counterexample is ``easy'' but the proof is hard.

Furthermore, instead of explicitly finding an example or counterexample, one only needs to show existence. However, how frustrating will it be if someone proves the existence of an NP-complete problem solvable in poly-time without constructing an example?

Monday, October 11, 2004

Diffie-Hellman Challenge

Find the value of x, 1440<=x<M-1, which minimizes the value of y=(3^x % M), where % is the "modulo" or "take the remainder" operator, and M=2^2281-1. M is the 17th Mersenne prime. 3 is a primitive root of M. The value 1440 makes 3^x loop around and the modulo operation take effect, i.e., 3^1440>M. This could be solved once and for all by solving the discrete logarithm problem 3^x == 2 (mod M). If this challenge gets solved, or is too easy, then do the same thing with 3^x % M21701, where M21701=2^21701-1 is also a Mersenne prime. By some analysis I don't fully remember, I have reason to believe that 3 is probably a primitive root of M21701. (I think the reasoning was that if 3 is not primitive, it gets eliminated from consideration by some small factor of M-1, and the small factors of M21701 were tested.) And if that's still too easy, try the modulus P=5359*2^5054502+1, which is a prime number found by the Seventeen or Bust project. I don't know the least primitive root of P, but it should be pretty easy since P-1 factors trivially.

Update: Pohlig-Hellman makes this a bad idea.

Sunday, October 10, 2004

Substrings of decimal expansions

Consider the first occurrence of a substring in the decimal expansions of all fraction a/b with 2<=b and and 1<=a<b, with fractions first sorted by b then by a, that is, 1/2, 1/3, 2/3, 1/4, 2/4, 3/4, ... For example, the substring "435" first occurs in the expansion of 14/39=.35897435897. Among three digit substrings, the last to occur are 999: 999/1000 = 0.999... (001,499): 1/501 = .0019960079840319361277445109780439121756487025948103792415169660678642714570858283433133732534930139720558882235528942115768463073852295409181636726546906187624750499... and then 998 (499/500), 002 (1/334), 997 (333/334), 249 (3/253), 667 (4/253), 003 (1/251), 498 (1/251), 501 (1/251), 749 (1/251), 332 (83/250), 996 (249/250), 799 (163/204), 334 (1/203), 399 (1/203), 599 (121/202), 199 (1/201), 004 (1/201), 665 (133/200), 995 (199/200). The last few interesting ones where the substring doesn't occur immediately after the decimal point are 499 as given above, and 249: 3/253 = .0118577075098814229249 667: 4/253 = .01581027667 (501,498,749): 1/251 = .00398406374501992031872509960159362549800796812749 (334,399): 1/203 = .0049261083743842364532019704433497536945812807881773399 Another interesting one: 197: 7/71 = .09859154929577464788732394366197 Complete 2 digit results. The number in parentheses is the number of digits after the decimal point the substring occurs. 00:1/2(2), 01:1/51(1), 02:1/34(1), 03:1/26(1), 04:1/21(1), 05:1/17(1), 06:1/15(1), 07:1/13(1), 08:1/12(1), 09:1/11(1), 10:1/10(1), 11:1/9(1), 12:1/8(1), 13:2/15(1), 14:1/7(1), 15:2/13(1), 16:1/6(1), 17:1/17(12), 18:2/11(1), 19:1/21(5), 20:1/5(1), 21:3/14(1), 22:2/9(1), 23:1/13(5), 24:6/25(1), 25:1/4(1), 26:4/15(1), 27:3/11(1), 28:1/7(3), 29:1/17(8), 30:3/10(1), 31:5/16(1), 32:8/25(1), 33:1/3(1), 34:1/23(3), 35:5/14(1), 36:4/11(1), 37:3/8(1), 38:2/13(3), 39:1/23(19), 40:2/5(1), 41:5/12(1), 42:1/7(2), 43:7/16(1), 44:4/9(1), 45:5/11(1), 46:2/13(5), 47:1/17(15), 48:12/25(1), 49:1/51(15), 50:1/2(1), 51:5/27(3), 52:1/17(7), 53:2/13(2), 54:5/11(2), 55:5/9(1), 56:9/16(1), 57:1/7(5), 58:7/12(1), 59:13/22(1), 60:3/5(1), 61:2/13(6), 62:5/8(1), 63:4/11(2), 64:9/14(1), 65:13/20(1), 66:2/3(1), 67:19/28(1), 68:11/16(1), 69:1/13(3), 70:7/10(1), 71:1/7(6), 72:3/11(2), 73:11/15(1), 74:2/27(2), 75:3/4(1), 76:1/13(2), 77:7/9(1), 78:11/14(1), 79:19/24(1), 80:4/5(1), 81:2/11(2), 82:1/17(4), 83:5/6(1), 84:2/13(4), 85:1/7(4), 86:13/15(1), 87:7/8(1), 88:8/9(1), 89:1/19(9), 90:9/10(1), 91:11/12(1), 92:1/13(4), 93:14/15(1), 94:1/17(9), 95:19/20(1), 96:24/25(1), 97:33/34(1), 98:49/50(1), 99:99/100(1) perl -nwae 'next if /no/;print "",($F[1]-1)*($F[3]-1), " $_"' r2 | sort -n

Saturday, October 02, 2004

Roomba w/ UV lamp

Hi intensity UV lamp on the underside to be germicidal. Unleash it in locker room against athlete foot fungus. -- Mobile Email from a Cingular Wireless Customer http://www.cingular.com