Inspiré d'un vieux manuel ...
Le défi
Je définis le a ème suffixe vecteur de b comme la liste booléenne de longueur a avec b des valeurs vraies de fin.
Écrivez un programme ou une fonction qui, étant donné a et b par n'importe quel moyen, retourne le a ème vecteur suffixe de b par n'importe quel moyen.
Cela peut sembler trivial, mais voici le problème: votre score est le nombre d'octets plus la première année de fonctionnement de votre solution.
Règles
Toutes les règles standard s'appliquent, sauf que les langues et les versions linguistiques publiées après ce défi peuvent également être utilisées.
Sortie utilisant n'importe quelle représentation des valeurs booléennes que votre langue utilise, par exemple 1
/ 0
, True
/ False
, TRUE
/ FALSE
, "True"
/ "False"
, etc.
Sortie en utilisant un minimum de représentation des listes que votre utilisation de la langue, par exemple 0 0 1
, [False,False,True]
, (FALSE;FALSE;TRUE)
, {"False","False","True"}
, etc.
Vous pouvez supposer que a ≥ b est toujours vrai et qu'ils sont d'un type de données approprié.
Cas de test
Étant donné a = 7 et b = 3, retournez0 0 0 0 1 1 1
Étant donné a = 4 et b = 4, retournez[True,True,True,True]
Étant donné a = 2 et b = 0, retournez(FALSE;FALSE)
Étant donné a = 0 et b = 0, retournez{}
Exemple de solution et de notation
Je voudrais peut-être soumettre la solution à l' {⌽⍺↑⍵⍴1}
aide de Dyalog APL. Ce serait un bytecount de 8. Il s'agit d'une fonction dynamique, qui fonctionne à partir de la version 8.1 de Dyalog APL, sortie en 1998, donc mon score total est 2006. Ma réponse soumise devrait ressembler à ceci:
# Dyalog APL 8.1, 1998 + 8 = 2006
{⌽⍺↑⍵⍴1}
Optional explanation...
Recommended: Link to documentation showing when the features you used were released.
Le score le plus bas gagne!
la source
Réponses:
APL \ 360, 1968 + 3 octets = 1971
Un intégré du tutoriel @NBZ lié à. Je ne sais pas pourquoi @NBZ a dit qu'il marquerait 1970, car APL \ 360 n'a été implémenté qu'en 1968, et les APL antérieures comme APL \ 1130 n'avaient pas la fonction de vecteur de suffixe (voir page 208 d' ici ).
la source
Quatrième, 1970 + 38 = 2008
utilisation:
7 3 s
imprime "0 0 0 0 -1 -1 -1"la source
sv
et nons
, ou autre chose d'un octet?APL, 1968 + 5 = 1973
Jusqu'à 5 caractères:
Ancienne version:
Eh bien, vous avez déjà donné la réponse, je viens de supprimer la définition de la fonction dynamique et de vérifier que celle-ci fonctionnait en 1968. Pour référence, voici le manuel:
http://www.softwarepreservation.org/projects/apl/Books/APL360ReferenceManual
la source
SAS, 1966 + 45 = 2011
Il est temps que SAS brille!
SAS n'a été publié pour la première fois qu'en 1972, mais cette étape de données n'utilise que des fonctionnalités très basiques qui, je suis assez confiant, auraient été disponibles même dans les premières versions préliminaires à partir de 1966, donc je pense que cela aurait fonctionné à ce moment-là. L'entrée va après
a=
etb=
, et la sortie est imprimée dans le journal.Je serais étonné si quelqu'un avait encore un IBM System / 360 avec la bonne version de SAS pour vérifier cela!
la source
Mouse-1979, 1979 + 19 = 1998
Translation of: Forth.
The spec is really cryptic to me but I think this does the right thing.
la source
&Tuck
was available until the 2002 version. And the loops appear to be infinite.TI-Basic, 1990 + 21 = 2011
The first TI calculator that this program works on is the TI-81, introduced in 1990.
Edit: noticed that I must support an empty list... increased code by 4 bytes
Test Cases
la source
Ans
an acceptable output method, unless it's printed.Prompt
andseq(
are one byte tokens and the other characters are one byte each.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.Mathematica 1.0, 1988+22 bytes=2010
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)
la source
/.
and->
,Array
68k TI-Basic, 1995 + 25 = 2020
The first TI calculator that this program works on is the TI-92, introduced in 1995.
Unlike the TI-83 series, 68k TI-Basic supports the empty list.
la source
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)define
and callingf(2,1)
or similar to tokenize it, the size reported by the OS is 25 bytes.Python 1.0, 1994 + 26 = 2020
Saved 2 bytes thanks to DSM.
Lambda was introduced with the first major release, 1.0
la source
MATL, 2015 + 1 + 4 = 2020
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
la source
J, 1990 + 8 = 1998
Argh. Was researching this answer and someone got to APL before I could hope to understand the language. Here's my J solution instead.
la source
Prolog, 1972 + 57 = 2029
Usage:
a(7,3,L).
will unifyL
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.
la source
SMP, 1983+28 bytes=2011
I think I got this right...
S
:2.10, page 48Ar
:7.1, page 102Map
:7.2, page 106$1
:7.1, page 104And if you're familiar with Mathematica, no,
Ar
doesn't work like that. More likeRange
+Select
.la source
(#>x&/.x->#)/@Range[#+#2]&
in Mathematica(#>x&/.x->#-#2)/@Range[#]&
Vim, 1991 + 21 = 2012
Input looks like this:
And output looks like this:
Explanation:
la source
B, 1971 + 54 = 2025
See "The User's Reference to B" for the manual for this typeless C precursor.
la source
Pyth, 2015 +
94 =20242019Thanks to @FryAmTheEggman for his help!
Try it here!
Explanation
la source
><>, 2009 + 14 + 3 for -v = 2026
b
anda
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.
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.la source
05AB1E, 2016 + 9 = 2025
This can definitely be golfed further, but here's a start :p. Code:
Try it online! The input is given as b, a.
Also 9 bytes:
0×1I×0ñRS
.la source
°
exist back in 2016 btw?)PowerShell v1, 2006 + 28 = 2034
Uses the comma operator to construct the array(s), which has been in PowerShell since the beginning.
la source
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.
la source
PHP, 1995 + 56 bytes = 2051
Exploded viewla source
Javascript ES6, 2015 + 46 = 2061
Returns array of 0 and 1
Javascript ES6, 2015 + 50 = 2065
Returns a string of
0
and1
charsJavascript, 1995 + 61 = 2056
Returns a string of
0
and1
charsla source
k (kona), 1993 + 15 = 2008
Creates list of b True values, and concatenates it to a list of (a-b) False values.
la source
R, 20 bytes + 1993 = 2013
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.
la source
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.)
la source