Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#26 2015-01-17 15:15:39

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

I want to ask you something: Can I choose both players from a same match in problem 1? For example, is {A,B,C,D,E} a valid combination in problem 1?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#27 2015-01-17 15:20:58

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

I'm geting this for problem 2.

data Player = Player Char Int

instance Show Player where
	show (Player name _) = show [name]

players = cutinto2 $ zipWith Player ['A'..'T'] [91,109,104,95,79,120,86,114,106,94,
					80,118,75,127,103,97,107,93,94,105]

choose :: [b] -> Int -> [[b]]
_      `choose` 0       = [[]]
[]     `choose` _       =  []
(x:xs) `choose` k       =  (x:) `fmap` (xs `choose` (k-1)) ++ xs `choose` k

cutinto2 :: [b] -> [[b]]
cutinto2 [x,y] = [[x,y]]
cutinto2 (x:y:xs) = [[x,y]] ++ cutinto2 xs

value (Player _ x) = x

combies =  foldr (++) [] (sequence `map` choose players 5)

main = print $ filter (\p -> sum(map value p) <= 500) combies

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#28 2015-01-17 15:22:32

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Re: Combination Problem

Well, you never specified that you don't want the two letters that are grouped together to both appear in a combination.


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#29 2015-01-17 15:24:08

ElainaVW
Member
Registered: 2013-04-29
Posts: 580

Re: Combination Problem

Hello,

You didn't mention all the constraints, please do that.

Offline

#30 2015-01-17 15:26:56

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

I'm using this principle to solve the second problem:

a. Generate a list of five matches.
b. Map a cartesian product over each set of five matches.
c. Check if the result is <= 500


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#31 2015-01-17 15:28:31

ElainaVW
Member
Registered: 2013-04-29
Posts: 580

Re: Combination Problem

He didn't mention that some can't be included in the 5.

Last edited by ElainaVW (2015-01-17 15:47:23)

Offline

#32 2015-01-17 15:38:52

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Re: Combination Problem

Agnishom wrote:

I'm using this principle to solve the second problem:

a. Generate a list of five matches.
b. Map a cartesian product over each set of five matches.
c. Check if the result is <= 500

Won't you just get 25 ordered pairs?


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#33 2015-01-17 15:58:28

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

NickMeyers wrote:

Problem:

There are 10 matches (A vs B, C vs D, E vs F, etc.).
Only one player from each match can be used.
5 players must be picked.
The total combined cost of the 5 picked, must be less that or equal to 500.
All combinations over 500 are not important.

I need to be able to generate a list of combinations, that fit this criteria, along with associated prices.

I'm sorry I thought i did list that in the problem, here is what I wrote before.  I thought I wrote that in the second line.


Edit: I see that I added this to the second problem and forgot to mention it in the first set.  I apologize for not including that information.

Last edited by NickMeyers (2015-01-17 16:01:12)

Offline

#34 2015-01-17 16:05:00

ElainaVW
Member
Registered: 2013-04-29
Posts: 580

Re: Combination Problem

Okay I see what you want now.

Offline

#35 2015-01-17 16:07:16

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

Agnishom wrote:

I want to ask you something: Can I choose both players from a same match in problem 1? For example, is {A,B,C,D,E} a valid combination in problem 1?

In problem one I forgot to add that constraint, I meant to say that only one player from each match could be used, sorry for leaving that out.

Offline

#36 2015-01-17 16:10:48

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

ElainaVW wrote:

Okay I see what you want now.


Thanks Elaina! Sorry for not addressing that earlier

Offline

#37 2015-01-17 16:16:37

ElainaVW
Member
Registered: 2013-04-29
Posts: 580

Re: Combination Problem

Which problem do you want solved?

Offline

#38 2015-01-17 16:37:51

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

The answer to question 1 with the new constraints is 4957

Here are the combinations:
Link

Last edited by Agnishom (2015-01-17 16:38:34)


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#39 2015-01-17 16:39:19

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

NickMeyers wrote:

Problem:

There are 10 matches (A vs B, C vs D, E vs F, etc.).
Only one player from each match can be used.
5 players must be picked.
The total combined cost of the 5 picked, must be less that or equal to 500.
All combinations over 500 are not important.

I need to be able to generate a list of combinations, that fit this criteria, along with associated prices.


Data Set:

Match    Cost
1    A    91   
      B    109   

2    C    104   
      D    95
   
3    E    79   
      F    120   

4    G    86   
      H    114   

5    I    106   
      J    94
   
6    K     80   
      L     118
   
7    M    75   
      N    127
   
8    O    103
      P    97
   
9    Q      107   
      R    93
   
10   S    94   
      T    105

This one is the one I was looking to solve

Offline

#40 2015-01-17 16:42:33

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

I suppose post 27 already solves that problem.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#41 2015-01-17 16:45:32

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

Edit: I didn't see the the word this was a hyperlink. Thank you!! What was the total number?

Agnishom wrote:

The answer to question 1 with the new constraints is 4957

Here are the combinations:
Link


This is fantastic, can this be done with the second problem with the new constraints?

NickMeyers wrote:

Problem:

There are 10 matches (A vs B, C vs D, E vs F, etc.).
Only one player from each match can be used.
5 players must be picked.
The total combined cost of the 5 picked, must be less that or equal to 500.
All combinations over 500 are not important.

I need to be able to generate a list of combinations, that fit this criteria, along with associated prices.


Data Set:

Match    Cost
1    A    91   
      B    109   

2    C    104   
      D    95
   
3    E    79   
      F    120   

4    G    86   
      H    114   

5    I    106   
      J    94
   
6    K     80   
      L     118
   
7    M    75   
      N    127
   
8    O    103
      P    97
   
9    Q      107   
      R    93
   
10   S    94   
      T    105

Last edited by NickMeyers (2015-01-17 16:50:10)

Offline

#42 2015-01-17 16:51:35

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

I will count(not manually, of course) and tell you in around 5 minutes.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#43 2015-01-17 16:52:47

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

I believe you posted that is was 4166 earlier? Is that correct?

Thanks again!

Offline

#44 2015-01-17 16:57:18

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

Oh, yes. It is 4166.

Can you please check around 10 random cases from the text file I gave you to be sure if that is what you want?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#45 2015-01-17 17:02:56

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

Stefy is also getting the same result! yay!


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#46 2015-01-17 17:14:32

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

I think you got it!! I am looking though it and not seeing any conflicts.

Thank you all so much!!!

Offline

#47 2015-01-17 17:20:31

ElainaVW
Member
Registered: 2013-04-29
Posts: 580

Re: Combination Problem

4166 is correct.

Offline

#48 2015-01-17 17:22:00

NickMeyers
Member
Registered: 2015-01-17
Posts: 46

Re: Combination Problem

Thank you Elaina!

Offline

#49 2015-01-17 17:23:24

ElainaVW
Member
Registered: 2013-04-29
Posts: 580

Re: Combination Problem

Checking 10 random cases isn't very likely to spot an error.

Offline

#50 2015-01-17 17:42:16

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Combination Problem

True but checking more than 10 random cases is likely to be tedious.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

Board footer

Powered by FluxBB