Mainly for Ian, I expect.

I’ve been playing with Raul Miller’s “countdown” solution as listed in 
https://rosettacode.org/wiki/Countdown#J

Actually, I’ve modified “task” slightly, in order to force the target number 
and the selection of the 6 numbers.

Here’s a copy of a so far successful session.  As usual, I hope it displays ok 
if using a fixed width font even though it looks awful on this iPad:

NB. timer just shows the crude elapsed time, and result, if any.
NB. task produces an empty result as the echo statements report what’s required.

   timer'154 task 1 5 6 9 25 100'  NB. runs reasonably fast
terms: 1 5 6 9 25 100
target: 154
#solutions: 392
for example: (5+9)*((1+6)+(100%25))  NB.  100+6*9 is my preference!
┌───────┬┐
│10.6086││
└───────┴┘
NB. Try program monitor,  wondering if {.a shows as costly,  cf Raul’s recent 
query.
   start_jpm_ 100000000
1785713
   timer'154 task 1 5 6 9 25 100'
terms: 1 5 6 9 25 100
target: 154
#solutions: 392
for example: (5+9)*((1+6)+(100%25)) NB. not 100+6*9 !
┌───────┬┐
│12.5705││
└───────┴┘
   showdetail_jpm_ 'task'
recorded all lines
used and max record count: 1,785,713 1,785,713
the PM data area has overflowed and records have been lost

 Time (seconds)
┌────────┬────────┬───┬─────────────────────────────────────┐
│all     │here    │rep│task                                 │
├────────┼────────┼───┼─────────────────────────────────────┤
│0.000000│0.000000│0  │monad                                │
│0.000000│0.000000│0  │[0] ''task y                         │
│0.000000│0.000000│0  │total monad                          │
│        │        │   │                                     │
│0.000000│0.000000│0  │dyad                                 │
│0.000000│0.000000│0  │[1] if. #y do. c=.y                  │
│0.000000│0.000000│0  │[2] else.                            │
│0.000000│0.000000│0  │[3] c=./:~deal''                     │
│0.000000│0.000000│0  │[4] end.                             │
│0.000000│0.000000│0  │[5] if. #x do. t=.x                  │
│0.000000│0.000000│0  │[6] else.                            │
│0.000000│0.000000│0  │[7] t=.targ''                        │
│0.000000│0.000000│0  │[8] end.                             │
│0.000000│0.000000│0  │[9] echo'terms: ',":c                │
│0.000000│0.000000│0  │[11] echo'target: ',":t              │
│0.000000│0.000000│0  │[12] echo'#solutions: ',":#a=.t all c│
│0.000000│0.000000│0  │[13] echo'for example: ',;{.a        │
│0.000000│0.000000│0  │total dyad                           │
│        │        │   │                                     │
└────────┴────────┴───┴─────────────────────────────────────┘

NB. Not a lot of use.  So I tried  
   start_jpm_ 200000000
3571427

NB. This might be relevant. What is the memory limit?
   9!:20''
17179869184

terms: 1 5 6 9 25 100
target: 154
#solutions: 392
for example: (5+9)*((1+6)+(100%25))
┌───────┬─┐
│12.7607│0│
└───────┴─┘
NB. So far so good,  BUT
   showdetail_jpm_ 'task' NB. leads to wipeout.  

   JVERSION
Engine: j903/j64/iOS
beta-k: GPL3/2021-10-15T01:07:05
Platform: iOS/iPadOS
Version: 901.1 49
Installer: App Store
Contact: www.jsoftware.com
   
I confess I copied jpm over from my Windows installation,  and its use in iOS 
might be deprecated,  but I suspect there’s a more general problem when 
exceeding memory.  In another Rosetta task,  seeking sum-partitions of a given 
integer into a strictly increasing set of primes with exactly m members,  some 
larger problems lead to a crash. The code is a lot longer, though not as 
sophisticated as Raul’s approach to countdown.

Cheers,

Mike

Sent from my iPad
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to