5
\$\begingroup\$

We all already crossed the look and say sequence, and where asked to guess the next element. As its name tells it very well, you just have to say what you see :

1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
3 1 2 2 1 1
...

But, what if we had to use a different base to describe it? You could count it in base 3 as this OEIS squence do. You could even do it in whatever base you want! That will be your job in this challenge.

Goal

Your have to write a program or a function that will accept two integers as input, either by STDIN or as function arguments. The first one will be the base b you have to work in, the second one will be the number n of elements to output. As this sequence never changes for b>=4, you will assume 0<b<5.

The only restriction you have is to NOT use any base-converison built-in :).

The original sequence (in base 10) is the sequence A005150. It cannot be constructed simply by using a formula, so you can help yourself with the different implementations present on the sequence's page.

Sample output

Here are the first 10 elements for each b

for b=1:
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111

for b=2:
1
11
101
111011
11110101
100110111011
111001011011110101
111100111010110100110111011
100110011110111010110111001011011110101
1110010110010011011110111010110111100111010110100110111011

for b=3:
1
11
21
1211
111221
1012211
1110112221
101102110211
111021101221101221
1011012211011222110112211

for b=4:
1
11
21
1211
111221
312211
13112211
1113212221
311312113211
132113111221131221

You can use whatever formating you want as long it is readable (so you could output it in Python-like lists, separated by commas/newline...).

This is code-golf, so the shortest code in byte wins. Have fun !

\$\endgroup\$
  • 1
    \$\begingroup\$ for obvious reason ... it's your choice, but it's not obvious to me how this restriction improves the challenge \$\endgroup\$ – Luis Mendo Jan 19 '16 at 13:06
  • \$\begingroup\$ @LuisMendo The base-conversion is a core part of this challenge (which remain pretty simple in facts), allowing conversion built-ins would break that. I will cut out that sentence if you think it's false, but I assume they have no reason to be allowed. \$\endgroup\$ – Katenkyo Jan 19 '16 at 13:12
  • \$\begingroup\$ It was just an idea. The challenge should be how you want it to be \$\endgroup\$ – Luis Mendo Jan 19 '16 at 13:21
  • \$\begingroup\$ Well, you have to describe the sequence. \$\endgroup\$ – Akangka Jan 19 '16 at 13:43
  • \$\begingroup\$ @LuisMendo I will let this challenge as it is, I was only speaking about cutting off the sentence "for obvious reason" \$\endgroup\$ – Katenkyo Jan 19 '16 at 13:58
1
\$\begingroup\$

Pyth, 34 bytes

L?gbQ+y/bQ%bQ]bjms`Md.usyMsrN8tE]1

Try it online!

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