int f(int x)
{
if (x < 1)
return 0;
else
return f(x - 3) + x;
}
Can some one explain how it calculates the final result for f(10)=22?
step by step please
Working through this step by step is not difficult.
f(10)
f(10 - 3) + 10
(f(7 - 3) + 7) + 10
((f(4 - 3) + 4) + 7) + 10
(((f(1 - 3) + 1) + 4) + 7) + 10
(((0 + 1) + 4) + 7) + 10
((1 + 4) + 7) + 10
(5 + 7) + 10
12 + 10
22
f(10) = f(7) + 10 = f(4) + 10 + 7 = f(1) + 10 + 7 + 4 = f(-2) + 10 + 7 + 4 + 1 = 0 + 10 + 7 + 4 + 1
Related
I have the following code:
u_ini = 0.1
v_ini = 0.1
z_ini = 0.1 # 初始化三个拉格朗日乘子
q = 0
lis = list(range(2))
u = list(sp.symbols('u:{}'.format(len(lis))))
v = list(sp.symbols('v:{}'.format(len(lis))))
z = sp.symbols('z')
p = list(sp.symbols('p:{}'.format(len(lis))))
lag1 = 0
lag2 = 0
lag3 = 0
p_symbol_sum = np.sum(p)
for i in range(k):
if i < k-1:
lag1 += B*ts_ratio[i]*sp.log(1+g[i]*p[i]/(sgm_2+g[i]*np.sum(p[i+1:k])),2)-q*(af_eff*p[i]+Pc-eh_eff*(1-ts_ratio[i])*g[i]*p_symbol_sum)
lag2 -= u[i] * (R_min - ts_ratio[i] * B * sp.log(1 + g[i] * p[i] / (sgm_2 + g[i] * np.sum(p[i + 1:k])),2))
elif i == k-1:
lag1 += B*ts_ratio[i]*sp.log(1+g[i]*p[i]/(sgm_2+g[i]*p[i]),2)-q*(af_eff*p[i]+Pc-eh_eff*(1-ts_ratio[i])*g[i]*p_symbol_sum)
lag2 -= u[i] * (R_min - ts_ratio[i] * B * sp.log(1+g[i]*p[i]/(sgm_2+g[i]*p[i]),2))
lag3 -= v[i] * (E_min - (1 - ts_ratio[i])*eh_eff*g[i]*p_symbol_sum) + z * (p[i] - p_max)
lag_fun = lag1 + lag2 + lag3
print("lag_fun:",lag_fun)
for i in range(k):
lag_fun.subs([(u[i],u_ini), (v[i],v_ini), (z,z_ini), (p[i],p_ini)]).evalf()
print("lag_fun:",lag_fun)
Why does the value of the expression not change after I count down the subs of the second line。
This is the output of the program. The first line is the output before using subs. The second is the output after using subs. Why hasn't it changed?
lag_fun: -u0*(-0.5*log(0.0410609879149758*p0/(0.0410609879149758*p1 + 0.001) + 1)/log(2) + 2) - u1*(-0.5*log(0.0123909311217172*p1/(0.0123909311217172*p1 + 0.001) + 1)/log(2) + 2) - v0*(-0.00205304939574879*p0 - 0.00205304939574879*p1 + 0.2) - v1*(-0.000619546556085859*p0 - 0.000619546556085859*p1 + 0.2) - z*(p0 - 20) - z*(p1 - 20) + 0.5*log(0.0410609879149758*p0/(0.0410609879149758*p1 + 0.001) + 1)/log(2) + 0.5*log(0.0123909311217172*p1/(0.0123909311217172*p1 + 0.001) + 1)/log(2)
lag_fun: -u0*(-0.5*log(0.0410609879149758*p0/(0.0410609879149758*p1 + 0.001) + 1)/log(2) + 2) - u1*(-0.5*log(0.0123909311217172*p1/(0.0123909311217172*p1 + 0.001) + 1)/log(2) + 2) - v0*(-0.00205304939574879*p0 - 0.00205304939574879*p1 + 0.2) - v1*(-0.000619546556085859*p0 - 0.000619546556085859*p1 + 0.2) - z*(p0 - 20) - z*(p1 - 20) + 0.5*log(0.0410609879149758*p0/(0.0410609879149758*p1 + 0.001) + 1)/log(2) + 0.5*log(0.0123909311217172*p1/(0.0123909311217172*p1 + 0.001) + 1)/log(2)
subs doesn't change anything in place, you have to capture the result for the same reason that this loop fails to change x:
>>> x = 0
>>> for i in range(10): x + 1
>>> x
0
So it must be
lag_fun = lag_fun.subs(etc...)
I was working on a simple problem and I came up with a recursive function in C++, below is my function.
void test(int arr[],int n,int x = 0){
cout<<arr[x];
for(int i = x+1;i < n;i++){
test(arr, n, i);
}
}
I wonder what will be the time complexity of the above function if anyone can calculate the time complexity for the above method it will be a great help in improving my function.
You can write its recurrent relation likes the following:
T(n) = T(n-1) + T(n-2) + ... + T(1) + 1
Indeed T'(x) is T(n - x) and T(1) = 1 (The last one in the realtion is is for cout). We can see:
T(2) = T(1) + 1 = 2
T(3) = T(2) + T(1) + 1 = 2 + 1 + 1 = 4
T(4) = 4 + 2 + 1 + 1 = 2^2 + 2^1 + 2^0 + 1 = 8
T(5) = 8 + 4 + 2 + 1 + 1 = 2^3 + 2^2 + 2^1 + 2^0 + 1 = 16
.
.
.
T(n) = 2^{n-2} + 2^{n-1} + ... + 2^0 + 1 = 2^{n-1}
Hence, T(n) = \Theta(2^n).
For some reason, both my online, and desktop compiling environments think that everything is invalid syntax all of the sudden! here is my code:
def sumn(n): #summation for sigma
return ((n + 1) * n) / 2
ipt = raw_input('How In Depth Would You Like To Go? ')
ipt = int(ipt)
pi = sumn(ipt) * ((4 / (8 * ipt + 1)) - (2 / (8 * ipt + 4)) - (1 / (8 * ipt + 5)) - (1 / (8 * ipt + 6)) * (1 / (16 ^ ipt))
print pi
Your indent for the function sumn(n)is invalid.
Your syntax for line : ipt = int(raw_input('How In Depth Would You Like To Go? ')) is incorrect.
For power use ** instead of ^.
I've got your code working with proper indentation and syntax for pi:
>>> def sumn(n): #summation for sigma
return ((n + 1) * n) / 2
>>> ipt = float(raw_input('How In Depth Would You Like To Go? '))
How In Depth Would You Like To Go? 4
>>> pi = sumn(ipt) * ((4 / (8 * ipt + 1)) - (2 / (8 * ipt + 4)) - (1 / (8 * ipt + 5)) - (1 / (8 * ipt + 6)) * (1 / (16 ** ipt)))
>>> print pi
0.386291370825
Yayy, I finally solved it!
from decimal import *
def sumn(n): #summation for sigma
return ((n + 1) * n) / 2
ipt = int(raw_input('How In Depth Would You Like To Go? '))
getcontext().prec = ipt
def factorial(n):
if n<1:
return 1
else:
return n * factorial(n-1)
def BBP(n):
pi = Decimal(0)
k = 0
while k < n:
pi += (Decimal(1) / (16 ** k)) * ((Decimal(4) / (8 * k + 1)) - (Decimal(2) / (8 * k + 4)) - (Decimal(1) / (8 * k + 5)) - (Decimal(1) / (8 * k + 6)))
k += 1
return pi
print BBP(ipt)
ex.
How In Depth Would You Like To Go? 1000
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420193
The last two values are usually wrong though, and I am still working on trying to truncate them. Then all I have to do is add 2 to ipt, which would take me all of 5 seconds ☺
I am getting an error in my c++/gurobi file:
Error code = 10004 Unable to retrieve attribute 'X'
I read that this might have something to do with labels? But I don't see how there is a problem.
It works for some input files, but not for others. So I have created a toy file, t5.txt in attachment. This file does not work, but removing the last column and setting 8 to 7 fixes it. I am puzzled...
Below is the output of model.write. Everything seems to make sense, any Ideas what I am doing wrong?
Whenever I do a model.write(test.sol), the program stops, so there seems to be something wrong with the solution>
Attachments:
main.cpp -> https://dl.dropboxusercontent.com/u/13564139/main.cpp
input.txt -> https://dl.dropboxusercontent.com/u/13564139/t5.txt
Maximize
15 student_has_projects4.1
Subject To
R0: student_has_projects0.0 + student_has_projects1.0
+ student_has_projects2.0 + student_has_projects3.0
+ student_has_projects4.0 + student_has_projects5.0
+ student_has_projects6.0 + student_has_projects7.0 <= 4
R1: student_has_projects1.0 + student_has_projects2.0 >= 1
R2: student_has_projects2.0 + 2 student_has_projects5.0 <= 2
R3: student_has_projects2.0 + 2 student_has_projects5.0 >= 1
R4: student_has_projects0.0 + student_has_projects3.0
+ student_has_projects4.0 + student_has_projects6.0
+ student_has_projects7.0 >= 1
R5: student_has_projects2.0 + student_has_projects5.0 <= 1
R6: student_has_projects0.1 + student_has_projects1.1
+ student_has_projects2.1 + student_has_projects3.1
+ student_has_projects4.1 + student_has_projects5.1
+ student_has_projects6.1 + student_has_projects7.1 <= 4
R7: student_has_projects1.1 + student_has_projects2.1 >= 1
R8: student_has_projects2.1 + 2 student_has_projects5.1 <= 2
R9: student_has_projects2.1 + 2 student_has_projects5.1 >= 1
R10: student_has_projects0.1 + student_has_projects3.1
+ student_has_projects4.1 + student_has_projects6.1
+ student_has_projects7.1 >= 1
R11: student_has_projects2.1 + student_has_projects5.1 <= 1
R12: student_has_projects0.2 + student_has_projects1.2
+ student_has_projects2.2 + student_has_projects3.2
+ student_has_projects4.2 + student_has_projects5.2
+ student_has_projects6.2 + student_has_projects7.2 <= 4
R13: student_has_projects1.2 + student_has_projects2.2 >= 1
R14: student_has_projects2.2 + 2 student_has_projects5.2 <= 2
R15: student_has_projects2.2 + 2 student_has_projects5.2 >= 1
R16: student_has_projects0.2 + student_has_projects3.2
+ student_has_projects4.2 + student_has_projects6.2
+ student_has_projects7.2 >= 1
R17: student_has_projects2.2 + student_has_projects5.2 <= 1
R18: student_has_projects0.0 + student_has_projects0.1
+ student_has_projects0.2 = 1
R19: student_has_projects1.0 + student_has_projects1.1
+ student_has_projects1.2 = 1
R20: student_has_projects2.0 + student_has_projects2.1
+ student_has_projects2.2 = 1
R21: student_has_projects3.0 + student_has_projects3.1
+ student_has_projects3.2 = 1
R22: student_has_projects4.0 + student_has_projects4.1
+ student_has_projects4.2 = 1
R23: student_has_projects5.0 + student_has_projects5.1
+ student_has_projects5.2 = 1
R24: student_has_projects6.0 + student_has_projects6.1
+ student_has_projects6.2 = 1
R25: student_has_projects7.0 + student_has_projects7.1
+ student_has_projects7.2 = 1
Bounds
Binaries
student_has_projects0.0 student_has_projects0.1 student_has_projects0.2
student_has_projects1.0 student_has_projects1.1 student_has_projects1.2
student_has_projects2.0 student_has_projects2.1 student_has_projects2.2
student_has_projects3.0 student_has_projects3.1 student_has_projects3.2
student_has_projects4.0 student_has_projects4.1 student_has_projects4.2
student_has_projects5.0 student_has_projects5.1 student_has_projects5.2
student_has_projects6.0 student_has_projects6.1 student_has_projects6.2
student_has_projects7.0 student_has_projects7.1 student_has_projects7.2
End
The issue is that your lp instance is infeasible so the call to .optimize() results in an infeasible status. From your code
model.write("test2.lp");
model.optimize();
model.write("forum2.sol");
if(model.get(GRB_IntAttr_Status) != GRB_OPTIMAL){
cout << "niet optimaal " << endl;
}
You are writing a .sol file before you check for success. Gurobi gets the 'X' attributes from the variables when it writes a .sol file. If the optimization fails, the 'X' attributes aren't available and an exception is thrown. You should make sure that gurobi has a solution before you write a .sol file, or get many attributes, including 'X', 'Pi' and 'ObjVal'. The OPTIMAL status codes assures you that that there is an available solution, but codes like SUBOPTIMAL also indicate that there is a solution available and others like TIME_LIMIT, NODE_LIMIT mean there might be a solution available. You can get the attribute SolCount to get a definitive indication that there is a solution available.
Your problem instance is infeasible because constraints (R1, R7, R13 imply you need at least 3 projects for students 1 and 2, but constraints (R19, R20) imply they can have exactly 1 project each. You can see this by using the IIS solver. In interactive gurobi you can get get an Irreducible Inconsistent Subsystem
m = read("test2.lp")
m.optimize()
m.computeIIS()
m.write("test2.ilp")
Given a date between 2010 and 2019, the function is supposed to return an int 0 though 6 corresponding to Sunday through Saturday. The function is based on the fact that January 1, 2010 was a Friday.
Why does the else statement toward the end else if year = 2019 elicit the error for its entire body: "This expression has type int but an expression was expected of type unit"?
let day_of_week (year: int) (month: int) (day: int): int =
if year < 2010 || year > 2019 then failwith "year out of range"
else if month < 1 || month > 12 then failwith "invalid month"
else if day < 1 then failwith "invalid day"
else if is_leap_year year != true then (
if month = 2 then (
if day > 28 then failwith "invalid day"
)
) else if month = 2 then
if day > 29 then failwith "invalid day"
else if month = 4 || month = 6 || month = 9 || month = 11 then
if day > 30 then failwith "invalid day"
else if day > 31 then failwith "invalid day"
else if year = 2010 then (
if month = 1 then ((day mod 7) + 4) mod 7
else if month = 2 then (((31 + day) mod 7) + 4) mod 7
else if month = 3 then (((59 + day) mod 7) + 4) mod 7
else if month = 4 then (((90 + day) mod 7) + 4) mod 7
else if month = 5 then (((120 + day) mod 7) + 4) mod 7
else if month = 6 then (((151 + day) mod 7) + 4) mod 7
else if month = 7 then (((181 + day) mod 7) + 4) mod 7
else if month = 8 then (((212 + day) mod 7) + 4) mod 7
else if month = 9 then (((243 + day) mod 7) + 4) mod 7
else if month = 10 then (((273 + day) mod 7) + 4) mod 7
else if month = 11 then (((304 + day) mod 7) + 4) mod 7
else (((334 + day) mod 7) + 4) mod 7
) else if year = 2011 then (
if month = 1 then (((365 + day) mod 7) + 4) mod 7
else if month = 2 then (((365 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((365 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((365 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((365 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((365 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((365 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((365 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((365 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((365 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((365 + 304 + day) mod 7) + 4) mod 7
else (((365 + 334 + day) mod 7) + 4) mod 7
) else if year = 2012 then (
if month = 1 then (((730 + day) mod 7) + 4) mod 7
else if month = 2 then (((730 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((730 + 60 + day) mod 7) + 4) mod 7
else if month = 4 then (((730 + 91 + day) mod 7) + 4) mod 7
else if month = 5 then (((730 + 121 + day) mod 7) + 4) mod 7
else if month = 6 then (((730 + 152 + day) mod 7) + 4) mod 7
else if month = 7 then (((730 + 182 + day) mod 7) + 4) mod 7
else if month = 8 then (((730 + 213 + day) mod 7) + 4) mod 7
else if month = 9 then (((730 + 244 + day) mod 7) + 4) mod 7
else if month = 10 then (((730 + 274 + day) mod 7) + 4) mod 7
else if month = 11 then (((730 + 305 + day) mod 7) + 4) mod 7
else (((730 + 335 + day) mod 7) + 4) mod 7
) else if year = 2013 then (
if month = 1 then (((1096 + day) mod 7) + 4) mod 7
else if month = 2 then (((1096 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((1096 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((1096 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((1096 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((1096 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((1096 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((1096 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((1096 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((1096 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((1096 + 304 + day) mod 7) + 4) mod 7
else (((1096 + 334 + day) mod 7) + 4) mod 7
) else if year = 2014 then (
if month = 1 then (((1461 + day) mod 7) + 4) mod 7
else if month = 2 then (((1461 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((1461 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((1461 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((1461 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((1461 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((1461 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((1461 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((1461 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((1461 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((1461 + 304 + day) mod 7) + 4) mod 7
else (((1461 + 334 + day) mod 7) + 4) mod 7
) else if year = 2015 then (
if month = 1 then (((1826 + day) mod 7) + 4) mod 7
else if month = 2 then (((1826 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((1826 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((1826 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((1826 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((1826 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((1826 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((1826 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((1826 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((1826 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((1826 + 304 + day) mod 7) + 4) mod 7
else (((1826 + 334 + day) mod 7) + 4) mod 7
) else if year = 2016 then (
if month = 1 then (((2191 + day) mod 7) + 4) mod 7
else if month = 2 then (((2191 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((2191 + 60 + day) mod 7) + 4) mod 7
else if month = 4 then (((2191 + 91 + day) mod 7) + 4) mod 7
else if month = 5 then (((2191 + 121 + day) mod 7) + 4) mod 7
else if month = 6 then (((2191 + 152 + day) mod 7) + 4) mod 7
else if month = 7 then (((2191 + 182 + day) mod 7) + 4) mod 7
else if month = 8 then (((2191 + 213 + day) mod 7) + 4) mod 7
else if month = 9 then (((2191 + 244 + day) mod 7) + 4) mod 7
else if month = 10 then (((2191 + 274 + day) mod 7) + 4) mod 7
else if month = 11 then (((2191 + 305 + day) mod 7) + 4) mod 7
else (((2191 + 335 + day) mod 7) + 4) mod 7
) else if year = 2017 then (
if month = 1 then (((2557 + day) mod 7) + 4) mod 7
else if month = 2 then (((2557 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((2557 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((2557 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((2557 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((2557 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((2557 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((2557 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((2557 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((2557 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((2557 + 304 + day) mod 7) + 4) mod 7
else (((2557 + 334 + day) mod 7) + 4) mod 7
) else if year = 2018 then (
if month = 1 then (((2922 + day) mod 7) + 4) mod 7
else if month = 2 then (((2922 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((2922 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((2922 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((2922 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((2922 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((2922 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((2922 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((2922 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((2922 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((2922 + 304 + day) mod 7) + 4) mod 7
else (((2922 + 334 + day) mod 7) + 4) mod 7
) else if year = 2019 then (
if month = 1 then (((3287 + day) mod 7) + 4) mod 7
else if month = 2 then (((3287 + 31 + day) mod 7) + 4) mod 7
else if month = 3 then (((3287 + 59 + day) mod 7) + 4) mod 7
else if month = 4 then (((3287 + 90 + day) mod 7) + 4) mod 7
else if month = 5 then (((3287 + 120 + day) mod 7) + 4) mod 7
else if month = 6 then (((3287 + 151 + day) mod 7) + 4) mod 7
else if month = 7 then (((3287 + 181 + day) mod 7) + 4) mod 7
else if month = 8 then (((3287 + 212 + day) mod 7) + 4) mod 7
else if month = 9 then (((3287 + 243 + day) mod 7) + 4) mod 7
else if month = 10 then (((3287 + 273 + day) mod 7) + 4) mod 7
else if month = 11 then (((3287 + 304 + day) mod 7) + 4) mod 7
else (((3287 + 334 + day) mod 7) + 4) mod 7
)
I believe your problem is this line:
if day > 28 then failwith "invalid day"
There's no else part. A missing else part is equivalent to (), which leads to the typing problem.
In fact the compiler is right. This code will in fact return () for non-leap years on days other than Feb 29, it seems to me.
One possible fix would be to change the section of code to this:
else if is_leap_year year != true && month = 2 && day > 28 then failwith "invalid day"
else . . .
As a side comment, is_leap_year != true is more clearly expressed as not is_leap_year in my opinion.
(As another side comment, Jeff Mercado is correct. You would never write code like this in a real project. There are many ways to do far better.)