Quantcast
Viewing all articles
Browse latest Browse all 67

Answer by Bubbler for Tips for golfing in C

Favor recursion over loops, especially if going forwards then backwards

Loops, 67 bytes

l;f(char*s){for(l=0;s[l];)putchar(s[l++]);for(;l;)putchar(s[--l]);}

Try it online!

Recursion, 47 bytes

f(char*s){*s?putchar(*s),f(s+1),putchar(*s):0;}

Try it online!

You can remove two for-loops and a counter variable. Even if you use just one for-loop in order to loop in one direction, you could save ~10 bytes with this transformation.


Viewing all articles
Browse latest Browse all 67

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>