| Bytes | Lang | Time | Link |
|---|---|---|---|
| 056 | JavaScript ES11 | 250428T103115Z | Arnauld |
| 017 | Charcoal | 250429T093814Z | Neil |
| 089 | Jelly | 250427T195415Z | Jonathan |
| 098 | 05AB1E | 250428T111527Z | Kevin Cr |
| 047 | Retina 0.8.2 | 250428T082958Z | Neil |
| 013 | APL+WIN | 250428T070716Z | Graham |
| 037 | Python 3.8 prerelease | 250427T235116Z | Lucenapo |
| 056 | JavaScript Node.js | 250427T190024Z | l4m2 |
JavaScript (ES11), 56 bytes
Expects a BigInt and returns another Bigint. The input is processed in big-endian format.
f=(n,o=n,q=4n**(k=8n))=>k--?f(n/q,n%q>o%q?o:k*q|n%q,q):o
Commented
f = ( // f is a recursive function taking:
n, // n = input Bigint
o = n, // o = output Bigint, initialized to n
q = 4n ** // q = 0x10000n (= 4n ** 8n)
(k = 8n) // k = global scope counter, initialized to 8n
) => //
k-- ? // if k is not 0 (decrement it afterwards):
f( // do a recursive call:
n / q, // discard the 16 least significant bits of n
n % q > o % q ? // if n % q is greater than o % q:
o // leave o unchanged
: // else:
k * q | n % q, // update it to k * q (i.e. k << 16n) OR n % q
q // pass q unchanged
) // end of recursive call
: // else:
o // stop and return o
Charcoal, 17 bytes
Using 128-bit hexadecimal integers as I/O:
≔⪪S⁴υ×0²⁷I⌕⮌υ⌊υ⌊υ
Try it online! Link is to verbose version of code. Explanation:
≔⪪S⁴υ
Split the input into eight 16-bit hexadecimal integers.
×0²⁷
Output 27 0s.
I⌕⮌υ⌊υ
Output the minimum index.
⌊υ
Output the minimum.
Using a big-endian list of eight 16-bit decimal integers as I/O:
≔⮌E⁸NυE⁶0I⟦⌕υ⌊υ⌊υ
Try it online! Link is to verbose version of code. Explanation:
≔⮌E⁸Nυ
Input eight integers reversed.
E⁶0
Output six zeros.
I⟦⌕υ⌊υ⌊υ
Output the minimum index and the minimum.
Using a little-endian list of eight 16-bit decimal integers as I/O:
F⁸⊞υNI⟦⌊υ⌕υ⌊υ⟧E⁶0
Try it online! Link is to verbose version of code. Explanation:
F⁸⊞υN
Input eight integers.
I⟦⌊υ⌕υ⌊υ⟧
Output the minimum and its index.
E⁶0
Output six zeros.
Jelly, (8?) 9 bytes
8 bytes if the reverse of this output is acceptable (remove Ṛ).
‘Ė’UṂo0€Ṛ
A monadic Link that accepts a list of integers and yields a list of the same number of integers, with zeros everywhere except the last element being the smallest in the input and the penultimate being the (earliest) 0-index of that element.
How?
‘Ė’UṂo0€Ṛ - Link: list of integers, V
‘ - increment {V}
Ė - enumerate -> [[1,v0+1],[2,v1+1],...]
’ - decrement -> [[0,v0],[1,v1],...]
U - reverse each -> [[v0,0],[v1,1],...]
Ṃ - minimum -> [vm,m]
0€ - zero for each of {V} -> [0,0,0,0,...,0]
o - logical OR -> [vm,m,0,0,...,0]
Ṛ - reverse -> [0,...,0,0,m,vm]
05AB1E, 9 (or 8?) bytes
.ā{н6Å0«R
Inspired by @JonathanAllan's Jelly answer.
I/O as a list of integers.
The trailing R might not be necessary?
Try it online or verify all test cases (I think..†).
†: I assumed all outputs of the test cases in the challenge description are incorrect based on the comments and implementation of existing answers.. :/
Explanation:
.ā # Enumerate the (implicit) input-list,
# pairing each value with its 0-based index
{ # Sort this list of [value,index]-pairs
н # Pop and leave the first pair
6Å0 # Push a list of 6 0s
« # Merge it to the earlier pair
R # (optionally?) Reverse the list
# (after which the result is output implicitly)
Retina 0.8.2, 47 bytes
$
¶$_
O`\G....
(....).+¶.*\1(....)*$
27$*0$#2$1
Try it online! Link includes test cases. Uses 128-bit hexadecimal integers as I/O. Explanation:
$
¶$_
Duplicate the input.
O`\G....
Sort the first copy, so that the minimum is at the beginning.
(....).+¶.*\1(....)*$
Match the minimum, find its last position in the original input, and take its index.
27$*0$#2$1
Output a 128-bit hexadecimal integer of the index and minimum.
APL+WIN, 13 bytes
Prompts for vector of integers. Index origin = 0
8↑m,v⍳m←⌊/v←⎕
JavaScript (Node.js), 56 bytes
x=>(y=x.map((t,i)=>+![t>=x||[x=t,p=i]]),y[0]=x,y[1]=p,y)
Test cases are data for PHMINPOSUD but anyway this code works for both