Password Bishop Goodness

10

Derived from this, now deleted, post.

Given a string, answer (truthy/falsy or two consistent values) if it constitutes a good Bishop password, which is when all the following conditions are met:

  1. it has at least 10 characters

  2. it has at least 3 digits ([0-9])

  3. it is not a palindrome (identical to itself when reversed)

You get 0 bytes bonus if your code is a good Bishop password.

Warning: Do not use Bishop goodness as a measure of actual password strength!

Examples

Good Bishop passwords

PPCG123GCPP
PPCG123PPCG
PPCG123gcpp
0123456789
Tr0ub4dor&3

Not Good Bishop passwords

PPCG123 (too short)
correct horse battery staple (not enough digits)
PPCG121GCPP (palindrome)
 (too short and not enough digits)
abc121cba (too short and palindrome)
aaaaaaaaaaaa (palindrome and not enough digits)
abc99cba (everything wrong)

Adám

Posted 2019-02-13T13:15:51.103

Reputation: 37 779

@KrystosTheOverlord The term is defined in this challenge itself. ;-P – Erik the Outgolfer – 2019-02-13T13:36:15.113

9Aw, I was expecting some chess logic password rules… – Bergi – 2019-02-13T17:29:47.970

1I read through all the answers and not one claimed the bonus. – Veskah – 2019-02-13T21:29:14.853

"You get 0 bytes bonus if your code is a good Bishop password" — this confuses me. Is it a real bonus or not? – JDL – 2019-02-14T09:01:34.563

1@JDL you really get to substract 0 bytes from your score if you qualify for this very real bonus! What are you waiting for? – Aaron – 2019-02-14T10:24:29.497

surely it would be far harder to write a legitimate solution that wasn't a good Bishop password (though I suppose you could add a comment at the end to make it into a palindrome) – JDL – 2019-02-14T11:43:52.123

1One of your criteria is actually the reverse of what Bishop (2013) proposed. He proposed that passwords must be 10 characters or less, not more. – PyRulez – 2019-02-17T03:39:38.340

Are you telling me correct horse battery staple is not a good password? /s

– Benjamin Urquhart – 2019-03-22T23:49:42.387

Answers

5

Python 2, 61 59 54 51 bytes

lambda s:sum(map(str.isdigit,s))>2<s[:9]<s<>s[::-1]

Try it online!

-5 bytes, thanks to Erik the Outgolfer
-3 bytes, thanks to xnor

TFeld

Posted 2019-02-13T13:15:51.103

Reputation: 19 246

Choo choo! – Erik the Outgolfer – 2019-02-13T14:08:45.543

@EriktheOutgolfer Thanks:) – TFeld – 2019-02-13T15:52:43.743

You can do the length check as s[:9]<s, which combines well with the non-palindrome check: s[:9]<s!=s[::-1] – xnor – 2019-02-14T01:18:16.547

@xnor Thanks :) – TFeld – 2019-02-14T07:50:25.463

4

Japt, 17 14 bytes

ʨA&U¦Ô&3§Uè\d

-3 bytes rearranged by @Shaggy

Try it online!


Japt, 15 bytes (0 Bytes Bonus :v)

ʨ10&U¦Ô&3§Uè\d

Try it online!

Luis felipe De jesus Munoz

Posted 2019-02-13T13:15:51.103

Reputation: 9 639

1

Dang! Should've checked the solutions before starting my own! 14 bytes

– Shaggy – 2019-02-13T14:47:19.793

4

05AB1E, 12 bytes

gT@Iþg3@IÂÊP

Try it online or verify all test cases.

Explanation:

g      # Get the length of the (implicit) input
 T@    # Check if this length >= 10
Iþ     # Get the input and only leave the digits
  g    # Then get the length (amount of digits)
   3@  # And check if the amount of digits >= 3
IÂ     # Get the input and the input reversed
  Ê    # Check if they are not equal (so not a palindrome)
P      # Check if all three above are truthy (and output implicitly)

Kevin Cruijssen

Posted 2019-02-13T13:15:51.103

Reputation: 67 575

4

R, 80 70 62 64 63 bytes

any(rev(U<-utf8ToInt(scan(,'')))<U)&sum(U>47&U<58)>2&sum(U|1)>9

Try it online!

From digEmAll, and some rearranging too

sum((s<-el(strsplit(scan(,''),"")))%in%0:9)>2&!all(s==rev(s))&s[10]>''

Try it online!

Pretty straightforward, no real amazing tricks here. After user inputs string:

  • Separates and searches the string for more than 2 numbers. (3 or more digits)
  • Checks if not all elements are equal to the reversed version of the string (palindrome)
  • Checks that length is greater than 9 (10 or more characters)

Sumner18

Posted 2019-02-13T13:15:51.103

Reputation: 1 334

I think you can replace !all(s==rev(s)) with any(s!=rev(s)) which will save one byte. I feel like the length check can be reduced too, but not sure how (either nchar or some kind of sum(x|1) hack) – JDL – 2019-02-14T09:05:55.643

1actually, I think any(s>rev(s)) will work --- if a character is less than its palindromic counterpart, then at the other end of the password the converse will be true. That saves another byte. – JDL – 2019-02-14T09:08:07.557

can use grepl() instead of grep()|1 to save 1 byte, or better use ()%in%0:9 – Aaron Hayman – 2019-02-14T15:35:09.420

instead of length(s)>9 you could use s[10]>''. it will return TRUE if there is a tenth element, and NA (which is falsy) if there is no tenth element. – Aaron Hayman – 2019-02-14T15:59:19.973

262 bytes using utf8ToInt – digEmAll – 2019-02-14T18:58:53.627

1@digEmAll your example returns true when there is only one number, you will need to include a >2 – Aaron Hayman – 2019-02-15T09:46:59.017

@AaronHayman: you're right, I should have erroneously deleted it – digEmAll – 2019-02-15T09:51:03.477

164 but correct ;) – digEmAll – 2019-02-15T09:52:22.120

You can still get it to 61 using U[10]>0 instead of sum(U|1)>9, but maybe returning NA instead of FALSE is ugly – Aaron Hayman – 2019-02-15T09:54:43.290

@AaronHayman: the problem is not returning NA, but that sometime it will return FALSE and sometime NA, depending on the condition not met. As far as I know one can return any thruthy/falsy value as long as they're consistent – digEmAll – 2019-02-16T16:45:35.907

63 with some rearrangement – MickyT – 2019-02-18T23:59:08.477

3

Brachylog, 18 12 bytes

Thanks for the tips, Kroppeb and Fatalize!

¬↔?l>9&ịˢl>2

Try it online!

Explanation

The program is a single predicate, composed of two parts that are chained with &.

First:

¬       The following assertion must fail:
 ↔        The input reversed
  ?       can be unified with the input
        Also, the input's
   l    length
    >9  must be greater than 9

Second:

 ˢ     Get all outputs from applying the following to each character in the input:
ị        Convert to number
       This gives an integer for a digit character and fails for a non-digit, so
       we now have a list containing one integer for each digit in the password
  l    Its length
   >2  must be greater than 2

DLosc

Posted 2019-02-13T13:15:51.103

Reputation: 21 213

{∋.∈Ị∧}ᶜ can be {∋ị}ᶜ – Kroppeb – 2019-02-14T00:07:58.543

Putting the "not palindrome" clause first, and changing the way to select digits, you can save 6 bytes: ¬↔?l>9&ịˢl>2

– Fatalize – 2019-02-14T08:03:33.793

@Kroppeb Oh, interesting! I didn't consider , but it makes sense that it would succeed iff the character is a digit. Thanks! – DLosc – 2019-02-14T19:09:00.090

@Fatalize Aha--reusing the ? like that is neat. Thanks! – DLosc – 2019-02-14T19:11:08.857

3

APL+WIN, 36, 30 29 bytes

7 bytes saved thank to Adám

Index origin = 0

Prompts for input string

(10≤⍴v)×(3≤+/v∊∊⍕¨⍳10)>v≡⌽v←⎕

Try it online! Courtesy of Dyalog Classic

Explanation:

(10≤⍴v) Length test pass 1 fail 0

(3≤+/v∊∊⍕¨⍳10) Number of digits test

>v≡⌽v Palindrome test

The code also qualifies for the bonus as it is a good Bishop password.

Graham

Posted 2019-02-13T13:15:51.103

Reputation: 3 184

@Adám. Thanks for saving 6 bytes. On ⎕IO agreed. v≡⌽v works fine if I prepend ~. As to use of x I tend to use it when stringing together boolean tests. Same result same number of bytes. – Graham – 2019-02-14T10:47:05.130

Do you have which is ~? And even if you don't, you can merge ×~ into > – Adám – 2019-02-14T11:25:09.330

@Adám No I do not have ≢. I can merge ×~ into > for one more byte. Thanks. I am afraid my "putting game" still needs more practice ;) – Graham – 2019-02-14T13:03:15.920

2

Jelly, 12 bytes

~Tṫ3ȧL9<Ɗ>ṚƑ

Try it online!

[] if not enough digits (empty list, falsy), 0 if otherwise bad (zero, falsy), 1 if good (nonzero, truthy).

Erik the Outgolfer

Posted 2019-02-13T13:15:51.103

Reputation: 38 134

2

Java 8, 92 bytes

s->s.length()>9&s.replaceAll("\\D","").length()>2&!s.contains(new StringBuffer(s).reverse())

Try it online.

Explanation:

s->                        // Method with String parameter and boolean return-type
  s.length()>9             //  Check if the length of the input-String is more than 9
  &s.replaceAll("\\D","")  //  AND: remove all non-digits from the input-String
    .length()>2            //       and check if the amount of digits is more than 2
  &!s.contains(new StringBuffer(s).reverse())
                           //  AND: check if the input-String does NOT have the reversed
                           //       input-String as substring (and thus is not a palindrome)

Kevin Cruijssen

Posted 2019-02-13T13:15:51.103

Reputation: 67 575

2

JavaScript, 60 56 46 bytes

Takes input as an array of characters. Outputs 1 for truthy and 0 for falsey.

s=>/(\d.*){3}/.test(s[9]&&s)&s+``!=s.reverse()

Try It Online!

Saved 10 bytes(!) thanks to Arnauld.

Shaggy

Posted 2019-02-13T13:15:51.103

Reputation: 24 623

2

Racket, 122 bytes

(define(d s)(let([t(string->list s)])(and(< 2(length(filter char-numeric? t)))(< 9(length t))(not(equal? t(reverse t))))))

Try it online!

Galen Ivanov

Posted 2019-02-13T13:15:51.103

Reputation: 13 815

2

APL (Dyalog Unicode), 25 bytesSBCS

{∧/(9<≢⍵)(3≤+/⍵∊⎕D),⍵≢⌽⍵}

Try it online!

voidhawk

Posted 2019-02-13T13:15:51.103

Reputation: 1 796

1Good. Now you can golf it by making it into a train: (9<≢)∧(3≤1⊥∊∘⎕D)∧⊢≢⌽ and then save one more byte by rearranging to avoid parens: (9<≢)∧≢∘⌽⍨∧3≤1⊥∊∘⎕D Let em know if you need explanation of these steps. – Adám – 2019-02-15T09:32:31.573

1

Perl 6, 32 bytes

{$_ ne.flip&&m:g/\d/>2&&.comb>9}

Try it online!

Anonymous code block that simply enforces that all the rules are complied with.

Explanation:

{          &&         &&       }  # Anonymous code block
 $_ ne.flip                       # Input is not equal to its reverse
             m:g/\d/>2            # There are more than two digits
                        .comb>9   # There are more than 9 characters

Jo King

Posted 2019-02-13T13:15:51.103

Reputation: 38 234

1

Red, 117 111 bytes

func[s][d: charset"0123456789"n: 0 parse s[any[d(n: n + 1)|
skip]]all[n > 2 9 < length? s s <> reverse copy s]]

Try it online!

Galen Ivanov

Posted 2019-02-13T13:15:51.103

Reputation: 13 815

1

Perl 5 -p, 33 bytes

$_=/.{10}/&y/0-9//>2&reverse ne$_

TIO

Nahuel Fouilleul

Posted 2019-02-13T13:15:51.103

Reputation: 5 582

1

K (oK), 31 28 bytes

-3 bytes thanks to ngn!

{(x~|x)<(2<#x^x^/$!10)*9<#x}

Try it online!

Galen Ivanov

Posted 2019-02-13T13:15:51.103

Reputation: 13 815

1you could use +// (sum until convergence) instead of +/+/ (sum sum) – ngn – 2019-02-20T21:54:58.793

1alternatively, you could use x^x^y to find the intersection between two lists: #x^x^,/!10. this can be shortened to #x^x^/!10 (^ is "without", x^/... is ^-reduction with initial value x) – ngn – 2019-02-20T22:04:11.897

1one more thing, > (or <) can be used as "and not": {(x~|x)<(2<#x^x^/$!10)*9<#x} – ngn – 2019-02-20T22:09:17.610

@ngn Thank you! Nice way to find the intersection! – Galen Ivanov – 2019-02-21T07:42:54.323

1

Clean, 66 bytes

import StdEnv
$s=s<>reverse s&&s%(0,8)<s&&sum[1\\c<-s|isDigit c]>2

Try it online!

  • s<>reverse s: s is not a palindrome
  • s%%(0,8)<s: the first 9 characters of s are less than all of s
  • sum[1\\c<-s|isDigit c]>2: s has more than two digits

Οurous

Posted 2019-02-13T13:15:51.103

Reputation: 7 916

1

Retina 0.8.2, 40 bytes

G`.{10}
G`(\d.*){3}
+`^(.)(.*)\1$
$2
^..

Try it online! Link includes test cases. Explanation:

G`.{10}

Checks for at least 10 characters.

G`(\d.*){3}

Checks for at least 3 digits.

+`^(.)(.*)\1$
$2

Remove the first and last character if they match.

^..

If there are at least 2 characters then it wasn't a palindrome.

.NET's balancing groups mean that this can be done in a single regular expression, but that takes 47 bytes:

^(?!(.)*.?(?<-1>\1)*$(?(1).))(?=.{10})(.*\d){3}

Try it online! Link includes test cases.

Neil

Posted 2019-02-13T13:15:51.103

Reputation: 95 035

1

Python 3, 74 72 64 bytes

Thanks Neil A. for -2 bytes!
Thanks Jo King for -8 bytes!

lambda s:s[9:]and re.findall('\d',s)[2:]and s[::-1]!=s
import re

Explanation:

lambda s: # Create lambda                                          
           s[9:] # Check if the string is at least 10 characters long                                 
                     and re.findall('\d',s)[2:] #Check for at least 3 matches of the regex \d (which matches all digits)
                     and s[::-1] != s # Check if the string reversed is equal to the string (palindrome test)
import re  # Import regex module

Try it online!

Epicness

Posted 2019-02-13T13:15:51.103

Reputation: 81

-2 bytes by shifting the parentheses around – Neil A. – 2019-02-14T05:31:53.570

0

JavaScript (Node.js), 70 bytes

a=>a.length>9&(a.match(/\d/g)||[]).length>2&a!=[...a].reverse().join``

Try it online!

Returns 1 for true and 0 for false

T. Dirks

Posted 2019-02-13T13:15:51.103

Reputation: 176

0

C# (Visual C# Interactive Compiler), 67 bytes

n=>n.Count(char.IsDigit)>2&!n.Reverse().SequenceEqual(n)&n.Length>9

Try it online!

Embodiment of Ignorance

Posted 2019-02-13T13:15:51.103

Reputation: 7 014

0

Pip, 19 bytes

#a>9&XD Na>2&aNERVa

Try it online! (all test cases)

Explanation

With a being the first command-line argument:

#a > 9      Length of a is greater than 9
&           and
XD N a > 2  Number of matches of regex [0-9] iN a is greater than 2
&           and
a NE RV a   a is not (string-)equal to reverse of a

DLosc

Posted 2019-02-13T13:15:51.103

Reputation: 21 213

0

Stax, 14 bytes

ûc╖»¬ë⌂╓âó╗cCé

Run and debug it

recursive

Posted 2019-02-13T13:15:51.103

Reputation: 8 616

0

Pyth, 17 bytes

&&<2l@`MTQ<9lQ!_I

Try it online here, or verify all the test cases at once here.

&&<2l@`MTQ<9lQ!_IQ   Implicit: Q=eval(input()), T=10
                     Trailing Q inferred
      `MT            [0-10), as strings
     @   Q           Take characters from input which are in the above
    l                Length
  <2                 Is the above greater than 2?
            lQ       Length of Q
          <9         Is the above greater than 9?
               _IQ   Is Q unchanged after reversal?
              !      Logical NOT
&&                   Logical AND the three results together

Sok

Posted 2019-02-13T13:15:51.103

Reputation: 5 592

0

Groovy, (47 bytes)

{p->p=~/.{10}/&&p=~/(\d.*){3}/&&p!=p.reverse()}

(Bonus inclusion is left as an exercise to the reader)

randomsimon

Posted 2019-02-13T13:15:51.103

Reputation: 151