31
\$\begingroup\$

Task

This one is simple. We want to compress a URL, but don't trust URL shorteners.

Write a program that prints to stdout (or a 0-argument function that returns) the following, working URL:

http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.oo.pp.qqq.rrrr.ssssss.tttttttt.uuuuuuuuuuu.vvvvvvvvvvvvvvv.wwwwwwwwwwwwwwwwwwwwww.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.me

Code golf, standard rules.

You may output uppercase or lowercase.

Leading or trailing whitespace is ok.

Context

Explanation taken from the website:

The domain is created to reach the maximum number of allowed characters (255 (really 253)) with an exponential curve in the length of the letters as you proceed through the alphabet. The formula used is "1 + 62 * (10/7)^(x-26)". To help illustrate this curve, reference the distribution on this spreadsheet. It's colorful because I like colors and wanted to do a progressive "rainbow" animation in CSS3.

\$\endgroup\$
1
  • \$\begingroup\$ Jesus, that sh*t crashed my browser... \$\endgroup\$
    – CreaZyp154
    Dec 7, 2021 at 13:19

20 Answers 20

6
\$\begingroup\$

05AB1E, 25 24 23 21 bytes

žXAS.7Ƶ-t∞-m>×….me¬ýJ

-1 byte thanks to @Neil's analysis that *(10/7)** is the same as /.7**.
-3 bytes thanks to @Grimmy using a different formula and ingenious use of ý!

Try it online.

Explanation:

The formula used to get the correct amount of characters of the alphabet, where \$n\$ is the 1-based index of the alphabetic letter:
\$a(n) = \left\lfloor0.7^{(\sqrt{208}-n)}+1\right\rfloor\$

žX                     # Push builtin "http://"
      Ƶ-               # Push compressed 208
        t              # Take the square-root of that: 14.422...
         ∞             # Push an infinite list of positive integers: [1,2,3,...]
          -            # Subtract each from the 14.422...: [13.442...,12.442...,...]
    .7     m           # Take 0.7 to the power of each of these: [0.008...,0.011...,...]
            >          # Increase each by 1: [1.008...,1.011...,...]
  AS                   # Push the lowercase alphabet as list of characters,
             ×         # and repeat each the calculated values amount of times as string
                       # (which implicitly truncates the floats to integers, and ignores
                       #  the floats beyond the length of the alphabet)
              ….me     # Push ".me"
                  ¬    # Push its head (the "."), without popping the ".me" itself
                   ý   # Join with delimiter. Normally it will use the top value as
                       # delimiter and joins the top-1'th list. In this case however, the
                       # top-1'th item is a string, so instead it will join the entire stack
                       # together. BUT, because the stack contains a list, it will instead
                       # only join all lists on the stacks by the "." delimiter
                    J  # And finally join the three strings on the stack together
                       # (after which this result is output implicitly)

See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ƶ- is 208.

\$\endgroup\$
5
  • \$\begingroup\$ 05AB1E even has a builtin for "http://". I'm impressed \$\endgroup\$
    – Gymhgy
    Feb 7, 2020 at 2:40
  • \$\begingroup\$ @EmbodimentofIgnorance Yep. žX is "http://"; žY is "https://" and žZ is "http://www." :) \$\endgroup\$ Feb 7, 2020 at 7:20
  • \$\begingroup\$ 22 \$\endgroup\$
    – Grimmy
    Feb 7, 2020 at 15:04
  • 1
    \$\begingroup\$ 21 (: Also, here's a 20 that almost works (1 extra v, 1 missing z). \$\endgroup\$
    – Grimmy
    Feb 7, 2020 at 17:35
  • \$\begingroup\$ @Grimmy Very nice! Both the new formula with sqrt(208) and how you've used the ý to join the list somewhere on the stack is ingenious! :D \$\endgroup\$ Feb 7, 2020 at 18:08
6
\$\begingroup\$

Python 3, 86 \$\cdots\$ 81 77 bytes

Saved 3 bytes thanks to mypetlion!!!
Saved 4 bytes thanks to Shieru Asakoto!!!

print(f"http://{'.'.join(chr(i+97)*int(1+.7**-i/120)for i in range(26))}.me")

Try it online!

Uses Shieru Asakoto's 0-based formula.

\$\endgroup\$
4
  • \$\begingroup\$ 81 bytes: print(f"http://{'.'.join(chr(i+122)*int(1+62*1.43**i)for i in range(-25,1))}.me") \$\endgroup\$
    – mypetlion
    Feb 5, 2020 at 23:47
  • 1
    \$\begingroup\$ @mypetlion Clever reshuffle of braced expressions - thanks! :-) \$\endgroup\$
    – Noodle9
    Feb 5, 2020 at 23:52
  • \$\begingroup\$ 77 bytes when using an alternative formula. \$\endgroup\$ Feb 6, 2020 at 1:00
  • 1
    \$\begingroup\$ @ShieruAsakoto Was just adding that - thanks! :-) \$\endgroup\$
    – Noodle9
    Feb 6, 2020 at 1:01
6
\$\begingroup\$

APL (Dyalog), 41 38 bytes

-3 bytes thanks to Bubbler

2⌽'mehttp://',∊'.',¨⍨⎕A⍴¨⍨⌊1+62×.7*⍒⎕A

Try it online!

Outputs the URL with the letters capitalised. Uses the 0 indexed formula \$ \lfloor 1 + 62 \times 0.7^{25-x} \rfloor \$, since \$ (\frac{10}{7})^{x-25} = ((\frac{7}{10})^{-1})^{x-25} = (\frac{7}{10})^{25-x}\$

Explanation:

2⌽                         ⍝ Rotate by two places (moving the 'me' to the end)
  'mehttp://'              ⍝ The start string
             ,             ⍝ Followed by
              ∊               ⍝ The flattened string of
               '.'            ⍝ A period
                  ,⍨¨         ⍝ Appended to the end of each of
                     ⎕A            ⍝ The uppercase alphabet
                       ⍴¨⍨         ⍝ Where each letter is repeated by
                          ⌊               ⍝ The floor of
                           1+             ⍝ 1 plus
                             62×          ⍝ 62 times
                                .7*       ⍝ 0.7 to the power of
                                   ⍒⎕A  ⍝ The range 26 to 1
\$\endgroup\$
3
  • \$\begingroup\$ are the final two dots in ,⍨¨ the equivalent of J's rank 0 adverb "0? Does APL have the ability to specify other specific ranks? \$\endgroup\$
    – Jonah
    Feb 6, 2020 at 1:52
  • 1
    \$\begingroup\$ @Jonah Yes, ¨ is the each function, which applies an operator to each element of the vector. I don't think you can specify rank with that specific function, though I'm not an expert with APL. Try asking Adam in chat \$\endgroup\$
    – Jo King
    Feb 6, 2020 at 2:01
  • 3
    \$\begingroup\$ @Jonah is like J's stdlib's each, or f&.:>"0. The "0 part is ⍤0 in APL. Unfortunately, we don't have J's (new) L: (though I'm arguing for adding it as ). \$\endgroup\$
    – Adám
    Feb 6, 2020 at 6:16
4
\$\begingroup\$

Perl 5, 61 57 55 bytes

-4 bytes thanks to @Neil

say"http://",(map{$_ x(1+62/.7**(++$p-26))."."}a..z),me

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ I think *(10/7)** is the same as /(7/10)** or /.7**. \$\endgroup\$
    – Neil
    Feb 6, 2020 at 1:10
4
\$\begingroup\$

JavaScript (Node.js), 77 bytes

Based on @ShieruAsakoto's formula. Builds the URL recursively.

f=n=>n>25?".me":(n?".".padEnd(2+.7**-n/120,Buffer([97+n])):"http://a")+f(-~n)

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Java (JDK), 108 bytes

v->{var s="HTTP://";for(char c=64,t;++c<91;s+=(""+c).repeat(t/=Math.pow(.7,c-90))+c+".")t=62;return s+"ME";}

Try it online!

Credits

  • -4 bytes thanks to Kevin Cruijssen
\$\endgroup\$
3
  • \$\begingroup\$ Very likely golfable using math. \$\endgroup\$ Feb 6, 2020 at 10:06
  • 1
    \$\begingroup\$ -3 byte using 62/Math.pow(.7,c-122) (credit goes to @Neil). \$\endgroup\$ Feb 6, 2020 at 10:22
  • 1
    \$\begingroup\$ And an additional -1 with for(char c=96,t;++c<123;s+=(""+c).repeat(t/=Math.pow(.7,c-122))+c+".")t=62; \$\endgroup\$ Feb 6, 2020 at 10:28
3
\$\begingroup\$

Charcoal, 27 bytes

http://⭆β⁺×ι⊕×⁶²X·⁷⁻²⁵κ.¦me

Try it online! Link is to verbose version of code. Explanation:

http://                     Implicitly print literal string `http://`
        β                   Lowercase alphabet
       ⭆                    Map over letters and join
                      κ     Current index
                   ⁻²⁵      Subtract from 25
                X·⁷         Raise 0.7 to that power
             ×⁶²            Multiply by 62
            ⊕               Increment
          ×ι                Repeat letter that many times
         ⁺             .    Concatenate literal string `.`
                        ¦   Implicitly print
                         me Implicitly print literal string `me`
\$\endgroup\$
3
\$\begingroup\$

Jelly, 49 48 46 31 bytes (send help)

A niladic link printing the URL

26RU.7*×89ĊØa×⁾meṭj”.“http://”;

-2 bytes thanks to Kevin

-15 bytes thanks to Nick!

I never wrote anything this complex in Jelly and the tacicity isn't obvious to me yet... So this is very golfable (see 49 byte link). I would appreciate feedback and golfing tips in small chunks so that I can digest it!

You can try this online.

\$\endgroup\$
6
  • \$\begingroup\$ Your https:// can be http:// ;) \$\endgroup\$ Feb 6, 2020 at 12:31
  • \$\begingroup\$ @KevinCruijssen gosh, I missed this entirely :D ty \$\endgroup\$
    – RGS
    Feb 6, 2020 at 13:22
  • 1
    \$\begingroup\$ Np. Unfortunately I can't really help you with the rest, since I don't know a lot about Jelly. Only thing that comes to mind is removing the trailing , since it's closed implicitly to save a byte. But since my 05AB1E answer is 23 bytes, I'm sure <30 should be easily possible for Jelly as well. ;) \$\endgroup\$ Feb 6, 2020 at 13:25
  • 1
    \$\begingroup\$ Here’s a 31 byte answer for comparison. In general, it’s helpful to try to have a single link that proceeds from left to right whenever possible. Other useful hints include use of j (join) for your last line (though I’ve changed it to add the me earlier), use of the Ø nilads, reversing the order of the list rather than subtracting from 26. Happy for you to use my answer (and improve it if possible). Note it was derived from @KevinCruijsen’s answer. It’s longer because of the “http://” \$\endgroup\$ Feb 6, 2020 at 19:56
  • 1
    \$\begingroup\$ @NickKennedy this was an unbelievable byte discount. I'll have to digest your submission calmly. Thanks a lot! \$\endgroup\$
    – RGS
    Feb 6, 2020 at 22:20
2
\$\begingroup\$

Wolfram Language (Mathematica), 71 bytes

"http://"<>Array[Table[Alphabet[][[#]],1+1.43^(#-26)62]<>"."&,26]<>"me"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 93 bytes

_=>`http://${[...Array(26)].map((x,i)=>Buffer(Array(1+.7**-i/120|0).fill(97+i))).join`.`}.me`

Try it online!

When turning the formula into 0-indexed, the formula becomes \$1+62\times(\frac{10}{7})^{x-25}=1+0.0083146\times0.7^{-x}\$, and then 0.0083146 is approximated by 1/120.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Same length variant: _=>`http://${"abcdefghijklmnopqrstuvwxuz".replace(/./g,(x,i)=>x.repeat(1+.7**-i/120)+`.`)}me` \$\endgroup\$
    – Neil
    Feb 6, 2020 at 1:08
  • 1
    \$\begingroup\$ 77 bytes \$\endgroup\$
    – Arnauld
    Feb 6, 2020 at 5:57
  • 1
    \$\begingroup\$ @Arnauld I suggest you post it as a separate answer because the approach is quite different on this. I've rolled back your golf to let you post it. \$\endgroup\$ Feb 6, 2020 at 5:59
2
\$\begingroup\$

C (gcc), 99 bytes

n;f(i){for(i=printf("http://");i<33;)for(n=62/pow(.7,i++-32)+2;n--;)putchar(n?89+i:46);puts("me");}

-3 or so bytes thanks to Noodle9!

-8 bytes thanks to gastropner!

Try it online!

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

Japt, 29 bytes

;`http://{C®p.7**T´/#xÄ +'.}´

Saved 2 bytes thanks to @Shaggy

Test it

\$\endgroup\$
2
  • \$\begingroup\$ 29 bytes? \$\endgroup\$
    – Shaggy
    Feb 6, 2020 at 8:19
  • \$\begingroup\$ @Shaggy Thanks, I forgot that ** exists \$\endgroup\$
    – Gymhgy
    Feb 7, 2020 at 2:34
2
\$\begingroup\$

Haskell, 86 bytes

g(c,x)=replicate(floor$1+62*1.43**x)c++"."
f="http://"++(zip['a'..][-25..0]>>=g)++"me"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

R, 124 115 63 bytes

This is way better than my original approach. Thanks to @Giuseppe and @Grimmy

cat("http://");cat(strrep(letters,1+62*.7^(25:0)),"me",sep=".")

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ 69 bytes; feel free to come to the R golfing chat if you wanna discuss ideas there :-) \$\endgroup\$
    – Giuseppe
    Feb 8, 2020 at 0:46
  • 2
    \$\begingroup\$ @Giuseppe 65 based on your 69. \$\endgroup\$
    – Grimmy
    Feb 8, 2020 at 1:20
  • \$\begingroup\$ @Giuseppe and Grimmy, thanks! Very impressive trimming. \$\endgroup\$
    – John
    Feb 8, 2020 at 13:10
1
\$\begingroup\$

Keg, 46 40 bytes

`3);://`0&(‡26   |⑻a+ⁿ⅍7
/⑻±Ëx/ℤ1+⑹*\.)`me

Try it online!

A port of the Python 3 answer by Noodle9.

-6 bytes due to using string compression and some other things

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

PHP, 94 bytes

for($c='a',$s='http://',$i=-26;$i++;$c++,$s.='.')for($l=62/.7**$i;$l-->=0;$s.=$c);echo$s.'me';

Try it online!

Probably still golfable, uses the formula from the question and PHP's char incrementing

EDIT: saved 3 bytes with code reorganization

EDIT2: another byte less starting from -26 and removing ($i-26)

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

Ruby, 64 bytes

Conveniently, when multiplying a string with a non-whole positive number, Ruby truncates the number to determine how many times to repeat the string.

puts"http://#{(?a..?z).map{|c|c*(1+62/0.7**(c.ord-122))}*?.}.me"

Try it online!

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

MATLAB 92 bytes

b="";for i=1:26;b=b+repelem(char(96+i),floor(1+62*(10/7).^(i-26)))+".";end;"http://"+b+"me"
\$\endgroup\$
1
\$\begingroup\$

C++ (gcc), 126 123 bytes

-3 bytes thanks to S.S. Anne

Some acrobatics needed to avoid having to include cmath.

#import<map>
using s=std::string;s f(){s r="http://";for(float i=26,p=7456;i--;p*=.7)r+=s(1+62/p,122-i)+'.';return r+"me";}

Try it online!

\$\endgroup\$
7
  • \$\begingroup\$ You could use bits/stdc++.h and use cmath's functions. \$\endgroup\$
    – S.S. Anne
    Feb 6, 2020 at 18:00
  • \$\begingroup\$ @S.S.Anne I might misunderstand you, but that would take even more bytes to include than cmath. \$\endgroup\$
    – gastropner
    Feb 6, 2020 at 20:45
  • \$\begingroup\$ But not string and cmath combined. Instead of #import<string> #import<cmath> (in this hypothetical solution) you could do #import<bits/stdc++.h>. \$\endgroup\$
    – S.S. Anne
    Feb 6, 2020 at 20:55
  • \$\begingroup\$ @S.S.Anne Oh, I see what you mean! Had no idea about that one. Sadly it came out longer, doing that. \$\endgroup\$
    – gastropner
    Feb 6, 2020 at 21:08
  • 1
    \$\begingroup\$ Well, then string can be replaced with map for -3 bytes. \$\endgroup\$
    – S.S. Anne
    Feb 6, 2020 at 21:11
0
\$\begingroup\$

Deadfish~, 809 bytes

{i}cc{{i}d}iiiic{i}iiccddddc{{d}iiiii}ddddc{d}dcc{{i}ddddd}c{{d}iiiii}dc{{i}ddddd}iic{{d}iiiii}ddc{{i}ddddd}iiic{{d}iiiii}dddc{{i}ddddd}iiiic{{d}iiiii}ddddc{{i}ddddd}iiiiic{{d}iiiii}dddddc{{i}ddddd}iiiiiic{{d}iiiii}ddddddc{{i}dddd}dddc{{d}iiii}iiic{{i}dddd}ddc{{d}iiii}iic{{i}dddd}dc{{d}iiii}ic{{i}dddd}c{{d}iiii}c{{i}dddd}ic{{d}iiii}dc{{i}dddd}iic{{d}iiii}ddc{{i}dddd}iiic{{d}iiii}dddc{{i}dddd}iiiic{{d}iiii}ddddc{{i}dddd}iiiiicc{{d}iiii}dddddc{{i}dddd}iiiiiicc{{d}iiii}ddddddc{{i}ddd}dddccc{{d}iii}iiic{{i}ddd}ddcccc{{d}iii}iic{{i}ddd}dcccccc{{d}iii}ic{{i}ddd}cccccccc{{d}iii}c{{i}ddd}i{c}c{{d}iii}dc{{i}ddd}ii{c}ccccc{{d}iii}ddc{{i}ddd}iii{c}{c}cc{{d}iii}dddc{{i}ddd}iiii{c}{c}{c}c{{d}iii}ddddc{{i}ddd}iiiii{c}{c}{c}{c}cccc{{d}iii}dddddc{{i}ddd}iiiiii{c}{c}{c}{c}{c}{c}ccc{{d}iii}ddddddc{{i}dddd}iiic{d}iic

Try it online!

E.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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