Skip to main content
added 8 characters in body
Source Link
scrawl
  • 1.4k
  • 7
  • 14

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" / let our input be 12!!, assign to x q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)m -> [0,m) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

here also is a version in k (same logic), 424241 bytes

{*/2+&1_i=last i:("J"$x[&~"J"$x@&~:n]n)#!+/n:"!"=x} 

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" / let our input be 12!!, assign to x q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)m -> [0,m) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

here also is a version in k (same logic), 42 bytes

{*/2+&1_i=last i:("J"$x[&~:n])#!+/n:"!"=x} 

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" / let our input be 12!!, assign to x q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)m -> [0,m) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

here also is a version in k (same logic), 4241 bytes

{*/2+&1_i=last i:("J"$x@&~:n)#!+/n:"!"=x} 
added 141 characters in body
Source Link
scrawl
  • 1.4k
  • 7
  • 14

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" / let our input be 12!!, assign to x q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)nm -> [0,nm) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

here also is a version in k (same logic), 42 bytes

{*/2+&1_i=last i:("J"$x[&~:n])#!+/n:"!"=x} 

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)n -> [0,n) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" / let our input be 12!!, assign to x q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)m -> [0,m) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

here also is a version in k (same logic), 42 bytes

{*/2+&1_i=last i:("J"$x[&~:n])#!+/n:"!"=x} 
added 1 character in body
Source Link
scrawl
  • 1.4k
  • 7
  • 14

q, 59 57 55 5553 bytes

{prd 2+(&)1_(last1_i=last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)n -> [0,n) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

q, 59 57 55 bytes

{prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)n -> [0,n) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 

q, 59 57 55 53 bytes

{prd 2+(&)1_i=last i:("J"$x(&)not[n])#(!)sum n:"!"=x} 

explanation:

q)x:"12!!" q)sum n:"!"=x / count "!"s 2i q)(!)sum n:"!"=x / (!)n -> [0,n) 0 1 q)("J"$x(&)not[n]) / isolate the number in input 12 q)("J"$x(&)not[n])#(!)sum n:"!"=x / x#y means take x items from list y, if x>y, circle around 0 1 0 1 0 1 0 1 0 1 0 1 q)i:("J"$x(&)not[n])#(!)sum n:"!"=x / assign to i q)i 0 1 0 1 0 1 0 1 0 1 0 1 q)(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / take last elem of i and see which are equal in i 010101010101b q)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / drop first elem 10101010101b q)(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / indices of 1b (boolean TRUE) 0 2 4 6 8 10 q)2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / add 2 across array 2 4 6 8 10 12 q)prd 2+(&)1_(last i)=i:("J"$x(&)not[n])#(!)sum n:"!"=x / product across array 46080 
added explanation
Source Link
scrawl
  • 1.4k
  • 7
  • 14
Loading
Added code formatting
Source Link
Wheat Wizard
  • 102.9k
  • 23
  • 299
  • 698
Loading
added 1 character in body
Source Link
scrawl
  • 1.4k
  • 7
  • 14
Loading
added 8 characters in body
Source Link
scrawl
  • 1.4k
  • 7
  • 14
Loading
Source Link
scrawl
  • 1.4k
  • 7
  • 14
Loading