---
title: "把若干鸡蛋放到篮子里快速取出的方法"
author: "yangyi"
date: "2011-05-03T20:15:05Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-05-03T20:15:05Z"
id: 1027737
url: "https://yangyi.iteye.com/blog/1027737"
---

有1000个鸡蛋，10个筐，将鸡蛋放入这样10个筐中，给定一个任意数N<1000,问如何放置，能使我们快速的取出相应数目的鸡蛋？


```python

r = int(input("Input a number:"))
n = 1000

i = 1
s = []
while (i - 1) < n:
    s.append(i)
    i <<= 1
    
rest = n - s.pop() + 1

useRest = False
if r >= rest:
    r = r - rest
    useRest = True

choice = map(lambda x: x & r != 0,s)

print("\t".join(str(v) for v in s) + "\t" + str(rest))
print("\t".join(str(v) for v in choice) + "\t" + str(useRest))

```