Puzzle of the day

sorex

Expert
Licensed User
Longtime User
If I moved them 2 by 2, or 3 by 3, or 4 by 4, or 5 by 5, or 6 by 6, then there's always 1 left.

you'll need

B4X:
n(i-2) = nrstart mod (i*i)

I guess
 

udg

Expert
Licensed User
Longtime User
Both @Jorge M A and @ilan shouldn't the increment be done in steps of 7 since we know beforehand that precedings values won't be multiples of it?
We will test 301, 308, 315... instead of 301,302,303...308,309..315..
We could optimize further, but probably it will be negligible compared to mod operator.
 

ilan

Expert
Licensed User
Longtime User
Both @Jorge M A and @ilan shouldn't the increment be done in steps of 7 since we know beforehand that precedings values won't be multiples of it?
We will test 301, 308, 315... instead of 301,302,303...308,309..315..
We could optimize further, but probably it will be negligible compared to mod operator.

sure you are right and the code can be very much optimized but as LucaMS already wrote we are not creating a project we want to get the answer. if i will look at the code and try to optimize it i will find lot of thing that can be done and 1 of them is your advice.
 

udg

Expert
Licensed User
Longtime User
I agree. I'd like to see the math formula that leads to 301 as the first valid result.
 

udg

Expert
Licensed User
Longtime User
Isn't it the original challenge?
find the smallest divisor of 7 which is not divisor of 2,3,4,5,6
I read it that way, but I could be wrong
 

JordiCP

Expert
Licensed User
Longtime User
I agree. I'd like to see the math formula that leads to 301 as the first valid result.
It's not a single formula directly deduced from the problem, but obtained as the solution of a set of equations. Just in case someone likes recreational maths :)
  • Each of the first conditions can be rewritten this way:
    • If I moved them 2 by 2, there's always one left --> eggs = k1*2 +1, for some k1
    • if I moved them 3 by 3, there's always one left --> eggs = k2*3+1, for some k2
    • ..... 4 by 4 ..... ---> eggs = k3*4+1, for some k3
    • ...
Joining them all (from 2 to 6), we can say eggs = k * lcm(2,3,4,5,6) + 1, where lcm is the least common multiple​
, so eggs = k*60 +1, for some k (if we only take the 2,3,4,5,6 conditions)​

  • But this number must still hold a second condition that is divisibility by 7, so we write:
eggs = k*60 + 1 = 0 (mod 7) ---> This means that k*60 = (6 mod 7) --> or, equivalently, k*(60 mod 7) = 6 (mod 7) --> k * 4 = 6 (mod 7)​
If we test with values of k from 0 to 6 (it will be ciclic for k + n*7) --> we have that k = 5 + n*7 , for every n>=0​
So, eggs = (5+ n*7)*60 + 1 --> grouping terms, eggs = 301 + n*420 ---> being the first result (when n=0) 301
 

sorex

Expert
Licensed User
Longtime User
why do I keep seeing 301 as the valid result? it isn't as I mentioned several times before.
it clearly states that fetching is done as equal x by y grids/sets and not just by x

B4X:
For x=2 To 7
    Log($"301 ${x} ${301 Mod (x*x)}"$)
Next

For x=2 To 7
    Log($"61201 ${x} ${61201 Mod (x*x)}"$)
Next

301 2 1
301 3 4
301 4 13
301 5 1
301 6 13
301 7 7
61201 2 1
61201 3 1
61201 4 1
61201 5 1
61201 6 1
61201 7 0
 

JordiCP

Expert
Licensed User
Longtime User
why do I keep seeing 301 as the valid result? it isn't as I mentioned several times before.
I think it is a translation issue.
With "2 by 2" I understand "2 each time".
If we interpret if as "2 multiplied by 2", then you are right ;)
 

sorex

Expert
Licensed User
Longtime User
well, if you say remove them by 2, by 3, by 4 or per 2, per 3, per 4 then it's 2,3,4.

2 by 2 is 4 and she'll need a container instead of a basket ;)
 
Top