Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 115 characters in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164

Python 2, (削除) 105 (削除ここまで) 95(削除) 95 (削除ここまで) 94 bytes

-10 bytes thanks to Kevin Cruijssen! (switch to Python 2)
-1 byte thanks to dingledooper !

Very inefficient, segfaults for \$ n \gtrsim 18500\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(`k`)==len(`n/k`)!=S<S(`k`+`n/k`)==S(`n`)))|f(n,k+1)

Try it online! Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(`k`) # the number of digits of k
 == len(`n/k`) # is equal to the number of digits of n//k
 != < S(`k`+`n/k`) # and sorting the digits of k and n//k 
 == S(`n`) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call

Python 2, (削除) 105 (削除ここまで) 95 bytes

-10 bytes thanks to Kevin Cruijssen! (switch to Python 2)

Very inefficient, segfaults for \$ n \gtrsim 18500\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(`k`)==len(`n/k`)!=S(`k`+`n/k`)==S(`n`)))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(`k`) # the number of digits of k
 == len(`n/k`) # is equal to the number of digits of n//k
 != S(`k`+`n/k`) # and sorting the digits of k and n//k 
 == S(`n`) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call

Python 2, (削除) 105 (削除ここまで) (削除) 95 (削除ここまで) 94 bytes

-10 bytes thanks to Kevin Cruijssen! (switch to Python 2)
-1 byte thanks to dingledooper !

Very inefficient, segfaults for \$ n \gtrsim 18500\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(`k`)==len(`n/k`)<S(`k`+`n/k`)==S(`n`)))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(`k`) # the number of digits of k
 == len(`n/k`) # is equal to the number of digits of n//k
  < S(`k`+`n/k`) # and sorting the digits of k and n//k 
 == S(`n`) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call
added 107 characters in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164

Python 3.8 Python 2, 105(削除) 105 (削除ここまで) 95 bytes

-10 bytes thanks to Kevin Cruijssen ! (switch to Python 2)

Very inefficient, segfaults for \$ n \gtrsim 13000\$\$ n \gtrsim 18500\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(a:=str(k)`k`)==len(b:=str(n/`n/k)k`)!=S(a+b`k`+`n/k`)==S(str(n)`n`)))|f(n,k+1)

Try it online! Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(a:=str(k)`k`) # the number of digits of k
 == len(b:=str(n/`n/k)k`) # is equal to the number of digits of n//k
 != S(a+b`k`+`n/k`) # and sorting the digits of k and n//k 
 == S(str(n)`n`) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call

Python 3.8, 105 bytes

Very inefficient, segfaults for \$ n \gtrsim 13000\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(a:=str(k))==len(b:=str(n//k))!=S(a+b)==S(str(n))))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(a:=str(k)) # the number of digits of k
 == len(b:=str(n//k)) # is equal to the number of digits of n//k
 != S(a+b) # and sorting the digits of k and n//k 
 == S(str(n)) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call

Python 2, (削除) 105 (削除ここまで) 95 bytes

-10 bytes thanks to Kevin Cruijssen ! (switch to Python 2)

Very inefficient, segfaults for \$ n \gtrsim 18500\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(`k`)==len(`n/k`)!=S(`k`+`n/k`)==S(`n`)))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(`k`) # the number of digits of k
 == len(`n/k`) # is equal to the number of digits of n//k
 != S(`k`+`n/k`) # and sorting the digits of k and n//k 
 == S(`n`) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call
edited body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164

Python 3.8, 105 bytes

Very inefficient, segfaults for \$ n \gtrsim 13000\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(a:=str(k))==len(b:=str(n//k))!=S(a+b)==S(str(n))))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(a:=str(k)) # the number of digits of k
 == len(b:=str(n//k)) # is equal to the number of digits of n//k
 != S(a+b) # and sorting the digits of nk and n//k 
 == S(str(n)) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call

Python 3.8, 105 bytes

Very inefficient, segfaults for \$ n \gtrsim 13000\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(a:=str(k))==len(b:=str(n//k))!=S(a+b)==S(str(n))))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(a:=str(k)) # the number of digits of k
 == len(b:=str(n//k)) # is equal to the number of digits of n//k
 != S(a+b) # and sorting the digits of n and n//k 
 == S(str(n)) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call

Python 3.8, 105 bytes

Very inefficient, segfaults for \$ n \gtrsim 13000\$ on TIO.

f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(a:=str(k))==len(b:=str(n//k))!=S(a+b)==S(str(n))))|f(n,k+1)

Try it online!

Commented:

f=lambda n,k=2,S=sorted # recursive function
 k<n # if k>=n return False
 and # otherwise:
 ( ... ) # long boolean expression which is True if k and n//k make n a valid vampire number
 k%10 # the last digit of k is 
 > n%k # larger than n%k which is
 < ( ... ) # less than another boolean expression
 # These two comparisons can only be satisfied with k%10>0<1
 len(a:=str(k)) # the number of digits of k
 == len(b:=str(n//k)) # is equal to the number of digits of n//k
 != S(a+b) # and sorting the digits of k and n//k 
 == S(str(n)) # results in the same list as sorting the digits of n
| f(n,k+1) # bitwise OR with result of the recursive call
added 934 characters in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164
Loading
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164
Loading

AltStyle によって変換されたページ (->オリジナル) /