Skip to main content
Commonmark migration
Source Link

#Pyth, 20 19 bytes

Pyth, 20 19 bytes

#Explanation

Explanation

#Pyth, 20 bytes

Pyth, 20 bytes

#Explanation

Explanation

#Pyth, 20 19 bytes

#Explanation

#Pyth, 20 bytes

#Explanation

Pyth, 20 19 bytes

Explanation

Pyth, 20 bytes

Explanation

added 48 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214

Test Suite.

I think that or try _M.__Q is golfable, working on a solution.an alternative approach with the same byte count.

To understand the concept better, we shall take an example, say "123".

  • We first get the prefixes of the input. Those are ['1', '12', '123'].

  • Then, we get the prefixes of the reversed input, i.e: ['3', '32', '321'] and reverse each, hence we get ['3', '23', '123'].

  • We concatenate the two lists and convert each element to an integer, so we obtain [3, 23, 123, 1, 12, 123].

  • By summing the list, the result is 285.

  • The product P is the length of the input - 1 (i.e 2) multiplied by the integer representation of it (2 * 123 = 246).

  • In the end, we sum the two results: 285 + 246, hence we obtain 531, which is the correct result.

Test Suite.

I think that _M.__Q is golfable, working on a solution.

Test Suite or try an alternative approach with the same byte count.

To understand the concept better, we shall take an example, say "123".

  • We first get the prefixes of the input. Those are ['1', '12', '123'].

  • Then, we get the prefixes of the reversed input, i.e: ['3', '32', '321'] and reverse each, hence we get ['3', '23', '123'].

  • We concatenate the two lists and convert each element to an integer, so we obtain [3, 23, 123, 1, 12, 123].

  • By summing the list, the result is 285.

  • The product P is the length of the input - 1 (i.e 2) multiplied by the integer representation of it (2 * 123 = 246).

  • In the end, we sum the two results: 285 + 246, hence we obtain 531, which is the correct result.

added 48 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214

My current prefix approach (will hopefully golf further), will add an explanation soon:.

I am confidentthink that _M.__Q is golfable, working on a solution.

#Explanation

+*tlQsQssM+_M.__Q._  - Full program that reads a String from STDIN, with implicit input.

  tlQ                - Length of the input - 1.
     sQ              - The input converted to an integer.
 *                   - Product of the above two elements. We will call this P.
                 ._  - Prefixes of the input.
          +          - Concatenated with:
           _M.__Q    - The prefixes of the reversed input, reversed.
        sM           - Convert each to an integer.
       s             - Sum.
+                    - Addition of the product P and the sum above.

My current prefix approach (will hopefully golf further), will add an explanation soon:

I am confident that _M.__Q is golfable, working on a solution.

My current prefix approach (will hopefully golf further).

I think that _M.__Q is golfable, working on a solution.

#Explanation

+*tlQsQssM+_M.__Q._  - Full program that reads a String from STDIN, with implicit input.

  tlQ                - Length of the input - 1.
     sQ              - The input converted to an integer.
 *                   - Product of the above two elements. We will call this P.
                 ._  - Prefixes of the input.
          +          - Concatenated with:
           _M.__Q    - The prefixes of the reversed input, reversed.
        sM           - Convert each to an integer.
       s             - Sum.
+                    - Addition of the product P and the sum above.
added 48 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading
deleted 14 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading
added 77 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading
added 769 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading