41
\$\begingroup\$

A string can be shifted by a number n by getting the byte value c of each character in the string, calculating (c + n) mod 256, and converting the result back to a character.

As an example, shifting "ABC123" by 1 results in "BCD234", shifting by 10 in "KLM;<=", and shifting by 255 in "@AB012".

The Task

Pick as many numbers n with 0 < n < 256 as you dare and write a program or function that takes a string as input and

  • returns the string unchanged when the source code is unchanged, but
  • returns the string shifted by n when the source code is shifted by n.

Rules

  • The score of your submission is the number of supported n, with a higher score being better. The maximum score is thus 255.
  • Your submission must support at least one shift, so the minimal score is 1.
  • In case of a tie the shorter program wins.
  • All shifted programs need to be in the same language.
\$\endgroup\$
4
  • \$\begingroup\$ Related. \$\endgroup\$ Mar 15, 2018 at 13:50
  • \$\begingroup\$ Related. \$\endgroup\$
    – jimmy23013
    Mar 15, 2018 at 16:11
  • \$\begingroup\$ Is it acceptable to have output before the desired output that is cleared via ANSI escape sequences, or hidden via \r? \$\endgroup\$ Mar 16, 2018 at 8:54
  • 4
    \$\begingroup\$ @DomHastings Since 0x0D and 0x1B are potentially part of the actual string output, I wouldn't think so. \$\endgroup\$ Mar 16, 2018 at 9:04

9 Answers 9

24
\$\begingroup\$

Brainfuck, score: 31 (2208 bytes)

Base64-encoded program:

LFsuLF0oVycnJycqKFkkUyMjIyMjIyMjJiRVIE8fHx8fHx8fHx8fHx8iIFEMOwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLDgw9CDcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcKCDkEMwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMGBDUAL8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w7/Dv8O/w78CADHDrBvDq8Orw6vDq8Orw6vDq8Orw6vDq8Orw6vDq8Orw6vDq8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qHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqHCocKhwqLCoMORwozCu8KNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKNwo3CjcKOwozCvcKIwrfCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJwonCicKJworCiMK5woTCs8KFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwoXChcKFwobChMK1woDCr8KBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKBwoHCgcKCwoDCsWzCm21tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1ubMKdaMKXaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpaWlpamjCmWTCk2VlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZmTClWDCj2FhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFiYMKRTHtNTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU5MfUh3SUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUpIeURzRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRkR1QG9BQUFBQUFBQUFBQUFBQUFBQUFBQUJAcQ==

Works for shifts 0, 4, 8, 12, 32, 36, 40, 44, 64, 68, 72, 76, 96, 100, 104, 108, 128, 132, 136, 140, 160, 164, 168, 172, 192, 196, 200, 204, 224, 228, 232 and 236.

For every value between 0 and 255, there is exactly one of those shifts that sends that character to a valid brainfuck instruction.

The program relies on 8-bit cells with wrapping on overflows. This could probably be golfed quite a bit, as the shift just consists of a repeated + or - (whichever is shorter).

Python code used to generate this:

l = [0, 4, 8, 12, 32, 36, 40, 44, 64, 68, 72, 76, 96, 100, 104, 108, 128, 132, 136, 140, 160, 164, 168, 172, 192, 196, 200, 204, 224, 228, 232, 236]
shift = lambda s,n:"".join(chr((ord(i)+n)%256) for i in s)
code = ""
for i in l:
    code += shift(",[{}.,]".format(i*"+" if i<=128 else (256-i)*"-"),-i)
\$\endgroup\$
2
  • \$\begingroup\$ Can you show some of the actual working code that was encoded and shift-proofed? (ie +[>,.<]?) \$\endgroup\$
    – Stan Strum
    Mar 16, 2018 at 15:02
  • \$\begingroup\$ @StanStrum It's just shifted versions of ,[+.,], where + is the amount of +s or -s \$\endgroup\$
    – Jo King
    Mar 17, 2018 at 9:01
21
\$\begingroup\$

lHaskell, Score 255 (27,026 bytes)

The program works but putting it in my clipboard seems to destroy it so here is code that outputs my program.

Verification

So if copying things to a clipboard breaks it how do I verify that it works?

You can use this here. You can adjust N and the string (currently Big ol' egg) to see that it works yourself.

This will test all N on a single input in succession but tends to time out.

Explanation

This abuses literate Haskell's comment notation. In literate Haskell any line that does not start with > is a comment. So to make our code work we make 255 copies of the program each shifting by n and then we shift each individual copy by -n.

\$\endgroup\$
20
\$\begingroup\$

C, score: 1 (73 bytes)

aZ0;/*0\:..*/f(s){puts(s);}//	e'bg`q)r(zenq':)r:**r(otsbg`q'')r*0($145(:|

Try it online!

Shifted by 1:

b[1<0+1];//+0g)t*|qvut)t*<~00
f(char*s){for(;*s;++s)putchar((*s+1)%256);}

Try it online!

\$\endgroup\$
7
\$\begingroup\$

05AB1E, Score: 3 (24 bytes)

¶Ä0(ä.g){n·Å0)åH*oHÆ0*æI

Try it online!

Explanation

¶Ä0(ä.g){n·Å0)åH*oHÆ0*æ  # Doesn't matter
                       I # Push the original input to the stack, implicit display

Shifted once:

·Å1)å/h*|o¸Æ1*æI+pIÇ1+çJ

Try it online!

Explanation

·Å1)å/h*|o¸Æ1*æI+p       # Doesn't matter    
                  IÇ     # Push the ASCII values of the input 
                    1+   # Increment by 1
                      çJ # Push the chars of the ASCII values, join, implicit display

Shifted twice:

¸Æ2*æ0i+}p¹Ç2+çJ,qJÈ2,èK

Try it online!

Explanation

Æ2*æ0i+}p         # Doesn't matter    
         ¹Ç       # Push the ASCII values of the input 
           2+     # Increment by 2
             çJ   # Push the chars of the ASCII values, join
               ,q # Print and terminate

Shifted thrice:

¹Ç3+ç1j,~qºÈ3,èK-rKÉ3-éL

Try it online!

Explanation

¹Ç        # Push the ASCII values of the input 
  3+      # Increment by 3
    ç1j   # Push the chars of the ASCII values, join
       ,q # Print and terminate
\$\endgroup\$
6
\$\begingroup\$

Javascript, score: 1 4 (94 346 bytes)

Pretty straight-forward, has different sections commented out when rotated, the difficult bit was finding usable variable names and comment sections that don't break Javascript syntax.

Unrotated:

hc/*% *%nnS/0S eb^[fRR _SbS/0Efd[`Y Xda_5ZSd5aVWS UZSd5aVW3f"#&$'( \a[`RR!! %34hc/*$ifb_jVV$cWfW34Ijh_d]$\hec9^Wh9eZ[W$Y^Wh9eZ[7j&!'&(+,$`e_dVV%%%*89hc/)nkgdo[[)h\k#\89Nomdib)amjh>c\m>j_`###\)^c\m>j_`<o#+$&0$ -01$$$)ejdi[[***/=>/*ch*/hc//chhcchvw*/g¬©¥¢­g¦©avw­«¢§ g«¨¦|¡«|¨aaag¡«|¨z­aibdjrrb^knobbbg£¨¢§

Rotated by 5:

mh4/*%$/*ssX45X%jgc`kWW%dXgX45Jki`e^%]ifd:_Xi:f[\X%Z_Xi:f[\8k' "(+ ),-   %af`eWW &&%*89mh4/)nkgdo[[)h\k#\89Nomdib)amjh>c\m>j_`###\)^c\m>j_`<o#+$&,+$ -01$$$)ejdi[[***/=>mh4.split``.map(a=>String.fromCharCode(((a.charCodeAt(0)+5)%256))).join``///4BC4/hm/4mh44hmmhhm{|/4l±®ª§²l«®f{|²°§¬¥l¤°­«¦°­¢£fffl¡¦°­¢£²fngiowwgcpstgggl¨­§¬

Rotated by 10:

rm94/*)4/xx$]9:]*olhep\\*i]l$]9:Opnejc*bnki?d]n?k`a$$$]*_d]n?k`a=p$,%'-0%!.12%%%*fkej\\%++*/=>rm94.split``.map(a=>String.fromCharCode(((a.charCodeAt(0)+10)%256))).join``///4BCrm93xuqnyee3rfu-fBCXywnsl3kwtrHmfwHtij---f3hmfwHtijFy-5.0:.*7:;...3otnsee4449GH94mr49rm99mrrmmr49q¶³¯¬·££q°¤³k¤·µ¬±ªq©µ²°«¤µ²§¨kkk¤q¦«¤µ²§¨·kslnt||lhuxylllq­²¬±££

Rotated by 14: things finally got interesting here, got to abuse the Javascript type system.

vq=83.-83||(a=>a.split``.map(a=>String.fromCharCode(((a.charCodeAt(0)+14)%256))).join``)//.3ABvq=82wtpmxdd2qet,eABWxvmrk2jvsqGlevGshi,,,e2glevGshiEx,4-/54-)69:---2nsmrdd3338FGvq=7|yur}ii7vjy1jFG\}{rwp7o{xvLqj{Lxmn111j7lqj{LxmnJ}1924>2.;>?2227sxrwii888=KL=8qv8=vq==qvvqqv8=uº·³°»§§u´¨·o¨»¹°µ®u­¹¶´¯¨¹¶«¬ooo¨uª¯¨¹¶«¬»owprxply|}pppu±¶°µ§§

Rotated by 199:

/*öñìçæñì55áö÷ç,)%"-ç&)áö÷-+"' ç+(&ü!+ü(áááç!+ü(ú-áéâäêíâÞëîïâââç#("'âèèçìúû/*öñë0-)&1ë*-åúû1/&+$ë#/,*%/,!"åååë %/,!"þ1åíæèîíæâïòóæææë',&+ìììñÿ/*öð52.+6""ð/#2ê#ÿ64+0)ð(41/*#41&'êêê#ð%*#41&'6êòëí÷ëçô÷øëëëð,1+0""ñññööñ*/ñö/*öö*//**/=>ñö.split``.map(a=>String.fromCharCode(((a.charCodeAt(0)+199)%256))).join``

To find the solutions, I built a small tool to show me different snippets when rotated by a variable amount, I then found certain patterns that I could use as useful building blocks.

The main gist of it is that a/**/=>a is still a valid function definition, which allows you to embed a reverse rotated function in the comment section. From there on, it can be repeated a few times, if done correctly.

Since most of the comment sections are nested, it might be possible to find another result, but making it work becomes increasingly difficult with each added answer due to collisions and control characters.


Replacing all usages of charCodeAt(0) with charCodeAt`` would shave 4 bytes off the whole solution, but it's too much work to do from scratch.

\$\endgroup\$
2
  • \$\begingroup\$ I tried the same approach with a different starting set-up, but it was also capped at 4 points, it seems likely that this approach doesn't yield a higher score. \$\endgroup\$
    – Etheryte
    Mar 16, 2018 at 13:34
  • \$\begingroup\$ Can you at least use charCodeAt() to save 2 bytes? \$\endgroup\$
    – Neil
    Mar 21, 2018 at 12:39
5
\$\begingroup\$

PHP with -d output_buffering=on -d short_open_tag=on, score: 255 (25,731 bytes)

<?die($argv[1]);?>
=@pc`dmfbo)*<ejf)qsfh`sfqmbdf`dbmmcbdl)#0/0#-gvodujpo)%n*|sfuvso!dis)pSe)%n\1^*.2*<~-%bshw\2^**<@?>Aqdaengcp*+=fkg*rtgiatgrncegaecnndcem*$101$.hwpevkqp*&o+}tgvwtp"ejt*qTf*&o]2_+/4+=.&ctix]3_++=A@?Brebfohdq+,>glh+suhjbuhsodfhbfdooedfn+%212%/ixqfwlrq+'p,~uhwxuq#fku+rUg+'p^3`,06,>?/'dujy^4`,,>BA
@Csfcgpier,-?hmi,tvikcvitpegicgeppfego,&323&0jyrgxmsr,(q-vixyvr$glv,sVh,(q_4a-18-??0(evkz_5a--?CBADtgdhqjfs-.@inj-uwjldwjuqfhjdhfqqgfhp-'434'1kzshynts-)r.?wjyzws%hmw-tWi-)r`5b.2:.@?1)fwl{`6b..@DCBEuheirkgt./Ajok.vxkmexkvrgikeigrrhgiq.(545(2l{tizout.*s/?xkz{xt&inx.uXj.*sa6c/3</A?2*gxm|a7c//AEDCFvifjslhu/0Bkpl/wylnfylwshjlfjhssihjr/)656)3m|uj{pvu/+t0?yl{|yu'joy/vYk/+tb7d04>0B?3+hyn}b8d00BFEDGwjgktmiv01Clqm0xzmogzmxtikmgkittjiks0*767*4n}vk|qwv0,u1?zm|}zv(kpz0wZl0,uc8e15@1C?4,izo~c9e11CGFEHxkhlunjw12Dmrn1y{nph{nyujlnhljuukjlt1+878+5o~wl}rxw1-v2?{n}~{w)lq{1x[m1-vd9f26B2D?5-j{pd:f22DHGFIylimvokx23Enso2z|oqi|ozvkmoimkvvlkmu2,989,6pxm~syx2.w3?|o~|x*mr|2y\n2.we:g37;:3E?6.k|q?e;g33EIHGJzmjnwply34Fotp3{}prj}p{wlnpjnlwwmlnv3-:9:-7q?yntzy3/x4?}p?}y+ns}3z]o3/xf;h48<<4F?7/l}r?f<h44FJIHK{nkoxqmz45Gpuq4|~qsk~q|xmoqkomxxnmow4.;:;.8r?zo?u{z40y5?~q??~z,ot~4{^p40yg<i59=>5G?80m~s?g=i55GKJIL|olpyrn{56Hqvr5}rtlr}ynprlpnyyonpx5/<;</9s?{p?v|{51z6?r??{-pu5|_q51zh=j6:>@6H?91nt?h>j66HLKJM}pmqzso|67Irws6~?sum?s~zoqsmqozzpoqy60=<=0:t?|q?w}|62{7??s???|.qv?6}`r62{i>k7;?A;?7I?:2o?u?i?k77IMLKN~qnr{tp}78Jsxt7?tvn?t{prtnrp{{qprz71>=>1;u?}r?x~}73|8??t???}/rw?7~as73|j?l8<@D8J?;3p?v?j@l88JNMLOros|uq~89Ktyu8??uwo?u?|qsuosq||rqs{82?>?2<v?~s?y~84}9??u???~0sx?8bt84}k@m9=AF9K?<4q?w?kAm99KONMP?spt}vr9:Luzv9??vxp?v?}rtvptr}}srt|93@?@3=w?t?z?95~:??v???1ty?9?cu95~lAn:>BH:L?=5r?x?lBn::LPO
...

Similar to the Haskell solution, copying and pasting this breaks, so I generated this using this Perl script.

Verification for shifted 1, 16, 32 and 255 times.

Explanation

Using PHP's <? delimiter made this fairly easy, but I had to avoid any strings that could end up as <? elsewhere in the code, this basically means 03, 14, 25, 36, 47, 58 and 69. Working around those was fairly easy using arithmetic. It might well be possible to reduce the byte count in the original program too.

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

Crane-Flak, Score 3 (252 bytes)

%&'()%&%X'Z&xx\()'()z%xz|%&'()%&'()%&'()9;=&'()9;=%XZ\&'z|%&'(9;=(9;=%&'XZ\(|xz|9;=%&'%&(%X'Z&\('()xxz%xz|9;=&'()9;=%XZ\&'z|9;=(9;=%&'XZ\(|9;=)))))))%&Y[]'()yy{}%&y{}%&'()%&'():<>'():<>%&Y[]'(){}y{}:<>%&Y[]'()yy{}::<><>:<>%&y{}:<>'():<>%&Y[]'(){}::<><>

Try it online!

(Doesn't quite work in Brain-Hack because only Crane-Flak mods by 256)

Shifted by 1

&'()*&'&Y(['yy])*()*{&y{}&'()*&'()*&'()*:<>'()*:<>&Y[]'({}&'():<>):<>&'(Y[])}y{}:<>&'(&')&Y(['])()*yy{&y{}:<>'()*:<>&Y[]'({}:<>):<>&'(Y[])}:<>*******&'Z\^()*zz|~&'z|~&'()*&'()*;=?()*;=?&'Z\^()*|~z|~;=?&'Z\^()*zz|~;;=?=?;=?&'z|~;=?()*;=?&'Z\^()*|~;;=?=?

Try it online!

Shifted by 2

'()*+'('Z)\(zz^*+)*+|'z|~'()*+'()*+'()*+;=?()*+;=?'Z\^()|~'()*;=?*;=?'()Z\^*~z|~;=?'()'(*'Z)\(^*)*+zz|'z|~;=?()*+;=?'Z\^()|~;=?*;=?'()Z\^*~;=?+++++++'([]_)*+{{}'({}'()*+'()*+<>@)*+<>@'([]_)*+}{}<>@'([]_)*+{{}<<>@>@<>@'({}<>@)*+<>@'([]_)*+}<<>@>@

Try it online!

Shifted by 3

()*+,()([*]){{_+,*+,}({}()*+,()*+,()*+,<>@)*+,<>@([]_)*}()*+<>@+<>@()*[]_+{}<>@()*()+([*])_+*+,{{}({}<>@)*+,<>@([]_)*}<>@+<>@()*[]_+<>@,,,,,,,()\^`*+,||~€()|~€()*+,()*+,=?A*+,=?A()\^`*+,~€|~€=?A()\^`*+,||~€==?A?A=?A()|~€=?A*+,=?A()\^`*+,~€==?A?A

Try it online!

Explanation

The main code at work here is

([]){{}({}n<>)<>([])}{}<>([]){{}({}<>)<>([])}<>

where n is an arbitrary number. This moves everything to the offstack adding n to each item (modulo 256 is implicit upon output), and then moves them all back.

However for the first program (i.e. shifted by 0) we don't need to do any of this because shifting by zero is the cat program. So we start with this code:

([]){{}({}()<>)<>([])}{}<>([]){{}({}<>)<>([])}<>

and shift it down by 1

'Z\(zz|'z|m;=(;='Z\(|z|;='Z\(zz|'z|;=(;='Z\(|;=

This is unbalanced so we have to fix it. There are a number of ways we could do this by my choice method (for reasons that will become apparent) is the following:

'Z\(zz|'z|m;=(;='Z\(|z|;='Z\(zz|'z|;=(;='Z\(|;=)))))){}{}{}{}{}

Shifting this up by 2 we get

)\^*||~)|~o=?*=?)\^*~|~=?)\^*||~)|~=?*=?)\^*~=?++++++}}}}}

Since () is easier to deal with than {} we will use the }s to complete the program we desire. That means that the ) can be balanced with pretty obvious means. With some fiddling we can turn that into:

()\^*||~()|~()*=?*=?()\^*~|~=?()\^*||~()|~=?*=?()\^*~=?+++++++([]_)*+{{}({}()*+()*+<>@)*+<>@([]_)*+}{}<>@([]_)*+{{}<<>@>@<>@({}<>@)*+<>@([]_)*+}<<>@>@

Shifting that back down we get

&'Z\(zz|&'z|&'(;=(;=&'Z\(|z|;=&'Z\(zz|&'z|;=(;=&'Z\(|;=)))))))&Y[]'()yy{}&y{}&'()&'():<>'():<>&Y[]'(){}y{}:<>&Y[]'()yy{}::<><>:<>&y{}:<>'():<>&Y[]'(){}::<><>

The step up to 3 is so complex I don't really understand it any more. I used the same technique and just fiddled around with it until I finally got all 4 of them to work at once. The technique is pretty much the same there is just a lot more fiddling.

\$\endgroup\$
3
\$\begingroup\$

Python 3, Score 1, 76 bytes

Shift 0: no change

""!="";print(input());exit()#   oqhms'&&-inhm'bgq'nqc'i(*0(enq'i(hm'hmots'((((

Shift 1:

##">##<qsjou)joqvu)**<fyju)*$
print(''.join(chr(ord(j)+1)for(j)in(input())))

Started work on shift 2, but "" becomes $$ and you can't start a line with that.

When you save it to a file, make sure it doesn't end with a newline. (vim -b file.py + set noeol)

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

Jelly, score 1 2

8 15 bytes

Shift 0:

M««Ṃ¬ịị¶Ɓ|L(0Ḷṇ

Try it online!

Shift 2:

O‘‘Ọµḷḷ¹Ɗ~N*2Ṇṛ

Try 2 online!

Shift 3:

P’’Ṛ½ṃṃ²Ƒ¶O+3Ọṣ

Try 3 online!

\$\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.