Undulating numbers: Difference between revisions

Content added Content deleted
(Added Perl)
(J draft (hopefully these expressions are sufficient labels for their results))
Line 227: Line 227:
which is: 8,786,648,372,058,464 in base 10
which is: 8,786,648,372,058,464 in base 10
</pre>
</pre>

=={{header|J}}==
Inspection shows that there are 81 undulating numbers (base 10) for any given digit count, and 36 for base 7. (In other words two times the number of two digit combinations of the base minus the number of non-zero digits (or: the square of one less than the base).)

So, given:
<syntaxhighlight lang=J>require'stats'
undul=: {{ m #. y$"1 (,|."1)2 comb m }}
und10=: 10 undul
und7=: 7 undul

fmt7=: 7{{' '-.~":m&#.inv y}}</syntaxhighlight>

<syntaxhighlight lang=J> 9 9$und10 3
121 131 141 151 161 171 181 191 232
242 252 262 272 282 292 343 353 363
373 383 393 454 464 474 484 494 565
575 585 595 676 686 696 787 797 898
101 202 303 404 505 606 707 808 909
212 313 414 515 616 717 818 919 323
424 525 626 727 828 929 434 535 636
737 838 939 545 646 747 848 949 656
757 858 959 767 868 969 878 979 989
9 9$und10 4
1212 1313 1414 1515 1616 1717 1818 1919 2323
2424 2525 2626 2727 2828 2929 3434 3535 3636
3737 3838 3939 4545 4646 4747 4848 4949 5656
5757 5858 5959 6767 6868 6969 7878 7979 8989
1010 2020 3030 4040 5050 6060 7070 8080 9090
2121 3131 4141 5151 6161 7171 8181 9191 3232
4242 5252 6262 7272 8282 9292 4343 5353 6363
7373 8383 9393 5454 6464 7474 8484 9494 6565
7575 8585 9595 7676 8686 9696 8787 9797 9898
(#~ 1 p:])und10 3
131 151 181 191 353 373 383 787 797 101 313 919 727 929 757
(<:600){/:~;und10&.>3+i.>.600%81
4646464646
(#,{:)/:~(#~ (2^53)>:]);und10&.>3+i.>.10^.2^53
1125 8989898989898989
6 7$ und7 3
64 71 78 85 92 121 128
135 142 178 185 192 235 242
292 50 100 150 200 250 300
107 157 207 257 307 164 214
264 314 221 271 321 278 328
335 64 71 78 85 92 121
6 7$ und7 4
450 500 550 600 650 850 900
950 1000 1250 1300 1350 1650 1700
2050 350 700 1050 1400 1750 2100
750 1100 1450 1800 2150 1150 1500
1850 2200 1550 1900 2250 1950 2300
2350 450 500 550 600 650 850
(#~ 1 p:])und7 3
71 107 157 257 307 271
fmt7(<:600){/:~;und7&.>3+i.>.600%36
4646464646464646464
(#,&":' ',fmt7@{:)/:~(#~ (2^53)>:]);und7&.>3+i.>.7^.2^53
603 5252525252525252525</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==