# Lists of power!

Generate the following list of lists consisting of the unique last digits of the powers from 1 to 9 for the numbers [0..9]

[[0], [1], [2, 4, 8, 6], [3, 9, 7, 1], [4, 6], [5], [6], [7, 9, 3, 1], [8, 4, 2, 6], [9, 1]]


e.g. For the number 2 we have: $$\2^1,2^2,2^3,2^4,2^5,... \to 2,4,8,16,32,64,128,... \to 2,4,8,6,4,8,... \to [2,4,8,6]\$$

This is , so shortest answer (as measured in bytes) wins and the usual golfing rules apply.

• Sandbox – hakr14 Mar 6 at 20:15
• Unfortunately I didn't think of this while it was in the sandbox, but are different delimiters allowed? – FryAmTheEggman Mar 6 at 20:24
• Some explanation please as to what, exactly, that list is. – Noodle9 Mar 6 at 20:27
• @Noodle9 It’s the unique last digits of the powers of each number 0 to 9 (e.g. $2^1, 2^2, 2^3, 2^4, 2^5 = 2,4,8,16,32 = 2,4,8,6$). Including this is the challenge would make it much better, and it’s omission is why I -1ed, as it seems like the OP cares more about people figuring out the pattern rather than actually golfing it – caird coinheringaahing Mar 6 at 20:33
• Why is the first entry [0] when 0**x = 1? – Shaggy Mar 8 at 20:54

# Lua, 71 bytes

for i=0,9 do u=i a=i while a*i%10~=i do a=a*i%10 u=u..a end print(u)end


Try it online!

Since you aren't specific about if you need a table/array or only printed results, I present my answer with printed results:

0
1
2486
3971
46
5
6
7931
8426
91



# CoffeeScript, 46 bytes

It was not specified whether a set can be considered a list, so this outputs a list of sets:

(new Set(v**x%10for x in[1..9])for v in[0..9])


Outputting a list of arrays would require 57 bytes:

(Array.from new Set(v**x%10for x in[1..9])for v in[0..9])


# JavaScript, 7169 67 bytes

Thanks to user81655 and tsh for reducing two bytes each

(a=[...'0123456789']).map(v=>[...new Set(a.map(x=>+x?v**x%10:+v))])


console.log(
(a=[...'0123456789']).map(v=>[...new Set(a.map(x=>+x?v**x%10:+v))])
)

• 69 bytes – user81655 Mar 7 at 0:55
• (a=[...'0123456789']).map(v=>[...new Set(a.map(x=>v**x*v%10))]) – tsh Mar 8 at 13:42

# JavaScript, 98 90 bytes

_=>{r=[];for(i=-1;++i<=9;){for(c=[],p=1;c[0]!=(a=(p*=i)%10);c.push(a));r.push(c)}return r}


Try it online!

# Charcoal, 17 bytes

Ｉ﹪ＥχＸιＩ…1§22553ιχ


Try it online! Link is to verbose version of code. Outputs each list element on its own line with lists double-spaced. Explanation:

   χ                Predefined variable 10
Ｅ                 Map over implicit range
ι              Current value
Ｘ               Vectorised to power
…            Range from
1           Literal string 1 to
22553     Literal string 22553
§          Cyclically indexed by
ι    Current value
Ｉ             Cast to integer
﹪                  Vectorised modulo by
χ   Predefined variable 10
Ｉ                   Cast to string
Implicitly print


# Wolfram Language (Mathematica), 50 bytes

DeleteDuplicates/@Array[Mod[(#-1)^#2,a]&,{a=10,a}]


Try it online!

l|d<-[1..9]=[foldl(\a x->a++[x|notElem x a])[][x^pmod10|p<-d]|x<-0:d]


Try it online!

# Python 3, 55 bytes

R=range(10);print([[*{a**-~i%10for i in R}]for a in R])


Try it online!

# Retina, 57 bytes


9*¶

$. .$& $.(**)$.(***) $.(**** .\B (.+?)( \1)+$1


Try it online! Explanation:


9*¶

$.  List the digits from 0 to 9. .$& $.(**)$.(***) $.(****  Calculate the first four powers of each digit. .\B  Take the last digit of each power. (.+?)( \1)+$1


Remove duplicates.

# JavaScript (Node.js), 61 bytes

f=t=>t>9?[]:[(g=x=>[x|0,...x%5>1?g(x*t%10):[]])(t),...f(-~t)]


Try it online!

# JavaScript (Node.js), 62 bytes

_=>[...'0123456789'].map(g=(t,x)=>[x,...x%5>1?g(t,x*t%10):[]])


Try it online!

# JavaScript (Node.js), 64 bytes

_=>Array(10).fill(1).map(g=(x,t)=>[x=x*t%10,...x%5>1?g(x,t):[]])


Try it online!

{{i}d}icc{dddd}dddc{iiii}iiiiic{ddddd}ic{iiiii}dddc{dddd}ddc{iiii}iiiic{ddddd}ic{iiiii}dddc{dddd}dcddddddc{i}ddc{d}iic{i}iic{d}ddc{i}c{iiii}dc{ddddd}ic{iiiii}dddc{dddd}c{d}iiic{i}iiic{d}dddc{i}ic{d}dciiiiic{iiii}iiiic{ddddd}ic{iiiii}dddc{dddd}ic{d}iic{i}c{iiii}dc{ddddd}ic{iiiii}dddc{dddd}iic{iiii}c{ddddd}ic{iiiii}dddc{dddd}iiic{iiii}dc{ddddd}ic{iiiii}dddc{ddd}ddddddc{d}dc{i}iiic{d}dddc{i}dddc{d}iiiciiiiic{iiii}iiiic{ddddd}ic{iiiii}dddc{ddd}dddddc{d}ddc{i}ddc{d}iiciiiiiicddddddc{i}c{iiii}dc{ddddd}ic{iiiii}dddc{ddd}ddddc{d}dddciiiiic{iiii}iiiicc


Try it online!

# 05AB1E, 9 bytes

TFN∞m€θÙ,


Try it online! Beats all other answers. Prints inner lists each on their own line. Takes an infinite amount of time to run, but does work in theory. Proof: replace ∞ with 4L and it will work. ∞ is simply the natural numbers, and 4L is the list [1, 2, 3, 4], and the current number (from 0 to 9) is raised to the power of all the elements in the list. 4 is the maximum length used in the output here, so any greater exponents will simply repeat and get thrown away by Ùniquify. ∎

TFN∞m€θÙ,  # full program
F         # for N in [0, 1, ...,
T          # ..., 10...
F         # ...minus 1]...
,  # output...
Ù   # the unique...
θ    # last...
€     # digits...
θ    # of...
∞       # all natural...
m      # exponents of...
N        # variable


# Vyxal, 10 bytes

9ʀƛn9ɾevtU


Try it Online!

# Pyth, 10 bytes

m.ue*Ndd)T


Try it here!

• I don't think it's particularly good form to post the first answer to your own challenge, especially when it wasn't very well described. – rak1507 Mar 6 at 21:11
• Though you can post this after a few days, if you don't get a solution in this language, and to post it earlier you can set a bounty for people who can beat your this answer in the same language, thanks! – Wasif Mar 7 at 7:50