Another Project Euler... This time PE #69: http://projecteuler.net/problem=69
Essentially, find n which has the maximum of n/totient(n), for all positive integers, n, up to 1000000. At first this seemed easy. I have a verb to calculate the ratio: totient=: (- ~:)&.q: func =. ] % totient then I can find the maximum: max=. (>./)"1@:((] % totient)"0) max 1+i.1000000 5.53939 But this gives me the ratio. I need to find n. This is a problem, because finding the maximum, the verb, >./ , collapsed the array so I don't think I can use I. or similar verb to get the index which gave the maximum ratio. So I am not sure how to find the n which gave this ratio. A second issue is I think my method seems to not be well thought out memory-wise. My method first calculates the ratio for every integer up to 1 million and holds them all in memory. Surely a better way would be to do them one at a time and find the maximum as we go. In J I am not sure how to do this. I am guessing the recursion verb $: will need to be used. Any help appreciated. Regards. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
