Perl, 173
Let me add another useless solution. This solution is so slow that it can't even output anything past the first weird number. I dare say it is the slowest of all the solution here.
$n=<>;$i=2;while($n){$b=qr/^(?=(.+)\1{2}$)((.+)(?=.*(?(2)(?=\2$)\3.+$|(?=\1$)\3.+$))(?=.*(?=\1$)\3+$))+/;$_='x'x3x$i;if(/$b/&&($+[0]>$i)&&!/$b\1{2}$/){print"$i\n";$n--}$i++}
Demo
The same code written in Java (which I am more comfortable with) can't even recognize the 2nd weird number (836), and I have already fed the number directly to the checking method (instead of looping and checking every number).
The core of this solution lies in the regex:
^(?=(.+)\1{2}$)((.+)(?=.*(?(2)(?=\2$)\3.+$|(?=\1$)\3.+$))(?=.*(?=\1$)\3+$))+
And how the string is set up to be 3 times the number that we are checking.
The length of the string is set up to be 3 times the number that we are checking i
: the first 2 i
is for matching summation of factors and the last 1 i
is reserved for checking whether a number is a factor of i
.
(?=(.+)\1{2}$)
is used to capture the number that we are checking.
((.+)(?=.*(?(2)(?=\2$)\3.+$|(?=\1$)\3.+$))(?=.*(?=\1$)\3+$))+
matches the factors of the number. Later iteration will match a smaller factor than an earlier iteration.
- We can see that these 2 parts
(.+)
and (?=.*(?=\1$)\3+$)
together selects a factor of the number being checked.
(?=.*(?(2)(?=\2$)\3.+$|(?=\1$)\3.+$))
makes sure that the factor selected is smaller than the number being checked in the first iteration, and is smaller than previous factor in subsequent iterations.
The regex tries to match as many factors of the number as it can within the limit of 2 i
. But we don't care about the actual value of sum of divisors, we only care whether the number is abundant.
Then the 2nd regex, which is the first regex with \1{2}$
added. As a result, the regex makes sure the sum of (some) factors of the number being checked is equal to the number itself:
^(?=(.+)\1{2}$)((.+)(?=.*(?(2)(?=\2$)\3.+$|(?=\1$)\3.+$))(?=.*(?=\1$)\3+$))+\1{2}$
The constraint added will cause the regex engine to perform a backtracking search on all possible subsets of factors, so it is going to be extremely slow.