Day 1:Calorie Counting

Day1 描述 大意就是给出如下的数据代表不同的食物消耗的卡路里(Calories) 样例: 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 第一部分 一共是$1000+2000+30

Day 2:Rock Paper Scissors

Day2 描述 大意就是石头剪刀布这个游戏分为对手和你 得分分为 你出手的形状得分 和最终胜利时的得分总和 出手形状得分: 石头:1分 布: 2分 剪刀:3分 胜利得分

Combinatoric selections

Problem 53 Description 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,$\displaystyle \binom 5 3 = 10$ . In general,$\displaystyle \binom n r = \dfrac{n!}{r!(n-r)!}$ , where $r \le n$, $n! = n \times (n-1) \times … \times 3 \times 2 \times 1$, and $0! = 1$. It is not until

Permuted multiples

Problem 52 Description 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. Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def solution(): for i in range(1, 1000000): a = str(i * 2) b = str(i * 3) c = str(i * 4) d = str(i * 5) e = str(i * 6) if ( sorted(a) == sorted(b) and sorted(a) == sorted(c) and sorted(a) == sorted(d) and sorted(a) == sorted(e) ): return i Summary It limit the number range to one billion.

位运算

描述 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include <stdio.h> #include "bit_ops.h" /* Returns the Nth bit of X. Assumes 0 <= N <= 31. */ unsigned get_bit(unsigned x, unsigned n) { return (x >> n) & 1; /* UPDATE WITH THE CORRECT RETURN VALUE*/ } /* Set the