Skip to main content
9 of 10
removed MathJax since it is being disabled temporarily
Calvin's Hobbies
  • 90k
  • 46
  • 339
  • 555

#JavaScript, 114 109 106 bytes

This is my first entry in a codegolf contest! Please tell me how to improve. Current entry (106 bytes) after removing false optimisation (thanks edc65!)

w="$$\\varphi=";y=n=>{return a=!n?w+"1+\\dots$$":w+"1+\\cfrac1{".repeat(n)+"1+\\ddots"+"}".repeat(n)+"$$"}

Previous entry (109 bytes):

x="repeat",w="$$\\varphi=";y=n=>{return a=!n?w+"1+\\dots$$":w+"1+\\cfrac1{"[x](n)+"1+\\ddots"+"}"[x](n)+"$$"}

Previous entry (114 bytes):

x="repeat";y=n=>{return a=!n?"$$\\varphi=1+\\dots$$":"$$\\varphi="+"1+\\cfrac1{"[x](n)+"1+\\ddots"+"}"[x](n)+"$$"}

Paste into browser console and call as f(n) where n is the number of 'steps'.

Simplified code:

function y(n) {
   if(n === 0) {
      return "$$\\varphi=1+\\dots$$";
   } else {
      return "$$\\varphi=" + "1+\\cfrac1{".repeat(n) + "1+\\ddots"+"}".repeat(n)+"$$";
   }
user31556