update,
This commit is contained in:
96
ttng1234/Q2/ans.py
Normal file
96
ttng1234/Q2/ans.py
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
test_list = [ 21,9,17,10 ]
|
||||||
|
|
||||||
|
def fibonacci_sequence(test_number):
|
||||||
|
# test_number represent the number that sequence should stop at.
|
||||||
|
|
||||||
|
# Initialize the sequence with the first two numbers
|
||||||
|
sequence = [0, 1]
|
||||||
|
|
||||||
|
# keep_find setup to let while loop keep find the number sequence
|
||||||
|
# unless the last generated number (next_num) is greater than the number
|
||||||
|
# need to be tested.
|
||||||
|
keep_find = True
|
||||||
|
|
||||||
|
# initialize to true to run the while loop at the very first execution
|
||||||
|
while keep_find:
|
||||||
|
# after the very first execution, the keep_find may not keep true anymore.
|
||||||
|
|
||||||
|
# 1st, 2nd, 3rd, 4th
|
||||||
|
# 0, 1, 1, 2
|
||||||
|
# at the first execution, the next_num is the 3rd number
|
||||||
|
# at the first execution, the sequence[-1] is the 2rd number
|
||||||
|
# at the first execution, the sequence[-2] is the 1st number
|
||||||
|
|
||||||
|
# at the second execution, the next_num is the 4th number
|
||||||
|
# at the second execution, the sequence[-1] is the 3rd number
|
||||||
|
# at the second execution, the sequence[-2] is the 2nd number
|
||||||
|
next_num = sequence[-1] + sequence[-2]
|
||||||
|
|
||||||
|
# append the number to the sequence
|
||||||
|
# append means extend the list to with the value given
|
||||||
|
# [0,1].append(2) => [0,1,2]
|
||||||
|
# at the first execution the number appended is at 3rd place
|
||||||
|
# at the second execution the number appended is at 4th place
|
||||||
|
sequence.append(next_num)
|
||||||
|
|
||||||
|
# test if:
|
||||||
|
# the last number(next_num) calculated is already larger than the number need to be tested
|
||||||
|
keep_find = (next_num < test_number)
|
||||||
|
|
||||||
|
# test the number if it exist in fibonacci sequence
|
||||||
|
# return true if the next_num is equal to the test_number
|
||||||
|
# it is because there are two possibilities of next_num
|
||||||
|
# next_num > test_number => means the number is not in sequence
|
||||||
|
# next_num = test_number => means the number is in sequence
|
||||||
|
return next_num == test_number
|
||||||
|
|
||||||
|
def triangular_sequence(test_number):
|
||||||
|
# Initialize the sequence with the first number
|
||||||
|
sequence = [1]
|
||||||
|
|
||||||
|
# Generate the Triangular sequence
|
||||||
|
keep_find = True
|
||||||
|
i = 2
|
||||||
|
while keep_find:
|
||||||
|
next_num = sequence[-1] + i
|
||||||
|
keep_find = next_num < test_number
|
||||||
|
sequence.append(next_num)
|
||||||
|
i = i + 1
|
||||||
|
return next_num == test_number
|
||||||
|
|
||||||
|
def square_number_sequence(test_number):
|
||||||
|
# Initialize the sequence with the first number
|
||||||
|
sequence = [1]
|
||||||
|
|
||||||
|
keep_find = True
|
||||||
|
i = 2
|
||||||
|
while keep_find:
|
||||||
|
next_num = i * i
|
||||||
|
keep_find = next_num < test_number
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
return next_num == test_number
|
||||||
|
|
||||||
|
def check_mathematical_series(n: int) -> str:
|
||||||
|
all_result = []
|
||||||
|
|
||||||
|
f_result = fibonacci_sequence(n)
|
||||||
|
t_result = triangular_sequence(n)
|
||||||
|
s_result = square_number_sequence(n)
|
||||||
|
|
||||||
|
if (f_result):
|
||||||
|
all_result.append('Fibonacci')
|
||||||
|
if (t_result):
|
||||||
|
all_result.append('Triangular')
|
||||||
|
if (s_result):
|
||||||
|
all_result.append('Square')
|
||||||
|
|
||||||
|
if (all_result == []):
|
||||||
|
print(f'n = {n}: None')
|
||||||
|
else:
|
||||||
|
print(f'n = {n}: '+', '.join(all_result))
|
||||||
|
|
||||||
|
for n in test_list:
|
||||||
|
check_mathematical_series(n)
|
22
ttng1234/Q2/hand_draft.md
Normal file
22
ttng1234/Q2/hand_draft.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# need to setup (minimum, my list)
|
||||||
|
- setup editor (vscode, windows)
|
||||||
|
- https://code.visualstudio.com/download
|
||||||
|
- setup python (windows)
|
||||||
|
- https://www.python.org/ftp/python/3.11.5/python-3.11.5-embed-amd64.zip
|
||||||
|
|
||||||
|
# string
|
||||||
|
|
||||||
|
string = '123'
|
||||||
|
string = 'abc'
|
||||||
|
|
||||||
|
|
||||||
|
# integer
|
||||||
|
|
||||||
|
integer = 1
|
||||||
|
integer = 1234567
|
||||||
|
|
||||||
|
|
||||||
|
# boolean
|
||||||
|
|
||||||
|
boolean = True
|
||||||
|
boolean = False
|
6
ttng1234/Q2/helloworld.py
Normal file
6
ttng1234/Q2/helloworld.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os,sys
|
||||||
|
|
||||||
|
|
||||||
|
print('helloworld')
|
125
ttng1234/Q2/notes.md
Normal file
125
ttng1234/Q2/notes.md
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
### Q2. 25%, Checking mathematical series number
|
||||||
|
|
||||||
|
Fibonacci Sequence
|
||||||
|
|
||||||
|
Write a Python function named `check_mathematical_series` that takes a positive integer n as input and checks whether the given number belongs to any of the following important mathematical series: `Fibonacci sequence`, `Triangular sequence`, `Square sequence`.
|
||||||
|
|
||||||
|
The function should determine the series type and return a string indicating the result.
|
||||||
|
|
||||||
|
The possible return values are:
|
||||||
|
|
||||||
|
- "Fibonacci" if the number belongs to the Fibonacci sequence.
|
||||||
|
- "Triangular" if the number belongs to the Triangular sequence.
|
||||||
|
- "Square" if the number belongs to the Square sequence.
|
||||||
|
- "None" if the number does not belong to any of the above sequences.
|
||||||
|
|
||||||
|
For this question, consider the following definitions for the series:
|
||||||
|
|
||||||
|
1. Fibonacci sequence: A series of numbers in which each number (after the first two) is the sum of the two preceding ones. The sequence starts with 0 and 1. For example, the Fibonacci sequence begins as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, …
|
||||||
|
|
||||||
|
```python
|
||||||
|
def fibonacci_sequence(n):
|
||||||
|
# Check if the input is valid
|
||||||
|
if n <= 0:
|
||||||
|
return []
|
||||||
|
elif n == 1:
|
||||||
|
return [0]
|
||||||
|
elif n == 2:
|
||||||
|
return [0, 1]
|
||||||
|
|
||||||
|
# Initialize the sequence with the first two numbers
|
||||||
|
sequence = [0, 1]
|
||||||
|
|
||||||
|
# Generate the Fibonacci sequence
|
||||||
|
for i in range(2, n):
|
||||||
|
next_num = sequence[-1] + sequence[-2]
|
||||||
|
sequence.append(next_num)
|
||||||
|
|
||||||
|
return sequence
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Triangular sequence: A sequence of numbers in which each term represents the
|
||||||
|
total number of dots required to form a triangle with that many dots on each side.
|
||||||
|
The nth term of the triangular sequence is given by the formula (n * (n + 1)) / 2.
|
||||||
|
For example, the triangular sequence begins as follows: 1, 3, 6, 10, 15, …
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
def triangular_sequence(n):
|
||||||
|
# Check if the input is valid
|
||||||
|
if n <= 0:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Initialize the sequence with the first number
|
||||||
|
sequence = [1]
|
||||||
|
|
||||||
|
# Generate the Triangular sequence
|
||||||
|
for i in range(2, n+1):
|
||||||
|
next_num = sequence[-1] + i
|
||||||
|
sequence.append(next_num)
|
||||||
|
|
||||||
|
return sequence
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Square number sequence: A sequence of numbers that are the squares of
|
||||||
|
consecutive integers. For example, the square number sequence begins as follows:
|
||||||
|
1, 4, 9, 16, 25, 36, ...
|
||||||
|
Write the check_mathematical_series function and test it with the following values
|
||||||
|
of n:
|
||||||
|
- 21
|
||||||
|
- 9
|
||||||
|
- 17
|
||||||
|
- 10
|
||||||
|
|
||||||
|
```python
|
||||||
|
def square_number_sequence(n):
|
||||||
|
# Check if the input is valid
|
||||||
|
if n <= 0:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Initialize the sequence with the first number
|
||||||
|
sequence = [1]
|
||||||
|
|
||||||
|
# Generate the Triangular sequence
|
||||||
|
for i in range(2, n+1):
|
||||||
|
next_num = sequence[-1] + i
|
||||||
|
sequence.append(next_num)
|
||||||
|
|
||||||
|
return sequence
|
||||||
|
```
|
||||||
|
|
||||||
|
Print the result for each value of n, indicating the series types to which it belongs.
|
||||||
|
|
||||||
|
Using commas (,) if it belongs to more than 1 series.
|
||||||
|
|
||||||
|
"None" if it doesn't belong to any of the series.
|
||||||
|
|
||||||
|
Your function should have the following signature:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def check_mathematical_series(n: int) -> str:
|
||||||
|
```
|
||||||
|
|
||||||
|
# Your code here
|
||||||
|
|
||||||
|
Example output:
|
||||||
|
|
||||||
|
```python
|
||||||
|
n = 21: Fibonacci, Triangular
|
||||||
|
n = 9: Square
|
||||||
|
n = 17: None
|
||||||
|
n = 10: Triangular
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: You can assume that the given n will be a positive integer
|
||||||
|
|
||||||
|
|
||||||
|
Q:
|
||||||
|
有冇話係邊到學python最好?
|
||||||
|
我睇完data camp都唔識 🙃🙃
|
||||||
|
覺得自己好蠢。
|
||||||
|
|
||||||
|
A:
|
||||||
|
你方唔方便比份 notes 我望一望?
|
||||||
|
同埋你係咪理科生?
|
9
ttng1234/Q2/step1.py
Normal file
9
ttng1234/Q2/step1.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
test_list = [ 21,9,17,10 ]
|
||||||
|
|
||||||
|
def check_mathematical_series(n: int) -> str:
|
||||||
|
print(n)
|
||||||
|
|
||||||
|
for n in test_list:
|
||||||
|
check_mathematical_series(n)
|
54
ttng1234/Q2/step2.py
Normal file
54
ttng1234/Q2/step2.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
test_list = [ 21,9,17,10 ]
|
||||||
|
|
||||||
|
def fibonacci_sequence(test_number):
|
||||||
|
# test_number represent the number that sequence should stop at.
|
||||||
|
|
||||||
|
# Initialize the sequence with the first two numbers
|
||||||
|
sequence = [0, 1]
|
||||||
|
|
||||||
|
# keep_find setup to let while loop keep find the number sequence
|
||||||
|
# unless the last generated number (next_num) is greater than the number
|
||||||
|
# need to be tested.
|
||||||
|
keep_find = True
|
||||||
|
|
||||||
|
# initialize to true to run the while loop at the very first execution
|
||||||
|
while keep_find:
|
||||||
|
# after the very first execution, the keep_find may not keep true anymore.
|
||||||
|
|
||||||
|
# 1st, 2nd, 3rd, 4th
|
||||||
|
# 0, 1, 1, 2
|
||||||
|
# at the first execution, the next_num is the 3rd number
|
||||||
|
# at the first execution, the sequence[-1] is the 2rd number
|
||||||
|
# at the first execution, the sequence[-2] is the 1st number
|
||||||
|
|
||||||
|
# at the second execution, the next_num is the 4th number
|
||||||
|
# at the second execution, the sequence[-1] is the 3rd number
|
||||||
|
# at the second execution, the sequence[-2] is the 2nd number
|
||||||
|
next_num = sequence[-1] + sequence[-2]
|
||||||
|
|
||||||
|
# append the number to the sequence
|
||||||
|
# append means extend the list to with the value given
|
||||||
|
# [0,1].append(2) => [0,1,2]
|
||||||
|
# at the first execution the number appended is at 3rd place
|
||||||
|
# at the second execution the number appended is at 4th place
|
||||||
|
sequence.append(next_num)
|
||||||
|
|
||||||
|
# test if:
|
||||||
|
# the last number(next_num) calculated is already larger than the number need to be tested
|
||||||
|
keep_find = (next_num < test_number)
|
||||||
|
|
||||||
|
# test the number if it exist in fibonacci sequence
|
||||||
|
# return true if the next_num is equal to the test_number
|
||||||
|
# it is because there are two possibilities of next_num
|
||||||
|
# next_num > test_number => means the number is not in sequence
|
||||||
|
# next_num = test_number => means the number is in sequence
|
||||||
|
return next_num == test_number
|
||||||
|
|
||||||
|
def check_mathematical_series(n: int) -> str:
|
||||||
|
print(fibonacci_sequence(n))
|
||||||
|
|
||||||
|
for n in test_list:
|
||||||
|
21, 9, 17, 10
|
||||||
|
check_mathematical_series(n)
|
26
ttng1234/Q2/step3.py
Normal file
26
ttng1234/Q2/step3.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
test_list = [ 21,9,17,10 ]
|
||||||
|
|
||||||
|
def triangular_sequence(test_number):
|
||||||
|
# test_number represent the number that sequence should stop at.
|
||||||
|
|
||||||
|
# Initialize the sequence with the first number
|
||||||
|
sequence = [1]
|
||||||
|
|
||||||
|
# Generate the Triangular sequence
|
||||||
|
keep_find = True
|
||||||
|
i = 2
|
||||||
|
while keep_find:
|
||||||
|
next_num = sequence[-1] + i
|
||||||
|
keep_find = next_num < test_number
|
||||||
|
sequence.append(next_num)
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
return next_num == test_number
|
||||||
|
|
||||||
|
def check_mathematical_series(n: int) -> str:
|
||||||
|
print(triangular_sequence(n))
|
||||||
|
|
||||||
|
for n in test_list:
|
||||||
|
check_mathematical_series(n)
|
24
ttng1234/Q2/step4.py
Normal file
24
ttng1234/Q2/step4.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
test_list = [ 21,9,17,10 ]
|
||||||
|
|
||||||
|
def square_number_sequence(test_number):
|
||||||
|
|
||||||
|
# Initialize the sequence with the first number
|
||||||
|
sequence = [1]
|
||||||
|
|
||||||
|
# Generate the Square sequence
|
||||||
|
keep_find = True
|
||||||
|
i = 2
|
||||||
|
while keep_find:
|
||||||
|
next_num = i * i
|
||||||
|
keep_find = next_num < test_number
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
return next_num == test_number
|
||||||
|
|
||||||
|
def check_mathematical_series(n: int) -> str:
|
||||||
|
print(square_number_sequence(n))
|
||||||
|
|
||||||
|
for n in test_list:
|
||||||
|
check_mathematical_series(n)
|
9
ttng1234/docker-share/Dockerfile
Normal file
9
ttng1234/docker-share/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# CREDIT: https://github.com/shren207/nextjs-docker-compose
|
||||||
|
# Dockerfile
|
||||||
|
FROM node:18-buster
|
||||||
|
|
||||||
|
RUN mkdir -p /app/node_modules
|
||||||
|
RUN chown 1000:1000 -R /app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
USER 1000:1000
|
5
ttng1234/docker-share/app/entry.sh
Normal file
5
ttng1234/docker-share/app/entry.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
npm i
|
||||||
|
npm run start
|
2117
ttng1234/docker-share/app/package-lock.json
generated
Normal file
2117
ttng1234/docker-share/app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
ttng1234/docker-share/app/package.json
Normal file
17
ttng1234/docker-share/app/package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "app",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "http-server --cors ./public"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"http-server": "^14.1.1",
|
||||||
|
"serve": "^14.2.0"
|
||||||
|
}
|
||||||
|
}
|
1
ttng1234/docker-share/app/public/index.html
Normal file
1
ttng1234/docker-share/app/public/index.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
helloworld ttng1234
|
32
ttng1234/docker-share/docker-compose.yml
Normal file
32
ttng1234/docker-share/docker-compose.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# CREDIT: https://github.com/shren207/nextjs-docker-compose
|
||||||
|
# CREATED: 09-09-2023
|
||||||
|
services:
|
||||||
|
ttng1234_share:
|
||||||
|
container_name: ttng1234_share
|
||||||
|
build: .
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- $PWD/app:/app
|
||||||
|
- ttng1234_node_modules:/app/node_modules
|
||||||
|
working_dir: /app
|
||||||
|
# command: sleep infinity
|
||||||
|
command: bash entry.sh
|
||||||
|
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.ttng1234-http.rule=Host(`ttng1234.louislabs.com`)"
|
||||||
|
- "traefik.http.routers.ttng1234-http.entrypoints=web"
|
||||||
|
- "traefik.http.routers.ttng1234-http.middlewares=ttng1234-https"
|
||||||
|
- "traefik.http.middlewares.ttng1234-https.redirectscheme.scheme=https"
|
||||||
|
- "traefik.http.routers.ttng1234.rule=Host(`ttng1234.louislabs.com`)"
|
||||||
|
- "traefik.http.routers.ttng1234.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.ttng1234.tls.certresolver=myresolver"
|
||||||
|
- "traefik.http.services.ttng1234.loadbalancer.server.port=8080"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
external:
|
||||||
|
name: traefik-proxy-network
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
ttng1234_node_modules:
|
13
ttng1234/docker-share/package.json
Normal file
13
ttng1234/docker-share/package.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "docker-helloworld",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"into_docker": "docker compose exec -it test bash"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
9
ttng1234/docker-share/up.sh
Normal file
9
ttng1234/docker-share/up.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
git pull
|
||||||
|
|
||||||
|
docker compose pull
|
||||||
|
docker compose build
|
||||||
|
docker compose kill
|
||||||
|
docker compose down
|
||||||
|
docker compose up -d
|
7
ttng1234/gitUpdate.bat
Normal file
7
ttng1234/gitUpdate.bat
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
git status .
|
||||||
|
|
||||||
|
@pause
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -m"update ttng1234,"
|
||||||
|
start git push
|
BIN
ttng1234/job1/Assignment 1.pdf
Normal file
BIN
ttng1234/job1/Assignment 1.pdf
Normal file
Binary file not shown.
1
ttng1234/job1/quotation.md
Normal file
1
ttng1234/job1/quotation.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# \ttng1234
|
23
ttng1234/meta.md
Normal file
23
ttng1234/meta.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
tags: [python, colab]
|
||||||
|
---
|
||||||
|
|
||||||
|
# ttng1234
|
||||||
|
|
||||||
|
## balance history
|
||||||
|
|
||||||
|
原則上我唔想表現到改小小野都要收錢
|
||||||
|
但係坦白講改完要全部對一轉都係工作量
|
||||||
|
|
||||||
|
https://sites.google.com/view/cuhk-stat5106-2023/week-1-7-sept
|
||||||
|
|
||||||
|
### quotation
|
||||||
|
|
||||||
|
HKD100
|
||||||
|
|
||||||
|
即係想睇我用 python 做一次
|
||||||
|
同埋比個 session 講點寫
|
||||||
|
係咪咁呀?
|
||||||
|
|
||||||
|
我諗我會報 HKD100
|
||||||
|
今次想收 python 定 colab ?
|
22
ttng1234/package.json
Normal file
22
ttng1234/package.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "daniel_jo_assignment_student",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"directories": {
|
||||||
|
"doc": "docs"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"gitUpdate": "git add . && git commit -m\"update ttng1234,\" && git push"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@fortawesome/free-solid-svg-icons": "^6.2.1",
|
||||||
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||||
|
"bootstrap": "^5.2.3",
|
||||||
|
"react-bootstrap": "^2.6.0"
|
||||||
|
}
|
||||||
|
}
|
BIN
ttng1234/quotation/Assignment 2.docx
Normal file
BIN
ttng1234/quotation/Assignment 2.docx
Normal file
Binary file not shown.
BIN
ttng1234/quotation/_img/table1.png
(Stored with Git LFS)
Normal file
BIN
ttng1234/quotation/_img/table1.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ttng1234/quotation/_img/table2.png
(Stored with Git LFS)
Normal file
BIN
ttng1234/quotation/_img/table2.png
(Stored with Git LFS)
Normal file
Binary file not shown.
10
ttng1234/quotation/part_x.py
Normal file
10
ttng1234/quotation/part_x.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
print("please enter number of your choice:")
|
||||||
|
user_entry = eval(input())
|
||||||
|
# [user_entry] = [1,2,3,4,5,6]
|
||||||
|
print('Number of your entry: ', user_entry)
|
||||||
|
pprint(user_entry[0])
|
||||||
|
pprint(user_entry[1])
|
||||||
|
pprint(user_entry[2])
|
||||||
|
pprint(user_entry[3])
|
109
ttng1234/quotation/question.md
Normal file
109
ttng1234/quotation/question.md
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
# ASSIGNMENT 2
|
||||||
|
|
||||||
|
## Q1. 25%, Mark Six Simulation
|
||||||
|
|
||||||
|
Mark Six introduction
|
||||||
|
The Mark Six Lottery is a 6 out of 49 lotto game which is conducted by HKJC Lotteries Limited, a subsidiary of The Hong Kong Jockey Club.
|
||||||
|
|
||||||
|
After each draw if your entry satisfies some situations, the prize will be paid.
|
||||||
|
Mark Six Prize Qualification
|
||||||
|
|
||||||
|
https://bet.hkjc.com/marksix/userinfo.aspx?lang=en&file=prize_entitlement.asp
|
||||||
|
|
||||||
|
| 1st Prize | Pick all the 6 Drawn Numbers | Prize is determined by the total number of winning unit investments in the First Division Prize. The minimum First Division Prize Fund is set at HK$8 million |
|
||||||
|
| --------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| 2nd Prize | Pick 5 Drawn Numbers plus the Extra Number | Prize is determined by the total number of winning unit investments in the Second Division Prize |
|
||||||
|
| 3rd Prize | Pick 5 Drawn Numbers | Prize is determined by the total number of winning unit investments in the Third Division Prize |
|
||||||
|
| 4th Prize | Pick 4 Drawn Numbers plus the Extra Number | A fixed prize of $9,600 |
|
||||||
|
| 5th Prize | Pick 4 Drawn Numbers | A fixed prize of $640 |
|
||||||
|
| 6th Prize | Pick 3 Drawn Numbers plus the Extra Number | A fixed prize of $320 |
|
||||||
|
| 7th Prize | Pick 3 Drawn Numbers | A fixed prize of $40 |
|
||||||
|
|
||||||
|
### For simplify the question, the prizes are assumed as following:
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
Task to do
|
||||||
|
a. Write a function for inputting the list of your entry numbers, and the tuple with list of the draw numbers and the special number,
|
||||||
|
then outputting the unit prize.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
Numbers of your entry: [14, 21, 25, 34, 37, 41]
|
||||||
|
Numbers of draw: ([21, 25, 34, 37, 41, 46], 14)
|
||||||
|
Unit prize of your entry: 885990 (2nd prize)
|
||||||
|
```
|
||||||
|
|
||||||
|
Please check in the function: ensure the input formats are as same as the example.
|
||||||
|
|
||||||
|
1. `np.random.choice`
|
||||||
|
1. `np.arange`
|
||||||
|
1. `np.random.seed(21800000)`
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
######
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
######
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
######
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
######
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
######
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
######
|
140
ttng1234/quotation/src/index.py
Normal file
140
ttng1234/quotation/src/index.py
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# NOTE: os and sys are library usually for troubleshooting purpose
|
||||||
|
import os,sys
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# NOTE: prepare prize table for lookup,
|
||||||
|
prize_table = [
|
||||||
|
['1st', 21531600],
|
||||||
|
['2nd', 885990],
|
||||||
|
['3rd', 157500],
|
||||||
|
['4th', 9600],
|
||||||
|
['5th', 640],
|
||||||
|
['6th', 320],
|
||||||
|
['7th', 40],
|
||||||
|
]
|
||||||
|
|
||||||
|
def prize_matching(all_drawn_number, user_entry_nums):
|
||||||
|
"""
|
||||||
|
A function that calculates the prize based on matching numbers with user entries.
|
||||||
|
Parameters:
|
||||||
|
all_drawn_number (tuple): Tuple containing a list of drawn numbers and an extra number.
|
||||||
|
user_entry_nums (list): List of user's chosen numbers.
|
||||||
|
Returns:
|
||||||
|
list: A list representing the prize won.
|
||||||
|
"""
|
||||||
|
# NOTE:
|
||||||
|
prize = ['',0]
|
||||||
|
[drawn_numbers, extra_number] = all_drawn_number
|
||||||
|
|
||||||
|
# NOTE: find number of match in drawn numbers with user entry numbers
|
||||||
|
matched_number = 0
|
||||||
|
for user_num in user_entry_nums:
|
||||||
|
for drawn_number in drawn_numbers:
|
||||||
|
if (drawn_number == user_num):
|
||||||
|
matched_number = matched_number + 1
|
||||||
|
break
|
||||||
|
|
||||||
|
# NOTE: find if any extra number match user entry number
|
||||||
|
matched_extra_number = 0
|
||||||
|
for user_num in user_entry_nums:
|
||||||
|
if (user_num == extra_number):
|
||||||
|
matched_extra_number = matched_extra_number + 1
|
||||||
|
break
|
||||||
|
|
||||||
|
if (matched_number == 6):
|
||||||
|
# first_prize = True
|
||||||
|
prize = prize_table[0]
|
||||||
|
elif (matched_number == 5 and matched_extra_number == 1):
|
||||||
|
# second_prize = True
|
||||||
|
prize = prize_table[1]
|
||||||
|
elif (matched_number == 5):
|
||||||
|
# third_prize = True
|
||||||
|
prize = prize_table[2]
|
||||||
|
elif (matched_number == 4 and matched_extra_number == 1):
|
||||||
|
# forth_prize = True
|
||||||
|
prize = prize_table[3]
|
||||||
|
elif (matched_number == 4):
|
||||||
|
# fifth_prize = True
|
||||||
|
prize = prize_table[4]
|
||||||
|
elif (matched_number == 3 and matched_extra_number == 1):
|
||||||
|
# sixth_prize = True
|
||||||
|
prize = prize_table[5]
|
||||||
|
elif (matched_number == 3):
|
||||||
|
# seventh_prize = True
|
||||||
|
prize = prize_table[6]
|
||||||
|
else:
|
||||||
|
# no prize matched
|
||||||
|
pass
|
||||||
|
return prize
|
||||||
|
|
||||||
|
def print_output(prize_result, user_entry_nums):
|
||||||
|
# deliver prize message
|
||||||
|
print("Numbers of your entry: ", user_entry_nums)
|
||||||
|
print('')
|
||||||
|
print('Result :')
|
||||||
|
if (prize_result[1] > 0):
|
||||||
|
print("Output prize = " + str(prize_result[0]) + " = $" + str(prize_result[1]))
|
||||||
|
else:
|
||||||
|
print("No prize given")
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
keep_asking = True
|
||||||
|
while keep_asking:
|
||||||
|
# part a
|
||||||
|
user_entry_numbers = input("Please entry 6 numbers of your choice:")
|
||||||
|
user_entry_numbers = eval(user_entry_numbers)
|
||||||
|
|
||||||
|
# NOTE: check if number of user entered is not equal to 6
|
||||||
|
len_equal_to_six = False
|
||||||
|
if (len(user_entry_numbers) != 6):
|
||||||
|
print('user entered numbers should be exactly 6')
|
||||||
|
print('Please input the correct number.')
|
||||||
|
print()
|
||||||
|
else:
|
||||||
|
len_equal_to_six = True
|
||||||
|
|
||||||
|
# NOTE: check if each number within range
|
||||||
|
numbers_are_in_range = True
|
||||||
|
for user_num in user_entry_numbers:
|
||||||
|
if (user_num < 1 or user_num > 49):
|
||||||
|
print('user entered number should be within 1 to 49')
|
||||||
|
print('Please input the correct number.')
|
||||||
|
print()
|
||||||
|
numbers_are_in_range = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if (len_equal_to_six == True and numbers_are_in_range == True):
|
||||||
|
keep_asking = False
|
||||||
|
|
||||||
|
# part b
|
||||||
|
# drawn 7 numbers
|
||||||
|
# init seed randomizer
|
||||||
|
np.random.seed(21800000)
|
||||||
|
|
||||||
|
# init empty slot for number
|
||||||
|
temp_numbers = np.arange(0, 7, 1, dtype=int)
|
||||||
|
|
||||||
|
# [1,2,3,4,5,6,7]
|
||||||
|
temp_numbers = np.random.choice(range(1,49), 7)
|
||||||
|
|
||||||
|
# the first 6 number are considered drawn number
|
||||||
|
# [1,2,3,4,5,6]
|
||||||
|
drawn_nums = temp_numbers[0:6].tolist()
|
||||||
|
|
||||||
|
# the last one considered extra number
|
||||||
|
# 7
|
||||||
|
extra_num = temp_numbers[6]
|
||||||
|
|
||||||
|
# re-format number to duple
|
||||||
|
# ([1,2,3,4,5,6],7)
|
||||||
|
all_drawn_nums = (drawn_nums, extra_num)
|
||||||
|
|
||||||
|
# part a
|
||||||
|
print("all drawn numbers: ", all_drawn_nums)
|
||||||
|
print("drawn numbers: " , drawn_nums)
|
||||||
|
print("extra number: " , extra_num)
|
||||||
|
|
||||||
|
# part a
|
||||||
|
result = prize_matching(all_drawn_nums, user_entry_numbers)
|
||||||
|
print_output(result, user_entry_numbers)
|
188
ttng1234/quotation/src/part_a.py
Normal file
188
ttng1234/quotation/src/part_a.py
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
import os,sys
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
prize_table = [
|
||||||
|
['1st', 21531600],
|
||||||
|
['2nd', 885990],
|
||||||
|
['3rd', 157500],
|
||||||
|
['4th', 9600],
|
||||||
|
['5th', 640],
|
||||||
|
['6th', 320],
|
||||||
|
['7th', 40],
|
||||||
|
]
|
||||||
|
|
||||||
|
def prize_matching(all_drawn_number, user_entry_nums):
|
||||||
|
# initialize to default output
|
||||||
|
prize = ['',0]
|
||||||
|
|
||||||
|
# all_drawn_number = ([1,2,3,4,...],7)
|
||||||
|
[drawn_numbers, extra_number] = all_drawn_number
|
||||||
|
# drawn_numbers = [1,2,3,4,...]
|
||||||
|
# extra_number = 7
|
||||||
|
|
||||||
|
# match drawn number
|
||||||
|
matched_number = 0
|
||||||
|
# user_entry_nums = [1,2,3,4,5,6]
|
||||||
|
for u_num in user_entry_nums:
|
||||||
|
# 1st loop u_num = 1
|
||||||
|
# 2nd loop u_num = 2
|
||||||
|
|
||||||
|
# drawn_numbers = [1,2,3,4,5,6]
|
||||||
|
for drawn_number in drawn_numbers:
|
||||||
|
# 1st loop drawn_number = 1
|
||||||
|
# 2nd loop drawn_number = 2
|
||||||
|
|
||||||
|
if (drawn_number == u_num):
|
||||||
|
matched_number = matched_number + 1
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
matched_extra_number = 0
|
||||||
|
# user_entry_nums = [1,2,3,4,5,6]
|
||||||
|
for user_num in user_entry_nums:
|
||||||
|
# 1st loop user_num = 1
|
||||||
|
# 2nd loop user_num = 2
|
||||||
|
if (user_num == extra_number):
|
||||||
|
matched_extra_number = matched_extra_number + 1
|
||||||
|
break
|
||||||
|
|
||||||
|
# matched_number = n
|
||||||
|
# matched_extra_number = n
|
||||||
|
|
||||||
|
# refer to HKJC https://bet.hkjc.com/marksix/userinfo.aspx?lang=en&file=prize_entitlement.asp
|
||||||
|
if (matched_number == 6):
|
||||||
|
# first_prize = True
|
||||||
|
prize = prize_table[0]
|
||||||
|
# prize = ['1st', 21531600]
|
||||||
|
elif (matched_number == 5 and matched_extra_number == 1):
|
||||||
|
# second_prize = True
|
||||||
|
prize = prize_table[1]
|
||||||
|
# prize = ['2nd', nnnnn]
|
||||||
|
elif (matched_number == 5):
|
||||||
|
# third_prize = True
|
||||||
|
prize = prize_table[2]
|
||||||
|
elif (matched_number == 4 and matched_extra_number == 1):
|
||||||
|
# forth_prize = True
|
||||||
|
prize = prize_table[3]
|
||||||
|
elif (matched_number == 4):
|
||||||
|
# fifth_prize = True
|
||||||
|
prize = prize_table[4]
|
||||||
|
elif (matched_number == 3 and matched_extra_number == 1):
|
||||||
|
# sixth_prize = True
|
||||||
|
prize = prize_table[5]
|
||||||
|
elif (matched_number == 3):
|
||||||
|
# seventh_prize = True
|
||||||
|
prize = prize_table[6]
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
return prize
|
||||||
|
|
||||||
|
def print_output(prize_result, user_entry_nums):
|
||||||
|
# prize_result = ['1st', 21531600]
|
||||||
|
# user_entry_nums = [1,2,3,4,5,6]
|
||||||
|
print("Numbers of your entry: ", user_entry_nums)
|
||||||
|
|
||||||
|
# str(prize_result[0]) = '1st'
|
||||||
|
# str(prize_result[1]) = '21531600'
|
||||||
|
print("Output prize = " + str(prize_result[0]) + " = $" + str(prize_result[1]))
|
||||||
|
pass
|
||||||
|
|
||||||
|
# number of entry
|
||||||
|
# Numbers of your entry: [14, 21, 25, 34, 37, 41]
|
||||||
|
# ask user for numbers
|
||||||
|
print("please enter number of your choice:")
|
||||||
|
user_entry = eval(input())
|
||||||
|
# [user_entry] = [1,2,3,4,5,6]
|
||||||
|
print('Number of your entry: ', user_entry)
|
||||||
|
# user_entry[0]
|
||||||
|
# user_entry[1]
|
||||||
|
# user_entry[2]
|
||||||
|
# user_entry[3]
|
||||||
|
|
||||||
|
# NOTE: check if number of user entered is not equal to 6
|
||||||
|
if (len(user_entry) != 6):
|
||||||
|
print('user entered numbers should be exactly 6')
|
||||||
|
print('quitting ... ')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# NOTE: check if each number within range
|
||||||
|
for user_num in user_entry:
|
||||||
|
if (user_num < 1 or user_num > 49):
|
||||||
|
print('user entered number should be within 1 to 49')
|
||||||
|
print('quitting ... ')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Number of draw
|
||||||
|
# Numbers of draw: ([21, 25, 34, 37, 41, 46], 14)
|
||||||
|
|
||||||
|
# init seed randomizer
|
||||||
|
np.random.seed(21800000)
|
||||||
|
|
||||||
|
# init empty slot for number
|
||||||
|
temp_numbers = np.arange(0, 7, 1, dtype=int)
|
||||||
|
|
||||||
|
# drawn 7 numbers
|
||||||
|
# [1,2,3,4,5,6,7]
|
||||||
|
temp_numbers = np.random.choice(range(1,49), 7)
|
||||||
|
|
||||||
|
# the first 6 number are considered drawn number
|
||||||
|
# [1,2,3,4,5,6]
|
||||||
|
drawn_nums = temp_numbers[0:6].tolist()
|
||||||
|
|
||||||
|
# the last one considered extra number
|
||||||
|
# 7
|
||||||
|
extra_num = temp_numbers[6]
|
||||||
|
|
||||||
|
# re-format number to tuple
|
||||||
|
# ([1,2,3,4,5,6],7)
|
||||||
|
all_drawn_nums = (drawn_nums, extra_num)
|
||||||
|
print(all_drawn_nums)
|
||||||
|
|
||||||
|
# (1,2) <- duple
|
||||||
|
# a = (1,2)
|
||||||
|
# print(a[0]) => 1
|
||||||
|
# print(a[1]) => 2
|
||||||
|
|
||||||
|
# ("A","B","C")
|
||||||
|
# (1,2,3) <- tuple
|
||||||
|
# print(a[0]) => 1
|
||||||
|
# print(a[1]) => 2
|
||||||
|
# print(a[2]) => 3
|
||||||
|
|
||||||
|
# ([1,2,3,4],5) <- tuple
|
||||||
|
|
||||||
|
# NOTE: test prize matching
|
||||||
|
# 1st prize
|
||||||
|
user_numbers = [1,2,3,4,5,6]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
||||||
|
|
||||||
|
# 2
|
||||||
|
user_numbers = [1,2,7,4,5,6]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
||||||
|
|
||||||
|
# 3
|
||||||
|
user_numbers = [1,9,2,3,4,5]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
||||||
|
|
||||||
|
# 4
|
||||||
|
user_numbers = [1,9,7,3,4,5]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
||||||
|
|
||||||
|
# 5
|
||||||
|
user_numbers = [10,9,1,3,4,5]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
||||||
|
|
||||||
|
# 6
|
||||||
|
user_numbers = [1,9,44,7,4,5]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
||||||
|
|
||||||
|
# 7
|
||||||
|
user_numbers = [1,9,44,45,4,5]
|
||||||
|
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
|
||||||
|
print_output(result, user_numbers)
|
9
ttng1234/quotation/src/part_b.py
Normal file
9
ttng1234/quotation/src/part_b.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
all_drawn_nums = np.random.choice(range(1,49), 7)
|
||||||
|
drawn_nums = all_drawn_nums[0:6]
|
||||||
|
extra_num = all_drawn_nums[6]
|
||||||
|
|
||||||
|
print("all drawn numbers: ", all_drawn_nums)
|
||||||
|
print("drawn numbers: " , drawn_nums)
|
||||||
|
print("extra number: " , extra_num)
|
Reference in New Issue
Block a user