Reverse Maths Cycles

18

Inspired by this

In the linked challenge, we are asked to apply addition to the elements of the original and the reverse of the input array. In this challenge, we are going to make it slightly more difficult, by introducing the other basic math operations.

Given an array of integers, cycle through +, *, -, //, %, ^, where // is integer division and ^ is exponent, while applying it to the reverse of the array. Or, in other words, apply one of the above functions to each element of an array, with the second argument being the reverse of the array, with the function applied cycling through the above list. This may still be confusing, so lets work through an example.

Input:   [1, 2, 3, 4, 5, 6, 7, 8, 9]
Reverse: [9, 8, 7, 6, 5, 4, 3, 2, 1]

         [ 1,  2,  3,  4,  5,    6,  7,  8,  9]
Operand:   +   *   -   /   %     ^   +   *   -
         [ 9,  8,  7,  6,  5,    4,  3,  2,  1]

Result:  [10, 16, -4,  0,  0, 1296, 10, 16,  8]

so the output for [1, 2, 3, 4, 5, 6, 7, 8, 9] would be [10, 16, -4, 0, 0, 1296, 10, 16, 8]

To cover the corner cases, the input will never contain a 0, but may contain any other integer in the range from negative infinity to positive infinity. You may take input as a list of strings representing digits if you want.

Test cases

input => output

[1, 2, 3, 4, 5, 6, 7, 8, 9]     => [10, 16, -4, 0, 0, 1296, 10, 16, 8]
[5, 3, 6, 1, 1]                 => [6, 3, 0, 0, 1]
[2, 1, 8]                       => [10, 1, 6]
[11, 4, -17, 15, 2, 361, 5, 28] => [39, 20, -378, 7, 2, 3.32948887119979e-44, 9, 308]

This is a so shortest code (in bytes) wins!

caird coinheringaahing

Posted 2017-09-11T19:28:27.400

Reputation: 13 702

Sandbox (2k+ only) – caird coinheringaahing – 2017-09-11T19:29:22.677

@AdmBorkBork He is addressing it, I pointed that out in chat. – Mr. Xcoder – 2017-09-11T19:34:42.527

@AdmBorkBork corrected. I missed that in my test case generator – caird coinheringaahing – 2017-09-11T19:37:20.653

Your third test case still contains 0 >.> – Mr. Xcoder – 2017-09-11T19:43:26.243

I was wrong, Ignore that – Mr. Xcoder – 2017-09-11T19:49:22.380

In the last example we have 361<sup>-17</sup>. Are there any guidelines about the precision to which this should be calculated? – Digital Trauma – 2017-09-11T22:53:08.420

@DigitalTrauma your program has to handle standard precision rules. If you have to do extra to make it perfectly match, don't do the extra. – caird coinheringaahing – 2017-09-11T22:54:21.097

@cairdcoinheringaahing I'm using bc to do my arithmetic, which by default uses integer precision. Are you OK with an answer of 0 for the 361<sup>-17</sup> case, or should I "do the extra" to calculate to set bc to calculate exponents to 60 or so decimal places? – Digital Trauma – 2017-09-11T22:57:59.243

1@DigitalTrauma for languages which default to integers, I think outputting 0 is acceptable for tiny numbers like that. – caird coinheringaahing – 2017-09-11T22:59:38.353

How flexible are you on not doing "the extra"? The exponentiation method in Japt can't (directly) take a negative number as an argument. I could work around that at a cost of 6 bytes (currently) or I could try using the exponentiation operator instead (but that would probably cost more bytes). Also, would Arnauld's original 60 byte solution (see his edit history) now be valid? – Shaggy – 2017-09-12T09:24:46.573

@Shaggy if the language's native number type can't handle floats without some extreme twisting of the arm (like bc), then you can not do the extra. Javascript, and by extension Japt, can handle floats quite easily, so no, it wouldn't be allowed. Sorry. – caird coinheringaahing – 2017-09-12T14:12:31.610

Though that might be the case; thanks for clarifying. – Shaggy – 2017-09-12T14:13:16.453

@cairdcoinheringaahing: bc does fixed-point decimal (default is zero places after the decimal, invoke as bc -l to set 20 places after the decimal and include math libraries), but it doesn't do scientific notation or floating point. So with only 3 more bytes of bash script, you could get stuff like 361 ^ -2 to print as .00000767336039471765 instead of 0. But then you'd have to mess with scale to get integer division instead of fixed-point... So yeah, I guess it's maybe justified to give bogus answers even for small negative exponents in bc, since it doesn't have float or types – Peter Cordes – 2017-09-17T03:35:23.740

Answers

6

Jelly, 10 bytes (fork)

+×_:%*6ƭ"Ṛ

I was just working on implementing a quick for this the other day, so it's quite surprising to see a use for it so soon. It still only exists as a fork, so you cannot try it online.

Sample output

$ ./jelly eun '+×_:%*6ƭ"Ṛ' '[1,2,3,4,5,6,7,8,9]'
[10, 16, -4, 0, 0, 1296, 10, 16, 8]
$ ./jelly eun '+×_:%*6ƭ"Ṛ' '[5,3,6,1,1]'
[6, 3, 0, 0, 1]
$ ./jelly eun '+×_:%*6ƭ"Ṛ' '[2,1,8]'
[10, 1, 6]
$ ./jelly eun '+×_:%*6ƭ"Ṛ' '[11,4,-17,15,2,361,5,28]'
[39, 20, -378, 7, 2, 3.32948887119979e-44, 9, 308]

Explanation

+×_:%*6ƭ"Ṛ  Input: array
      6ƭ    Tie 6 dyads
+             Addition
 ×            Multiplication
  _           Subtraction
   :          Integer division
    %         Modulo
     *        Power
        "   Vectorize with
         Ṛ  Reverse

miles

Posted 2017-09-11T19:28:27.400

Reputation: 15 654

whaaaaaaaat come on really :( but nice, this quick seems quite useful :D – HyperNeutrino – 2017-09-11T19:53:34.423

This needs to be pulled to Jelly. +1 although you may want to extend ƭ to support nilads (replace value) and monads (apply on left argument) as well – Erik the Outgolfer – 2017-09-12T09:50:09.190

@EriktheOutgolfer It already works with monads. See the examples I posted in Jelly chat. Nilads are a different case. – miles – 2017-09-12T11:52:51.343

@miles I mean just like how nilads behave here.

– Erik the Outgolfer – 2017-09-12T11:56:26.287

@EriktheOutgolfer Ok it supports nilads now, but requires you to define their length, and use a space between each. Example 2 1”q3ƭ€ on [7,4,9,0] returns [2, 1, 'q', 2] – miles – 2017-09-12T12:22:54.493

4

Husk, 16 bytes

This challenge favours languages that can create infinite lists of functions. Maybe not, eval FTW

zF¢+ë+*-÷e%^Ṡze↔

Try it online!

How?

  ¢+ë+*-÷e%^         The infinite list [+,*,-,÷,%,^,+,*,-,...
    ë+*-÷            The list [+,*,-,÷]
         e%^         The list [%,^]
   +                 Concatenated
  ¢                  Then repeated infinitely
               ↔     The input reversed e.g [9,8,7,6,5,4,3,2,1]
            Ṡze      Zipped with itself     [[9,1],[8,2],[7,3],[6,4],[5,5],[4,6],[3,7],[2,8],[1,9]]
zF                   Zipwith reduce, the list of functions and the list of lists.
                     [F+[9,1],F*[8,2],F-[7,3],F÷[6,4],F%[5,5],F^[4,6],F+[3,7],F*[2,8],F-[1,9]]
                     [10     ,16     ,-4     ,0      ,0      ,1296   ,10     ,16     ,8      ]

Alternative 17 byte solution:

ṠozIzI¢+ë+*-÷e%^↔

H.PWiz

Posted 2017-09-11T19:28:27.400

Reputation: 10 962

Out of curiosity, why can't you do ë+*-÷%^? Why do the e necessary? – caird coinheringaahing – 2017-11-14T01:15:34.397

@cairdcoinheringaahing ë takes 4 arguments, e takes 2. There isn't one for 6 – H.PWiz – 2017-11-14T01:30:02.873

3

Python 2, 67 bytes

-3 bytes thanks to ovs.

lambda l:[eval(j+'*+*-/%*'[-~i%6::6]+l[~i])for i,j in enumerate(l)]

Try it online!

Python 2, 95 bytes

lambda l:[[add,mul,sub,div,mod,pow][i%6](v,l[~i])for i,v in enumerate(l)]
from operator import*

Try it online!

eval is evil... but perhaps more golfy. :P

totallyhuman

Posted 2017-09-11T19:28:27.400

Reputation: 15 378

67 bytes – ovs – 2017-09-12T10:37:27.007

3

05AB1E, 18 bytes

Â"+*-÷%m"Ig×)øε`.V

Try it online!

Explanation

                    # push a reversed copy of the input
 "+*-÷%m"            # push the list of operators
         Ig×         # repeat it input times
            )ø       # zip together
              ε      # apply to each triplet
               `     # push separately to stack
                .V   # evaluate

Emigna

Posted 2017-09-11T19:28:27.400

Reputation: 50 798

Ig∍ if you wanted to use the "newish" command (haven't seen much here). – Magic Octopus Urn – 2017-10-12T18:58:49.763

3

Jelly, 15 bytes

żṚj"“+×_:%*”ṁ$V

Try it online! or see the test-suite.

How?

żṚj"“+×_:%*”ṁ$V - Link: list of numbers, a       e.g. [5, 3, 6, 1, 1]
 Ṛ              - reverse a                           [1, 1, 6, 3, 5]
ż               - interleave                          [[5,1],[3,1],[6,6],[1,3],[1,5]
             $  - last two links as a monad:
    “+×_:%*”    -   literal list of characters        ['+','×','_',':','%','*']
            ṁ   -   mould like a                      ['+','×','_',':','%']
   "            - zip with the dyad:
  j             -   join                              ["5+1","3×1","6_6","1:3","1%5"]
              V - evaluate as Jelly code (vectorises) [6, 3, 0, 0, 1]

Jonathan Allan

Posted 2017-09-11T19:28:27.400

Reputation: 67 804

Save a couple of bytes with ż“+×_:%*”;"ṚV – Erik the Outgolfer – 2017-09-12T12:23:33.740

@EriktheOutgolfer that only works if the length of the input is exactly 6. I think you'd need to do ż“+×_:%*”ṁ$;"ṚV which is also 15 bytes. – Jonathan Allan – 2017-09-12T15:24:48.377

ok what was I thinking of...I so miss "tie" :( – Erik the Outgolfer – 2017-09-12T15:29:53.440

3

Bash + GNU utilities, 53

tac $1|paste -d, $1 -|tr ',
' '
;'|paste -sd+*-/%^|bc

This script takes a filename as a command-line parameter.

Try it online.

The nice thing here is that paste -d allows a list of separators to be given, which are used cyclically. The rest it just getting the input into the right format to do this.

Digital Trauma

Posted 2017-09-11T19:28:27.400

Reputation: 64 644

@Shaggy OP seems to be OK with this result

– Digital Trauma – 2017-09-11T23:00:16.863

2

JavaScript (ES7), 68 67 bytes

a=>[...a].map((v,i)=>(x=a.pop(),o='+*-/%'[i%6])?eval(v+o+x)|0:v**x)

let f =

a=>[...a].map((v,i)=>(x=a.pop(),o='+*-/%'[i%6])?eval(v+o+x)|0:v**x)

console.log(JSON.stringify(f([1, 2, 3, 4, 5, 6, 7, 8, 9]    ))) // [10, 16, -4, 0, 0, 1296, 10, 16, 8]
console.log(JSON.stringify(f([5, 3, 6, 1, 1]                ))) // [6, 3, 0, 0, 1]
console.log(JSON.stringify(f([2, 1, 8]                      ))) // [10, 1, 6]
console.log(JSON.stringify(f([11, 4, -17, 15, 2, 361, 5, 28]))) // [39, 20, -378, 7, 2, 3.32948887119979e-44, 9, 308]

Arnauld

Posted 2017-09-11T19:28:27.400

Reputation: 111 334

Nice solution! Maybe you can move the assignment of o inside the parentheses of .pop() to save a few bytes. – Luke – 2017-09-11T21:10:47.470

@Luke The assignment to o is also used as the condition of the ternary operator. That would break that scheme. – Arnauld – 2017-09-11T21:15:51.987

@Shaggy. That was the exact same first Arnauld's answer.

– None – 2017-09-11T22:27:24.447

@ThePirateBay: Ah. On SE mobile so can't see edit histories. – Shaggy – 2017-09-11T22:28:49.920

2

Perl 6, 67 66 bytes

Saved 1 byte thanks to @nwellnhof.

{map {EVAL ".[0] {<+ * - div % **>[$++%6]} .[1]"},zip $_,.reverse}

Try it online!

Very unimaginative (and probably bad) solution. Zips the argument with itself reversed. The resulting list is then mapped with the block that EVALs the string a (operator) b. The operator is chosen from the list of strings <+ * - div % **> using the free state (think static in C — the value persists across the calls of the block) variable $. This is created for each block separately and set to 0. You can do anything you like with it, but you may reference it only once (each occurence of $ refers to another variable, actually). So $++%6 is actually 0 during the first call, 1 during the second, ... 5 during the 6th, 0 during the 7th and so on.

I at first tried to do without an EVAL. The operators are in fact just subs (= functions), but their names are so extremely ungolfy (&infix:<+> and so on) that I had to forgo that approach.

Ramillies

Posted 2017-09-11T19:28:27.400

Reputation: 1 923

map {EVAL ".[0] ... .[1]"},zip $_,.reverse is 1 byte shorter. – nwellnhof – 2017-09-11T23:40:39.527

@nwellnhof, thanks! – Ramillies – 2017-09-11T23:50:50.197

2

Haskell, 74 117 105 bytes

x#y=fromIntegral.floor$x/y
x%y=x-x#y
f u=[o a b|(o,a,b)<-zip3(cycle[(+),(*),(-),(#),(%),(**)])u(reverse u)]

Try it online!

Saved 12 bytes thanks to @nimi

There is certainly a better way to achieve this.

EDIT 1. Fixed exponent for integers; 2. There's definitely a better way, see comment below: 95 91 bytes

x#y=fromIntegral.floor$x/y
x%y=x-x#y
f=zipWith3($)(cycle[(+),(*),(-),(#),(%),(**)])<*>reverse

Try it online!

jferard

Posted 2017-09-11T19:28:27.400

Reputation: 1 764

zipWith3($)(cycle[(+),(*),(-),div,mod,(^)])<*>reverse Is a shorter, now deleted version of yours. – H.PWiz – 2017-09-11T20:28:07.947

@H.PWiz I was looking for something like that but didn't have the time to look further. Why did you delete it? I believe it's not forbidden to have two different solutions in the same language, especially when one is far better than the other... – jferard – 2017-09-11T20:54:48.043

@H.PWiz Fixed exponent. – jferard – 2017-09-12T08:30:16.430

No need for the h in the call of o: o a b and without that you can inline h (TIO).

– nimi – 2017-09-12T15:00:04.943

1

Python 2, 71 bytes

lambda l:[eval(y+'+*-/%*'[x%6]*-~(x%6>4)+l[~x])for x,y in enumerate(l)]

Try it online!

Saved 2 bytes thanks to ovs!

Mr. Xcoder

Posted 2017-09-11T19:28:27.400

Reputation: 39 774

1

J, 44 42 bytes

Crossed out 44, yada yada...

-2 bytes thanks to @ConorO'Brien

_2+/`(*/)`(-/)`(<.@%/)`(|~/)`(^/)\[:,],.|.

Try it online!

So many parens and inserts... Surely there's a better way to do this (maybe using insert rather than infix?)

Explanation

_2(+/)`(*/)`(-/)`(<.@%/)`(|~/)`(^/)\[:,],.|.  Input: a
                                       ],.|.  Join a with reverse(a)
                                      ,       Ravel (zip a with reverse(a))
_2                                 \          To non-overlapping intervals of 2
  (+/)`(*/)`(-/)`(<.@%/)`(|~/)`(^/)           Apply the cyclic gerund
   +/                                           Insert addition
        */                                      Insert subtraction
             -/                                 Insert division 
                  <.@%/                         Insert integer division
                          |~/                   Insert mod
                                ^/              Insert exponentiation

Some notes:

J doesn't have integer division, so we compose %-division with >.-floor. J's mod (|) does the reverse order of what we'd expect, so we have to invert its order using ~-reflexive.

Even though we're moving over intervals of 2, we have to use /-insert to insert the verbs to have them be used dyadically since that's how \-infix works.

cole

Posted 2017-09-11T19:28:27.400

Reputation: 3 526

I'd also love to know how to avoid all the () and repeated / -- I wasn't able to figure it out.... – Jonah – 2017-09-11T22:16:01.483

@Jonah, best I can think of is something like / on a reversed array (since it operates backwards...) with verbs like (,+)\(,*)` but that doesn't help much... (also it doesn't work) – cole – 2017-09-11T22:27:06.450

1The gerund can be +/`(*/)`... – Conor O'Brien – 2017-09-11T23:01:30.450

1

MATL, 27 23 bytes

-4 bytes thanks to @LuisMendo

tP+1M*1M-IM&\w1M^v"@X@)

Try it online!

Explanation:

tP         % duplicate and flip elements
+          % push array of sums (element-wise)
1M*        % push array of products (element-wise)
1M-        % push array of subtractions (element-wise)
IM&\w      % push array of divisions and modulo (element-wise)
1M^        % push array of power (element-wise)
v          % vertically concatenate all arrays
"@X@)    % push to stack values with the correct index based on operator
           % (implicit) convert to string and display

Cinaski

Posted 2017-09-11T19:28:27.400

Reputation: 1 588

1

Ruby, 63 57 bytes

->a{t=0;a.map{|x|eval [x,a[t-=1]]*%w(** % / - * +)[t%6]}}

Nothing fancy, really. Just iterate on the array, use an index as reverse iterator, join into a string using the right operator, evaluate, rinse and repeat.

Try it online!

G B

Posted 2017-09-11T19:28:27.400

Reputation: 11 099

1

k, 40 bytes

{_((#x)#(+;*;-;%;{y!x};{*/y#x})).'x,'|x}

Try it online!

{                                      } /function(x)
                                     |x  /reverse x
                                  x,'    /zip concat with x
        ( ; ; ; ;     ;       )          /list of operations
         + * - %                         /add, mult, sub, div
                 {y!x}                   /mod (arguments need to be reversed)
                       {*/y#x}           /pow (repeat and fold multiply)
  ((#x)#                       )         /resize operations to length of x
                                .'       /zip apply
 _                                       /floor result

zgrep

Posted 2017-09-11T19:28:27.400

Reputation: 1 291

0

Perl 5, 68 + 1 (-p) = 69 bytes

print$",eval'int 'x($i%6==3).$_.qw|+ ** % / - *|[$i--%6].$F[$i]for@F

Try it online!

Takes input as space separated list of numbers.

Xcali

Posted 2017-09-11T19:28:27.400

Reputation: 7 671

Not anymore. :) – Xcali – 2017-09-11T23:04:56.133

0

R, 74 bytes

function(l)Map(Map,c(`+`, `*`, `-`, `%/%`, `%%`,`^`),l,rev(l))[1:sum(l|1)]

Try it online!

This is the final answer I came up with. It returns a list of length length(l) where each element is a list containing the corresponding element. Kinda crappy but they're all there. If that's unacceptable, either of the Map can be replaced with mapply for +3 bytes.

Since R operators are all functions (the infix notation just being syntactic sugar), I tried to select one from a list; for example, the 94 byte solution below.

To try and get rid of the loop, I tried sapply, but that only works with a single function and input list. Then I remembered the multivariate form, mapply, which takes an n-ary function FUN and n succeeding arguments, applying FUN to the first, second, ..., elements of each of the arguments, recycling if necessary. There is also a wrapper function to mapply, Map that "makes no attempt to simplify the result". Since it's three bytes shorter, it's a good golfing opportunity.

So I defined a trinary function (as in the 80 byte solution below) that takes a function as its first argument, and applies it to its second and third ones. However, I realized that Map is a function that takes a function as its first argument and applies it to successive ones. Neat!

Finally, we subset at the end to ensure we only return the first length(l) values.

R, 80 bytes

function(l)Map(function(x,y,z)x(y,z),c(`+`, `*`, `-`, `%/%`, `%%`,`^`),l,rev(l))

Try it online!

This one doesn't work, as it will return 6 values for lists with less than 6 elements.

R, 94 bytes

function(l){for(i in 1:sum(l|1))T[i]=switch(i%%6+1,`^`,`+`,`*`,`-`,`%/%`,`%%`)(l,rev(l))[i]
T}

Try it online!

Explanation (mildly ungolfed):

function(l){
 for(i in 1:length(l)){
  fun <- switch(i%%6+1,`^`,`+`,`*`,`-`,`%/%`,`%%`) # select a function
  res <- fun(l,rev(l))                             # apply to l and its reverse
  T[i] <- res[i]                                   # get the i'th thing in the result
 }
 T                                                 # return the values
}

Because each of the functions is vectorized, we can index at the end (res[i]). This is better than the eval approach below.

R, 100 bytes

function(l)eval(parse(t=paste("c(",paste(l,c("+","*","-","%/%","%%","^"),rev(l),collapse=","),")")))

Try it online!

This is the shortest eval approach I could find; because we have to collect the results into one vector, we need to paste a c( ) around all the expressions, which adds a ton of unnecessary bytes

Giuseppe

Posted 2017-09-11T19:28:27.400

Reputation: 21 077

0

Casio-Basic, 108 bytes

{x+y,x*y,x-y,int(x/y),x-int(x/y)y,x^y}⇒o
dim(l)⇒e
Print seq(o[i-int(i/6)6+1]|{x=l[i+1],y=l[e-i]},i,0,e-1)

That was painful. Especially because mod(x,y) returns x when it really shouldn't, which meant I had to make my own mod function: hence the x-int(x/y)y.

Loops i from 0 to length(l)-1, taking successive elements in the o list and applying l[i] for x and l[-i] for y. (negative indices don't work though, so instead I subtract i from the length of the list and take that index.)

107 bytes for the function, +1 byte to add l in the parameters box.

numbermaniac

Posted 2017-09-11T19:28:27.400

Reputation: 639

0

Java 8, 336 bytes

import java.math.*;a->{int b[]=a.clone(),i=0,l=b.length,s,t;for(;i<l/2;b[i]=b[l+~i],b[l+~i++]=t)t=b[i];BigInteger r[]=new BigInteger[l],u,v;for(i=-1;++i<l;t=b[i],v=new BigInteger(t+""),r[i]=(s=i%6)<1?u.add(v):s<2?u.multiply(v):s<3?u.subtract(v):s<4?u.divide(v):s<5?u.remainder(v):t<0?u.ZERO:u.pow(t))u=new BigInteger(a[i]+"");return r;}

Try it here.

Sigh..
Input as int[], output as java.math.BigInteger[].

Without the rule "To cover the corner cases, the input will never contain a 0, but may contain any other integer in the range from negative infinity to positive infinity.", using integers in the range -2147483648 to 2147483647, it would be 186 bytes (input as int[], and no output because it modifies this input-array instead to save bytes):

a->{int b[]=a.clone(),i=0,l=b.length,t,u,v;for(;i<l/2;b[i]=b[l+~i],b[l+~i++]=t)t=b[i];for(i=-1;++i<l;v=b[i],a[i]=(t=i%6)<1?u+v:t<2?u*v:t<3?u-v:t<4?u/v:t<5?u%v:(int)Math.pow(u,v))u=a[i];}

Try it here.

Explanation:

import java.math.*;            // Required import for BigInteger

a->{                           // Method with int[] parameter and BigInteger[] return-type
  int b[]=a.clone(),           //  Make a copy of the input-array
      i=0,                     //  Index-integer
      l=b.length,              //  Length of the input
      s,t;                     //  Temp integers
  for(;i<l/2;b[i]=b[l+~i],b[l+~i++]=t)t=b[i];
                               //  Reverse the input-array and store it in `b`
  BigInteger r[]=new BigInteger[l],
                               //  Result-array
             u,v;              //  Temp BigIntegers
  for(i=-1;                    //  Reset `i` to -1
      ++i<l;                   //  Loop over the array(s):
                               //    After every iteration:
      t=b[i],                  //     Set the current item of `b` in `t`
      v=new BigInteger(t+""),  //     And also set it in `v` as BigInteger
      r[i]=(s=i%6)<1?          //   If the index `i` modulo-6 is 0:
            u.add(v)           //    Add the items with each other
           :s<2?               //   Else-if index `i` modulo-6 is 1:
            u.multiply(v)      //    Multiply the items with each other
           :s<3?               //   Else-if index `i` modulo-6 is 2:
            u.subtract(v)      //    Subtract the items with each other
           :s<4?               //   Else-if index `i` modulo-6 is 3:
            u.divide(v)        //    Divide the items with each other
           :s<5?               //   Else-if index `i` modulo-6 is 4:
            u.remainder(v)     //    Use modulo for the items
           :                   //   Else (index `i` modulo-6 is 5):
            t<0?               //    If `t` is negative:
             u.ZERO            //     Simply use 0
            :                  //    Else:
             u.pow(t))         //     Use the power of the items
    u=new BigInteger(a[i]+""); //  Set the current item of `a` to `u` as BigInteger
                               //  End of loop (implicit / single-line body)
  return r;                    //  Return the result BigInteger-array
}                              // End of method

Kevin Cruijssen

Posted 2017-09-11T19:28:27.400

Reputation: 67 575