March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,74 @@
SetBatchLines -1 ; used to improve performance
; (you can make it much faster by removing the informative tooltips)
;********************
; CONFIG
;********************
StartingNumber := 10
NumberLimit := 126030
CounterLimit := 25 ; calculations stop when one of these limits is reached
AdditionalNumbers := "16758243290880,24959017348650,14593825548650"
;********************
CurrentCounter := 0, CurrentNumber := StartingNumber
Loop {
if !Mod(A_Index,75) ; informative tooltip (every 75 calculations, to avoid slowing down)
ToolTip, % "Checking numbers...`nNumber: " CurrentNumber
. "/" NumberLimit "`nFound: " CurrentCounter "/" CounterLimit
if ( CurrentCounter >= CounterLimit ) || ( CurrentNumber >= NumberLimit )
Break
if Mod(StrLen(CurrentNumber),2)
CurrentNumber *= 10
else if ( ( CurrentResult := GetFangs(CurrentNumber) ) <> "" )
Output .= "`n" CurrentNumber ":`t" CurrentResult, CurrentCounter++
CurrentNumber++
}
ToolTip ; hide informative tooltip
MsgBox % SubStr(Output,2) ; show output (first part)
Output := ""
Loop, Parse, AdditionalNumbers, % ","
{
ToolTip, % "Getting fangs for " A_LoopField " ..." ; informative tooltip
Output .= "`n" A_LoopField ":`n`t" GetFangs(A_LoopField) "`n"
}
ToolTip ; hide informative tooltip
MsgBox % SubStr(Output,2) ; show output (second part - additional numbers)
ExitApp
;----------------------------------------------------------------------------------
CharSorter(Input) { ; required by GetFangs()
Loop, Parse, Input
Output .= A_LoopField "`n"
Sort, Output
StringReplace, Output, Output, % "`n",, All
Return Output
}
;----------------------------------------------------------------------------------
GetFangs(CurrentNumber) { ; requires CharSorter()
ResultIndex := 1
Length := StrLen(CurrentNumber)
Power := (Length//2)-1
if Mod(Length,2) OR !Power
Return ""
NumberLimit := Floor(Sqrt(CurrentNumber))
Lower := 10 ** Power
Loop, % NumberLimit - Lower {
if !Mod(CurrentNumber,Lower) {
FactorTwo := CurrentNumber//Lower
if ( !Mod(Lower,10) && !Mod(FactorTwo,10) )
Return ""
Check := CharSorter( Lower . FactorTwo )
if (CharSorter(CurrentNumber) = Check) && (StrLen(Lower) = StrLen(FactorTwo))
Output .= "`n`t[" Lower "," FactorTwo "]"
}
Lower++
}
Return SubStr(Output,3) ; 3 = 1 + length of "`n`t"
}

View file

@ -3,7 +3,7 @@ import std.stdio, std.math, std.algorithm, std.array, std.traits;
T[N] pows(T, size_t N)() {
typeof(return) result;
result[0] = 1;
foreach (i, ref r; result[1 .. $])
foreach (immutable i, ref r; result[1 .. $])
r = result[i] * 10;
return result;
}
@ -42,7 +42,7 @@ pure nothrow if (is(T == uint) || is(T == ulong)) {
immutable lo = max(tenPows[nd - 1],
(x + tenPows[nd] - 2) / (tenPows[nd] - 1));
immutable hi = min(x / lo, cast(T)sqrt(cast(real)x));
immutable hi = min(x / lo, cast(T)sqrt(real(x)));
immutable t = x.dTally;
size_t n = 0;

View file

@ -1,3 +1,5 @@
from __future__ import division
import math
from operator import mul
from itertools import product
@ -54,7 +56,7 @@ def divisors(n):
def vampire(n):
fangsets = set( frozenset([d, n//d])
for d in divisors(n)
if (len(str(d)) == len(str(n))/2
if (len(str(d)) == len(str(n))/2.
and sorted(str(d) + str(n//d)) == sorted(str(n))
and (str(d)[-1] == 0) + (str(n//d)[-1] == 0) <=1) )
return sorted(tuple(sorted(fangs)) for fangs in fangsets)