Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Comparing two lists' topicStudent Support Forum > General > "Comparing two lists"

Next Comment >Help | Reply To Topic
Author Comment/Response
Laura
12/15/04 09:23am

I have two queries (sorry) both of which I thought were trivial until I came to try to solve them!!

I am trying to write a function relating to the least number of ways any even number greater than four can be created by the addition of two primes. So for example, if I we to call my function gc, gc[5] = {1,1,1,2,1} where the first one represents 4=2+2, the second 1 represent 6=3+3 etc.

However, if you use the function Outer[Plus,p,p] where p is a list of primes then you end up with 8 occuring twice because of permutations. Equally, 10 appears three times because of 3+7,7+3 and 5+5. Does anyone know how to remove the cases where the number is created by a permutation. (I have tried DeleteCases, but it removes all 8's, 10's etc.)

My second query (sorry this post is so long) relates to what I thought would be easy - comparing two lists. All I want is for Mathematica to Count the number of times that each element in a list (called h) appears in another list (called f) so if h={4,6,8,10,12} and f={1,3,4,5,7,8,9,4,2,9} then it would produce {2,0,1,0,0}

I have tried using the Count and the Cases operators but I am obviously doing something wrong.

Please can someone help.

Thank you.

URL: ,

Subject (listing for 'Comparing two lists')
Author Date Posted
Comparing two lists Laura 12/15/04 09:23am
Re: Comparing two lists yehuda ben-s... 12/16/04 5:36pm
Next Comment >Help | Reply To Topic