10
\$\begingroup\$

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)

\$\endgroup\$
8
  • \$\begingroup\$ @KrystosTheOverlord The term is defined in this challenge itself. ;-P \$\endgroup\$ Feb 13, 2019 at 13:36
  • 9
    \$\begingroup\$ Aw, I was expecting some chess logic password rules… \$\endgroup\$
    – Bergi
    Feb 13, 2019 at 17:29
  • 1
    \$\begingroup\$ I read through all the answers and not one claimed the bonus. \$\endgroup\$
    – Veskah
    Feb 13, 2019 at 21:29
  • 1
    \$\begingroup\$ @JDL you really get to substract 0 bytes from your score if you qualify for this very real bonus! What are you waiting for? \$\endgroup\$
    – Aaron
    Feb 14, 2019 at 10:24
  • 1
    \$\begingroup\$ One of your criteria is actually the reverse of what Bishop (2013) proposed. He proposed that passwords must be 10 characters or less, not more. \$\endgroup\$
    – PyRulez
    Feb 17, 2019 at 3:39

24 Answers 24

5
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Choo choo! \$\endgroup\$ Feb 13, 2019 at 14:08
  • \$\begingroup\$ @EriktheOutgolfer Thanks:) \$\endgroup\$
    – TFeld
    Feb 13, 2019 at 15:52
  • \$\begingroup\$ You can do the length check as s[:9]<s, which combines well with the non-palindrome check: s[:9]<s!=s[::-1] \$\endgroup\$
    – xnor
    Feb 14, 2019 at 1:18
4
\$\begingroup\$

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)
\$\endgroup\$
4
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Dang! Should've checked the solutions before starting my own! 14 bytes \$\endgroup\$
    – Shaggy
    Feb 13, 2019 at 14:47
4
\$\begingroup\$

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)
\$\endgroup\$
11
  • \$\begingroup\$ 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) \$\endgroup\$
    – JDL
    Feb 14, 2019 at 9:05
  • 1
    \$\begingroup\$ actually, 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. \$\endgroup\$
    – JDL
    Feb 14, 2019 at 9:08
  • 2
    \$\begingroup\$ 62 bytes using utf8ToInt \$\endgroup\$
    – digEmAll
    Feb 14, 2019 at 18:58
  • 1
    \$\begingroup\$ @digEmAll your example returns true when there is only one number, you will need to include a >2 \$\endgroup\$ Feb 15, 2019 at 9:46
  • 1
    \$\begingroup\$ 64 but correct ;) \$\endgroup\$
    – digEmAll
    Feb 15, 2019 at 9:52
3
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ @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. \$\endgroup\$
    – Graham
    Feb 14, 2019 at 10:47
  • \$\begingroup\$ Do you have which is ~? And even if you don't, you can merge ×~ into > \$\endgroup\$
    – Adám
    Feb 14, 2019 at 11:25
  • \$\begingroup\$ @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 ;) \$\endgroup\$
    – Graham
    Feb 14, 2019 at 13:03
3
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ {∋.∈Ị∧}ᶜ can be {∋ị}ᶜ \$\endgroup\$
    – Kroppeb
    Feb 14, 2019 at 0:07
  • \$\begingroup\$ Putting the "not palindrome" clause first, and changing the way to select digits, you can save 6 bytes: ¬↔?l>9&ịˢl>2 \$\endgroup\$
    – Fatalize
    Feb 14, 2019 at 8:03
  • \$\begingroup\$ @Kroppeb Oh, interesting! I didn't consider , but it makes sense that it would succeed iff the character is a digit. Thanks! \$\endgroup\$
    – DLosc
    Feb 14, 2019 at 19:09
  • \$\begingroup\$ @Fatalize Aha--reusing the ? like that is neat. Thanks! \$\endgroup\$
    – DLosc
    Feb 14, 2019 at 19:11
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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)
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
0
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

APL (Dyalog Unicode), 25 bytesSBCS

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

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Good. 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. \$\endgroup\$
    – Adám
    Feb 15, 2019 at 9:32
1
\$\begingroup\$

Perl 5 -p, 33 bytes

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

TIO

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

K (oK), 31 28 bytes

-3 bytes thanks to ngn!

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

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ you could use +// (sum until convergence) instead of +/+/ (sum sum) \$\endgroup\$
    – ngn
    Feb 20, 2019 at 21:54
  • 1
    \$\begingroup\$ alternatively, 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) \$\endgroup\$
    – ngn
    Feb 20, 2019 at 22:04
  • 1
    \$\begingroup\$ one more thing, > (or <) can be used as "and not": {(x~|x)<(2<#x^x^/$!10)*9<#x} \$\endgroup\$
    – ngn
    Feb 20, 2019 at 22:09
  • \$\begingroup\$ @ngn Thank you! Nice way to find the intersection! \$\endgroup\$ Feb 21, 2019 at 7:42
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

Stax, 14 bytes

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

Run and debug it

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

Groovy, (47 bytes)

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

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.