Skip to main content
added 25 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Jelly, 8 7 bytes

‘;ṀỤḢṬ+

Try it online! or verify all test cases.

How it works (outdated)

;E¡0ỤḢṬ+‘;ṀỤḢṬ+  Main link. Argument: A

        DoIncrement eall times,elements whereof eA.
 is 1 if all elements of A areYield equalthe andmaximum 0of otherwiseA.
 ;  0     Concatenate both results. Note that the appended Appendmaximum 0will tobe the 
         minimum of the resulting array if and only if all elements of A are equal.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0maximum.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum or appending a 1.

Jelly, 8 7 bytes

‘;ṀỤḢṬ+

Try it online! or verify all test cases.

How it works (outdated)

;E¡0ỤḢṬ+  Main link. Argument: A

        Do e times, where e is 1 if all elements of A are equal and 0 otherwise.
;  0          Append 0 to the array.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum.

Jelly, 8 7 bytes

‘;ṀỤḢṬ+

Try it online! or verify all test cases.

How it works

‘;ṀỤḢṬ+  Main link. Argument: A

        Increment all elements of A.
        Yield the maximum of A.
 ;       Concatenate both results. Note that the appended maximum will be the 
         minimum of the resulting array if and only if all elements of A are equal.
   Ụ     Grade up; yield the indices of the resulting array, sorted by their
         corresponding values in that array.
    Ḣ    Head; extract the first index, which is the index of the first occurrence
         of the minimum. For an array of equal elements, this will be the index
         of the appended maximum.
     Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
      +  Add this array to A, incrementing the minimum or appending a 1.
added 25 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Jelly, 8 8 7 bytes

;E¡0ỤḢṬ+‘;ṀỤḢṬ+

Try it online!Try it online! or verify all test casesverify all test cases.

How it works (outdated)

;E¡0ỤḢṬ+  Main link. Argument: A

 E¡       Do e times, where e is 1 if all elements of A are equal and 0 otherwise.
;  0          Append 0 to the array.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum.

Jelly, 8 bytes

;E¡0ỤḢṬ+

Try it online! or verify all test cases.

How it works

;E¡0ỤḢṬ+  Main link. Argument: A

 E¡       Do e times, where e is 1 if all elements of A are equal and 0 otherwise.
;  0          Append 0 to the array.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum.

Jelly, 8 7 bytes

‘;ṀỤḢṬ+

Try it online! or verify all test cases.

How it works (outdated)

;E¡0ỤḢṬ+  Main link. Argument: A

 E¡       Do e times, where e is 1 if all elements of A are equal and 0 otherwise.
;  0          Append 0 to the array.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum.
added 463 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Jelly, 8 bytes

;E¡0ỤḢṬ+

Try it online! or verify all test cases.

How it works

;E¡0ỤḢṬ+  Main link. Argument: A

 E¡       Do e times, where e is 1 if all elements of A are equal and 0 otherwise.
;  0          Append 0 to the array.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum.

Jelly, 8 bytes

;E¡0ỤḢṬ+

Try it online! or verify all test cases.

How it works

;E¡0ỤḢṬ+  Main link. Argument: A

 E¡       Do e times, where e is 1 if all elements of A are equal and 0 otherwise.
;  0          Append 0 to the array.
    Ụ     Grade up; yield the indices of the resulting array, sorted by their
          corresponding values in that array.
     Ḣ    Head; extract the first index, which is the index of the first occurrence
          of the minimum. For an array of equal elements, this will be the index
          of the appended 0.
      Ṭ   Untruth; for index i, yield an array of i-1 zeroes, followed by a 1.
       +  Add this array to A, incrementing the minimum.
added 463 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading