VEVO用户帐户检查器


21

我们经常在YouTube上看到音乐视频。许多托管音乐视频的YouTube频道都是“由VEVO提供支持”的。通过将VEVO嵌入到其视频缩略图中并将VEVO附加到其频道名称,可以轻松识别这些内容。

现在,编写一些代码来测试用户给定的字符串是否为VEVO用户帐户。

有效的VEVO用户帐户字符串的要求:

  • 必须仅包含大写,小写和数字字符。(无空格或标点符号)

  • 长度不能超过80个字符。

  • 字符串末尾必须有“ VEVO”子字符串

测试用例:

有效输入:

AdeleVEVO
ConnieTalbotVEVO
SHMVEVO
justimberlakeVEVO
DJMartinJensenVEVO
test123VEVO

输入无效:

syam kapuk
jypentertainment
Noche de Brujas
testVEVO123

当然,因为这是,所以我正在寻找使用任何编程语言的最短代码。


4
不错的第一个问题!+1
LiefdeWen

12
测试用例:VEVOūņīčōdēVEVO
dzaima

8
其他建议的测试用例:test123VeVo和一个超过80个字符的测试用例
Arnauld

6
您应该等待更长的时间才能接受最佳答案。这个问题只用了一个小时,人们可能会回答更多的语言!
路加·史蒂文斯

5
“大写,小写和数字字符”需要定义(我假设(我相信,所有情况都已经做了))您的意思是A-Za-z0-9;但是对于任何可能是大写或小写的东西,示例以及其他字母中的数字,例如(9)
Jonathan Allan

Answers:


9

Python 2 2,45个字节

-3个字节,感谢Rod。-2个字节,感谢ovs。

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

在线尝试!

正则表达式解决方案会更长。

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

6

Japt v2.0a0,20 16个字节

返回1有效还是0无效。对于相同的字节数[\l\d]也可以代替[^\W_]

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

试试吧 | 检查所有测试用例

说明è计算输入中RegEx的匹配数。在Japt中,\wRegEx类不包含下划线。


好东西。没有正则表达式,我能做的最好的就是;¥oB+mc)¯80 ©"VEVO"¥Ut4n
ETHproductions'Dec 21'17

@ETHproductions,一个不错的技巧B+mc:)顺便说一句,如果Japt2具有的字符类[A-Za-z0-9],我们可以在这里击败Retina!甚至可能是值得重写\w\W
毛茸茸的

嘿,我想我原本打算这样做的...我应该回到一般的Japt上工作​​:P
ETHproductions

4

JavaScript(ES6),27 36 34 31字节

@Neil节省了2个字节,@ Shaggy节省了3个字节

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

测试用例


2
也不\w匹配_s吗?
尼尔,

我认为((?!_)\w)可以节省2个字节。
尼尔,

1
[^\W_]一个工作3个字节保存
毛茸茸的

@Shaggy Heck. For some reason, I was thinking such characters classes were not working within character sets. Thanks!
Arnauld

Doesn't JS have any way of skipping the lambda? Like /^[^\W_]{0,76}VEVO$/.test or something?
totallyhuman

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!


1
Instead of <?php echo, you can do <?=preg_match("/^[^\W_]{0,76}VEVO$/",fgets(STDIN));.
Ismael Miguel

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." (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

1
Thanks as well, I have a few answers to update now!
NK1406

You're welcome. One advice: reading the documentation and getting familiar with it will help a lot.
Ismael Miguel


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!


I don't see any return statement, how does this return c? Undefined behavior?
MD XF

@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

that's very impressive. How did you find that out?
MD XF

sometimes f("VO" also be true, when before is "VI" stored; or maybe fault
l4m2

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

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}
Kritixi Lithos

@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

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.


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")

Wouldn't this fail if the input contains any non-alphanumeric characters?
Shaggy

@Shaggy You are right, will fix a bit later.
LiefdeWen

I have checked with TIO and found that input "ConnieTalbotVEVO" (which should be valid input) was falsely declared as invalid input.
Bagas Sanjaya

@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

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

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)


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

@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

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!


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

Okay, wasn't sure what sort of output (if any) was required. The question didn't really say.
Probably

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

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

@Shaggy The output is via exit code.
totallyhuman

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.


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

Thanks @Tealpelican. Fixed that and killed a few more bytes
Jo King

You are missing the check for characters between "Z" and "a".
Emigna

@Emigna Oops, thanks! Fixed!
Jo King

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


Where's TIO link at your answer? I'd like to test your code...
Bagas Sanjaya

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ý

There is an unneeded space after the comma
Zacharý

You can remove the comma the space after the comma.
Zacharý



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!





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

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.





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!


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

+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

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

Where's the closing bracket?
Bagas Sanjaya

@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

-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")))

Any TIO link for testing?
Bagas Sanjaya

@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

@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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.