Problem 54 Poker hands

2016-11-22 10:18:00

In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:

在扑克牌游戏中,一手牌由五张牌构成,从低牌型到高牌型有以下几种分布:

  • High Card: Highest value card.
    散牌:啥都不是
  • One Pair: Two cards of the same value.
    一对:有2张相同点数
  • Two Pairs: Two different pairs.
    两对:有2对相同点数
  • Three of a Kind: Three cards of the same value.
    三条:有3张相同点数
  • Straight: All cards are consecutive values.
    顺子:所有牌点数都能连起来
  • Flush: All cards of the same suit.
    同花:所有牌花色相同
  • Full House: Three of a kind and a pair.
    葫芦(俘虏):三张相同点数加一对
  • Four of a Kind: Four cards of the same value.
    四条(炸弹):四张相同点数
  • Straight Flush: All cards are consecutive values of same suit.
    同花顺:统一花色的顺子
  • Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.
    同花大顺:同一花色的10,J,Q,K,A

The cards are valued in the order:

牌点数从小到大:

2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.

If two players have the same ranked hands then the rank made up of the highest value wins; for example, a pair of eights beats a pair of fives (see example 1 below). But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on.

如果两个玩家有用相同的牌型,那么组成牌型的牌点高的赢 比如,一对8比一对5大(下面例子1)。如果牌型大小平局了,就检查剩下的最高点数的牌(下面例子4)。如果最大的牌又平局了就算剩下牌的最大牌,以此类推。

Consider the following five hands dealt to two players:

Hand Player 1 Player 2 Winner
1 5H 5C 6S 7S KD
Pair of Fives
2C 3S 8S 8D TD
Pair of Eights
Player 2
2 5D 8C 9S JS AC
Highest card Ace
2C 5C 7D 8S QH
Highest card Queen
Player 1
3 2D 9C AS AH AC
Three Aces
3D 6D 7D TD QD
Flush with Diamonds
Player 2
4 4D 6S 9H QH QC
Pair of Queens
Highest card Nine
3D 6D 7H QD QS
Pair of Queens
Highest card Seven
Player 1
5 2H 2D 4C 4D 4S
Full House
With Three Fours
3C 3D 3S 9S 9D
Full House
with Three Threes
Player 1

The file, poker.txt, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five are Player 1’s cards and the last five are Player 2’s cards. You can assume that all hands are valid (no invalid characters or repeated cards), each player’s hand is in no specific order, and in each hand there is a clear winner.

有这么个文件,里面有随机(呵呵 :smile: )的2个玩家的手牌。每行10张牌,被当个空格分隔。前5张牌是玩家1的,后5张是玩家2的。你可以假定所有的手牌都是合法的(没有无效牌符号或者重复的牌),每个玩家的牌都打乱的,每一手牌都有明确的胜利者(这句话其实已经排除很多情况了)。

How many hands does Player 1 win?

玩家1赢了多少次?

There are exactly ten ways of selecting three from five, 12345:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

In combinatorics, we use the notation, 5C3 = 10.

In general,

\(^nC_r =\frac{n!}{r!(n−r)!}\) ,where r ≤ n, n! = n×(n−1)×…×3×2×1, and 0! = 1.

It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.

How many, not necessarily distinct, values of nCr, for 1 ≤ n ≤ 100, are greater than one-million?

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.

By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.

By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property.

Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family.

The prime 41, can be written as the sum of six consecutive primes:

\[41 = 2 + 3 + 5 + 7 + 11 + 13\]

This is the longest sum of consecutive primes that adds to a prime below one-hundred.

The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.

Which prime, below one-million, can be written as the sum of the most consecutive primes?

The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.

What 12-digit number do you form by concatenating the three terms in this sequence?

Problem 48 Self powers

2016-11-11 10:38:00

The series, \(1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317\).

Find the last ten digits of the series, \(1^1 + 2^2 + 3^3 + 1000^1000\).