18 "output_type": "execute_result"
23 "load 'array-numbers.rb'"
28 "execution_count": 13,
39 "execution_count": 13,
41 "output_type": "execute_result"
50 "execution_count": 53,
61 "execution_count": 53,
63 "output_type": "execute_result"
67 "def valid(n, debug=false)\n",
68 " digits = n.to_digits\n",
69 " perms = digits.permutation.select {|ds| ds.to_i.prime?}.to_set.to_a.permutation(3)\n",
70 " puts \"perms: #{perms}\" if debug\n",
71 " triples = perms.to_a.map {|t| t.map {|ds| ds.to_i}}\n",
72 " puts \"triples: #{triples}\" if debug\n",
73 " valids = triples.select {|t| t[0] == n && t[1] > t[0] && t[1] - t[0] == t[2] - t[1]}\n",
74 " puts \"valids: #{valids}\" if debug\n",
81 "execution_count": 35,
92 "execution_count": 35,
94 "output_type": "execute_result"
103 "execution_count": 56,
111 "[148748178147, 296962999629]"
114 "execution_count": 56,
116 "output_type": "execute_result"
120 "(1000..9999).map {|n| valid n}.select {|t| !t.nil?}.map {|t| t.flat_map {|n| n.to_digits}.to_i}"
125 "execution_count": 57,
133 "output_type": "stream",
135 "perms: #<Enumerator:0x005594b994f0e0>\n",
136 "triples: [[2969, 2699, 9629], [2969, 2699, 6299], [2969, 9629, 2699], [2969, 9629, 6299], [2969, 6299, 2699], [2969, 6299, 9629], [2699, 2969, 9629], [2699, 2969, 6299], [2699, 9629, 2969], [2699, 9629, 6299], [2699, 6299, 2969], [2699, 6299, 9629], [9629, 2969, 2699], [9629, 2969, 6299], [9629, 2699, 2969], [9629, 2699, 6299], [9629, 6299, 2969], [9629, 6299, 2699], [6299, 2969, 2699], [6299, 2969, 9629], [6299, 2699, 2969], [6299, 2699, 9629], [6299, 9629, 2969], [6299, 9629, 2699]]\n",
137 "valids: [[2969, 6299, 9629]]\n"
146 "execution_count": 57,
148 "output_type": "execute_result"
152 "valid(2969, debug=true)"
157 "execution_count": null,
167 "display_name": "Ruby 2.4.0",
172 "file_extension": ".rb",
173 "mimetype": "application/x-ruby",