[Answer and Winners] Mathematics × Programming Competition #8 [答案及得獎名單] 數學 × 程式編寫比賽 (第八回)

Mathematics × Programming Competition #8
Announcement of Answer and Winners

Designed by @nicolemoker

For Chinese version please scroll to the bottom. 中文版請見文末。


Question

Ken has a four-digit calculator which displays numbers using the seven-segment-display. For example the number 159 is displayed as


Note that 159 is displayed as 0159

Suppose we want to use non-transparent cards to represent all the possible 4-digit numbers from 0000 to 9999. Each card will show one 4-digit number, where the numbers are written using seven-segment-display. However when some cards are rotated 180°, a new number can be formed. For example when the card 0159 is rotated 180°, it becomes 6510.


Note that it is acceptable for the ‘1’ to be displayed on the left hand side

Considering the possibility of rotating a card 180°, what is the minimum number of non-transparent cards required to represent all the possible 4-digit numbers from 0000 to 9999?


Answer: 8824

Mathematical approach

Among all digits, only ‘0’, ‘1’, ‘2’, ‘5’, ‘6’, ‘8’ and ‘9’ can be rotated, which would form ‘0’, ‘1’, ‘2’, ‘5’, ‘9’, ‘8’, ‘6’ respectively.

First of all, there are 74 = 2401 4-digit numbers which can be rotated to form a meaningful number.

Among these 2401 numbers, there are 72 = 49 4-digit numbers which can be rotated to form the original number. This is because the first 2 digits of the number will determine the remaining 2 digits.

Therefore there are 2401 - 49 = 2352 numbers which can be rotated to form a new number. Each pair of numbers can help us to save one card.

So we only require 10000 - 2352 / 2 = 8824 cards.

Programming approach

The logic of a programming solution would be quite similar to the flow above, except the counting will be done by program instead of maths.

Psuedocode:

Define the rotation mapping for digits 0, 1, 2,... ,9
Counter = 0  // for storing number of 4-digit numbers which can be rotated to form a new number
For number = 0000 to 9999
    Rotate the number
    If the new number is meaningful and different from original
    Then counter+1
Loop
Output 10000 - counter / 2

Solutions written by other participants

AuthorArticle
@speedingSolving with one line of Python script!
@speedingSolving with C#
@leedslemonSolving by Excel
@vincentyipSolving by JavaScript
@tvbSolving by PHP / Maths
@armandocatSolving by JavaScript
@justyySolving by JavaScript
@breathewindSolving by Qt
@firstamendmentSolving by Java

Winners

Among 32 participants, there are 20 people who got the correct answers. Thank you for your participation!

@armandocat @challk @vincentyip @nanosesame @victorier @daut44 @justyy @kona @aaronli @john811 @heimindanger @tvb @cifer @breathewind @victory622 @firstamendment @doughtaker @nahaha @tensaix2j @biuiam @krischy @speeding @leedslemon @jeffreytong @ghasemkiani @thomaskikansha @wilkinshui @guyverckw @mcw @gladyslui @connieleung @rfece143

SBD payout of the the question post = 30.123 SBD

Besides, @steemstem has generously sponsored 15 SP, 10 SP and 5 SP for the first, second and third prizes!

The winners and prizes are tabulated below:

WinnerPrizeSBD
@armandocatFirst prize30.123 / 8 = 3.765 SBD + 15 SP
@vincentyipSecond prize30.123 / 8 = 3.765 SBD + 10 SP
@justyyThird prize30.123 / 8 = 3.765 SBD + 5 SP
@breathewindConsolation prize30.123 / 8 = 3.765 SBD
@biuiamConsolation prize30.123 / 8 = 3.765 SBD
@speedingConsolation prize30.123 / 8 = 3.765 SBD
@leedslemonConsolation prize30.123 / 8 = 3.765 SBD
@jeffreytongConsolation prize30.123 / 8 = 3.765 SBD

Congratulations to the winners!


The steemSTEM project (@steemstem) is a community-supported project aiming to increase the quality and the visibility of STEM (STEM is the acronym for Science, Technology, Engineering and Mathematics) articles on Steemit. Please support steemSTEM by following @steemstem and joining the chat channel. You can also consider joining a private curation trail to further support steemSTEM by asking about it in the chat channel. In order to further promote the use of the chat channel, I will stop announcing the time of next competition via a post. Instead I will announce the time in advance in the chat channel!



數學 × 程式編寫比賽 (第八回)
答案及得獎名單公佈


Designed by @nicolemoker


問題

Ken有一部只能顯示四位數的計算器,它使用七段顯示來顯示數字。例如,159顯示為


注意159顯示為0159

假設我們要使用非透明卡紙來表示從0000到9999所有可能的4位數字。每張卡紙將顯示一個4位數字,而這些數字是使用七段顯示器所寫成的。留意當某些卡片旋轉180°時,可以形成新的數字。例如當卡片0159旋轉180°時,它將變成6510。


注意'1'顯示在左側亦可接受

考慮到將卡紙旋轉180°的可能性,最少需要多少張卡紙才能表示從0000到9999所有可能的4位數字?


答案: 8824

數學方法

在所有數字中,只有 ‘0’, ‘1’, ‘2’, ‘5’, ‘6’, ‘8’ 及 ‘9’ 能在旋轉後產生有意義的數字,分別為 ‘0’, ‘1’, ‘2’, ‘5’, ‘9’, ‘8’ 及 ‘6’。

首先,共有 74 = 2401 個4位數字可以旋轉至形成一個有意義的數字。

而在這2401個數字中,有 72 = 49 個4位數字可以旋轉至形成原本的數字。這是因為號碼的前2位數字將決定剩餘的2位數字。

因此,共有2401 - 49 = 2352 個4位數字可以旋轉至形成一個新的數字。每對數字可以幫助我們節省一張卡。

所以我們只需要10000 - 2352/2 = 8824張卡。

編程方法

編程方法的邏輯與上述流程非常相似,只是計算可能組合將由程序而不是數學方法完成。

偽代碼:

0-9 
Counter = 0  // 用於儲存有多少個數字可以在旋轉後形成新數字
For number = 0000 to 9999
    
    
    Then counter+1
Loop
 10000 - counter / 2

由其他參賽者提供的答案

作者文章
@speeding以一行Python script 求出答案!
@speeding以C#求解
@leedslemon以Excel求解
@vincentyip以JavaScript求解
@tvb以PHP或數學方法求解
@armandocat以JavaScript求解
@justyy以JavaScript求解
@breathewind以Qt求解
@firstamendment以Java求解

得獎者

在32個參加者之中,有20人答對。多謝大家的熱烈參與!

@armandocat @challk @vincentyip @nanosesame @victorier @daut44 @justyy @kona @aaronli @john811 @heimindanger @tvb @cifer @breathewind @victory622 @firstamendment @doughtaker @nahaha @tensaix2j @biuiam @krischy @speeding @leedslemon @jeffreytong @ghasemkiani @thomaskikansha @wilkinshui @guyverckw @mcw @gladyslui @connieleung @rfece143

比賽題目帖文的SBD收入 = 30.123 SBD

另外,@steemstem 慷慨贊助了15 SP、10 SP以及5 SP予是次比賽的第一、二及三等獎!

下表顯示得獎者及其所得獎金:

得獎者獎項SBD
@armandocat一等獎30.123 / 8 = 3.765 SBD + 15 SP
@vincentyip二等獎30.123 / 8 = 3.765 SBD + 10 SP
@justyy三等獎30.123 / 8 = 3.765 SBD + 5 SP
@breathewind安慰獎30.123 / 8 = 3.765 SBD
@biuiam安慰獎30.123 / 8 = 3.765 SBD
@speeding安慰獎30.123 / 8 = 3.765 SBD
@leedslemon安慰獎30.123 / 8 = 3.765 SBD
@jeffreytong安慰獎30.123 / 8 = 3.765 SBD

恭喜所有得獎者!


steemSTEM(@steemstem)是一個由steemit社群支持的項目,旨在宣傳STEM(STEM是科學,技術,工程和數學的首字母縮略詞)。 請追蹤 @steemSTEM 以及加入聊天頻道來支持steemSTEM。你還可以透過加入自動點讚系統來在為了進一步支持steemSTEM,詳情請在聊天頻道內向負責人士查詢。為了推廣聊天頻道的使用,我將不再透過發文來宣布下一場比賽的時間,我會在聊天頻道中提前公佈比賽時間。

H2
H3
H4
3 columns
2 columns
1 column
21 Comments