Lah numbers: Difference between revisions

(Added Prolog solution)
Line 462:
</pre>
 
=={{header|J}}==
<lang J>
NB. use: k lah n
lah=: ! :(!&<: * %&!~)&x: NB. %~ is shorter than *inv
 
Monad =: :[: NB. permit only a y argument
Dyad =: [: : NB. require x and y arguments
but_1st =: &
decrement =: <: Monad
 
NB. ! means either factorial or combinations (just as - means negate or subtract)
factorial =: ! Monad
combinations =: ! Dyad
 
into =: *inv Dyad
times =: * Dyad
extend_precision =: x: Monad
wordy_lah =: (combinations but_1st decrement times into but_1st factorial)but_1st extend_precision Dyad
</lang>
<pre>
NB. match the tab
lah&>~table~>:i.12
+------+---------------------------------------------------------------------------------------------------+
|lah&>~| 1 2 3 4 5 6 7 8 9 10 11 12|
+------+---------------------------------------------------------------------------------------------------+
| 1 | 1 0 0 0 0 0 0 0 0 0 0 0|
| 2 | 2 1 0 0 0 0 0 0 0 0 0 0|
| 3 | 6 6 1 0 0 0 0 0 0 0 0 0|
| 4 | 24 36 12 1 0 0 0 0 0 0 0 0|
| 5 | 120 240 120 20 1 0 0 0 0 0 0 0|
| 6 | 720 1800 1200 300 30 1 0 0 0 0 0 0|
| 7 | 5040 15120 12600 4200 630 42 1 0 0 0 0 0|
| 8 | 40320 141120 141120 58800 11760 1176 56 1 0 0 0 0|
| 9 | 362880 1451520 1693440 846720 211680 28224 2016 72 1 0 0 0|
|10 | 3628800 16329600 21772800 12700800 3810240 635040 60480 3240 90 1 0 0|
|11 | 39916800 199584000 299376000 199584000 69854400 13970880 1663200 118800 4950 110 1 0|
|12 |479001600 2634508800 4390848000 3293136000 1317254400 307359360 43908480 3920400 217800 7260 132 1|
+------+---------------------------------------------------------------------------------------------------+
 
wordy_lah f.
[: :(([: :!&(<: :[:) [: :* [: :(*^:_1)&(! :[:))&(x: :[:))
 
lah NB. 1 or 2 arguments are clear from the context
! :(!&<: * %&!~)&x:
 
(lah/ -: wordy_lah/)~>:i.12 NB. the lah and wordy_lah tables agree
1
 
NB. maximum Lah value with n = 100
>./(lah~ >:@:i.)100
44519005448993144810881324947684737529186447692709328597242209638906324913313742508392928375354932241404408343800007105650554669129521241784320000000000000000000000
</pre>
=={{header|Java}}==
<lang java>
Anonymous user