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:
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.
-
\$\begingroup\$ Jesus, that sh*t crashed my browser... \$\endgroup\$CreaZyp154– CreaZyp1542021年12月07日 13:19:18 +00:00Commented Dec 7, 2021 at 13:19
20 Answers 20
05AB1E, (削除) 25 (削除ここまで) (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) 21 bytes
žXAS.7Ƶ-t∞-m&g×ばつ....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 ý!
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.
-
\$\begingroup\$ 05AB1E even has a builtin for "http://". I'm impressed \$\endgroup\$Gymhgy– Gymhgy2020年02月07日 02:40:43 +00:00Commented Feb 7, 2020 at 2:40
-
\$\begingroup\$ @EmbodimentofIgnorance Yep.
žXis"http://";žYis"https://"andžZis"http://www.":) \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2020年02月07日 07:20:49 +00:00Commented Feb 7, 2020 at 7:20 -
-
1\$\begingroup\$ 21 (: Also, here's a 20 that almost works (1 extra
v, 1 missingz). \$\endgroup\$Grimmy– Grimmy2020年02月07日 17:35:30 +00:00Commented 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\$Kevin Cruijssen– Kevin Cruijssen2020年02月07日 18:08:10 +00:00Commented Feb 7, 2020 at 18:08
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")
Uses Shieru Asakoto's 0-based formula.
-
\$\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– mypetlion2020年02月05日 23:47:40 +00:00Commented Feb 5, 2020 at 23:47 -
1\$\begingroup\$ @mypetlion Clever reshuffle of braced expressions - thanks! :-) \$\endgroup\$Noodle9– Noodle92020年02月05日 23:52:52 +00:00Commented Feb 5, 2020 at 23:52
-
\$\begingroup\$ 77 bytes when using an alternative formula. \$\endgroup\$Shieru Asakoto– Shieru Asakoto2020年02月06日 01:00:18 +00:00Commented Feb 6, 2020 at 1:00
-
1\$\begingroup\$ @ShieruAsakoto Was just adding that - thanks! :-) \$\endgroup\$Noodle9– Noodle92020年02月06日 01:01:32 +00:00Commented Feb 6, 2020 at 1:01
APL (Dyalog), (削除) 41 (削除ここまで) 38 bytes
-3 bytes thanks to Bubbler
2⌽'mehttp://',∊'.', ̈⍨⎕A⍴ ×ばつ.7*⍒⎕A
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 times
.7* ⍝ 0.7 to the power of
⍒⎕A ⍝ The range 26 to 1
-
\$\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– Jonah2020年02月06日 01:52:23 +00:00Commented 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– Jo King2020年02月06日 02:01:48 +00:00Commented Feb 6, 2020 at 2:01
-
3\$\begingroup\$ @Jonah
f¨is like J's stdlib'seach, orf&.:>"0. The"0part is⍤0in APL. Unfortunately, we don't have J's (new)L:(though I'm arguing for adding it as⍥). \$\endgroup\$Adám– Adám2020年02月06日 06:16:58 +00:00Commented Feb 6, 2020 at 6:16
Perl 5, (削除) 61 (削除ここまで) (削除) 57 (削除ここまで) 55 bytes
-4 bytes thanks to @Neil
say"http://",(map{$_ x(1+62/.7**(++$p-26))."."}a..z),me
-
2\$\begingroup\$ I think
*(10/7)**is the same as/(7/10)**or/.7**. \$\endgroup\$Neil– Neil2020年02月06日 01:10:52 +00:00Commented Feb 6, 2020 at 1:10
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)
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";}
Credits
- -4 bytes thanks to Kevin Cruijssen
-
\$\begingroup\$ Very likely golfable using math. \$\endgroup\$Olivier Grégoire– Olivier Grégoire2020年02月06日 10:06:14 +00:00Commented Feb 6, 2020 at 10:06
-
1\$\begingroup\$ -3 byte using
62/Math.pow(.7,c-122)(credit goes to @Neil). \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2020年02月06日 10:22:47 +00:00Commented 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\$Kevin Cruijssen– Kevin Cruijssen2020年02月06日 10:28:12 +00:00Commented Feb 6, 2020 at 10:28
Charcoal, 27 bytes
http×ばつ62X·7−25κ.¦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
−25 Subtract from 25
X·7 Raise 0.7 to that power
×ばつ62 Multiply by 62
⊕ Increment
×ばつι Repeat letter that many times
+ . Concatenate literal string `.`
¦ Implicitly print
me Implicitly print literal string `me`
Jelly, (削除) 49 (削除ここまで) (削除) 48 (削除ここまで) (削除) 46 (削除ここまで) 31 bytes (send help)
A niladic link printing the URL
×ばつ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.
-
\$\begingroup\$ Your
https://can behttp://;) \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2020年02月06日 12:31:04 +00:00Commented Feb 6, 2020 at 12:31 -
\$\begingroup\$ @KevinCruijssen gosh, I missed this entirely :D ty \$\endgroup\$RGS– RGS2020年02月06日 13:22:51 +00:00Commented 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\$Kevin Cruijssen– Kevin Cruijssen2020年02月06日 13:25:49 +00:00Commented 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 themeearlier), 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\$Nick Kennedy– Nick Kennedy2020年02月06日 19:56:28 +00:00Commented 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– RGS2020年02月06日 22:20:10 +00:00Commented Feb 6, 2020 at 22:20
Wolfram Language (Mathematica), 71 bytes
"http://"<>Array[Table[Alphabet[][[#]],1+1.43^(#-26)62]<>"."&,26]<>"me"
JavaScript (Node.js), 93 bytes
_=>`http://${[...Array(26)].map((x,i)=>Buffer(Array(1+.7**-i/120|0).fill(97+i))).join`.`}.me`
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.
-
1\$\begingroup\$ Same length variant:
_=>`http://${"abcdefghijklmnopqrstuvwxuz".replace(/./g,(x,i)=>x.repeat(1+.7**-i/120)+`.`)}me`\$\endgroup\$Neil– Neil2020年02月06日 01:08:06 +00:00Commented Feb 6, 2020 at 1:08 -
1
-
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\$Shieru Asakoto– Shieru Asakoto2020年02月06日 05:59:35 +00:00Commented Feb 6, 2020 at 5:59
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!
-
-
\$\begingroup\$ @Shaggy Thanks, I forgot that
**exists \$\endgroup\$Gymhgy– Gymhgy2020年02月07日 02:34:23 +00:00Commented Feb 7, 2020 at 2:34
Haskell, 86 bytes
g(c,x)=replicate(floor1ドル+62*1.43**x)c++"."
f="http://"++(zip['a'..][-25..0]>>=g)++"me"
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=".")
-
2\$\begingroup\$ 69 bytes; feel free to come to the R golfing chat if you wanna discuss ideas there :-) \$\endgroup\$Giuseppe– Giuseppe2020年02月08日 00:46:29 +00:00Commented Feb 8, 2020 at 0:46
-
2\$\begingroup\$ @Giuseppe 65 based on your 69. \$\endgroup\$Grimmy– Grimmy2020年02月08日 01:20:21 +00:00Commented Feb 8, 2020 at 1:20
-
\$\begingroup\$ @Giuseppe and Grimmy, thanks! Very impressive trimming. \$\endgroup\$John– John2020年02月08日 13:10:51 +00:00Commented Feb 8, 2020 at 13:10
Keg, (削除) 46 (削除ここまで) 40 bytes
`3);://`0&(‡26 |(8)a+n⅍7
/(8)±Ëx/Z1+(6)*\.)`me
A port of the Python 3 answer by Noodle9.
-6 bytes due to using string compression and some other things
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';
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)
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"
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"
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";}
-
\$\begingroup\$ You could use
bits/stdc++.hand usecmath's functions. \$\endgroup\$S.S. Anne– S.S. Anne2020年02月06日 18:00:49 +00:00Commented 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– gastropner2020年02月06日 20:45:51 +00:00Commented Feb 6, 2020 at 20:45
-
\$\begingroup\$ But not
stringandcmathcombined. Instead of#import<string> #import<cmath>(in this hypothetical solution) you could do#import<bits/stdc++.h>. \$\endgroup\$S.S. Anne– S.S. Anne2020年02月06日 20:55:35 +00:00Commented 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– gastropner2020年02月06日 21:08:36 +00:00Commented Feb 6, 2020 at 21:08
-
1\$\begingroup\$ Well, then
stringcan be replaced withmapfor -3 bytes. \$\endgroup\$S.S. Anne– S.S. Anne2020年02月06日 21:11:28 +00:00Commented Feb 6, 2020 at 21:11
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
E.
Explore related questions
See similar questions with these tags.