Timeline for Find the next number in the pattern
Current License: CC BY-SA 3.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 20, 2014 at 2:57 | vote | accept | vero | ||
| Sep 23, 2014 at 4:50 | |||||
| Sep 19, 2014 at 20:01 | comment | added | xnor | @flornquake Thanks, I see. To be more specific, the if/else to and/or conversion always gives the same value if it evaluates, but has slightly different short-circuiting behavior. When b is Truthy and a is Falsey, c is evaluated though its value doesn't matter. | |
| Sep 19, 2014 at 10:58 | history | edited | Will | CC BY-SA 3.0 | added 96 characters in body |
| Sep 19, 2014 at 10:56 | comment | added | Will | @flornquake oooh thx of course! | |
| Sep 19, 2014 at 10:48 | comment | added | flornquake | It think k==j*j==j*i*i should work in place of (j==i*i)&(k==j*j). | |
| Sep 19, 2014 at 10:43 | comment | added | flornquake | @xnor It doesn't work because the a if b else c-to-b and a or c trick relies on a being truthy. | |
| Sep 19, 2014 at 9:18 | comment | added | Will | @xnor thx that was neat :) | |
| Sep 19, 2014 at 9:16 | history | edited | Will | CC BY-SA 3.0 | added 80 characters in body |
| Sep 19, 2014 at 9:11 | comment | added | xnor | Weird, that seems totally right, I have no idea why the behavior changes. I'll have to figure that out. The switched version works though: q=lambda i,j,k,l,m:j-i!=k-j and((j==i*i)&(k==j*j)and m*m or m*l/k)or m+j-i | |
| Sep 19, 2014 at 9:06 | history | edited | Will | CC BY-SA 3.0 | better test code |
| Sep 19, 2014 at 9:05 | comment | added | Will | @xnor q=lambda i,j,k,l,m:j-i==k-j and m+j-i or(j==i*i)&(k==j*j)and m*m or m*l/k is how I wrote it. | |
| Sep 19, 2014 at 9:04 | comment | added | xnor | Hmm, I think and/or should just work, independent of the truthiness of the output. Let's try to fix it. Can you check that you converted a if b else c to b and a or c? And also that the two of it are nested right and perhaps parenthesized to parse right? If it still doesn't work, could you please tell me what you have. | |
| Sep 19, 2014 at 8:59 | comment | added | Will | @xnor thx for the encouragement and leads :) I don't really want to take advantage of holes in the test cases. And the I didn't know that neat and/or trick! But its not applicable for this particular problem because the correct prediction may be falsy, e.g. -10, -8, -6, -4, -2, 0. Still neat to learn. | |
| Sep 19, 2014 at 8:57 | history | edited | Will | CC BY-SA 3.0 | silly omission |
| Sep 19, 2014 at 8:56 | comment | added | xnor | I had deleted my suggestion of k==j*j==i**4 on realizing it fails for 1, -1, 1, -1, 1, -1, but it turns out you can dodge it by using j,k,l instead, which changes the parity. I assume it's allowed to take advantage of a coincidental hole in the test cases? | |
| Sep 19, 2014 at 8:33 | comment | added | xnor | You can usually save chars from the if/else ternany operator using the and/or trick: codegolf.stackexchange.com/a/57/20260 | |
| Sep 19, 2014 at 8:10 | history | answered | Will | CC BY-SA 3.0 |