[Question]
  [
When you look at the last decimal digit of each power of a non-negative integer a repeating pattern forms. For example, 3:
```
3^1 =     3
3^2 =     9
3^3 =    27
3^4 =    81
3^5 =   243
3^6 =   729
3^7 =  2187
3^8 =  6561
3^9 = 19683
```
The last digits go `3971` which repeats indefinitely. In fact any number we choose that ends in 3 has that same pattern because none of the other digits can have an effect on the ones place during repeated multiplication.
What's curious is that some numbers have a much shorter cycle of power-ending digits. For example with 5 the powers all end in 5 so the pattern, written as short as possible, is simply `5`.
Looking at the minimal power-ending digits patterns for 0 through 9 we get:
```
0 -> 0
1 -> 1
2 -> 2486
3 -> 3971
4 -> 46
5 -> 5
6 -> 6
7 -> 7931
8 -> 8426
9 -> 91
```
(The lengths of these being `11442` repeated is a curious tidbit itself.)
Remember, any numbers above 9 will have the same pattern as their last digit as was explained above with 3.
# Challenge
Your challenge here is to write a program that takes in any non-negative integer and outputs its minimal power-ending digit pattern.
The exact output formatting, whether string or list, doesn't matter. For example, here are some potential inputs followed by valid potential outputs:
```
900 -> [0]
11 -> 1
2 -> 2486
303 -> 3, 9, 7, 1
44 -> 4 6
45 -> 5
666 -> "6"
3857 -> [7 9 3 1]
118 -> '8426'
129 -> [9, 1]
```
**The shortest code in bytes wins.**
  
[Answer]
# Python 3, ~~44~~ ~~43~~ 40 bytes
Based off of [mabel's answer](https://codegolf.stackexchange.com/a/198817/75323) but using dictionary comprehensions:
```
lambda n:[*{n**i%10:0for i in[1,2,3,4]}]
```
Saved 1 byte thanks to mabel.
Saved 3 bytes thanks to xnor.
You can [try it online](https://tio.run/##K6gsycjPM/6fpmCrEPM/JzE3KSVRIc8qWqs6T0srU9XQwMogLb9IIVMhMy/aUMdIx1jHJLY29j9ILA8oplCUmJeeqmFoYqZpxaUABAVFmXklGmlK1Xm1Crp2CtVpGnmatUqa/wE)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
*Ɱ4%⁵Q
```
A monadic link which accepts an integer and yield a list of integers.
**[Try it online!](https://tio.run/##y0rNyan8/1/r0cZ1JqqPGrcG/v//39DIEgA "Jelly – Try It Online")**
### How?
```
*Ɱ4%⁵Q - Link: integer, n
  4    - four
 Ɱ     - map across (implicit range of [1..4]) with:
*      -    exponentiate
    ⁵  - ten
   %   - (powers) mod (ten)
     Q - de-duplicate
```
[Answer]
# JavaScript (ES6), 41 bytes
```
n=>[n%=10]+[[,,486,971,6,,,931,426,1][n]]
```
[Try it online!](https://tio.run/##Zc9BDsIgEIXhvadgY9LG0TJAKSzqRQiLprbGpgFjjddHktnB@sufmbdNv@mYP6/39xriY0nrmMJ4d@E8IvcX5wCU0WAHBA0AViIooQG9C96nOYYj7sttj89mbZjlvG1Z1zF@KoQhkmAlTJCIfKdEySWhzA9UpVKEStfUE/WlaK1JykaafiAZ8sgyQzSEJq@vUFhCi@kP "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 42 bytes
A recursive version.
```
n=>(g=k=>(d=(k*n)%10)-n?[k]+g(d):k)(n%=10)
```
[Try it online!](https://tio.run/##Zc1NDsIgFATgvadg0wQ0tTygFEzQgxgXTf@iNGCs8frY5O1gM4v5MplX/@u34fN8f@sQxynNLgV3pYvze46O@mNgFXBWh9vdP04LHdnFMxoqt5dpiGGL63Re40JnSiznjJGmIfyQCQFAgUKIQBHK6Bwll4jSduVSKUSlS2qR2ly01ij5Rpq2Q@msLL4ADKJRongDYREtpD8 "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 54 bytes
```
lambda n:list(dict.fromkeys(n**i%10for i in(1,2,3,4)))
```
[Try it online!](https://tio.run/##NcrBCoMwDADQXwmCkEgZVj0JfonzUKfRME2l9iLit3envfM7rrh6rRNDB@@0uX2cHGi7yRlxkk98cfD7d75O1KKQ3JbsAwiIojWVqU1DRKk/gmhEzm55WrgZhZ6M4F8hOF1mtCUN6Qc "Python 3 – Try It Online")
Could have been 38 bytes if `set()` was ordered.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 6 bytes
-1 byte thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
```
4LmT%Ù
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fxCc3RPXwzP//DY0sAQ "05AB1E – Try It Online")
Just a port of [Jonathan Allan's Jelly answer](https://codegolf.stackexchange.com/a/198811/91097).
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
4:^10\u
```
[Try it online!](https://tio.run/##y00syfn/38QqztAgpvT/f2MLU3MA "MATL – Try It Online")
### Explanation
```
4:    % Push [1 2 3 4]
^     % Implicit input, n. Element-wise power: gives [n n^2 n^3 n^4]
10\   % Modulo 10
u     % Unique (remove duplicates). Implicit display
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~10~~ 8 bytes
Jo King suggested a shorter function than what I originally had, `∪10⊤*∘⍳∘4` (a train at 9 bytes) vs my 10-byter dfn, and ngn pointed out a tradfn would be shorter than both altogether
```
∪10⊤⎕*⍳4
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKM9DUisMjSoedQ3VetR72YTkNj/NC5DYyMA "APL (Dyalog Unicode) – Try It Online")
`⍳4` the vector 1 2 3 4
`⎕*` the input raised to the power of, i.e. `(⍵*1)(⍵*2)(⍵*3)(⍵*4)` (using `⍵` to represent the value of the input)
`10⊤` mod 10
`∪` unique
[Answer]
# Haskell, ~~48~~ 46 bytes
`import Data.List;f n=nub[n^i`mod`10|i<-[1..4]]` 
-2 bytes thanks to @Laikoni
Having to import `nub` is really annoying... Any suggestions to remove it?
You can [Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzyezuIQrTSHPNq80KTovLjMhNz8lwdCgJtNGN9pQT88kNvZ/bmJmnoKtQkFpSXBJkYKKQnFGfjmQyk0sUEhTACkyMoj9/x8A)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 42 bytes
```
n=>new Set([1,2,3,4].map(v=>(n%10)**v%10))
```
[Try it online!](https://tio.run/##Zc1NDoIwFATgvafoxqQQhL7@0S7gEi6NC4LFaLAlQvD4VfN27WqS@TKZ57AP6/h@LNvJh5uLUxd913v3IWe30QtUvBKVvNavYaF711N/BFaU5f6PIo7Br2F29RzudKLEsl9JmoawQyIEAAUyIRyFS6NTFEwgCtvmSykRpc5JIalUtNYo6UYY1aK0VmRfAAbRSJ69AbeIFuIX "JavaScript (Node.js) – Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 37 bytes
This solution is suggested by @Expired Data, it is shorter, elegant but it will have problems when working with large number.
```
n=>new Set([1,2,3,4].map(v=>n**v%10))
```
[Try it online!](https://tio.run/##Zc29DoIwGIXh3avoYlIIQr/@0Q54E47GgWAxGGyJELz8SvJt7XqenLzvfu/X4Tst28WHp4tjF3139e5Hbm6jd6h4JSr5qD/9QvcDynI/AyuKOAS/htnVc3jRkRLLjpE0DWGnRAgACmRCOAqXRqcomEAUts2fUiJKnZNCUqlorVHSjzCqRWmtyFoABtFIntWAW0QL8Q8 "JavaScript (Node.js) – Try It Online")
[Answer]
# x86-16 machine code, IBM PC DOS, 26 bytes
**Binary:**
```
00000000: b380 8a07 d72c 308a d850 0430 b40e cd10  .....,0..P.0....
00000010: 58f6 e3d4 0a3a c375 f0c3                 X....:.u..
```
**Unassembled:**
```
B3 80       MOV  BL, 80H            ; BX to command line input tail
8A 07       MOV  AL, BYTE PTR[BX]   ; input length into AL 
D7          XLAT                    ; AL = [BX+AL] (get the last char of input) 
2C 30       SUB  AL, '0'            ; convert from ASCII
8A D8       MOV  BL, AL             ; save N to BL for compare/multiply
        POW_LOOP: 
50          PUSH AX                 ; save AX 
04 30       ADD  AL, '0'            ; convert to ASCII 
B4 0E       MOV  AH, 0EH            ; BIOS tty function 
CD 10       INT  10H                ; call BIOS, write char to console 
58          POP  AX                 ; restore AX 
F6 E3       MUL  BL                 ; AX = AL * BL 
D4 0A       AAM                     ; AL = AL % 10 
3A C3       CMP  AL, BL             ; is sequence repeating? 
75 F0       JNE  POW_LOOP           ; if not, keep looping 
C3          RET                     ; return to DOS 
```
A standalone PC DOS executable program. Input via command line args.
**I/O:**
[![enter image description here](https://i.stack.imgur.com/3jH3H.png)](https://i.stack.imgur.com/3jH3H.png)
[![enter image description here](https://i.stack.imgur.com/gmaOX.png)](https://i.stack.imgur.com/gmaOX.png)
[Answer]
# [PHP](https://php.net/), ~~54~~ 50 bytes
```
for($n=$o=$argn%10;print$n;$n-$o||die)$n=$n*$o%10;
```
[Try it online!](https://tio.run/##K8go@G9jXwAk0/KLNFTybFXybVUSi9LzVA0NrAuKMvNKVPKsVfJ0VfJralIyUzVBKvK0VPJB0v//m5iaGf3LLyjJzM8r/q/rBgA "PHP – Try It Online")
---
Alternate Solution:
# [PHP](https://php.net/), ~~50~~ 45 bytes
```
for(;$i<'11442'[$argn%5];)echo$argn**++$i%10;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRoPA/Lb9Iw1ol00bd0NDExEg9WiWxKD1P1TTWWjM1OSMfzNPS0tZWyVQ1NLD@/9/Y@F9@QUlmfl7xf103AA "PHP – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~58~~ 50 bytes
```
.*(.)
$1$1$*_,,486,971,6,,,931,426,1
+`_\d*,
,.*
```
[Try it online!](https://tio.run/##PcFLDkAwFAXQ@V0HSdVN41WVrsAmJEgYmBiI/dffOdu8L@sYU9UO0WhlMiRy1j3pGs9QCz3JUAqd9RTkQ99NmgCNRowFRGCtRXmCu6C6wT9Qv9B8EH4H "Retina 0.8.2 – Try It Online") Link includes test cases. Edit: Saved 8 bytes by not including the input digit in the digit patterns. Explanation:
```
.*(.)
$1$1$*_,,486,971,6,,,931,426,1
```
Create a unary copy of the last digit and append the list of power-ending digit pattern suffixes.
```
+`_\d+,
```
Delete the appropriate number of entries from the start of the list.
```
,.*
```
Delete unneeded entries from the end of the list.
Actually calculating the digits takes 69 bytes:
```
M!`.$
{`(.).*
$&;$1$*_,$&$*
_(?=.*,(1*))|,1*
$1
;(1{10})*(1*)
$.2
D`.
```
[Try it online!](https://tio.run/##Pcm7DoJAEEbh/n8Lk4HMTjYTZgWUEGNjYsUzsBQWNBaGDnz2Fbx95TmP2zTeh5TxNaZuF5UwR1anAspbMpLeU06Cns8nFc8mzi3e1m1o2WYrnk62CtKAS9SUCpghhID9CuUG1RvqDxy@cPxB8/cC "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
M!`.$
```
Modulo the input by 10.
```
{`
```
Repeat while new digits can be added.
```
(.).*
$&;$1$*_,$&$*
```
Create unary copies of the first digit and power-ending digits so far.
```
_(?=.*,(1*))|,1*
$1
```
Multiply them together.
```
;(1{10})*(1*)
$.2
```
Take the remainder modulo 10 and convert it to decimal.
```
D`.
```
Deduplicate the digits.
Of course it only takes 34 bytes in Retina 1:
```
L`.$
{`(.).*
$&_$.(*$1*
_.*\B
D`.
```
[Try it online!](https://tio.run/##PcG7DkBAEAXQ/n7HkjXFxKx3KxKNT5BYhUKjEJ2PH2/nrNM2L6NoYFuvnWeD3VuOmGDCwbAlI4SBqa@BxrNqDBE455CckF6Q3ZA/ULxQflD9Dg "Retina – Try It Online") Link includes test cases. Explanation:
```
L`.$
```
Modulo the input by 10.
```
{`
```
Repeat while new digits can be added.
```
(.).*
$&_$.(*$1*
```
Multiply the power-ending pattern so far by its first digit. (`*` has higher precedence than `$^`, so multiplying by its reverse ends up costing a byte more than it saves.)
```
_.*\B
```
Modulo the result by 10.
```
D`.
```
Deduplicate the digits.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 23 bytes
```
((*X**1..4)X%10).unique
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPtfQ0MrQkvLUE/PRDNC1dBAU680L7OwNPW/NVdxYqWCHlBNWn6RAlDe8j8A "Perl 6 – Try It Online")
Returns the unique values of the input to the power of 1 through 4 modulo 10.
[Answer]
# Excel, 53 bytes
```
=CHOOSE(RIGHT(A1)+1,,1,2486,3971,46,5,6,7931,8426,91)
```
`RIGHT(A1)` defaults to `RIGHT(A1,1)`, making it more efficient than `MOD(A1,10)`
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 6 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
4╒#♂%▀
```
port of [*@JonathanAllan*'s Jelly answer](https://codegolf.stackexchange.com/a/198811/52210), so make sure to upvote him as well!
[Try it online.](https://tio.run/##y00syUjPz0n7/9/k0dRJyo9mNqk@mtbw/7@lgQGXoSGXEZexgTGXiQmXiSmXmZkZl7GFqTlQ3ILL0MgSAA)
**Explanation:**
```
4╒      # Push the list [1,2,3,4]
  #     # Take the (implicit) input-integer to each of this power
   ♂%   # Take modulo-10 for each of these
     ▀  # Uniquify the list
        # (after which the entire stack is output implicitly)
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~56~~ 51 bytes
Saved 5 bytes thanks to [S.S. Anne](https://codegolf.stackexchange.com/users/89298/s-s-anne)!!!
```
i;f(n){for(i=n%10;putchar(i+48),i=n*i%10,i-n%10;);}
```
[Try it online!](https://tio.run/##HYzBCoMwEETv@YpgKWwaLbb0UIj2S3qRtakL7So2QkDy7enqZYZ5MwxWb8ScyXlgs/pxBmr5eKndtAQcOon2djelwBMJLqnaW@NSPhDjZ@lfuvmFnsbz8FDfjhjMqvR@xEHHtnY6NldRa@PWaA/ROPFploGH4snFlpNK@Q8 "C (gcc) – Try It Online")
[Answer]
# x86\_64 machine code, ~~63~~ 61 bytes
```
B8 BF 84 7B 09 B9 0A 00 00 00 31 D2 C7 44 24 FC
A4 10 0A 00 48 C1 E0 22 48 89 44 24 EC 48 B8 3C
00 00 00 00 00 5E 24 48 89 44 24 F4 89 F8 66 F7
F1 48 89 D0 83 E0 0F 66 03 54 44 EC C3
```
Disassembly:
```
00000000  B8BF847B09        mov eax,0x97b84bf
00000005  B90A000000        mov ecx,0xa
0000000A  31D2              xor edx,edx
0000000C  C74424FCA4100A00  mov dword [rsp-0x4],0xa10a4
00000014  48C1E022          shl rax,byte 0x22
00000018  48894424EC        mov [rsp-0x14],rax
0000001D  48B83C0000000000  mov rax,0x245e00000000003c
         -5E24
00000027  48894424F4        mov [rsp-0xc],rax
0000002C  89F8              mov eax,edi
0000002E  66F7F1            div cx
00000031  4889D0            mov rax,rdx
00000034  83E00F            and eax,byte +0xf
00000037  66035444EC        add dx,[rsp+rax*2-0x14]
0000003C  C3                ret
```
Input: `edi`, Output: `dx`, requires `rsp` to be set to a correct value.
Example call:
```
main:
  mov edi, 1337
  call f
  movzx eax, dx
  ret
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 30 bytes
```
->n{(1..4).map{|g|n**g%10}|[]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNQT89EUy83saC6Jr0mT0srXdXQoLYmOrb2v6GBXklmbmpxdU1RTYFCdJFOWnRRLFAcAA "Ruby – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
```
{m%^QdTS4
```
[Try it online!](https://tio.run/##K6gsyfj/vzpXNS4wJSTY5P9/43/5BSWZ@XnF/3VTAA "Pyth – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 24 bytes
```
⭆⁺0§⪪”←‴Ki⦃k‽” Ｉθ﹪⁺ＩθＩιχ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCO4BEil@yYWaATklBZrKBko6Sg4lnjmpaRWaAQX5GSWaCgpKBiZmSiYmVgoGAEllRSUNHUUnBOLSzQKNTWBTN/8lNKcfIh2qDBUPhMkbWgAVGX9/7@FxX/dshwA "Charcoal – Try It Online") Link is to verbose version of code. Uses the repetition between the first and second halves of the table. Explanation:
```
     ”←‴Ki⦃k‽”              Compressed string `  264 648 2`
    ⪪                       Split on literal space
   §           Ｉθ           Cyclically index by the input as a number
 ⁺0                         Prefix a literal `0`
⭆                           Map over characters and join
                 ﹪⁺ＩθＩιχ    Add to the input and reduce modulo 10
```
[Answer]
# Jelly, 7 bytes
```
4R*@%⁵Q
```
You can [try it online](https://tio.run/##y0rNyan8/98kSMtB9VHj1sD///8bmhgBAA). [It doesn't beat Jonathan's answer nor was it posted first. I just got to this answer by myself and I like posting Jelly answers while I'm learning]
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 116 bytes
```
x,c,a[4];f(n){n%=10;for(c=0,x=n;c<4;x*=n)a[c++]=x%10;n=*a*10+a[1];n=a[2]*10+a[3]-n?n*100+a[2]*10+a[3]:*a-a[1]?n:*a;}
```
Can almost certainly be golfed more but I haven't figured it out yet.
[Try it online!](https://tio.run/##RY7NDoIwEITvfYoGQ9IfMEU5WSoPUntoimgTXQyiaUJ4dmz14FxmZuc7rCsvzq1rKFxhdW1kT4DOkKtKyH4YiVOiCAqka2oZmAJqtePcqJBHABSzrBLc6srEYvXO/OrelNBCzKn8jwdmy8S2EJNc1o0Hd3t1Z9w8p84P2@sRIQ8TvlsP5D34jqIZ4aj0SRoCVljIaA2uknNOv3vSY4xET7K8O0FW4J4ESiVa1g8 "C (gcc) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 15 bytes
```
[:~.10|]^1+i.@4
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o63q9AwNamLjDLUz9RxM/mtyKXClJmfkK6QpqOnZKWQCJf8DAA "J – Try It Online")
# [K (Kona)](https://github.com/kevinlawler/kona), 14 bytes
```
{?(x^1+!4)!10}
```
[Try it online!](https://tio.run/##y9bNzs9L/P8/zaraXqMizlBb0URT0dCg9n@aOpD6DwA "K (Kona) – Try It Online")
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 12 bytes
```
ri4ro?^)[~NB
```
[Try it online!](https://tio.run/##SyotykktLixN/f@/KNOkKN8@TjO6zs/p/39DQ0MA "Burlesque – Try It Online")
```
ri   # Read input to int
4ro  # Range [1,4]
?^   # Raise input to powers [1,4]
)[~  # Take last digit of each
NB   # Remove duplicates
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 12 bytes
```
UQ(a**\,4)%t
```
takes range from 1 to 4, takes powers, mod 10, uniquify.
[Try it online!](https://tio.run/##K8gs@P8/NFAjUUsrRsdEU7Xk////xgbGAA "Pip – Try It Online")
]