This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import openai | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Load your API key from an environment variable or secret management service | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
NBTRAIN = 100 | |
NBTEST = 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem: 821`763= | |
Explanation: | |
The first number is 821, FN=[8,2,1]. The second number is 763, SN=[7,6,3]. Since FN [8,2,1] has 3 digits, SN [7,6,3] has 3 digits, thus the maximum number of digits is 3. In each subsequent step, we remove one number from the beginning of FN and one from the beginning of SN. | |
Length of FN is 3. FN=[8,2,1]. Length of SN is 3. SN=[7,6,3]. FN[3]=8. SN[3]=7. C[3]=0. Since 8*7=56, 56%10=6, 56//10=5. Length of A is 1. Thus A=[6]. Since 5 is odd, we change the value of C. Since C[3]=0, C[2]=1. | |
Length of FN is 2. FN=[2,1]. Length of SN is 2. SN=[6,3]. FN[2]=2. SN[2]=6. C[2]=1. Since 2*6=12, 12%10=2, 12//10=1. Length of A is 2. Thus A=[6,2]. Since 1 is odd, we change the value of C. Since C[2]=1, C[1]=0. | |
Length of FN is 1. FN=[1]. Length of SN is 1. SN=[3]. FN[1]=1. SN[1]=3. C[1]=0. Since 1*3=4, 4%10=4, 4//10=0. Length of A is 3. Thus A=[6,2,4]. Since 0 is even, we do not change the value of C. Since C[1]=0, C[0]=0. | |
There are no more digits and C[0]=0. Thus the process is complete. Sin |