刪除wallet里面登機牌_登機牌丟失問題

刪除wallet里面登機牌

On a sold-out flight, 100 people line up to board the plane. The first passenger in the line has lost his boarding pass but was allowed in regardless. He takes a random seat. Each subsequent passenger takes their assigned seat if available, or a random unoccupied seat, otherwise.What is the probability that the last passenger to board the plane finds their seat unoccupied?

在售罄的航班上,有100人排隊等候登機。 排隊的第一位乘客丟失了登機牌,但無論如何都被允許進入。 他隨便坐。 如果有空位,則其后每位乘客都將坐上他們分配的座位,否則將坐一個隨機的空座位,最后登機的乘客發現自己的座位沒有座的可能性是多少?

If your first instinct is to map out the possibilities with a smaller number of people boarding the plane, I invite you to take a moment and try the puzzle out for yourself. This approach resulted in a great deal of suffering on my end, and I wouldn’t want to deprive you of that experience.

如果您的第一個直覺是在登機的人較少的情況下確定各種可能性,那么我請您花點時間為自己解決難題。 這種方法給我帶來了很大的痛苦,我不想剝奪您的經驗。

Alternatively, read on for a Monte Carlo simulation and an explanation of the analytic solution.

另外,請繼續閱讀以進行蒙特卡洛模擬和解析解的說明。

蒙特卡羅模擬 (Monte Carlo Simulation)

Annoyed at my failure to manually solve the problem, I quickly typed out a messy Monte Carlo simulation in Python:

由于無法手動解決問題而感到惱火,我很快用Python輸入了一個混亂的蒙特卡洛模擬:

import random
import numpy as npairplane = []#positive indicates that the criteria (last passenger reaches their seat) is fulfilled & vice versapositive = 0
negative = 0#constructing airplane
for i in range (1,101):
airplane.append(i)def simulate():

global airplane
global positive
global negative#first passenger
airplane.remove(np.random.choice(airplane))#subsequent passengers
for i in range (2,100):
if i in airplane:
airplane.remove(i)
else:
airplane.remove(np.random.choice(airplane))if 100 in airplane:
positive += 1
else:
negative += 1airplane = []
for i in range (1,101):
airplane.append(i)#running 100k trials
for i in range (0,100000):
simulate()print(positive/(positive+negative)*100)Output: 50.076

By Monte Carlo, the probability of the last passenger finding his seat is about 50%. I found it surprising that the probability was this high, considering that it represents the last passenger sitting in one particular seat in a 100-person plane.

根據蒙特卡洛,最后一位乘客找到座位的可能性約為50%。 考慮到它代表了坐著100人的飛機上一個特定座位的最后一位乘客,我發現這種可能性如此之高令人驚訝。

This is yet another probability puzzle where our intuition fails us. It reminds me specifically of the Birthday Paradox, where most people also tend to vastly underestimate the probability of a certain outcome as a result of deeply-flawed mental calculations.

這是我們的直覺使我們失敗的另一個概率難題。 它特別讓我想起了生日悖論 ,因為大多數人也往往由于心理計算的嚴重缺陷而大大低估了某種結果的可能性。

分析解決方案 (Analytic Solution)

The real probability is exactly 1/2. Here’s why:

實際概率恰好是1/2 。 原因如下:

Image for post
Photo by Jonathan Farber on Unsplash
喬納森·法伯 ( Jonathan Farber)在Unsplash上拍攝的照片

From this point forward, I refer to passengers and their assigned seats in order of entry, such that the first passenger to board is Passenger 1 and the last to board is Passenger 100. Similarly, Seat 1 is the assigned seat of Passenger 1, and so forth.

從這一點開始,我將按照進入的順序指代乘客及其分配的座位,這樣第一個登機的乘客就是乘客1,最后一個登機的乘客是乘客100。類似地,座位1是乘客1的分配座位,并且等等。

Fact: Passenger 100 will sit in either Seat 100 (his assigned seat) or Seat 1.

事實:乘客100將坐在座位100(他指定的座位)或座位1中。

I best understand this observation through the perspective of each passenger boarding in-between the first and last. There are two possibilities for Passengers 2–99.

我從頭一個和最后一個之間的每個乘客登機的角度來最好地理解這一發現。 2–99號旅客有兩種可能性。

  1. The passenger’s assigned seat is empty. They sit in that seat.

    乘客分配的座位空著。 他們坐在那個座位上。
  2. The passenger’s assigned seat is occupied. They sit in some other seat at random.

    乘客分配的座位已被占用。 他們隨意地坐在其他座位上。

After each of these passengers takes a seat on the plane, it is necessarily true that their assigned seat is occupied. Either it was previously unoccupied (option 1 above) and they sit in it, or it was already occupied (option 2).

這些乘客中的每一個在飛機上坐下之后,一定要占用他們分配的座位。 可能是以前沒有人住過(上面的選項1),他們坐在了里面,或者已經有人住過了(選項2)。

Before the last passenger boards the plane, the assigned seats of Passengers 2–99 are occupied. At this point, 99 people (including Passenger 1) have taken a seat, meaning that only one seat remains vacant.

在最后一位乘客登機之前,已分配了2–99位乘客的指定座位。 此時,有99人(包括乘客1)已經就座,這意味著只有一個座位空缺。

Since there is one seat left and Seats 2–99 are guaranteed to be occupied, the vacant seat must be Seat 1 or Seat 100. It is impossible for both Seat 1 and Seat 100 to be occupied before the last passenger boards, because that would mean all 100 seats on the plane are occupied by only 99 passengers.

由于只剩一個座位,并且保證要占用2至99座位,因此空座位必須是1或100座位。在最后一個乘客登機牌之前,不可能同時占用1和100座位,因為那樣會表示飛機上的所有100個座位都只有99位乘客。

Fact: there is an equal probability of the last passenger sitting in Seat 1 and Seat 100.

事實:最后一位乘客坐在1號座位和100號座位的機率相等。

By the time the last passenger boards, the outcome of the lost boarding pass problem is already determined, as there is only one seat for them to choose. We must therefore look at the decisions faced by Passengers 1–99.

到最后一個乘客登機時,已經確定了丟失登機牌問題的結果,因為他們只能選擇一個座位。 因此,我們必須研究1–99號乘客面臨的決策。

For Passenger 1, there is equal probability of choosing any of the 100 seats. By extension, the probability of him choosing his own assigned seat and the probability of him choosing the last passenger’s assigned seat are equal.

對于乘客1,選擇100個座位中的任何一個的可能性均等。 通過擴展,他選擇自己的分配座位的概率與他選擇最后一個乘客的分配座位的概率相等。

The only way Passengers 2–99 sit in Seat 1 or Seat 100 is if their assigned seat is occupied. In this case, there is also an equal probability of sitting in any available seat.

2–99號乘客坐在1號或100號座位的唯一方法是,如果他們分配的座位被占用。 在這種情況下,坐在任何可用座位上的可能性也相等。

While both Seat 1 and Seat 100 are unoccupied, it is equally probable that either seat will be chosen. After one of these two seats is occupied, the other seat is guaranteed to remain unoccupied until the last passenger boards. The probability that Seat 100 is occupied by a previous passenger is 1/2.

雖然座位1和座位100均未占用,但同樣有可能會選擇其中一個座位。 在這兩個座位中的一個座位被占用之后,另一個座位將保證在最后一個乘客登機之前保持空置。 前座乘客占用座位100的概率為1/2。

Therefore, the probability that the last passenger finds his seat unoccupied is also 1/2.

因此,最后一位乘客發現自己的座位未被占用的概率也為1/2。

Though I’m a very inexperienced coder, it was still much faster to solve the lost boarding pass problem using Monte Carlo via Python than it was to wrap my head around the analytic solution. I could say something here about the power of simulations in problem solving, but you’ve probably heard it before.

盡管我是一個非常缺乏經驗的編碼員,但是使用Monte Carlo通過Python解決登機牌丟失問題的速度要比把頭放在分析解決方案上要快得多。 我可以在這里談談模擬在解決問題中的作用,但是您以前可能已經聽說過。

Instead, I will publicly thank whoever came up with the idea of airlines being able to print boarding passes at the gate.

相反,我將公開感謝誰想到航空公司能夠在登機口打印登機牌的想法。

資料來源 (Sources)

The lost boarding pass problem doesn’t have a massive online presence, though I was able to find versions with slightly different wordings here, here, and here.

丟失登機牌問題并沒有在網上廣泛使用,盡管我能夠在這里 , 這里和這里找到措辭略有不同的版本。

翻譯自: https://towardsdatascience.com/the-lost-boarding-pass-problem-2a17313b2d8a

刪除wallet里面登機牌

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388210.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388210.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388210.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

PHP 備份還原 MySql 數據庫

原生 PHP 備份還原 MySql 數據庫 支持 MySql,PDO 兩種方式備份還原 php5.5 以上的版本建議開啟pdo擴展,使用 pdo 備份還原數據 備份文件夾 db_backup、import/log 文件要有讀寫權限環境版本 本人測試環境 php:5.5.38 /5.6.27-nts/7.0.12-nts; mysql: 5.5…

Java? 教程(Queue接口)

Queue接口 Queue是在處理之前保存元素的集合&#xff0c;除了基本的Collection操作外&#xff0c;隊列還提供額外的插入、刪除和檢查操作&#xff0c;Queue接口如下。 public interface Queue<E> extends Collection<E> {E element();boolean offer(E e);E peek();…

字符串操作截取后面的字符串_對字符串的5個必知的熊貓操作

字符串操作截取后面的字符串We have to represent every bit of data in numerical values to be processed and analyzed by machine learning and deep learning models. However, strings do not usually come in a nice and clean format and require preprocessing to con…

最新 Unity3D鼠標滑輪控制物體放大縮小 [

var s 1.0;function Update () {var cube GameObject.Find("Cube");if(Input.GetAxis("Mouse ScrollWheel")){s Input.GetAxis("Mouse ScrollWheel");cube.transform.localScaleVector3(1*s,1*s,1*s);}}

sublime-text3 安裝 emmet 插件

下載sublime&#xff0c;http://www.sublimetext.com/ 安裝package control &#xff1a;https://packagecontrol.io/ins... 這個地址需要翻墻&#xff0c;訪問不了的可以看下圖 import urllib.request,os,hashlib; h 6f4c264a24d933ce70df5dedcf1dcaee ebe013ee18cced0ef93d…

數據科學家訪談錄 百度網盤_您應該在數據科學訪談中向THEM提問。

數據科學家訪談錄 百度網盤A quick search on Medium with the keywords “Data Science Interview” resulted in hundreds of Medium articles to help guide the reader from what concepts are covered to even specific company interviews ranging from Tesla, Walmart, …

unity3d]鼠標點擊地面人物自動走動(也包含按鍵wasdspace控制)

目錄(?)[-] 一效果圖二大概步驟 創建一個plane設置層為Terrain因為后面要判斷是否點擊的是這個層準備好人物模型并且將三個腳本拖放到人物上并且將動畫文件也拖放好記得看前面提醒哦 ThirdPersonCamera相當于smoothflowThirdPersonController修改版mouseMoveContr鼠標點擊人物…

uva 524(Prime Ring Problem UVA - 524 )

dfs練習題,我素數打表的時候ji了&#xff0c;一直沒發現實際上是ji*i&#xff0c;以后可記住了。還有最后一行不能有空格。。。昏迷了半天 我的代碼(紫書上的算法) #include <bits/stdc.h> using namespace std; int bk[110]; int num[110]; int vis[110]; int n; void d…

Web 開發基礎

一、 Web 開發簡介 最早的軟件都是運行在大型機上的&#xff0c;軟件使用者登陸到大型機上去運行軟件。后來隨著 PC 機的興起&#xff0c;軟件開始主要運行在桌面上&#xff0c;而數據庫這樣的軟件運行在服務器端&#xff0c;這種 Client/Server 模式簡稱 CS 架構。隨著互聯網的…

power bi函數_在Power BI中的行上使用聚合函數

power bi函數Aggregate functions are one of the main building blocks in Power BI. Being used explicitly in measures, or implicitly defined by Power BI, there is no single Power BI report which doesn’t use some sort of aggregate functions.聚合功能是Power BI…

關于如何在Python中使用靜態、類或抽象方法的權威指南

Python中方法的工作方式 方法是存儲在類屬性中的函數&#xff0c;你可以用下面這種方式聲明和訪問一個函數 >>> class Pizza(object):... def __init__(self, size):... self.size size... def get_size(self):... return self.size...>&…

廣義估計方程估計方法_廣義估計方程簡介

廣義估計方程估計方法A key assumption underpinning generalized linear models (which linear regression is a type of) is the independence of observations. In longitudinal data this will simply not hold. Observations within an individual (between time points) …

css二

結構性偽類:nth-child(index)系列1.:first-child2.:last-child3.nth-last-child(index)4.only-child :nth-of-type(index)系列1.first-of-type2.last-of-type3.nth-last-type(index)4.only-of-type :not偽類處理導航欄最后一個豎劃線a:not(:last-of-type) :empty偽類 選中所有內…

Unity3d鼠標點擊屏幕來控制人物的走動

今天呢&#xff0c;我們來一起實現一個在RPG中游戲中十分常見的功能&#xff0c;通過鼠標點擊屏幕來控制人物的走動。首先來說一下原理&#xff0c;當我們點擊屏幕時&#xff0c;我們按照一定的方法&#xff0c;將屏幕上的二維坐標轉化為三維坐標&#xff0c;然后我們從攝像機位…

Java中的ReentrantLock和synchronized兩種鎖定機制的對比

2019獨角獸企業重金招聘Python工程師標準>>> 多線程和并發性并不是什么新內容&#xff0c;但是 Java 語言設計中的創新之一就是&#xff0c;它是第一個直接把跨平臺線程模型和正規的內存模型集成到語言中的主流語言。核心類庫包含一個 Thread 類&#xff0c;可以用它…

10.15 lzxkj

幾天前寫的&#xff0c;忘了放了&#xff0c;在此填坑 10月16的題我出的不寫題解了 lzxkj 題目背景 眾所不周知的是&#xff0c; 酒店之王 xkj 一個經常迷失自我的人 有一天&#xff0c; 當起床鈴再一次打響的時候&#xff0c; TA 用 O(1)的時間在 TA 那早就已經生銹的大腦中自…

大數定理 中心極限定理_中心極限定理:直觀的遍歷

大數定理 中心極限定理One of the most beautiful concepts in statistics and probability is Central Limit Theorem,people often face difficulties in getting a clear understanding of this and the related concepts, I myself struggled understanding this during my…

萬惡之源 - Python數據類型二

列表 列表的介紹 列表是python的基礎數據類型之一 ,其他編程語言也有類似的數據類型. 比如JS中的數 組, java中的數組等等. 它是以[ ]括起來, 每個元素用 , 隔開而且可以存放各種數據類型: lst [1,a,True,[2,3,4]]列表相比于字符串,不僅可以存放不同的數據類型.而且可…

230. Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BSTs total elements.Example 1: Input: root [3,1,4,null,2], k 13/ \1 4\2 Output: 1 Example 2: Input: root …

探索性數據分析(EDA)-不要問如何,不要問什么

數據科學 &#xff0c; 機器學習 (Data Science, Machine Learning) This is part 1 in a series of articles guiding the reader through an entire data science project.這是一系列文章的第1部分 &#xff0c;指導讀者完成整個數據科學項目。 I am a new writer on Medium…