Sunday, October 2, 2022
HomeWordPress Developmentphp - Methods to calculate the sum of each potential combos of...

php – Methods to calculate the sum of each potential combos of the Integer array?


Given an array of constructive integers a, I wish to calculate the sum of each potential a[i] ∘ a[j], the place a[i] ∘ a[j] is the concatenation of the string representations of a[i] and a[j] respectively.

Instance

For a = [10, 2], the output ought to be answer(a) = 1344.

a[0] ∘ a[0] = 10 ∘ 10 = 1010,
a[0] ∘ a[1] = 10 ∘ 2 = 102,
a[1] ∘ a[0] = 2 ∘ 10 = 210,
a[1] ∘ a[1] = 2 ∘ 2 = 22.
So the sum is the same as 1010 + 102 + 210 + 22 = 1344.

For a = [8], the output ought to be answer(a) = 88.

For a = [1, 2, 3], the output ought to be answer(a) = 198.

a[0] ∘ a[0] = 1 ∘ 1 = 11,
a[0] ∘ a[1] = 1 ∘ 2 = 12,
a[0] ∘ a[2] = 1 ∘ 3 = 13,
a[1] ∘ a[0] = 2 ∘ 1 = 21,
a[1] ∘ a[1] = 2 ∘ 2 = 22,
a[1] ∘ a[2] = 2 ∘ 3 = 23,
a[2] ∘ a[0] = 3 ∘ 1 = 31,
a[2] ∘ a[1] = 3 ∘ 2 = 32,
a[2] ∘ a[2] = 3 ∘ 3 = 33.
The entire result's 11 + 12 + 13 + 21 + 22 + 23 + 31 + 32 + 33 = 198.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments