Skip to main content
2 of 3
minor commentary edit; deleted 11 characters in body
att
  • 22.8k
  • 2
  • 19
  • 70

C (gcc), 114 112 bytes

f(n,s){int i[19]={};for(s=n/10,n%=10;i[s]-n;n+=n>9?-9:s%10,s=i[s])i[s]=n;do printf("%d ",s);while(i[s=i[s]]-n);} 

Try it online!

Includes a trailing space.

f(n,s){ int i[19]={}; //re-initialize edges upon call for(s=n/10,n%=10; //initialize from input i[s]-n; //detect loop when an edge s->n repeats n+=n>9?-9:s%10,s=i[s])i[s]=n; //step do printf("%d ",s);while(i[s=i[s]]-n); //output loop } 
att
  • 22.8k
  • 2
  • 19
  • 70