Post Reply 
[VA] SRC #008 - 2021 is here !
01-02-2021, 12:57 AM (This post was last modified: 01-05-2021 06:31 PM by Valentin Albillo.)
Post: #1
[VA] SRC #008 - 2021 is here !
      
... and what better way to welcome 2021 than a little 2021-themed SRC ?

Welcome to my SRC #008 - 2021 is here !, a small nice one to commemorate 2021's arrival. See if you can deliver using your HP calculator, physical or emulated.

  • Please NO Lua, NO Python, NO Excel, NO Mathematica, etc. This is the Museum of HP Calculators, so if you can't or won't use an HP calculator please post your results somewhere else, there are plenty of threads suitable for you to show off your non-HP achievements. Thank you.

That said, try your HP-hand with these three:

1) Let's partition 2021 into a set of positive integer numbers that add up to 2021. Find the set of such numbers whose product is maximum, and output that maximum in all its full glory.

For instance, we could have 2021 = 1 + 1 + ... + 1 (2021 1's) and their product would be 1 x 1 x ... x 1 = 1, which doesn't quite cut it. We could also have 2021 = 137 + 682 + 1202 and their product would be 137 x 682 x 1202 = 112307668, which is much better but still far from the maximum as well.


2) Numerically evaluate as accurately as possible this nice definite integral using your favorite HP calc (per standard notation, the | ... | vertical bars mean "absolute value"):

[Image: Integral.gif]

and for extra points, see if you can symbolically recognize the resulting value. You'll need a sufficiently accurate value to do it, though ... Smile


3) It is trivially easy to express the fraction 4/2021 as the sum of 4 numbers of the form 1/N where N is a positive integer, namely:

            4/2021   =   1/2021 + 1/2021 + 1/2021 + 1/2021

See if you can do it with just 3 such numbers.


My own solutions and comments in a few days.
  • P.S.: If you manage to solve them, do not spoil the fun for others: include your solutions in a CODE block leaving a number of blank lines at the beginning so that they can't be seen without willingly scrolling.
V.

P.S.: Edited to include a third case, see post #21 below.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
01-02-2021, 01:49 AM
Post: #2
RE: [VA] SRC #008 - 2021 is here !
Happy New Year Valentin!

My idea for #1 came after a few minutes thought. I will wait a bit to post it, but it came without an HP being used - no cheating either. I will verify that my thoughts work with an HP, but ...

Gene
Find all posts by this user
Quote this message in a reply
01-02-2021, 05:42 AM (This post was last modified: 01-02-2021 05:42 AM by RMollov.)
Post: #3
RE: [VA] SRC #008 - 2021 is here !
#1 is interesting for me and I think I know the answer even though I can't prove it. Furthermore I'm really curious how much a calculator helps in this case; there must be some theoretical mathematical basis under and not calculations.

Thanks
Find all posts by this user
Quote this message in a reply
01-02-2021, 04:09 PM (This post was last modified: 01-02-2021 07:39 PM by Nihotte(lma).)
Post: #4
RE: [VA] SRC #008 - 2021 is here !
(01-02-2021 12:57 AM)Valentin Albillo Wrote:        
...

My own solutions and comments in a few days.
  • P.S.: If you manage to solve them, do not spoil the fun for others: include your solutions in a CODE block leaving a number of blank lines at the beginning so that they can't be seen without willingly scrolling.
V.

Thanks for the challenge Valentin Albillo !

Code:

1) at 07.09 PM 2021/01/02
2) at 10.31 PM 2021/01/02
.
.
.
.
.
.
.
.
.
.
At first, I wanted to try some different calculation configurations 
I asked help to my hp35s
.
1)
 **  LBL  D
      RCL  L
      STO  I
      CLx
      STO  C
      STO  D
007 RCL  N
      STO+  C
      LOG
      STO+  D
      DSE  I
      GTO  D007
      RCL  R
      STO+  C
      LOG
      STO+  D
      RCL  C
      RCL  D
      RTN

With finally :
673  STO  L  //  L is the number of loops
3     STO  N  //  N is the incremental constant
2     STO  R  //  R is the residual number to reach 2021
In the spirit, XEQ D001 evaluates L * N + R  (LOL)
It's quite complicated but I have been making several tests around "RCL I" instead of just "RCL N"

My approach started from the way I laid the foundations of the problem :

1a) Σ for i=1..n of the xi gives 2021 : x1 + x2 +  ...  + xn = 2021
1b) П for i=1..n of the xi is maximized : x1 * x2 * ... * xn is as greater as possible
It means also that LOG(П for i=1..n of xi) is as greater as possible
Or Σ for i=1..n of LOG(xi) is maximized

I have tested several configurations but it seems to me that 673x3 + 2 gives the best result
With a result of 2021 and 2,5329955 x 10^321 [it is ALOG(LOG(3)x673 + LOG(2)) ]

2)
For this time, I'm already waiting after my hp35s result !!
I'm sorry it's INTEGRATING !!!
See you later !
------------------------------------------------------------------------
So, I'm coming back 

With my first generation of program, the hp35s didn't gives any satisfying result...
I've made a second approach :
- where SIN(π) gives -2,06761537357 x 10^-13 in RAD MODE on the hp35s, SIN(180) gives 0 in DEG MODE !
--> I prefered to make my calculations in DEG MODE

- because 2.021 x COS(180°) x SIN(180°) gives 0
--> I prefered to insert a test in my function on the hp35s, of course to avoid the error of division by 0

There is the program I used in the spirit of the HP15C :

   ** LBL  I
      STO  A
      RCL  A
      SIN
      STO  I
      LASTx
      COS
      STO  J
      RCL  I
      ABS
      RCL  E
      y^x
      2
      ÷
      RCL  J
      2
      1/x
      RCL  I
      x
      RCL  E
      x√y
      +
      ABS
      RCL  E
      y^x
      +
      LOG
      RCL  E
      RCL  J
      x
      RCL  I
      x
      x=y?
      GTO  I037
      ÷
      RTN
 037 1
      RTN

With this usage :
- 2.021 [blue] STO  E
- [yellow] FN=  I
- MODE 1 DEG
- 0 ENTER 180 
- [yellow] ∫  A
==> INTEGRATING and ∫= 180 in DEG MODE
Since then, in RAD MODE, I think the expected result would be π...


Now, what I can regret, while wishing my answers are correct with with theory and not just by practice, is not being able to prove what I am saying in mathematical terms. 
I am impatiently awaiting the answers of the specialists!
Find all posts by this user
Quote this message in a reply
01-02-2021, 09:24 PM (This post was last modified: 01-02-2021 09:26 PM by J-F Garnier.)
Post: #5
RE: [VA] SRC #008 - 2021 is here !
Hi Valentin,

Thanks for this nice New Year present !

I was inspired by your 2nd problem:

(01-02-2021 12:57 AM)Valentin Albillo Wrote:  2) Numerically evaluate as accurately as possible this nice definite integral using your favorite HP calc (per standard notation, the | ... | vertical bars mean "absolute value"):

[Image: Integral.gif]

I had no special problem to evaluate it on the HP-71 (actually Emu71:-) with the Math ROM, after a simple operation.

Quote:and for extra points, see if you can symbolically recognize the resulting value. You'll need a sufficiently accurate value to do it, though ... Smile

Using your great "Identifying Constants" program, I found the symbolic value, a nice surprise, that lead me to another conclusion about the expression to integrate :-)

Thanks again,

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-03-2021, 06:33 PM (This post was last modified: 02-16-2021 01:38 AM by robve.)
Post: #6
RE: [VA] SRC #008 - 2021 is here !
Thanks for posting. A good motivation to write some code on HP Prime. You did not mention that RPN is required...

#1 I couldn't find a way to run HP Prime programs with bigint (only up to 64bit), so the full decimal result is computed and displayed with HP Prime CAS in the code below.

Here is another puzzle: Compute the smallest set(s) of square numbers that sum up to 2021. In other words, what are the sets of fewest square numbers that sum up to 2021 such that each square number is used at most once?

For example, 1+9+36 sums up to 46 and 1=1^2, 9=3^2, 36=6^2 are square numbers. The size of this set is three, which is minimal since no two square numbers sum up to 46. Another solution is 1+4+16+25=46, but that solution has four square numbers and thus is not a minimal set.

There may be multiple minimal sets of square numbers for 2021. A set is minimal if no other set exists that is smaller.



Since we want to write some code, let's verify that powers of 3 give the max,
by brute force trying all products from 2 to sqrt(2021).
We use log here, which means we can simply sum up instead of using products,
e.g. to prevent overflow on some calculators (but HP Prime handles large floats.)

EXPORT T2021()
BEGIN
  LOCAL N := 2021, M := 0, J, K, R, X;
  FOR I FROM 2 TO SQRT(N) DO
    K := FLOOR(N/I);
    R := N-K*I;
    IF R=0 THEN
      R := 1;
    END;
    X := K*LN(I)+LN(R);
    IF X>M THEN
      M := X;
      J := I;
    END;
  END;
  MSGBOX(J);
  MSGBOX(e^M);
END;

After playing with this, it is interesting that 3 is best.
The reason is that 3 is close to the number e, which you can easily see is the best number to pick, because we have that
N/3*LN(3)<N/e
and
N/2*LN(2)<N/e
for any N>0 e.g. N=2021. Graphing N/x*LN(x) shows x=e is optimal.

The full number is displayed in HP Prime CAS:

2*3^673

25329955218868262923281496551277939397110796485699809049268130708906002579675557​8
80841323830523234581366754082537819748828642552123142645059118075006593388245733​4
55569632621982327471866288083832732135816196262336795334877060602534949818961126​6
4520885716630483899029142003916544644957076791520721759240671604739781810307846

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
01-03-2021, 09:11 PM
Post: #7
RE: [VA] SRC #008 - 2021 is here !
RE #1


With a brute force approach, I searched for the largest product of:

(2021/n)^n

Code:









Quickly got to 9.999e99 on my 15C, so switched to Free 42. 
Determined that the answer appeared to be in the 700-800 range 
for “n” so wrote and ran this program:

HP42S

LBL VA2021
2021
RCL 00
/
RCL 00
Y^X
PSE
1
STO +00
GTO VA2021
RTN

resulting in:
7.781840369084335804554270907184552e322
when n= ~743

2021 / 743 = ~2.72, very close to e
Find all posts by this user
Quote this message in a reply
01-04-2021, 09:12 AM (This post was last modified: 01-04-2021 09:14 AM by J-F Garnier.)
Post: #8
RE: [VA] SRC #008 - 2021 is here !
(01-02-2021 09:24 PM)J-F Garnier Wrote:  I was inspired by [the] 2nd problem:
...
I had no special problem to evaluate it on the HP-71 (actually Emu71:-) with the Math ROM, after a simple operation.

Here is my solution, not for the HP-71 but the 32S (not even the 32SII) that is, as I mentioned several times, my favourite machine for simple calculations.
Well, I cheated a bit since I used the observation I made in my previous message :-) so the execution time is reduced to less than two minutes including keystrokes. Not bad for this machine....

Code:






Program for the 32S/32SII:
LBL V
RCL X
COS
STO C
LASTx
SIN
STO S
2
SQRT
/
+

RCL S

2
/
+
LN
RCL C
/
RCL S
/
2
/
RTN


Keystokes:
RAD
FN= V
FIX 10
0
PI 2 /
§FN dX
>>  §=0.925275413
STO A
PI 2 /
PI
§FN dX
>> §=1.542125688
RCL+ A
>> 2.4674011003   ***
Exactly the expected constant (to 10 places).

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2021, 03:00 PM
Post: #9
RE: [VA] SRC #008 - 2021 is here !
Code:


For #2, it seems constant 2.021 can be changed, and still gives same integral result.
Why ?



Let k = 2.021, c = 2^(-1/k)

I = ∫ [(ln(|sin(x)|^k/2 + |cos(x)+c*sin(x)|^k) / (k*sin(x)*cos(x))] dx  , x = 0 .. pi

Let y=pi/2-x, dy=-dx:  sin → cos, cos → sin:

I = ∫ [(ln(|cos(y)|^k/2 + |sin(y)+c*cos(y)|^k) / (k*sin(y)*cos(y))] dy  , y = -pi/2 .. pi/2
  = ∫ f(y) dy            , y = -pi/2 .. pi/2
  = ∫ [f(y) + f(-y)] dy  , y = 0 .. pi/2

          |cos(y)|^k/2 + |sin(y)+c*cos(y)|^k        sec(y)^2
I = ∫ ln(------------------------------------) × (------------) dy  , y = 0 .. pi/2
          |cos(y)|^k/2 + |sin(y)-c*cos(y)|^k       k * tan(y)

          1/2 + |t+c|^k       1 + t^2
  = ∫ ln(---------------) × (---------) dy  , where t = tan(y)      , y = 0 .. pi/2
          1/2 + |t-c|^k        k * t

For HP-71B INTEGRAL command, it preferred smooth curve.
So, we split the integral into 2 parts, when |t-c| = 0, or x = atan(c)

10 INPUT "K? ";K @ C=2^(-1/K) @ P=.0000000001
20 DEF FNT(T)=LN((.5+ABS(T+C)^K)/(.5+ABS(T-C)^K))*(1/T+T)
30 T=TIME @ S=ATAN(C)
40 S1=INTEGRAL(0,S,P,FNT(TAN(IVAR)))/K
50 S2=INTEGRAL(S,PI/2,P,FNT(TAN(IVAR)))/K
60 DISP S1;"+";S2;"=";S1+S2,TIME-T

>RUN
k? 2.021
 .936151026289 + 1.53125007399 = 2.46740110028                  .44
>RUN
k? 1
 1.0306547334 + 1.43674636688 = 2.46740110028                   .55
>RUN
k? 2
 .937458075515 + 1.52994302478 = 2.4674011003                   .44
>RUN
k? 3
 .891862933413 + 1.57553816686 = 2.46740110027                  .66
>PI*PI/4
 2.46740110027
Find all posts by this user
Quote this message in a reply
01-04-2021, 03:59 PM (This post was last modified: 01-04-2021 04:41 PM by StephenG1CMZ.)
Post: #10
RE: [VA] SRC #008 - 2021 is here !
On the HP Prime, I get a result for number 2 if I use the constant 2.021 (2.021 approximately 2).
But if that "." is meant to be a thousands separator rather than decimal, representing the year 2021 rather than the year 2 Smile, I get undef (in home mode).
(And to get the answers others are giving, remember to change log into Ln)

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2021, 04:16 PM (This post was last modified: 01-04-2021 04:17 PM by Albert Chan.)
Post: #11
RE: [VA] SRC #008 - 2021 is here !
Code:


Post #10, we transform I by using substitution: y = pi/2-x, dy = -dx

We can continue substitutions: t = tan(y), dt = (1+t^2) dy
This shift integration limit from y = 0 .. pi/2, to t = 0 .. infinity

One more substitution, t = (1-u)/u, dt  = (-1/u^2) du
This shift back integration limit back to finite: u = 0 .. 1

This remove all use of trigonometric functions, or constant PI :)

10 INPUT "K? ";K @ C=2^(-1/K) @ P=.0000000001
20 DEF FNU(U)=LN((.5+ABS((1-U)/U+C)^K)/(.5+ABS((1-U)/U-C)^K))/(U*(1-U))
30 T=TIME @ S=1/(C+1)
40 S1=INTEGRAL(0,S,P,FNU(IVAR))/K
50 S2=INTEGRAL(S,1,P,FNU(IVAR))/K
60 DISP S1;"+";S2;"=";S1+S2,TIME-T

>RUN
k? 2.021
 1.53125007397 + .936151026314 = 2.46740110028                  .66
>RUN
k? 1
 1.43674636688 + 1.03065473339 = 2.46740110027                  .66
>RUN
k? 2
 1.52994302476 + .937458075515 = 2.46740110028                  .65
>RUN
k? 3
 1.57553816687 + .891862933407 = 2.46740110028                  .66

reference: http://fmnt.info/blog/20180818_infinite-integrals.html
Find all posts by this user
Quote this message in a reply
01-04-2021, 05:56 PM
Post: #12
RE: [VA] SRC #008 - 2021 is here !
For problem 1, I don't understand the Y^X function showing up in the answers... ?

A + B + C = 2021 (or however many #'s you propose in your solution)

Then A x B x C = Big number.

505 + 505 + 505 + 505 + 1 works, but the product would be 505 x 505 x 505 x 505 x 1 or 6.5038 x 10^10.

Biggest number I can see is a portion of the factorial.

For example 63! = (roughly) 1.98 x 10^87. The sum of 63, 62, ... down to 2 is 2015. So with a little adjustment, one could get 2021 as a sum and something in the 10^80-something as a product.

Think I've missed something :-) but don't see where. Wouldn't be the first time!
Find all posts by this user
Quote this message in a reply
01-04-2021, 06:24 PM (This post was last modified: 01-04-2021 06:26 PM by ijabbott.)
Post: #13
RE: [VA] SRC #008 - 2021 is here !
Here's my quick and dirty RPL solution for #1:

Code:











« DUP
  IF 4 >
  THEN
    3 IDIV2
    CASE
      DUP 0 == THEN DROP 1 END
      DUP 1 == THEN DROP 1 - 4 END
    END
    3 ROT ^ *
  END
»
'MAXPROD' STO
2021 MAXPROD
{resulting string of 322 digits here!}
->NUM
2.53299552189E321

— Ian Abbott
Find all posts by this user
Quote this message in a reply
01-04-2021, 07:08 PM
Post: #14
RE: [VA] SRC #008 - 2021 is here !
(01-04-2021 05:56 PM)Gene Wrote:  Biggest number I can see is a portion of the factorial.

No, we would like as many equal numbers as possible.
Say, we partition number N into n parts.

AM-GM inequality:

\(\Large{x_1\,+\,x_2\,+\,x_3\,+\,\cdots\,+\,x_n \over n} \normalsize
≥ \sqrt[n]{x_1\;x_2\;x_3\;\cdots\;x_n}\)

LHS = N/n = constant
RHS = LHS, i.e. maximized products, when \(x_1 = x_2 = x_3 = \cdots = x_n\)
Find all posts by this user
Quote this message in a reply
01-04-2021, 07:24 PM
Post: #15
RE: [VA] SRC #008 - 2021 is here !
Ah, now I see it more clearly.

For example... 2 + 2 + 2... + 2 + 21 (suppose there are one thousand 2's there).

Sum is 2021.

Product is 2^1000 x 21 which is huge... and still not the biggest.

ty
Find all posts by this user
Quote this message in a reply
01-04-2021, 08:27 PM (This post was last modified: 01-04-2021 08:56 PM by ijabbott.)
Post: #16
RE: [VA] SRC #008 - 2021 is here !
Some clues:

Code:









* Splitting a 1 out of the number makes things worse unless (unless the number is 1).
  E.g. 2 -> 1+1 -> 1*1 = 1 which is less than 2.
* Splitting 4 -> 2+2 -> 2*2 = 4, so splitting out a 4 is the same as splitting out 2 2s.
* Splitting 5 -> 2+3 -> 2*3 = 6 which is larger than 5.
  Therefore split the number only into 2s, 3s and 4s (or just into 2s and 3s since 4s can be split into 2 2s).
* Splitting 6 -> 2+2+2 -> 2*2*2 = 8, but 6 -> 3+3 -> 3*3 = 9. 
  9 is larger than 8, so splitting out 3s is preferable to splitting out 2s (or 4s),
  except when that would leave a 1 remaining.

Conclusion:

Code:









* If N > 3 and N ≡ 0 (mod 3) then only split out 3s.
* If N > 3 and N ≡ 1 (mod 3) then split out a single 4 (or 2 2s) and only split out 3s for any remaining part.
* If N > 3 and N ≡ 2 (mod 3) then split out a single 2 and only split out 3s for the remaining part.
* If N < 4 then leave it as is.

For example:

Code:









 7 -> 4+3 -> 4*3 = 12 (or 7 -> 2+2+3 -> 2*2*3 = 12)
 8 -> 2+3+3 -> 2*3*3 = 18
 9 -> 3+3+3 -> 3*3*3 = 27
10 -> 4+3+3 -> 4*3*3 = 36

— Ian Abbott
Find all posts by this user
Quote this message in a reply
01-04-2021, 08:36 PM
Post: #17
RE: [VA] SRC #008 - 2021 is here !
As to No. 1, my candidate for greatest product exceeds my candidate for second-greatest by 12.5%. I'll explain later. I obtained these results without coding, but I knew the route to a solution many years ago.

Valentin, while we wait for your solutions, would you be willing to tell us how you came to choose the number 5, in gold, as your avatar/icon? I ask because the image was a puzzle until yesterday, when I saw that number on a postcard.
Find all posts by this user
Quote this message in a reply
01-04-2021, 11:52 PM
Post: #18
RE: [VA] SRC #008 - 2021 is here !
.
Hi, telemachos:

(01-04-2021 08:36 PM)telemachos Wrote:  Valentin, while we wait for your solutions, would you be willing to tell us how you came to choose the number 5, in gold, as your avatar/icon?

I ask because the image was a puzzle until yesterday, when I saw that number on a postcard.


Well, being very fond of both the number 5 and fine art, I've liked Charles Demuth's 1928 painting "I Saw the Figure 5 in Gold" since I saw it for the first time many decades ago, and I thought it would make a very nice, classy, artistic avatar for me in the MoHPC's forums, which it does.

Full info on the painting here

Thanks for your interest in both my SRC #008 and my avatar ! Smile

Best regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
01-05-2021, 03:39 AM (This post was last modified: 02-16-2021 01:41 AM by robve.)
Post: #19
RE: [VA] SRC #008 - 2021 is here !
My solution for #1 is in my earlier post with the non-CAS program listing, followed by the full number printed with HP Prime CAS. But if you really can't accept the number printed with HP Prime CAS, then below is a simple non-CAS program to produce the full decimal result as a list of digits:


EXPORT POWER3()
BEGIN
  L0:=MAKELIST(0,I,1,322);
  L0(SIZE(L0)):=2;
  FOR N FROM 1 TO 673 DO
    L1:=L0;
    FOR T FROM 1 TO 2 DO
      C:=0;
      FOR I FROM SIZE(L0) DOWNTO 1 DO
        D:=L0[I]+L1[I]+C;
        IF D>9 THEN
          D:=D-10;
          C:=1;
        ELSE
          C:=0;
        END;
        L0[I]:=D;
      END;
    END;
  END;
  PRINT(L0);
END;

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
01-05-2021, 06:32 PM (This post was last modified: 01-05-2021 06:33 PM by Valentin Albillo.)
Post: #20
RE: [VA] SRC #008 - 2021 is here !
      
Hi all:

Thanks for your interest in this SRC #008, many more replies than I expected, many correct solutions and last but not least, A-Chan finally saw the light and actually refrained from posting solutions using everything but HP calcs in my threads, and has posted HP-71B code ! Shocking ! Smile

To express my gratitude, and as we say in Spain "No hay dos sin tres", I've edited my original post to include a third 2021-related question, namely this one:

  • It is trivially easy to express the fraction 4/2021 as the sum of 4 numbers of the form 1/N where N is a positive integer, namely:

                4/2021   =   1/2021 + 1/2021 + 1/2021 + 1/2021

    See if you can do it with just 3 such numbers.

As I've added this third "teaser" I'll delay posting my own solutions to all three for a few days, to allow you to ponder it and post your own solution.

Thanks again and best regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: