2
1
the question is "complete this subtraction by replacing the asterisks with digits so the numbers 1-9 only appear once each"
9**
-*4*
____
**1
my code tries random numbers until it works, and displays the answer. here is the entire html app. I want one to fit in a tweet at 140 characters (not counting tags)
<script>
function r(){return Math.random()*9+1^0}
do{a=900+r()*10+r(),b=r()*100+40+r(),c=a-b,s=''+a+b+c
}while(c%10!=1||eval('for(i=0;i++<9;)if(s.indexOf(i)<0)1'))alert(s)
</script>
Is there any way to make this shorter, including with a different solution?
SOLVED!: Thanks Peter, Shmiddty and copy, currently I have 91 chars!
for(x=1;++x<999;)for(y=1;y<x;)/(?!.*0|.*(.).*\1)9...4...1/.test(s=''+x+y+(x-y++))&&alert(s)
I'm thinking there must be a better way to check if it has each of the numbers 1-9 – AwokeKnowing – 2013-03-01T18:03:38.867