VEVO User Account Checker

21

1

We often see music videos on Youtube. Many Youtube channels that host music videos are "powered by VEVO". Those can be easily identified by both embedding VEVO at their video thumbnails and appending VEVO to their channel name.

Now write some code to test whether a string given by user is a VEVO user account or not.

Requirements for valid VEVO user account strings:

  • Must only contain uppercase, lowercase, and digit characters. (no whitespace or punctuation)

  • Must not exceed 80 characters length.

  • Must have "VEVO" substring at the end of string

Test cases:

Valid inputs:

AdeleVEVO
ConnieTalbotVEVO
SHMVEVO
justimberlakeVEVO
DJMartinJensenVEVO
test123VEVO

Invalid inputs:

syam kapuk
jypentertainment
Noche de Brujas
testVEVO123

Of course, because this is , I'm looking for the shortest code using any programming language.

Bagas Sanjaya

Posted 2017-12-21T10:28:34.413

Reputation: 317

4Nice first question! +1 – LiefdeWen – 2017-12-21T10:47:45.557

12test-cases: VEVO and ūņīčōdēVEVO – dzaima – 2017-12-21T11:02:37.773

8other suggested test cases: test123VeVo and one with more than 80 characters – Arnauld – 2017-12-21T11:09:05.517

6You should wait a lot longer before accepting a best answer; the question has only been up for an hour and there are plenty more languages that people might answer in! – Luke Stevens – 2017-12-21T11:56:54.687

2What's considered acceptable output here? Would 0 for valid and another/any other number for invalid be allowed? – Shaggy – 2017-12-21T12:11:29.033

4Another suggested test case: test123 VEVO (ends with VEVO but contains whitespace) – Brian J – 2017-12-21T14:38:05.200

3Alternatively, it is even better if you don't accept an answer at all, so that it is more a competition between answers in each language, rather than between languages. – caird coinheringaahing – 2017-12-21T15:43:42.607

5"uppercase, lowercase, and digit characters" requires defining (I would assume (as, I believe, all have done already) that you mean A-Za-z0-9; but it could mean anything that may be uppercased or lowercased, for example and and digits in other alphabets, for example (9). – Jonathan Allan – 2017-12-21T21:19:50.363

3If you're going to accept any answer, please accept the shortest (the winner), rather than an arbitrary answer. – caird coinheringaahing – 2017-12-23T20:30:58.673

Can I invert the the valid/invalid and return True for an invalid string and false for a valid one? – Rɪᴋᴇʀ – 2017-12-29T04:57:37.363

2Downside of accepting the Fish answer after only an hour: its the second longest answer that's currently available and most definitely not the winner... – Draco18s no longer trusts SE – 2017-12-29T07:05:16.057

Answers

9

Python 2, 45 bytes

-3 bytes thanks to Rod. -2 bytes thanks to ovs.

lambda s:len(s)<81*s.isalnum()<'VEVO'==s[-4:]

Try it online!

A regex solution turns out to be longer.

lambda s:re.match('^[^\W_]{0,76}VEVO$',s)
import re

totallyhuman

Posted 2017-12-21T10:28:34.413

Reputation: 15 378

6

Japt v2.0a0, 20 16 bytes

Returns 1 for valid or 0 for invalid. [\l\d] would also work in place of [^\W_] for the same byte count.

è/^\w{0,76}VEVO$

Try it | Check all test cases

Explanation: è counts the number of matches of the RegEx in the input. In Japt, the \w RegEx class doesn't include underscore.

Shaggy

Posted 2017-12-21T10:28:34.413

Reputation: 24 623

Nice one. Best I could do without regex is ;¥oB+mc)¯80 ©"VEVO"¥Ut4n

– ETHproductions – 2017-12-21T14:13:53.033

@ETHproductions, nice trick with B+mc :) By the way, if Japt2 had a character class for [A-Za-z0-9], we could beat Retina here! Might even be worth overriding \w & \W. – Shaggy – 2017-12-21T15:37:01.830

Heh, I think I was actually planning to do that originally... I should get back to work on Japt in general :P – ETHproductions – 2017-12-21T15:48:57.883

4

JavaScript (ES6), 27 36 34 31 bytes

Saved 2 bytes thanks to @Neil and 3 bytes thanks to @Shaggy

s=>/^[^\W_]{0,76}VEVO$/.test(s)

Test cases

let f =

s=>/^[^\W_]{0,76}VEVO$/.test(s)

console.log(f('syam kapuk')) // (INVALID)
console.log(f('jypentertainment')) // (INVALID)
console.log(f('Noche de Brujas')) // (INVALID)
console.log(f('testVEVO123')) // (INVALID)
console.log(f('AdeleVEVO')) // (VALID)
console.log(f('ConnieTalbotVEVO')) // (VALID)
console.log(f('SHMVEVO')) // (VALID)
console.log(f('justimberlakeVEVO')) // (VALID)
console.log(f('DJMartinJensenVEVO')) // (VALID)

Arnauld

Posted 2017-12-21T10:28:34.413

Reputation: 111 334

2Doesn't \w match _s as well? – Neil – 2017-12-21T11:19:31.757

I think ((?!_)\w) saves 2 bytes. – Neil – 2017-12-21T11:28:48.363

1

Would [^\W_] work for a 3 byte saving?

– Shaggy – 2017-12-21T12:14:50.713

@Shaggy Heck. For some reason, I was thinking such characters classes were not working within character sets. Thanks! – Arnauld – 2017-12-21T12:41:57.127

Doesn't JS have any way of skipping the lambda? Like /^[^\W_]{0,76}VEVO$/.test or something? – totallyhuman – 2017-12-21T18:02:04.420

@totallyhuman Indeed, this is a function that is equivalent to the function in this answer, but 6 bytes shorter… – user42589 – 2017-12-22T12:26:08.340

@Xufox I'm not sure what the consensus is. We could do (new RegExp).test.bind(/^[^\W_]{0,76}VEVO$/), which indeed gives a function that can be called in a standard way. But how would you use (and re-use) /^[^\W_]{0,76}VEVO$/.test? – Arnauld – 2017-12-22T13:54:17.423

@Arnauld Well, /^[^\W_]{0,76}VEVO$/.test is an expression that evaluates to a function which you can directly use like this: /^[^\W_]{0,76}VEVO$/.test("TestVEVO") or (/^[^\W_]{0,76}VEVO$/.test)("TestVEVO"). You can save it in a variable f=/^[^\W_]{0,76}VEVO$/.test; and use f("TestVEVO"), but as far as I know, this assignment is optional in terms of code golf, so you can just skip it. – user42589 – 2017-12-22T23:08:15.107

@Xufox No, we can't save it in a variable, because test would lose its this context (hence the need to bind). This is why it's quite special and not equivalent to the function in this answer. – Arnauld – 2017-12-23T09:04:54.920

4

PHP, 51 bytes

-10 bytes thanks to @Ismael Miguel for using <?= instead of <?php echo! and removing the closing tag

<?=preg_match("/^[^\W_]{0,76}VEVO$/",fgets(STDIN));

Try it online!

Thanks for the other answers so I didn't have to write the regex!

NK1406

Posted 2017-12-21T10:28:34.413

Reputation: 739

1Instead of <?php echo, you can do <?=preg_match("/^[^\W_]{0,76}VEVO$/",fgets(STDIN));. – Ismael Miguel – 2017-12-22T01:50:09.117

You're welcome. You can leave out the closing PHP tag. Quoting the documentation: "If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file." (http://php.net/manual/en/language.basic-syntax.phptags.php). This should save you 2 more bytes. Also, instead of [^\W_], just use \w, which is the same as [a-zA-Z_].

– Ismael Miguel – 2017-12-22T15:47:41.887

1Thanks as well, I have a few answers to update now! – NK1406 – 2017-12-22T15:49:02.873

You're welcome. One advice: reading the documentation and getting familiar with it will help a lot. – Ismael Miguel – 2017-12-22T15:52:55.710

3

Dyalog APL, 47 bytes

{0::0⋄(∧/(1(819⌶)t)∊⎕A,⎕D)∧77>≢t←,∘'VEVO'⍣¯1⊢⍵}

Try it online!

A pure regex solution is 32 bytes, but also is much more boring than this approach.

{0::0⋄(∧/(1(819⌶)t)∊⎕A,⎕D)∧77>≢t←,∘'VEVO'⍣¯1⊢⍵} a dfn with right arg '⍵'
 0::0⋄                                          on error, return 0
                                 ,∘'VEVO'       a train that appends VEVO
                                         ⍣¯1    apply it -1 times
                                             ⍵  on '⍵'
                                                and error if impossible (which returns 0)
                               t←               save on variable 't'
                              ≢                 get the length of that
                           77>                  if that's smaller than 77
                          ∧                     and
         (1(819I)t)                              [for each of] 't' uppercased
                   ∊⎕A,⎕D                        is it in the uppercase alphabet concatenated with the digits
       ∧/                                        reduced by and

dzaima

Posted 2017-12-21T10:28:34.413

Reputation: 19 048

Instead of using ⍣¯1 to check for VEVO and needing the dfn guard, you can do 'VEVO'≡¯4↑⍵. Moving things around a bit gets me {('VEVO'≡¯4↑⍵)∧∧/⍵∊⎕D,⎕A,(819⌶)⎕A} – user41805 – 2017-12-21T18:24:19.290

@Cowsquack yeah, I might have forgotten about .. There are other better ways to do this challenge though (i.e. Eriks answer) and I like this idea :p – dzaima – 2017-12-21T18:34:03.453

3

C# (.NET Core), 87 + 18 = 105 bytes

Try it online!

a=>a.Where(x=>char.IsLetterOrDigit(x)).Count()==a.Length&a.Length<81&a.EndsWith("VEVO")

LiefdeWen

Posted 2017-12-21T10:28:34.413

Reputation: 3 381

Wouldn't this fail if the input contains any non-alphanumeric characters? – Shaggy – 2017-12-21T12:21:50.863

@Shaggy You are right, will fix a bit later. – LiefdeWen – 2017-12-21T13:05:43.533

I have checked with TIO and found that input "ConnieTalbotVEVO" (which should be valid input) was falsely declared as invalid input. – Bagas Sanjaya – 2017-12-21T23:32:12.267

@BagasSanjaya It is because I put tabs after it in the test case, take the tabs out and it will be the same as the test case above and will work. – LiefdeWen – 2017-12-22T05:56:29.717

73+18: a=>a.All(x=>char.IsLetterOrDigit(x)&x<123)&a.Length<81&a.EndsWith("VEVO") only ASCII letters or 67+18: a=>a.All(x=>char.IsLetterOrDigit(x))&a.Length<81&a.EndsWith("VEVO") with unicode support – dg3 – 2017-12-22T10:50:44.867

3

APL (Dyalog), 25 bytes

≢'^[^_\W]{0,76}VEVO$'⎕S 3

Try it online!

Erik the Outgolfer

Posted 2017-12-21T10:28:34.413

Reputation: 38 134

3

C (gcc), 83 bytes

c,i;f(char*s){for(c=i=0;s[i];c+=!isalnum(s[i++]));c=i<81*!c*!strcmp("VEVO",s+i-4);}

Try it online!

scottinet

Posted 2017-12-21T10:28:34.413

Reputation: 981

I don't see any return statement, how does this return c? Undefined behavior? – MD XF – 2017-12-22T03:33:21.793

@MDXF This is indeed undefined behavior and an abuse of how gcc uses the same registers for variable assignment and return values (see tips for golfing in C ). This is not portable and does not necessarily work with other compilers (for instance it doesn't work with clang)

– scottinet – 2017-12-22T09:12:26.377

that's very impressive. How did you find that out? – MD XF – 2017-12-22T22:26:24.683

sometimes f("VO" also be true, when before is "VI" stored; or maybe fault – l4m2 – 2017-12-29T06:56:32.780

3

Grime, 13 bytes

e`n{-76"VEVO"

Try it online!

Nothing fancy here. Match the entire input against the pattern: at most 76 alphanumeric characters, followed by the string VEVO. Prints 1 for match and 0 for no match. I remembered that the last quote could be removed at end of line, but apparently it just causes a parse error.

Zgarb

Posted 2017-12-21T10:28:34.413

Reputation: 39 083

2

><>, 147 125 bytes

!\i:0(?^1[::::::"/9@Z`z"!
;>{(?;{(?v{(?;{(?v{(?;{(?v
 ~l1-?!v >       > !|!: !<
;v    ]/~l99*-0(?!;4["OVEV"{-?;{-?;{-?;{-?;1n

Try it online!

><>, 147 bytes

Try it online!

This prints 1 if the input string is valid and nothing for an invalid input.

Edit 1: Changed the Alphanumeric checks to use ranges rather than comparing against every character. (saving 22 bytes)

Teal pelican

Posted 2017-12-21T10:28:34.413

Reputation: 1 338

I don't have the time right now to golf this, but I'm pretty sure you can lose bytes by doing comparisons to character codes. The gist of it would be to reject things less than '0' and greater than 'z' and then reject things between '9' and 'A' as well as between 'Z' and 'a'. – cole – 2017-12-21T17:14:38.883

@cole :- I wasn't at my PC to change this yesterday after the post but you are right, comparisons do cut a bit off. I'm sure if you scan across the code you may be able to drop some extra bytes off. – Teal pelican – 2017-12-22T10:26:15.937

2

Bash, 53 26 30 bytes

[[ $1 =~ ^[^\W_]{0,76}VEVO$ ]]

Exit code 0 for VALID results and 1 for INVALID results.

Still working on 80 characters or less.

-27 bytes from removing output, thanks to @KeyWeeUsr

+4 bytes, fixed regex (same as everyone else)

Try it online!

Probably

Posted 2017-12-21T10:28:34.413

Reputation: 207

You can just echo 1 for true, or just go without any echo. There's no need to echo anything as you still end up with an exit code that you actually check with && and || – KeyWeeUsr – 2017-12-21T17:41:38.083

Okay, wasn't sure what sort of output (if any) was required. The question didn't really say. – Probably – 2017-12-21T17:47:31.173

The idea of 'truthy' is explained here https://codegolf.meta.stackexchange.com/q/2190/16658 and is generally implied universally unless specified as otherwise

– Sirens – 2017-12-22T07:32:45.110

This doesn't output anything on TIO. Also, your RegEx allows underscores, which it shouldn't. And you're not checking for length. We require solutions to be fully functional here, works in progress shouldn't be posted. I'd recommend deleting it until you can fix the problems. (On a related note, why do people upvote solutions that clearly don't work?) – Shaggy – 2017-12-22T10:35:11.913

@Shaggy The output is via exit code. – totallyhuman – 2017-12-24T17:38:03.727

2

><>, 101 89 83 81 94 bytes

Edit: Switched to checking for non-alphanumeric characters rather than for alphanumeric. Switched back cause I forget to check between Z and a. Thanks @Emigna. Rip those lost bytes though

Edit 2: Also, I can totally just get rid of those }}}}. Thanks Teal pelican for that and finding the problem with TIO

Edit 3: replaced a ~~~ with a p

!\i::0(?v:::"/")$":"(*$:"`")$"{"(*+$:"@")$"["(*+?
0/?("S"l/
l/"VEVO"[4pn?$0(6
!\{-?vl?
1/;n0/n

I don't know why this won't work on TIO, but it works fine here. The problem was that the {} commands in TIO don't work for an empty list. Try It Here

How It Works

!\i::0(?v:::"/")$":"(*$:"`")$"{"(*+$:"@")$"["(*+?
0/....../
......... Checks each input is alphanumeric
...       If any isn't, print 0 and exit with an error
...

...
0/?("S"l/ Checks if there are more than 80 characters
...       If so, print 0 and exit with an error
...
...

...
...
l/"VEVO"[4pn?$0(6 Check if the input is less than 4 characters
...               If so, print 0 and exit with an error
...

...
...
./"VEVO"[4pn?$0(6 Take the last 4 characters of the input into a new stack (first time I've actually used [)
...               Add "VEVO" to the stack to compare
...

...
0/....../n
........V
!\{-?vl?  Check if the last 4 characters are VEVO
1/;n0/n   Print 1 and exit with an error if so, else print 0 and exit

For consistency, replacing the ; in the last line with an invalid instruction makes every output an error.

Jo King

Posted 2017-12-21T10:28:34.413

Reputation: 38 234

I believe your TIO error might be how it works with ordering on the ending stack split. TIO LINK HERE Having a mess around in TIO you can change it to this.

– Teal pelican – 2017-12-22T11:52:51.080

Thanks @Tealpelican. Fixed that and killed a few more bytes – Jo King – 2017-12-22T12:40:30.043

You are missing the check for characters between "Z" and "a". – Emigna – 2017-12-22T12:55:21.743

@Emigna Oops, thanks! Fixed! – Jo King – 2017-12-22T13:00:52.397

2

C++, 129 105 102 bytes

Thanks to other answers that showed me that i can count the number of characters
-2 bytes thanks to Zacharý

#include<regex>
int v(std::string s){return std::regex_match(s, std::regex("[a-zA-Z0-9]{0,76}VEVO"));}

TIO LINK

HatsuPointerKun

Posted 2017-12-21T10:28:34.413

Reputation: 1 891

Where's TIO link at your answer? I'd like to test your code... – Bagas Sanjaya – 2017-12-23T07:16:44.810

Forgive me if this is a lack of knowledge of C++. Can you move remove the variable r, and just have the regex inside the call to std::regex_match? – Zacharý – 2017-12-23T15:33:47.257

There is an unneeded space after the comma – Zacharý – 2017-12-24T16:12:44.860

You can remove the comma the space after the comma. – Zacharý – 2018-12-04T18:30:25.913

2

Stacked, 21 bytes

['^\i{0,76}VEVO'-''=]

Try it online!

Rɪᴋᴇʀ

Posted 2017-12-21T10:28:34.413

Reputation: 7 410

1

05AB1E, 21 bytes

žKÃQsg81‹IR4£"OVEV"QP

Try it online!

Emigna

Posted 2017-12-21T10:28:34.413

Reputation: 50 798

1

Retina, 18 bytes

A`\W|_|.{81}
VEVO$

Try it online!

or

^[^\W_]{0,76}VEVO$

Try it online!

ovs

Posted 2017-12-21T10:28:34.413

Reputation: 21 408

1

Haskell, 75 bytes

-2 bytes thanks to user28667.

import Data.Char
f s|l<-length s=all isAlphaNum s&&l<81&&drop(l-4)s=="VEVO"

Try it online!

totallyhuman

Posted 2017-12-21T10:28:34.413

Reputation: 15 378

1-2 bytes if you use drop(length s-4) and extract length s – user28667 – 2017-12-21T15:38:47.057

1

Java (OpenJDK 8), 37 36 bytes

Pretty simple answer using some lovely regex.
Quite possibly the shortest Java answer I've ever done.
-1 bytes thanks to Neil on the Javascript answer

w->w.matches("((?!_)\\w){0,76}VEVO")

Try it online!

Luke Stevens

Posted 2017-12-21T10:28:34.413

Reputation: 979

1

Deorst, 22 bytes

'^[^\W_]{0,76}VEVO$'gm

Try it online!

Just uses the regex found by Shaggy

caird coinheringaahing

Posted 2017-12-21T10:28:34.413

Reputation: 13 702

1

V, 17 bytes

ø^¨áüä©û,76}VEVO$

Try it online!

Hexdump:

00000000: f85e a8e1 fce4 a9fb 2c37 367d 5645 564f  .^......,76}VEVO
00000010: 24                                       $

Compressed regexes for the win!

ø                   " Count the number of matches of
 ^                  "   The beginning of the line
  ¨áüä©             "   A letter or number...
       û,76}        "   From 0 to 76 times...
            VEVO    "   Followed by "VEVO"
                $   "   At the end of the line

James

Posted 2017-12-21T10:28:34.413

Reputation: 54 537

1

Perl 5, 35 29+1(-a) = 30 bytes

-6 bytes thanks to ETHproductions

Added 4 bytes. Didn't see that underscore wasn't allowed.

This is my first golf, so here's hoping I did it right.

Returns 1 if valid, 0 if not.

print/^[^\W_]{0,76}VEVO$/?1:0

Try it online!

Geoffrey H.

Posted 2017-12-21T10:28:34.413

Reputation: 41

1Welcome to PPCG! You can remove extraneous whitespace to get down to 25 (+1) bytes: print/^\w{1,76}VEVO$/?1:0 – ETHproductions – 2017-12-21T22:16:44.790

+0 converts match bool into number, rather than ?1:0, saves 2 bytes. Calling with -ple prints $_ for you. So: perl -ple '$_=/^[^\W_]{0,76}VEVO$/+0'. 25 bytes. If you are happy to get blanks on non-matching lines, $_=/^[^\W_]{0,76}VEVO$/ is 23 bytes. – Phil H – 2017-12-22T11:06:36.843

1

Ruby -n, 22+1 = 23 bytes

p~/^[^\W_]{0,76}VEVO$/

Output 0 if true, nil if false

Try it online!

Using the same boring regex as everybody else.

G B

Posted 2017-12-21T10:28:34.413

Reputation: 11 099

1

Swift 4, 113 bytes

import Foundation;var f={(s:String)->Bool in s.range(of:"^[^\\W_]{0,76}VEVO$",options:.regularExpression) != nil}

Try it online!

Zeke Snider

Posted 2017-12-21T10:28:34.413

Reputation: 121

1

AWK, 23 bytes

$0~/^[^\W_]{0,76}VEVO$/

Try it online!

Outputs the account name if valid, and outputs nothing if it isn't valid

Noskcaj

Posted 2017-12-21T10:28:34.413

Reputation: 421

1

Clean, 61 bytes

import StdEnv
?['VEVO']=True
?[_:l]=length l<80&& ?l
?_=False

Try it online!

Οurous

Posted 2017-12-21T10:28:34.413

Reputation: 7 916

0

Google Sheets, 33 Bytes

Anonymous worksheet function that takes input from range A1 and outputs to the calling cell

=RegexMatch(A1,"^[^\W_]{0,76}VEVO

Taylor Scott

Posted 2017-12-21T10:28:34.413

Reputation: 6 709

Where's the closing bracket? – Bagas Sanjaya – 2018-01-02T09:11:19.547

@BagasSanjaya that's one of the wonderful things about Google Sheets, it autocompletes unclosed strings and groups. So when this is pasted into a cell and you either click off the cell or press enter GS converts this to =RegexMatch(A1,"^[^\W_]{0,76}VEVO") without any feedback to the user and executes – Taylor Scott – 2018-01-02T13:55:27.867

-1

Clojure, 146 bytes

(fn[u](let[c count](and(<(c u)81)(=(c(filter #(let[i(int %)](or(< 47 i 58)(< 64 i 91)(< 96 i 123)))u))(c u))(clojure.string/ends-with? u"VEVO"))))

Try it online!

This would be much shorter using a regex, but I figured doing it manually would be more interesting.

(defn vevo? [username]
  (and (< (count username) 81)

       ; Filter out the illegal characters, then check if the length is the same as the original string
       (= (count (filter #(let [i (int %)]
                            ; Make sure the char code is in the valid ranges
                            (or (< 47 i 58) (< 64 i 91) (< 96 i 123)))
                         username))
          (count username))

       (clojure.string/ends-with? username "VEVO")))

Carcigenicate

Posted 2017-12-21T10:28:34.413

Reputation: 3 295

Any TIO link for testing? – Bagas Sanjaya – 2018-01-04T12:45:10.910

@BagasSanjaya I can add one in a bit. It seems like adding TIO links are standard now. They were optional last time I used the site frequently, but now everyone's adding them. – Carcigenicate – 2018-01-04T14:03:54.443

@BagasSanjaya I added a link. Unfortunately TIO seems broken. It can't find the ends-with? function, even though that's part of the standard library. – Carcigenicate – 2018-01-06T22:34:44.503