While I know the most efficient way would be implement something like
an interval set, I'm just too lazy so instead I trust J can be efficient
enough and I can write efficient enough J program to solve by brutal force.

It spent about 30 minute to get the result up to the fourth pair, that
is 2714499581+i.312077252, which happens to be the final answer, and
the virtual memory usage reach 67GB while used up all my 16GB physical
memory on my Intel MacBook and in addition 6GB swap. And the intense
computation even glitched the display out.

Here is my program

NB. input data
seeds=:3121711159 166491471 3942191905 154855415 3423756552 210503354 
2714499581 312077252 1371898531 165242002 752983293 93023991 3321707304 
21275084 949929163 233055973 3626585 170407229 395618482 226312891

seed_to_soil=:". >cutopen noun define
522866878 679694818 556344137
1206934522 1236038955 57448427
2572695651 3529213882 270580892
1082547209 29063229 124387313

......

transform2 =: {{
  ms=.(((+/1 2{|:x)>/])*.(1{|:x)<:/])y
  y+,(|:ms)#([:-/2{.])"1 x
}}

part2 =: {{
  'a b'=.y
  tmp=.(seed_to_soil&transform2) a+i.b
  smoutput 'ok'
  tmp=.(soil_to_fertilizer&transform2) tmp
  smoutput 'ok'
  tmp=.(fertilizer_to_water&transform2) tmp
  smoutput 'ok'
  tmp=.(water_to_light&transform2) tmp
  smoutput 'ok'
  tmp=.(light_to_temperature&transform2) tmp
  smoutput 'ok'
  tmp=.(temperature_to_humidity&transform2) tmp
  smoutput 'ok'
  tmp=.(humidity_to_location&transform2) tmp
  smoutput 'ok'
  tmp=.<./tmp
  smoutput tmp
  tmp
}}

res=:part2 " 1]10 2$seeds
smoutput <./res
exit 0

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to