7
\$\begingroup\$

I'm (still) trying to make another submission to the Largest Number Printable question, and I've got the following bit of code:

f=->a{b,c,d=a;b ?a==b ?~-a:a==a-[c-c]?[[b,c,f[d]],~-c,b]:b:$n}
h=[],$n=?~.ord,[]
h=f[h]until h==p($n+=$n)-$n

Ungolfed:

f=->{b,c,d=a
if b
  if a==b # a is not an array
    return a-1
  elsif a==a-[0] # a does not contain 0
    t = [b,c,f[d]]
    return [t,c-1,b]
  else # a is an array containing 0
    return b
  end
else # if a == []
  return $n
end}

$n = 126
h = [[],n,[]]

until h==0 do
  $n += $n
  p $n
  h = f[h]
end

The conditions I'm working with:

  • Maximum 100 bytes.

  • No digits allowed in my code.

My code is currently at 108 bytes, but I can't figure out how to golf it further.

The h==p($n+=$n)-$n may be replaced with h==0, but I can't use digits and I still need to print $n and apply $n+=$n in the until loop.

I'm also satisfied with code that replaces $n+=$n with $n+=1, but I can't use digits unfortunately.

Any suggestions?

\$\endgroup\$
  • \$\begingroup\$ It would be helpful if you could include in your question a version of the code with whitespace and comments so we don’t have to figure every bit out on our own. \$\endgroup\$ – Jordan Dec 2 '17 at 21:43
  • \$\begingroup\$ @Jordan Updated, sorry. \$\endgroup\$ – Simply Beautiful Art Dec 2 '17 at 22:11
2
\$\begingroup\$

105

You can save three bytes by declaring n as a local variable (instead of a global) before f:

n=?~.ord
f=->a{b,c,d=a;b ?a==b ?~-a:a==a-[c-c]?[[b,c,f[d]],~-c,b]:b:n}
h=[],n,[]
h=f[h]until h==p(n+=n)-n
\$\endgroup\$
  • \$\begingroup\$ Thanks! For my purposes, this can be written like so, making it 103 bytes. \$\endgroup\$ – Simply Beautiful Art Dec 2 '17 at 22:12
2
\$\begingroup\$

100 bytes

For my purposes, this is good enough.

h=[],n=?~.ord,n
f=->a{b,c,d=a;b ?a==b ?~-a:a==a-[c-c]?[[b,c,f[d]],~-c,b]:b:p(n+=n)}
h=f[h]until h==n

Replacing h==0 with h==n will not cause the program to fail to terminate, which is what I needed.

Also improves on Jordan's answer by declaring h and n in the same line.

\$\endgroup\$

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.