Good Old Suffix Vector

17

4

Inspired by an old manual...

The challenge

I define the ath suffix vector of b as the boolean list of length a with b trailing truthy values.

Write a program or function that, given a and b by any means, returns the ath suffix vector of b by any means.

Now this may seem trivial, but here is the catch: Your score is the byte count plus the earliest year your solution would have worked.

Rules

All standard rules apply, except that languages and language versions that were released after this challenge, may also be used.

Output using whatever representation of boolean values that your language uses, e.g. 1/0, True/False, TRUE/FALSE, "True"/"False", etc.

Output using whatever representation of lists that your language uses, e.g. 0 0 1, [False,False,True], (FALSE;FALSE;TRUE), {"False","False","True"}, etc.

You may assume that ab is always true and that they are of an appropriate data type.

Test cases

Given a = 7 and b = 3, return 0 0 0 0 1 1 1

Given a = 4 and b = 4, return [True,True,True,True]

Given a = 2 and b = 0, return (FALSE;FALSE)

Given a = 0 and b = 0, return {}

Example solution and scoring

I might want to submit the solution {⌽⍺↑⍵⍴1} using Dyalog APL. That would be a bytecount of 8. This is a dynamic function, which works from version 8.1 of Dyalog APL, released in 1998, so my total score is 2006. My submitted answer should look something like:

# Dyalog APL 8.1, 1998 + 8 = 2006
    {⌽⍺↑⍵⍴1}

Optional explanation...
Recommended: Link to documentation showing when the features you used were released.

Lowest score wins!

Adám

Posted 2016-03-10T14:31:21.380

Reputation: 37 779

14I'm deeply concerned about the verifiability of the answers. – Dennis – 2016-03-10T15:33:06.457

@Dennis Same. For example I am fairly confident that my answer would have worked on the first Prolog interpreters but I actually can't easily check it. – Fatalize – 2016-03-10T15:35:44.053

1@Dennis I understand you concern. However, 1) the answers will mostly be very simple, and thus could be verified by hand – not requiring an actual running system, and 2) some users have taken to linking to documentation of their claim. – Adám – 2016-03-10T15:36:06.480

8I'm not so sure "verified by hand" is necessarily going to work for some answers - the past is a foreign place, and sometimes initial versions of things can lack things that feels commonplace today... – Sp3000 – 2016-03-10T15:55:16.500

1@Sp3000 Maybe, but this is all for fun anyway, and with 8 answers and 9 upvotes in 1.5h, I think this challenge is fun enough accept that someone might cheat. Maybe some extra research on the eventual winner... – Adám – 2016-03-10T16:03:47.480

@Nᴮᶻ If a release is dated on 31 December, that may be interpreted as the following year depending on locale (see drolex's comment to my answer). Can Github date be used as the official date (whatever locale the Github server is using)? Should I add 1 to the score just in case? – Luis Mendo – 2016-03-10T17:01:14.770

SMP, 1983+94=2077:{[0]:{[0]:{},[2]:"(FALSE;FALSE)"},[3]:{[7]:"0 0 0 0 1 1 1"},[4]:{[4]:"[True,True,True,True]"}} Moral of the story: don't mix output formats. – CalculatorFeline – 2016-03-10T17:10:42.170

@CatsAreFluffy What? – Adám – 2016-03-10T17:14:12.443

I'd suggest using one array format for the test cases. – CalculatorFeline – 2016-03-10T17:15:11.563

1@CatsAreFluffy The idea was to show that any of those formats are valid. I think the cases are few and simple enough that ease of copy-paste'ing isn't an issue. – Adám – 2016-03-10T17:16:24.297

There's an answer that displays the string {} for the empty list. However, in TI-BASIC, {} doesn't represent anything; it throws an error when evaluated. Is this valid? – lirtosiast – 2016-03-10T22:23:36.257

1

Hang on, working on an answer using http://history-computer.com/Babbage/NextDifferentialEngines/Scheutz.html. :-)

– msh210 – 2016-03-11T19:49:02.720

Things to avoid when writing challenges. – cat – 2016-03-13T02:40:51.723

This is an old challenge, but it isn't explicitly stated: is a lower score better? – caird coinheringaahing – 2018-04-12T12:34:09.013

@cairdcoinheringaahing Yes. – Adám – 2018-04-12T12:54:37.273

Answers

7

APL\360, 1968 + 3 bytes = 1971

⎕⍵⎕

A builtin from the tutorial @NBZ linked to. I don't know why @NBZ said it would score 1970, because APL\360 wasn't implemented until 1968, and earlier APLs like APL\1130 didn't have the suffix vector function (see page 208 of here).

lirtosiast

Posted 2016-03-10T14:31:21.380

Reputation: 20 331

8

Forth, 1970 + 38 = 2008

:s tuck +do 0 . loop 0 +do -1 . loop ;

usage: 7 3 s prints "0 0 0 0 -1 -1 -1"

AShelly

Posted 2016-03-10T14:31:21.380

Reputation: 4 281

Now we're talking! – Adám – 2016-03-10T20:20:02.390

Why -1? filler+ – CalculatorFeline – 2016-03-10T21:18:03.863

2That's one of the more interesting 'truthy' values I've seen lately. – user3490 – 2016-03-10T23:45:02.240

4http://stackoverflow.com/q/23832703/10396 – AShelly – 2016-03-11T00:46:41.090

Is there a good reason this is named sv and not s, or something else one byte? – cat – 2016-03-11T15:11:06.747

Good question; changed. – AShelly – 2016-03-11T16:11:10.737

What's +do do? – cat – 2016-03-12T13:58:02.500

Pops i, then j from the stack and does the equivalent of for (;i<j;i++) on the following instructions up to loop – AShelly – 2016-03-12T17:59:47.513

8

APL, 1968+5=1973

Down to 5 chars:

⌽⎕≥⍳⎕

Older version:

⌽⎕↑⎕⍴1

Well, you actually already gave the answer, i just removed the dynamic function definition and checked that this one worked in 1968. For reference here is the manual:

http://www.softwarepreservation.org/projects/apl/Books/APL360ReferenceManual

Moris Zucca

Posted 2016-03-10T14:31:21.380

Reputation: 1 519

Kids, this is called a winner. Please write that down in your notes. – CalculatorFeline – 2016-03-11T16:14:13.723

@CatsAreFluffy Not yet. @​Moris Zucca: Finally, but you can actually golf half of those bytes away. Can you figure out how? Also, here is a much more modern and readable version of the manual.

– Adám – 2016-03-11T16:21:27.343

7

SAS, 1966 + 45 = 2011

data;a=;b=;do i=1to a;c=a-i<b;put c@;end;run; 

Time for SAS to shine!

SAS wasn't first published until 1972, but this data step only uses very basic features that I'm fairly confident would have been available even in the earliest pre-release versions from 1966 onwards, so I believe it would have worked then. Input goes after a= and b=, and output is printed to the log.

I would be amazed if anyone still had an IBM System/360 with the right version of SAS to actually verify this!

user3490

Posted 2016-03-10T14:31:21.380

Reputation: 809

The machine is available.... – Adám – 2016-03-11T15:40:57.697

Now, if only I had the cash for a mainframe SAS licence...

– user3490 – 2016-03-11T16:48:28.263

5

Mouse-1979, 1979 + 19 = 1998

??&TUCK (0.a)0(1-.)

Translation of: Forth.

The spec is really cryptic to me but I think this does the right thing.

cat

Posted 2016-03-10T14:31:21.380

Reputation: 4 989

Broken link.... – CalculatorFeline – 2016-03-11T16:31:44.380

@CatsAreFluffy Fixed; I typed it from memory. – cat – 2016-03-11T16:44:35.970

Interesting. But I don't think the &Tuck was available until the 2002 version. And the loops appear to be infinite. – AShelly – 2016-03-12T00:05:12.360

4

TI-Basic, 1990 + 21 = 2011

The first TI calculator that this program works on is the TI-81, introduced in 1990.

Prompt A,B:"{}
seq(I>A-B,I,1,A

Edit: noticed that I must support an empty list... increased code by 4 bytes

Test Cases

A=?7
B=?3
{0 0 0 0 1 1 1}

A=?4
B=?4
{1 1 1 1}

A=?2
B=?0
{0 0}

A=?0
B=?0
{}   * throws an error but still returns successfully

Timtech

Posted 2016-03-10T14:31:21.380

Reputation: 12 038

Could you add commentary on which parts of the source are single bytes in TI-Basic? I think that includes Prompt and seq( but I'm not sure about the rest – Sparr – 2016-03-10T18:02:12.550

We don't consider returning through Ans an acceptable output method, unless it's printed. – lirtosiast – 2016-03-10T18:04:24.847

@Sparr Sure, Prompt and seq( are one byte tokens and the other characters are one byte each. – Timtech – 2016-03-10T19:13:50.287

@lirtosiast Ans is the default way to return a value in the TI-83 series Basic. Additionally, when a program is run, the last line is printed automatically. So you have the best of both worlds. – Timtech – 2016-03-10T19:22:30.847

When the list is empty, though, Ans contains the string {}. Even if we say that's a representation of an empty list, it's never printed. As for Ans being the default return variable, you should ask on meta. – lirtosiast – 2016-03-10T20:32:12.307

@lirtosiast True, for the last case it is not explicitly displayed, but it is still returned. There is no other way to return a value except for Ans. – Timtech – 2016-03-10T20:33:51.997

In general we do not allow programs or functions to output values by storing them into variables, but we do allow them to print. If you think an exception should be made for Ans, please post on meta. – lirtosiast – 2016-03-10T20:36:12.513

Too bad this has to support empty list...then it would be winning (by 1 yearbyte) – CalculatorFeline – 2016-03-10T21:22:08.347

@CatsAreFluffy I know... – Timtech – 2016-03-10T21:33:23.220

@CatsAreFluffy NOt at all, I have a solution in mind that scores 1970. – Adám – 2016-03-11T14:47:04.053

2Is it the Analytical Engine? Somebody should do that... – CalculatorFeline – 2016-03-11T14:47:35.070

4

Mathematica 1.0, 1988+22 bytes=2010

Array[#>m&/.m->#-#2,#]&

I'm not sure if this works, just went through the documentation on 10.3 and looked for things that said Introduced in 1988 (1.0)

CalculatorFeline

Posted 2016-03-10T14:31:21.380

Reputation: 2 608

Just about the current winner. If only the SMP code could get shorter... – CalculatorFeline – 2016-03-10T16:15:20.560

On another note though, some docs: pure functions, /. and ->, Array

– Sp3000 – 2016-03-10T16:35:32.087

4

68k TI-Basic, 1995 + 25 = 2020

The first TI calculator that this program works on is the TI-92, introduced in 1995.

define f(a,b)=seq(x>a-b,x,1,a)

Unlike the TI-83 series, 68k TI-Basic supports the empty list.

Timtech

Posted 2016-03-10T14:31:21.380

Reputation: 12 038

How is the size counted? Tokenization is very different on the 68k series. – lirtosiast – 2016-03-10T20:33:46.813

Prompt and seq are both two bytes plus a one byte flag for multiple arguments. (21 bytes) – Timtech – 2016-03-11T15:31:56.240

Note that this is neither a program nor a function in the context of the 68k calculators: Prompt is invalid in a function, and a program can't return a value. So this has to be entered on the home screen. On the other hand, define f(a,b)=seq(x>a-b,x,1,a) does define a valid function that can be given a and b as arguments. (Verified on my TI-92 from 1995-09-13) – Fox – 2016-03-18T08:13:14.347

I own several TI calculators (the only z80-version being the 81), but usually use a TI-92 Plus. After running this define and calling f(2,1) or similar to tokenize it, the size reported by the OS is 25 bytes. – Fox – 2016-03-18T22:39:06.657

3

Python 1.0, 1994 + 26 = 2020

Saved 2 bytes thanks to DSM.

Lambda was introduced with the first major release, 1.0

lambda a,b:[0]*(a-b)+[1]*b

Morgan Thrapp

Posted 2016-03-10T14:31:21.380

Reputation: 3 574

1

Confirmed lambda introduced in 1.0, list (sequence) repetition in 0.9.2. The oldest version I could test this on (apart from 0.9.1) was 1.5.2, and it works fine there.

– Sp3000 – 2016-03-10T15:14:39.623

@Sp3000 Oh wow, that's awesome. I've been trying to find some change logs to confirm that the sequence repetition was in the language that early. – Morgan Thrapp – 2016-03-10T15:18:23.623

3

MATL, 2015 + 1 + 4 = 2020

:P<~

This works since release 6.0.0 of the language (it uses implicit input, which was introduced in that release), dated December 31, 2015.

I've added 1 to the score in accordance with @drolex comment on possibly different locales.

Try it online!

Explanation

:    % take first input implicitly. Generate inclusive range from 1 to that
P    % flip that array
<~   % take second input implicitly. True for elements of flipped array that
     % exceed second number. Display implicitly

Luis Mendo

Posted 2016-03-10T14:31:21.380

Reputation: 87 464

4One day later, and... – Adám – 2016-03-10T14:55:46.280

2Objection! We'll need to have the locales for the github server and the release submitter. If one is in Tonga and the other in Hawaii, this count might need to be incremented. – drolex – 2016-03-10T16:50:41.673

@drolex The OP should define what he means by "year", exactly. Meantime, I'm adding 1 to my score – Luis Mendo – 2016-03-10T16:57:15.487

@DonMuesli I didn't mean it, just showing the potential limitations of this type of scoring – drolex – 2016-03-10T17:00:08.503

@drolex Oh, I thought you were serious. I've asked the OP, anyway. Github date should probably count as official – Luis Mendo – 2016-03-10T17:02:05.740

3

J, 1990 + 8 = 1998

|.a{.b#1

Argh. Was researching this answer and someone got to APL before I could hope to understand the language. Here's my J solution instead.

Simon Major

Posted 2016-03-10T14:31:21.380

Reputation: 401

2

Prolog, 1972 + 57 = 2029

a(0,_,[]).
a(A,B,[H|L]):-Z is A-1,a(Z,B,L),(Z<B,H=1;H=0).

Usage: a(7,3,L). will unify L with [0,0,0,0,1,1,1].

I'm really not quite sure when is was implemented in the language, and I doubt you can actually find the exact date. It's a pretty basic built-in though so I assume it was already existing when the language first appeared in 1972.

Not that it really matters though, I'm far from winning with this answer.

Fatalize

Posted 2016-03-10T14:31:21.380

Reputation: 32 976

This may not be the winner, but it clearly illustrates the advantage of exploring - ehm - mature languages... – Adám – 2016-03-10T15:30:24.380

2

SMP, 1983+28 bytes=2011

Map[S[$1>x,x->$1-$2],Ar[$1]]

I think I got this right... S:2.10, page 48 Ar:7.1, page 102 Map:7.2, page 106 $1:7.1, page 104

And if you're familiar with Mathematica, no, Ar doesn't work like that. More like Range+Select.

CalculatorFeline

Posted 2016-03-10T14:31:21.380

Reputation: 2 608

(#>x&/.x->#)/@Range[#+#2]& in Mathematica – CalculatorFeline – 2016-03-10T21:20:31.410

I mean (#>x&/.x->#-#2)/@Range[#]& – CalculatorFeline – 2016-03-11T14:50:00.927

2

Vim, 1991 + 21 = 2012

"adwj<c-x>"bdw@ai0<esc>v@bhr1

Input looks like this:

7
3

And output looks like this:

0000111

Explanation:

"adw                            'Delete a word into register a
    j<c-x>                      'Go down a line, and decrement the next number to occur
          "bdw                  'Delete a word into register b
              @ai0<esc>         'Insert a '0' "a" times
                       v        'Enter visual mode
                        @bh     'Move "b" characters left
                           r1   'Replace the whole selection with the character '1'

James

Posted 2016-03-10T14:31:21.380

Reputation: 54 537

Too bad vi doesn't support registers, because it was released in 1976! – James – 2016-03-10T18:37:14.220

Explanation please? – CalculatorFeline – 2016-03-10T21:22:35.707

2

B, 1971 + 54 = 2025

s(l,t){while(t<l--)printn(0,8);while(t--)printn(1,8);}

See "The User's Reference to B" for the manual for this typeless C precursor.

AShelly

Posted 2016-03-10T14:31:21.380

Reputation: 4 281

2

Pyth, 2015 + 9 4 = 2024 2019

Thanks to @FryAmTheEggman for his help!

gRQE

Try it here!

Explanation

gRQE    # Q = amount of trailing truthy values
        # E = length of the vector
 R E    # map over range(E)
g Q     # d >= Q

Denker

Posted 2016-03-10T14:31:21.380

Reputation: 6 639

2

><>, 2009 + 14 + 3 for -v = 2026

b and a should be provided directly on the stack with -v, in reverse order.

The output isn't space separated as in the examples, but that does not seem to go against any stated rule. It uses 0 and 1 to represent false and true, as used by the language.

:?!;{:0(n1-}1-

It doesn't work with the current version since ? now pops its test value from the stack.

I'm not confident every feature was implemented from day 1, -v for example could have been provided later as a commodity. I'll try to make sure my answer is correct this weekend.

Aaron

Posted 2016-03-10T14:31:21.380

Reputation: 3 689

1? didn't pop (a long time ago) as stated in the quine challenge – CalculatorFeline – 2016-03-11T14:48:44.937

Thanks, that's great news, I'll save 1 byte :) I'll edit that now, but I'll have to check the resources linked on esolang.org, some date back to at least 2011. – Aaron – 2016-03-11T14:53:08.467

Quine challenge and esolang – CalculatorFeline – 2016-03-11T15:05:03.040

Thanks for your help, I wouldn't have thought to check the wiki's revisions ! I'm currently at work and won't probably be able to check everything yet, but I'll make sure to do it this evening or tomorrow. – Aaron – 2016-03-11T15:40:09.053

Score=2026 now. – CalculatorFeline – 2016-03-11T16:12:45.677

Woops, thanks. Although I think I'll have to put 2010, that's the oldest documented version on the wiki. – Aaron – 2016-03-11T16:14:23.450

1

05AB1E, 2016 + 9 = 2025

This can definitely be golfed further, but here's a start :p. Code:

-0s×1¹×«S

Try it online! The input is given as b, a.

Also 9 bytes: 0×1I×0ñRS.

Adnan

Posted 2016-03-10T14:31:21.380

Reputation: 41 965

Yeah, it can definitely be golfed... (did ° exist back in 2016 btw?) – Erik the Outgolfer – 2018-04-12T14:00:40.893

1

PowerShell v1, 2006 + 28 = 2034

param($a,$b),0*($a-$b)+,1*$b

Uses the comma operator to construct the array(s), which has been in PowerShell since the beginning.

AdmBorkBork

Posted 2016-03-10T14:31:21.380

Reputation: 41 581

1

Mathcad, 1998 + 42 = 2040

"bytes" are interpreted as number of distinct keyboard characters (eg, 'for' operator (including one programming line) is a single character ctl-shft-#, or a click on the Programming toolbar)).

The above byte count assumes that the a and b definitions don't count towards the total; add 4 bytes for definitions if this assumption is invalid.

The function version shown below adds 5 bytes for the definition and a further 3 bytes for each use (assuming the a and b values are directly typed in).

As my Mathcad solution should clearly be playing off the red tees and not the competition ones, I've added a table of solutions. Note that as Mathcad has no empty array, I've used an empty string ("") instead; I've used 0 to indicate where I haven't calculated the b>a pairs.

enter image description here

Stuart Bruff

Posted 2016-03-10T14:31:21.380

Reputation: 501

Very interesting! – Timtech – 2016-03-11T15:34:03.187

1

k (kona), 1993 + 15 = 2008

((a-b)#0b),b#1b

Creates list of b True values, and concatenates it to a list of (a-b) False values.

Simon Major

Posted 2016-03-10T14:31:21.380

Reputation: 401

1

PHP, 1995 + 56 bytes = 2051

function s($a,$b){while($i++<$a)$v[]=$i>$a-$b;return$v;}
Exploded view
function s($a,$b) {
  while ($i++ < $a) $v[] = $i > $a - $b;
  return $v;
}

ricdesi

Posted 2016-03-10T14:31:21.380

Reputation: 499

Uh..there's custom scoring. It's first year language woks in+byte count. – CalculatorFeline – 2016-03-11T22:31:22.627

Whoops, right you are! Fixing... – ricdesi – 2016-03-11T22:33:58.740

Making the probably-incorrect assumption of this working in PHP 1. Will verify version soon. – ricdesi – 2016-03-11T22:43:41.590

1

Javascript ES6, 2015 + 46 = 2061

Returns array of 0 and 1

(a,b)=>Array(a-b).fill(0).concat(Array(b).fill(1))

Javascript ES6, 2015 + 50 = 2065

Returns a string of 0 and 1 chars

(a,b)=>Array(a-b+1).join(0)+Array(b+1).join(1)

Javascript, 1995 + 61 = 2056

Returns a string of 0 and 1 chars

function(a,b){return Array(a-b+1).join(0)+Array(b+1).join(1)}

Qwertiy

Posted 2016-03-10T14:31:21.380

Reputation: 2 697

0

R, 20 bytes + 1993 = 2013

function(a,b)1:a>a-b

Try it online!

Possibly this might work in S, which would drop the score to 2008, but I haven't been able to verify it.

Giuseppe

Posted 2016-03-10T14:31:21.380

Reputation: 21 077

0

SmileBASIC 3, 2014 + 25 = 2039

The first publicly available version of SmileBASIC 3 launched in Japan with the SmileBASIC app for Nintendo 3DS in November 2014.

Prints a string where 0 is false and 1 is true (as they are in the language itself.)

INPUT A,B?"0"*(A-B)+"1"*B

snail_

Posted 2016-03-10T14:31:21.380

Reputation: 1 982