Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Determine whether an integer is square-free

Parent

Determine whether an integer is square-free

+7
−0

An integer is called square-free if it is not a multiple of a perfect square other than 1. For example, 42 is square-free, but 44 is not because it is a multiple of the perfect square 4 = 2².

Your task is to write a program or function that takes a positive integer, and returns a truthy value if the integer is square-free and a falsey value otherwise.

This is code golf, the shortest code wins.

The square-free numbers are OEIS sequence A005117 (thanks to Razetime for pointing this out).

Some test cases:

  1  true
  2  true
  3  true
  4  false
  5  true
  6  true
  7  true
  8  false
  9  false
 10  true
 12  false
 14  true
 16  false
 18  false
 20  false
 30  true
 40  false
 50  false
100  false
110  true
111  true
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Testcases? (2 comments)
[relevant oeis](http://oeis.org/A005117) (2 comments)
Post
+1
−0

Myby, 12 5 bytes

primf=primfd
primf        : prime factors
     =       : equals
      primfd : unique prime factors

Evaluated as a monadic fork in J (f y) g (h y).

The test cases (retested) can be viewed here and were generated using this ruby script.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

How is this 5 bytes? I count 12 letters, each of which requires one byte. (2 comments)
How is this 5 bytes? I count 12 letters, each of which requires one byte.
celtschk‭ wrote over 2 years ago

How is this 5 bytes?

I count 12 letters, each of which requires one byte.

Conor O'Brien‭ wrote over 2 years ago

Myby uses a "Literate Mode" to write and communicate programs. However, programs are scored by the bytes used by the interpreter, which are not (as) human readable. In this case, the program primf=primfd corresponds to the 5 bytes (written here by the corresponding hex) FE 72 F4 FE 74. FE72 corresponds to primf, F4 corresponds to =, and FE74 corresponds to primfd. Naturally, it is much more informative to share the Literate Mode as opposed to the actual bytes, which are, in this case, entirely printable as þrôþt, but often contain unprintable characters. Furthermore, since Myby programs bestow meaning to individual NIbbles (half-bytes), such a representation does not come close to reasonably representing the program's behavior. You can read more about the language here: https://github.com/ConorOBrien-Foxx/Myby