-4
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ Sandbox \$\endgroup\$ – hakr14 Mar 6 at 20:15
  • \$\begingroup\$ Unfortunately I didn't think of this while it was in the sandbox, but are different delimiters allowed? \$\endgroup\$ – FryAmTheEggman Mar 6 at 20:24
  • 7
    \$\begingroup\$ Some explanation please as to what, exactly, that list is. \$\endgroup\$ – Noodle9 Mar 6 at 20:27
  • 5
    \$\begingroup\$ @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 \$\endgroup\$ – caird coinheringaahing Mar 6 at 20:33
  • \$\begingroup\$ Why is the first entry [0] when 0**x = 1? \$\endgroup\$ – Shaggy Mar 8 at 20:54

14 Answers 14

1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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])
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 71 69 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))])
)

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

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!

\$\endgroup\$
0
\$\begingroup\$

Charcoal, 17 bytes

I﹪EχXιI…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
  E                 Map over implicit range
     ι              Current value
    X               Vectorised to power
       …            Range from
        1           Literal string `1` to
          22553     Literal string `22553`
         §          Cyclically indexed by
               ι    Current value
      I             Cast to integer
 ﹪                  Vectorised modulo by
                χ   Predefined variable 10
I                   Cast to string
                    Implicitly print
\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica), 50 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Haskell, 71 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 3, 55 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

Deadfish~, 549 bytes

{{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!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

Vyxal, 10 bytes

9ʀƛn9ɾevtU

Try it Online!

\$\endgroup\$
-3
\$\begingroup\$

Pyth, 10 bytes

m.ue*Ndd)T

Try it here!

\$\endgroup\$
2
  • 10
    \$\begingroup\$ 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. \$\endgroup\$ – rak1507 Mar 6 at 21:11
  • \$\begingroup\$ 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! \$\endgroup\$ – Wasif Mar 7 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.