Skip to main content
Commonmark migration
Source Link

#Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 

#Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 

Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

#Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal DennisDennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A SimmonsA Simmons)

BitAnd[#-1,1-#]^2>#& 

#Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 

#Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 
added 8 characters in body
Source Link
Michael L.
  • 231
  • 1
  • 8

#Mathematica, 50 48 45 40 38 35 3131 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

f=1<#<4^IntegerExponent[#1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 

#Mathematica, 50 48 45 40 38 35 31 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

f=1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 

#Mathematica, 50 48 45 40 38 35 31 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]& 

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]] {3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993} 

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to 23 22 20 bytes.

#Mathematica, 23 22 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#& 
added 96 characters in body
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
added 215 characters in body
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
added 8 characters in body
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
Rollback to Revision 4
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
Rollback to Revision 3
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
[Edit removed during grace period]
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
added 8 characters in body
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
removed assignment of variable "a," shortened code
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
added 7 characters in body
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading
Source Link
Michael L.
  • 231
  • 1
  • 8
Loading