33
\$\begingroup\$

Robber's thread

Your task as cops is to select three things:

  • A programming language

  • An OEIS sequence

  • A byte set

You are then to secretly write a program in that language that computes the nth term sequence using only the bytes in the set. You will reveal the three pieces of information so that robbers can try to figure out the program.

Answers will be scored by the number of bytes in the byte set with more score being good. Cracked answers have an automatic score of 0. If your answer is uncracked after one week you may reveal the intended program and mark your answer as "safe".

Answers must be capable of calculating every term in the b-files of the sequence, but are not required to calculate any terms after.

Sequences can be either 1 or 0 indexed for both cops and robbers.

Here is a Python Script that checks if your code matches the given byte set.

\$\endgroup\$
  • 1
    \$\begingroup\$ Lower score is better? Or higher? So in essence we're trying to find a restricted character set that makes it difficult for someone else to make a program in the chosen language, after we've already worked out a solution? \$\endgroup\$ – BradC Jul 27 '17 at 16:56
  • 1
    \$\begingroup\$ Do we need to use all the bytes in our set? I would guess yes but it should probably be specified in the challenge. \$\endgroup\$ – Shaggy Jul 27 '17 at 17:06
  • 1
    \$\begingroup\$ @Shaggy generally no, you can includes others for red herrings, but robbers can use everything \$\endgroup\$ – Stephen Jul 27 '17 at 17:08
  • 1
    \$\begingroup\$ Can robbers use the same byte twice or more? \$\endgroup\$ – Mr. Xcoder Jul 27 '17 at 17:19
  • 2
    \$\begingroup\$ @Azulflame The b-files are files that are associated with each sequence the can be accessed by replacing the A with a b and appending a .txt. For example oeis.org/b4.txt would access the b-files for that sequence. \$\endgroup\$ – Sriotchilism O'Zaic Jul 27 '17 at 23:47

69 Answers 69

11
\$\begingroup\$

Haskell, A209229, (cracked)

11 characters (including newline):

s<=[ ]
how!

Outputs True/False as an indicator function for powers of 2:

1 => True
2 => True
3 => False
4 => True
5 => False
6 => False
7 => False
8 => True
9 => False
...

Inputs are positive integers.

\$\endgroup\$
  • \$\begingroup\$ Does 0 give False? \$\endgroup\$ – H.PWiz Jul 27 '17 at 21:33
  • \$\begingroup\$ @H.PWiz My code doesn't work for 0, your crack can do whatever you want for it. \$\endgroup\$ – xnor Jul 27 '17 at 21:35
  • \$\begingroup\$ Cracked! Very clever~ \$\endgroup\$ – Lynn Jul 27 '17 at 22:00
  • \$\begingroup\$ @Lynn Nicely done! \$\endgroup\$ – xnor Jul 27 '17 at 22:16
5
\$\begingroup\$

Python 2, A000045 (Cracked)

ml:= input(as,forge)

it contains a whitespace and a newline
Try it Online!
Intended solution

\$\endgroup\$
  • 1
    \$\begingroup\$ +1 I am surprised this doesn't use + at all \$\endgroup\$ – Mr. Xcoder Jul 27 '17 at 17:49
  • 2
    \$\begingroup\$ Congrats on 10k btw :) \$\endgroup\$ – Adnan Jul 27 '17 at 17:55
  • \$\begingroup\$ Cracked \$\endgroup\$ – Adnan Jul 27 '17 at 18:05
  • \$\begingroup\$ @Mr.Xcoder Don't know python that well, but would plus work? \$\endgroup\$ – JAD Jul 27 '17 at 18:10
  • \$\begingroup\$ @JarkoDubbeldam No, sum would \$\endgroup\$ – Mr. Xcoder Jul 27 '17 at 18:11
5
\$\begingroup\$

Haskell, A000045 (cracked)

I made up my mind, I think I like t more than s.

So let's use these 30 bytes (including newline) instead:

abcdeFgh|jklmnopqrtTuvwxyz
=()

Please note that the general challenge description demands that

Answers must be capable of calculating every term in the b-files of the sequence [...].

In this case, the b-file goes up to the 2000th number, which is way beyond what can be computed using Int.

\$\endgroup\$
  • \$\begingroup\$ Cracked! \$\endgroup\$ – Lynn Jul 28 '17 at 13:28
  • \$\begingroup\$ Cracked \$\endgroup\$ – H.PWiz Jul 28 '17 at 15:15
4
\$\begingroup\$

Octave, A000290, Cracked!

The sequence is the square numbers: 0, 1, 4, 9, 16, 25, 36, 49 ... (so that you don't have to check the link).

'()/@^_
\$\endgroup\$
  • \$\begingroup\$ Cracked! \$\endgroup\$ – Conor O'Brien Jul 27 '17 at 19:14
  • \$\begingroup\$ That was indeed the intended solution :) \$\endgroup\$ – Stewie Griffin Jul 27 '17 at 22:08
4
\$\begingroup\$

Haskell, A000045 (Cracked)

Everyone likes Fibonacci numbers, I like Haskell...

I have carefully selected 30 bytes for you: the lowercase letters except f, i and t, you get the uppercase letters F and T and the pipe symbol | instead, and the three symbols =(), and newline. Here they are again:

abcdeFgh|jklmnopqrsTuvwxyz
=()
\$\endgroup\$
  • \$\begingroup\$ Cracked \$\endgroup\$ – xnor Jul 27 '17 at 22:17
4
\$\begingroup\$

Haskell, A034262, 43 bytes, cracked

!"#%',.=?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_{|}~

Computes a(n) = n³ + n.

\$\endgroup\$
  • \$\begingroup\$ Can't get the b-file now. Is returning an Int good enough? \$\endgroup\$ – Christian Sievers Jul 28 '17 at 9:28
  • 1
    \$\begingroup\$ Cracked? \$\endgroup\$ – Christian Sievers Jul 28 '17 at 9:42
  • \$\begingroup\$ @ChristianSievers Yes, that's exactly my solution. \$\endgroup\$ – Laikoni Jul 28 '17 at 10:21
4
\$\begingroup\$

Haskell, A009056 (cracked)

Another simple one, now again with enough letters to make it look like ordinary Haskell and maybe for you to amaze me by finding a solution completely different from mine.

The sequence is Numbers >=3 and the charset consists of these 30 bytes:

{[abcdefghijklmnopqr uvwxyz]}.

The crack has some nice techniques. I was just thinking of this:

head . flip drop [ floor pi .. ]

\$\endgroup\$
  • 1
    \$\begingroup\$ Cracked. \$\endgroup\$ – nimi Aug 5 '17 at 19:24
3
\$\begingroup\$

C (C99), A000005, 25 Bytes#, Cracked!

These are the bytes for a full problem, takes n as a command line argument and outputs answer to stdout.(Space is included in bytecount).

<=>,;!"()*%+acdfhimnoprt 
\$\endgroup\$
  • \$\begingroup\$ ok I was wondering lol. as a command line argument? \$\endgroup\$ – Conor O'Brien Jul 27 '17 at 19:25
  • \$\begingroup\$ Yes, I'll make that clearer \$\endgroup\$ – dj0wns Jul 27 '17 at 19:27
  • 1
    \$\begingroup\$ Cracked! this was fun :D \$\endgroup\$ – Conor O'Brien Jul 27 '17 at 19:40
3
\$\begingroup\$

Unary, A002275, 1 Byte

Byte set:

0

I had to at least try it :3

(I don't think it will be particularly hard seeing as every command in the language is available)

\$\endgroup\$
  • 1
    \$\begingroup\$ Why not include all of the bytes to maximize your score? You have scored the lowest amount possible, when it would make no difference to include all of the bytes. \$\endgroup\$ – Sriotchilism O'Zaic Jul 27 '17 at 19:52
  • \$\begingroup\$ I thought we were going for a low score (sorry, I'm new here). \$\endgroup\$ – sonar235 Jul 27 '17 at 19:59
  • 1
    \$\begingroup\$ Cracked \$\endgroup\$ – Blue Jul 27 '17 at 20:04
  • \$\begingroup\$ @muddyfish Is input as a character allowed for brainfuck? \$\endgroup\$ – sonar235 Jul 27 '17 at 20:06
  • \$\begingroup\$ @sonar235 In general we do allow input as character for brainfuck. Although since values here exceed 255, I don't think an answer that uses them can be valid. \$\endgroup\$ – Sriotchilism O'Zaic Jul 27 '17 at 20:07
3
\$\begingroup\$

Perl 5, A000030 (Cracked)

Byte set:

imnprt7 $;()<>=~.

Try it online!

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

JavaScript (ES6), 17 bytes, A000290 (Cracked)

Again, this is the simple square sequence a(n) = n2.

Byte set:

$()=>CI`abelotv{}
\$\endgroup\$
  • \$\begingroup\$ Cracked! \$\endgroup\$ – LarsW Jul 27 '17 at 22:33
3
\$\begingroup\$

Hexagony, A057077, 77 bytes

Periodic sequence 1, 1, -1, -1. As a list:

a(0) = 1
a(1) = 1
a(2) = -1
a(3) = -1
a(4) = 1
a(5) = 1
a(6) = -1
   ...

Character set (edited), which includes a newline and a space character:

!%&(),0123456789;?@ABCDEFGHIJKLMOPQRSTUVWXYZ^abcdefghijklmnopqrstuvwxyz[]#. 

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Any reason you modified the character set? \$\endgroup\$ – Poke Jul 28 '17 at 0:49
  • 1
    \$\begingroup\$ @Poke apparently the higher the byte count the better, so I just added a bunch of non-useful commands. \$\endgroup\$ – Adnan Jul 28 '17 at 0:53
3
\$\begingroup\$

Haskell, A000045 (cracked)

It's cracked, and I won't start a new version, but if you want to play more: it's possible without y, and it's possible to be efficient.


I apologize for leading you in wrong directions by giving a g. Let's do the same without!

Here are the 29 remaining bytes (including newline):

abcdeFh|jklmnopqrtTuvwxyz
=()

Again, remember that Int won't be enough to compute the 2000th Fibonacci number which is needed because it is in the b-file.

\$\endgroup\$
  • \$\begingroup\$ Cracked \$\endgroup\$ – nimi Jul 29 '17 at 13:01
3
\$\begingroup\$

Haskell, A000045 (cracked)

This is kindof (as announced) not a new version, but completely different. (Right?)

I still hope I can make you rediscover my nice little observation.

This time you are asked to implement the Fibonacci sequence using a charset of size 17, which (as far as I know) contains only one two unneeded chars:

eilnt=(,).[ ]_:0!

Note that there is no newline (but feel free to show a version which has them for readability) and remember that you have to be able to compute the 2000th Fibonacci number.

\$\endgroup\$
  • \$\begingroup\$ Cracked. \$\endgroup\$ – nimi Jul 30 '17 at 15:12
3
\$\begingroup\$

Cubix, A000027 (SAFE) 17 points

!&')-/0;@Oiru.NSQ

My solution:

!O!;i)!/u&!!r-)0'u;;!@

watch it online here

I originally did this without .NSQ but I figured I could add them safely.

Explanation:

This sequence is just "The Positive Integers". However, Cubix has three input commands, i, which reads in a single char (pushing -1 if input is empty), A, which reads in the rest of the input as chars (pushing a -1 to the bettom of the stack), and I, which reads the next number off the input (pushing 0 if there isn't a match). So naturally, I only provided i which reads in digits as their ascii value. uh-oh. Additionally, -1 is the usual marker for end of input, in conjunction with ? so I got rid of ?, forcing me to use ! (skip next instruction if TOS is not zero) for control flow. Finally, I thought I needed & to concatenate digits for printing with O (which outputs the top of stack as a number), but I realize now that that wasn't necessary either!

Another part of the challenge was originally to not have . the no-op character, but you can use pairs of ! instead if you're careful:

    ! O
    ! ;
i ) ! / u & ! !
r - ) 0 ' u ; ;
    ! @
    . .

i) : read input, increment.

!/ : if top of stack is zero (end of input), turn left

left: ;O.@ : pop top of stack, output as number, halt.

otherwise:

u'0: push char code of 0 to top of stack

)-r: increment, subtract, and rotate

;; : pop top of stack twice

u& : concatenate digits

!! : net zero effect, now we are at i) again.

\$\endgroup\$
  • \$\begingroup\$ Cubix has some noop characters right? Why don't you add those to increase your score? Or is part of the challenge that there are no noops. \$\endgroup\$ – Sriotchilism O'Zaic Jul 27 '17 at 20:34
  • \$\begingroup\$ @WheatWizard I decided to be merciful and add . but it can be done without it. \$\endgroup\$ – Giuseppe Jul 27 '17 at 21:23
3
\$\begingroup\$

Seed, A005408 (Odd Numbers) - Safe

Here's a slightly more challenging one. You may use any characters valid in Seed:

[0-9 ]

You shouldn't be able to brute force this one in a week unless you have a monster of a computer. Good luck! It's crackable.

Hint

This is the Befunge-98 program used in my solution: 9&2*1-.@ (the 9 can be removed, but my solution just happens to have

Solution

8 47142938850356537668025719950342285215695875470457212766920093958965599014291682211474803930206233718243166021324700185443274842742744297183042397910454208210130742260519105651032450664856693714718759816232968955289663444878636053035645231246428917992493766505872029989544065894418166685284738859999912471659057565000392419689361271972485444731284404987238803115210428572945108908191097214978382112218242627719651728712577306652405452922782307249485947045215982784790396555726144526602778473387279897334709142853151393812930171163300904436548870603006549005515709074682843356844201220668045057407146751793470423217099467145255174198241606814578351260769359571053755888106818197239116973006365593563235361647743411341624822052103816968153274122434280200888824954875622811325064255818154979564925710534165572852442761249176778416688044630942040966271963723430245979221181930857841829694362184653939393940015797332978459794253176110314873994228261888801228999293570329618551223457182420746927212801550646743152754821640064626761542582557138452651970009253770914346130172884305622027370793496993281847017017643506435562229916984107083951938286577012273222191422054315198157936674247934699496471202544270325061352014830137178245082445717253260177560449757186762445707057028987371278573629077370632470496186218574320801798046510846708620502139560277546345198686675095078255875594169064796673074708822106659920187882062247609587560174781170641367430722951002242213604709887062481149928551745163110045572994991844223216663621203042075294195007458339984527333125093390189721042315604498435269143549420166732177200370228527273606218617171975362431824163269672003982537382982066136613799403024924018145511099557720492305303748099327810811511080314262364010281851651151072957475365629128068033597559560186625877942054704386175359499573139930378099420149452745731809033737756051947913924265484582800618244473333957173960222243311738522875022546610298627492222587971756897328087719407454153248557203886421828643453889090192355970705084245312184441674098515659253482621260617211786550204852895652236768886852209506535523414991099331857674826373947830587028494510697603296607361093480842935154672353288419699354739650168309017848485131553416956405911683526896232046773861961911767319373432460217755874481607587604361758089936007730253450733375831228127106295259261723611771334468553746160739548375950046831923765023329346333968732796413192682936767133122325481273354810124729664400173367781325488656859581438769940474229394692089519981810909719628263357284973442177568041416363386891516725592952892168077523560584005586276794967492051823290615767599202657060820223928678900774601616908031321346819422162123048834532926372862962159255934240435694566497798544870186550219886342379298214007368081326725550763589917206162393892085506551547475259270513853987294911388226039365971184089828739349642347312302559286882065147953715607221387657413593069535573044067517274676745306396611760657091792151803798859781616126637075577936361782593546481811651450365118155866449850474140044293772144065341051900055416408240857348697564252386403719942197789892382627153382011984996644288495699209129097948405810551134169739499539470610790009272281731894550593600643079188663110695127017324336488487580799309995227054576681630676222848231145106058050452439356753552872060820230589152143268436210090733908507724084889788244157692417246691477400856716677564609725979550100138132944851304473466485128295568194188600539248624248078558656162635444219199062786468487219220160009464328883337821175254405764395407405891483810757405446047244460754827113527540703326714751461178900155717130399854358953609995319006890674085682111514072508440632941090209366005504352890092326935445829213294943731517698438648298921337375443947066950275955144209037675013663600062205168551851984361951824731229113379464426979717688372371011461890139087487634586087688796134318950140718824105959727161482389914414206768064990410615468858520426399188835467970981786227122743162945627167772066100574532803061925537235491026486409948728571706557098859331941260622260924660292578136091523126589085799981416326395824628987154802653126685882440760385315869346960183809644486238810912663304360284449610976505715001267334297285036791711464142665122000857666018757370925847113798258537503747803972255591351740843663253694303946089997282812556281486820325652814785261116697261899511762129550421005941055852897451832731304151488058522478260009347144486599715629242208891126238083949281490804191584238425634093683587199278186505945727829025071885767559828670803412582690901456978557379916793144695491189633486065077294485660840922713748873840986104486221528464294334436081663106336911265802650605150347413103936140565054608396116572669757269475369570465915381045895991937087068526458273755454602799814909213983801968791431574508976448235055061998715636460946550584682626461010298101802277643570201189324102499951196290880892383380284543173390448406975616650185808619832614403133944687275834716343817926764699295672501869876060896683204343897481630037607159476461359111190545646447421653872016775582115425356868533678655969328210255235050133718364831289991244684695035034122861927276046255405376531096051541299607470934463981741370397268760811035606321455156217990078359217247117349544774085111287345436916077577032709684005131011429476229617901273007027774182864475737502587896225475248267937497254066190335088823904767397814233350286976811901982274477445433872253983823904938249655089770642137858608313524715533520654523880832056453080193644871440738737277389718589793074725139142291918837706550037934799585495183374639955887618135803388399608755212147742199481865453122900714456703147150994585431640652462593333773031385396586933380738103697887063571042512186708015948688088011290197524699274772775288900864690592106393483764109837848793374117655194139018455509931621247697015323332300969105814058088442693320033876473960017819576425062784644138417943454576404265382986995583045527928832
\$\endgroup\$
  • \$\begingroup\$ How did you generate this? \$\endgroup\$ – Christopher Aug 6 '17 at 23:58
  • \$\begingroup\$ @2EZ4RTZ Painfully, and with Python's source as a reference. It can probably be golfed a lot though. \$\endgroup\$ – TehPers Aug 7 '17 at 4:31
2
\$\begingroup\$

Python 2, A000045 (Cracked)

l:= input(a,forge)[]

it contains a whitespace and a newline
Try it Online!
Intended solution

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

R, A000142, (Cracked)

Byte set:

-()*,`=cfinotu

Intended solution:

f=function(n,c=n==n)'if'(n,f(n-(n==n),c*n),c*(n==n))

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

cQuents, A000027, Cracked


 !"#%&'()*+,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

That's right! You get all of ASCII! Wait... there's no $... what's $ again in cQuents? Oh, yeah, the index builtin. Well, tough luck :/

Intended Solution:

#|A:A

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Cracked? \$\endgroup\$ – Adnan Jul 27 '17 at 18:56
  • \$\begingroup\$ @Adnan yup that works, I guess I shouldn't have opened it up as much as I did :P I couldn't think of any different ways to do it, good job. Added intended solution. \$\endgroup\$ – Stephen Jul 27 '17 at 18:57
2
\$\begingroup\$

CJam, A000042, cracked by Lynn

Byte set:

{})_%si
\$\endgroup\$
  • 1
    \$\begingroup\$ Cracked! Cute~ \$\endgroup\$ – Lynn Jul 27 '17 at 21:04
2
\$\begingroup\$

Ruby, A000004, 5 bytes, Cracked

Just messing around to start off. Should be easy for anyone familiar with Ruby. It's a low score, but whatever.

/np.$

Cracked, unintended exploit

Cracked (intended answer using n flag)

\$\endgroup\$
  • \$\begingroup\$ Cracked? \$\endgroup\$ – Adnan Jul 27 '17 at 20:42
  • \$\begingroup\$ @Adnan Eh, I'll accept it. Should've required the n flag (which is the reason it's in the byte sequence, and would make $. equal 1) \$\endgroup\$ – Value Ink Jul 27 '17 at 20:45
  • \$\begingroup\$ Think I have your intended solution \$\endgroup\$ – histocrat Jul 27 '17 at 21:59
2
\$\begingroup\$

Python 3, A007504 (Cracked)

This byteset, including newline:

bfuwo)nm1h[=(t+;0a
sig%pr, le:]

My code does not provide infinite output, but can compute the entire b-list.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Zacharý Jul 28 '17 at 0:03
  • 1
    \$\begingroup\$ Cracked \$\endgroup\$ – Jonathan Allan Jul 28 '17 at 1:15
  • 1
    \$\begingroup\$ Scrap that I used a . :( \$\endgroup\$ – Jonathan Allan Jul 28 '17 at 1:21
  • 1
    \$\begingroup\$ I've fixed the crack. \$\endgroup\$ – Jonathan Allan Jul 28 '17 at 1:32
  • 1
    \$\begingroup\$ ...and migrated to Python 3. \$\endgroup\$ – Jonathan Allan Jul 28 '17 at 1:39
2
\$\begingroup\$

R, A000290, (cracked)

Byte set:

()%cfinotu
\$\endgroup\$
  • \$\begingroup\$ no c, but everything else for function? That's horrifying. I know how to do this except for reading in input... \$\endgroup\$ – Giuseppe Jul 27 '17 at 19:52
  • \$\begingroup\$ @Giuseppe woops, the a shouldve been a c. sorry. \$\endgroup\$ – JAD Jul 27 '17 at 19:53
  • 1
    \$\begingroup\$ This is what I get for doing this shit manually... \$\endgroup\$ – JAD Jul 27 '17 at 19:53
  • \$\begingroup\$ No worries; this is tough enough! \$\endgroup\$ – Giuseppe Jul 27 '17 at 19:54
  • \$\begingroup\$ cracked \$\endgroup\$ – Giuseppe Jul 27 '17 at 19:56
2
\$\begingroup\$

Snowman, 212 bytes, A000042

#$%&*01:;=?@CEFGHIJLMOQUVXYZbcdefghijlmnopqsuvxyz~

... plus space, 0x00-0x1f inclusive, and 0x7f-0xff inclusive.

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

cQuents, A000217, Cracked

Byteset:

$:=1;
\-

Note that this uses a feature that I haven't pushed the documentation for yet, so I'll push that tonight, if you wait until then. (Or you can slop through my source code... have fun). Documentation pushed. Would be a byte less if a recent bugfix was on TIO.

Intended solution:

=1-1:--\1$ ;$

Try It Online!

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

JavaScript (ES6), 13 10 bytes, A000045, Cracked

This should be easy.

This is the Fibonacci sequence: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.

Byte set:

$()-:<=>?[]_~

Edit:

It can be even done with the following 10 bytes:

$()-:=>?_~
\$\endgroup\$
  • \$\begingroup\$ Cracked! \$\endgroup\$ – Cows quack Jul 28 '17 at 10:55
  • 1
    \$\begingroup\$ This isn't [code-golf]: "Answers will be scored by the number of bytes in the byte set with score being good." More bytes are better. \$\endgroup\$ – LarsW Jul 28 '17 at 12:55
  • \$\begingroup\$ @LarsW on the other hand, more bytes also makes it easier to crack :) \$\endgroup\$ – JAD Jul 28 '17 at 13:48
2
\$\begingroup\$

R, A105311, (Cracked)

Byte set:

'%(),:=acdegilnopstx
\$\endgroup\$
2
\$\begingroup\$

Python3, A008615, Cracked

Bytemap (with newline):

n)ir=-
(u0*pt
\$\endgroup\$
  • \$\begingroup\$ Cracked \$\endgroup\$ – xnor Jul 28 '17 at 6:45
2
\$\begingroup\$

Befunge, A000142, 29 Bytes, (Cracked)

Byte Set: @.$_ ^*:\v>-1&

If you can't tell, that Byte set includes a space.

This should be moderately easy to solve.

Edit: Forgot the "A" before the OEIS

\$\endgroup\$
  • \$\begingroup\$ Cracked \$\endgroup\$ – KSmarts Jul 28 '17 at 16:06
2
\$\begingroup\$

R, A105311, (cracked)

'%(),:=acdeginpstx

Let's try this without the l or o.

Since this has been cracked, the intended solution:

cat(diag(diag((a=scan()))%x%diag((a==a):a)),sep=''). diag is an interesting function, that can be used in three different ways. When presented with a single integer (diag(n)), it creates a NxN matrix with 1 on the diagonal. When presented with a vector (diag(1:n)), it creates an NxN matrix with the vector on the diagonal. When presented with a matrix (diag(diag(n))), it returns the diagonal as a vector. %x% computed the Kronecker product of two matrices, where each element in matrix 1 is multiplied with each element in matrix 2 separately. Doing this with a length n identity matrix and a 1:n diagonal matrix, creates a length n^2 diagonal matrix with 1:n repeated n times. diag extracts that again, and cat prints.

\$\endgroup\$
  • 1
    \$\begingroup\$ this'll be even more fun :) \$\endgroup\$ – Giuseppe Jul 28 '17 at 13:17
  • \$\begingroup\$ does this include a newline? \$\endgroup\$ – Giuseppe Jul 28 '17 at 13:57
  • \$\begingroup\$ @Giuseppe No newlines \$\endgroup\$ – JAD Jul 28 '17 at 13:59
  • 1
    \$\begingroup\$ @Giuseppe and I just double double checked, this byteset is correct \$\endgroup\$ – JAD Jul 28 '17 at 13:59
  • \$\begingroup\$ [cracked! ](codegolf.stackexchange.com/a/136457/67312) -- I (incorrectly) used %o% before I realized that %x% existed. I guess I could have done 'i'=='i' for 1 but either way works, so. \$\endgroup\$ – Giuseppe Jul 28 '17 at 17:04

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.