0
$\begingroup$

I'm trying to create a prime signature for line segments.

lpfSignature[n_, k_] :=
  Sort[Tally[Table[FactorInteger[m][[1, 1]], {m, n - k + 1, n }]]]
k = 10; n = k;
lpfSignature[n, k]
n = k^2;
lpfSignature[n, k]
n = k^2 + k;
lpfSignature[n, k]

$\{\{1,1\},\{2,5\},\{3,2\},\{5,1\},\{7,1\}\}$
$\{\{2,5\},\{3,2\},\{5,1\},\{7,1\},\{97,1\}\}$
$\{\{2,5\},\{3,1\},\{101,1\},\{103,1\},\{107,1\},\{109,1\}\}$

I want to strip the left-hand values to leave the following:

$\{1,5,2,1,1\}$
$\{5,2,1,1,1\}$
$\{5,1,1,1,1,1\}$

How would I change the function to do this?

$\endgroup$
3
  • $\begingroup$ lpfSignature[n, k][[All,2]] ? $\endgroup$ Jul 29, 2012 at 12:37
  • $\begingroup$ @b.gatessucks, that was perfect. Make it an answer and I'll sign off. $\endgroup$ Jul 29, 2012 at 12:45
  • $\begingroup$ I reverted your question code to its original state; the question doesn't make any sense if it is already fixed. $\endgroup$
    – Mr.Wizard
    Jul 29, 2012 at 15:49

1 Answer 1

6
$\begingroup$

The origin of the doublets is Tally of course :

k = 10; n = k;
Table[FactorInteger[m][[1, 1]], {m, n - k + 1, n}]
Tally[Table[FactorInteger[m][[1, 1]], {m, n - k + 1, n}]]

(* {1, 2, 3, 2, 5, 2, 7, 2, 3, 2} *)
(* {{1, 1}, {2, 5}, {3, 2}, {5, 1}, {7, 1}} *)

If you are only interested in the multiplicity you can modify your function as :

lpfSignature[n_, k_] := Sort[Tally[Table[FactorInteger[m][[1, 1]], {m, n - k + 1, n}]][[All,2]]]

Alternatively you can leave your function as it is but use it as :

k = 10; n = k;
lpfSignature[n, k][[All,2]]

(* {1, 5, 2, 1, 1} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.