Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
lpfSignature[n, k][[All,2]] ? –  b.gatessucks Jul 29 '12 at 12:37
    
@b.gatessucks, that was perfect. Make it an answer and I'll sign off. –  Fred Kline Jul 29 '12 at 12:45
    
I reverted your question code to its original state; the question doesn't make any sense if it is already fixed. –  Mr.Wizard Jul 29 '12 at 15:49
add comment

1 Answer

up vote 6 down vote accepted

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} *)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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