Give 4 1-9 natural numbers, calculate these 4 numbers +, -, *,operations 55 algorithms

xiaoxiao2021-03-06  22

First, let's take a look at the rules of this game, give 4 1-9 natural numbers, for example: 1, 5, 5, 5 (this is a very classic example ^ _ ^). The number of 24 is obtained with , -, *, / / ​​to operate in the middle of 1, 5, 5, and /. Each number can only be used once. If there is no calculated basics, it will be difficult. Haha, the answer is 5 * (5-1 / 5). Is it very classic? There are also 3, 3, 8, 8 similar to it.

Let's see the specific algorithm. Generally we consider such problems, it is directly written to a large SELECT to judge. But the work of repeatability is the most bored! ! Let's analyze this simple game rule to find a simple way.

For example: 4 numbers A, B, C, D, we can use f (a, b, c, d) = 24. Then. We can disassemble the function F into F1 (B, C, D) = P1 (24, A). (Mean: B, C, and D) The four calculations can obtain four calculation results between A and 24). Then F1 can continue to disassemble the four calculation relationship between C and D to obtain the result and b. In this way, it is possible to get a simple array 6 * 6 * 6 = 216 results. Of course, this is a combination of A, B, C, and D sequence, then converts A, B, C, D to the position, yet another combination. Therefore, all the results have 6 * 6 * 6 * 12. However, we have also ignored a situation: A and B's values ​​of C and D are still four computing, then we also need to add a group of 6 * 6 * 6.

Ok, let me say, everyone look at the code below.

'-------------------------------- Calculate 24's algorithm ------------- -------------- 'algorithm author: 9CBS (penguinMII) - penguins' development time: 2005-3-23 'if referencing this algorithm Please keep this information' ----- -------------------------------------------------- ----------------

'About F1 (F2 (F3 (A1, A2), A3), A4) variable definitions DIM F_F (0 to 5) as double' 2 numbers DIM S_S (0 TO 5) AS The expression DIM F_F (0 TO 5) as Double 'third number after 2 numbers, the result of the third number and the above 2 count DIM S_S_S (0 to 5) as string' third number and top 2-numbers DIM F_F_F (0 TO 5) AS Double 'The fourth number and the result of the above 3 count DIM S_S_S_S (0 to 5) AS String' The fourth number and the above 3 count Result 'About F1 (F2 (A1, A2), F3 (A3, A4)) Variable Definition DIM F_F1 (0 TO 5) as Double' The third number of the fourth number of arithmetic results DIM S_S1 (0 TO 5) AS String 'third number of the fourth number of expressions DIM F_F2 (0 to 5) as double' No. 1, 2 and 3, 4 results DIM S_S2 (0 to 5) as String 'No. 1, 2 and 3, 4 Number of Expression Sub Ff2 (X as double, y as double, s, s, sy, sy, sx, sy, s, s, s, s, Sy, String), ON Error ResMe nextf_f2 (0) = x ys_s2 (0 ) = "(" SX " " "" f_f2 (1) = x - ys_s2 (1) = "(" SX "-" Sy ")" f_f2 (2) = Y - XS_S2 (2) = "(" SY "-" SX ")" F_F2 (3) = x * _s2 (3) = "(" SX "*" SY ")" f_f2 ( 4) = x / ys_s2 (4) = "(" SX "/" SY ")" f_f2 (5) = Y / XS_S2 (5) = "(" SY "/" SX ")"

End Sub

SUB FF1 (x as integer, y as integer) on error resume nextf_f1 (0) = x ys_s1 (0) = "(" CSTR (X) " " CSTR (Y) ")" f_f1 (1 ) = x - ys_s1 (1) = "(" CSTR (X) "-" CSTR (Y) ")" F_F1 (2) = Y - XS_S1 (2) = "(" CSTR (Y) "-" " ") "f_f1 (3) = x * ys_s1 (3) =" (" CSTR (X) " * " CSTR (Y) ") "f_f1 (4) = X / YS_S1 (4) = "(" CSTR (X) "/" CSTR (Y) ")" F_F1 (5) = Y / XS_S1 (5) = "(" CSTR (Y) "/" CSTR (X) ")" End Sub

SUB FF (x as integer, y as integer) on error resume nextf_f (0) = x ys_s (0) = "(" CSTR (X) " " CSTR (Y) ")" F_f (1 ) = x - ys_s (1) = "(" CSTR (X) "-" CSTR (Y) ")" F_f (2) = Y - XS_S (2) = "(" CSTR (Y) "-" " " f_f (3) = x * ys_s (3) = "(" CSTR (X) "*" CSTR (Y) ")" f_f (4) = x / ys_s (4) = "(" CSTR (X) "/" CSTR (Y) ")" F_f (5) = Y / XS_S (5) = "(" CSTR (Y) "/" CSTR (X) ")"

End Sub

SUB FFF (X AS STEGER, Y AS DOUBLE, S, STRING) ON Error ResMe nextf_f_f (0) = "(" CSTR (X) " " S ")" "F_F_F ( 1) = x - ys_s_s (1) = "(" CSTR (X) "-" S ")" f_f_f (2) = Y - XS_S (2) = "(" S "-" CSTR (X) ")" F_f_f (3) = x * YS_S (3) = "(" CSTR (X) "*" S ")" f_f_f (4) = x / ys_s_s (4) = "(" "" ")" "F_f_f (5) = Y / XS_S (5) =" (" S " / " CSTR (X) ") ")") ")" End Sub

SUB FFF (X AS STEGER, Y AS DOUBLE, STEGER, ON ERROR RESUME NEXTF_F_F (0) = X YS_S_S (0) = "(" CSTR (X) " " ")") "f_f_f_f ( 1) = x - ys_s_s_s (1) = "(" CSTR (X) "-" S ")" f_f_f_f (2) = Y - XS_S_S (2) = "(" S "-" CSTR (X) ")" f_f_f_f (3) = x * YS_S_S (3) = "(" CSTR (X) "*" ")" "f_f_f_f (4) = x / ys_s_s_s (4) = "(" ")" (" ") "(" S "/" CSTR (X) ")" (" S " / " CSTR (X) ") "

End Sub

SUB PPP (A1 AS INTEGER, A2 AS INTEGER, A3 AS INTEGER, A4 AS INTEGER) DIM TEMPP AS INTEGER

Tempp = 0

Call FF (A1, A2) FOR I = 0 to 5Call FFF (A3, F_F (I), S_S (I)) for J = 0 to 5Call FFFF (A4, F_F_F (J), S_S_S (J)) for K = 0 TO 5IF F_F_F (K)> 23.99999 and f_f_f_f (k) <24.00001 THEN

Tempp = 0for XYZ = 0 to me.list1.listcount - 1if me.list1.list (xyz) = s_s_s (k) THENTEMPP = Tempp 1END IFNEXT XYZIF TEMPP = 0 THENME.LIST1.ADDITEM S_S_S_S (K) End IF

End ifnext Knext JNext i

End Sub

SUB QQQ (A1 AS INTEGER, A2 AS INTEGER, A3 AS INTEGER, A4 AS Integer DIM TEMPP AS INTEGERTEMPPPPP = 0

Call FF (A1, A2) Call FF1 (A3, A4) FOR i = 0 to 5for J = 0 to 5Call FF2 (f_f (i), f_f1 (j), s_s (i), s_s1 (j)) for k = 0 TO 5IF F_F2 (K)> 23.9999 And F_f2 (k) <24.00001 THEN

Tempp = 0for XYZ = 0 to me.list1.listcount - 1if me.list1.list (xyz) = s_s2 (k) THENTEMPP = Tempp 1END IFNext XYZ

IF Tempp = 0 THENME.LIST1.ADDITEM S_S2 (K) End IF

End ifnext Knext JNext Iend Sub

PRIVATE SUB Command1_Click () me.list1.clear

Call PPP (Me.Text1 (0) .text, me.text1 (1) .text, me.text1 (2) .text, me.text1 (3) .text) Call PPP (Me.Text1 (0) .Text , Me.Text1 (1) .Text, Me.Text1 (3) .text, me.text1 (2) .text) Call PPP (Me.Text1 (0) .text, me.text1 (2) .text, ME .Text1 (1) .text, me.text1 (3) .text) Call PPP (Me.Text1 (0) .text, me.text1 (2) .text, me.text1 (3) .text, me.text1 (1) .Text) Call PPP (Me.Text1 (0) .text, me.text1 (3) .text, me.text1 (1) .text, me.text1 (2) .text) Call PPP (ME. Text1 (0) .text, me.text1 (3) .text, me.text1 (2) .text, me.text1 (1) .text) Call PPP (Me.Text1 (1) .Text, Me.Text1 ( 2) .Text, Me.Text1 (3) .text, me.text1 (0) .text) Call PPP (Me.Text1 (1) .text, me.text1 (2) .text, me.text1 (0) .Text, Me.Text1 (3) .text) Call PPP (Me.Text1 (1) .text, me.text1 (3) .text, me.text1 (0) .text, me.text1 (2) .text Call PPP (Me.Text1 (1) .Text, Me.Text1 (3) .text, me.text1 (2) .text, me.text1 (0) .Text) Call PPP (Me.Text1 (2). Text, Me.Text1 (3) .text, me.text1 (1) .text, me.text1 (0) .text) Call PPP (Me.Text1 (2) .text, me.text1 (3) .text, Me.Text1 (0) .text, me.text1 (1) .text)

Call QQQ (Me.Text1 (0) .Text, Me.Text1 (1) .text, me.text1 (2) .text, me.text1 (3) .text) End Sub

转载请注明原文地址:https://www.9cbs.com/read-43777.html

New Post(0)