※ 本文為 zbali.bbs. 轉寄自 ptt.cc 更新時間: 2018-08-14 13:42:15
看板 Gossiping
作者 gocreating (小平)
標題 Re: [問卦] 線上等,問個數學問題,謝謝
時間 Tue Aug 14 13:19:13 2018


※ 引述《kbgarnett (Ice)》之銘言:
: 餓死抬頭
: 剛一個數學問題想了很久想不出來
: 總數13204
: 如果用399、888、1299、2999
: 在總計26次裡
: 可以各幾次總加成13204嗎
: 謝謝
: -----
: Sent from JPTT on my iPhone

用 python 搭配 numpy 暴力解一下:

import numpy as np
import math
from itertools import product

TARGET = 13204
PARTS = [399, 888, 1299, 2999]
upper_bounds = [math.ceil(TARGET / part) for part in PARTS]
candidates = [np.arange(upper_bound) for upper_bound in upper_bounds]
cartesian_products = np.array([prod for prod in product(*candidates)])
inner_products = np.inner(PARTS, cartesian_products)
indices = np.argwhere(inner_products == TARGET)[:, 0]
results = cartesian_products[indices]

print(TARGET, end='')
for result in results:
    print('\n= ', end='')
    for i in range(len(PARTS)):
        print(' +' if i > 0 else '', PARTS[i], '*', result[i], end='')

靠北根本無解啊

--
http://i.imgur.com/OyDCwTJ.jpg
by 系列圖簽名檔產生器:
https://github.com/gocreating/signature-image-generator

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.236.60
※ 文章代碼(AID): #1RScPW_h (Gossiping)
※ 文章網址: https://www.ptt.cc/bbs/Gossiping/M.1534223968.A.FEB.html
randy101021: 樓下 懂嗎1F 115.82.63.68 台灣 08/14 13:19
hh800315: ㄅ欠 不懂2F 111.83.78.166 台灣 08/14 13:20
randy101021: 沒關係 我也不懂3F 115.82.63.68 台灣 08/14 13:20
yottaloser: 五樓文組看不懂4F 111.71.53.96 台灣 08/14 13:20
eudemon85219: 快推免得別人以為我不…算了5F 180.204.147.231 台灣 08/14 13:21
dodomilk: 這個你也要用np解......6F 111.250.201.223 台灣 08/14 13:24
joj4211: 殺雞牛刀7F 111.71.107.65 台灣 08/14 13:32

--
※ 看板: ott 文章推薦值: 0 目前人氣: 0 累積人氣: 76 
guest
x)推文 r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇