[PYTHON] Prime number enumeration in one line

Introduction

Suddenly, I wrote a program to find a prime number in one line. Emphasis on code amount rather than efficiency.

Ruby

If you think it's filter, it's select in the case of Range. (Ruby 2.5)

(2..99).select {|x| (2...x).select {|i| x % i == 0} == []}

Python

You can use filter, but list comprehension is easier to write.

[x for x in range(2, 100) if [i for i in range(2, x) if x % i == 0] == []]

Haskell

Haskell is stuck with beginners studying for years.

[x | x <- [2..100], [i | i <- [2..(x - 1)], mod x i == 0] == []]

Summary

When I thought that Ruby, which cannot include list comprehension, was disadvantageous, it was surprisingly the shortest I wrote.

Recommended Posts

Prime number enumeration in one line
Prime number 2 in Python
Prime number enumeration and primality test in Python
Fizzbuzz in Python (in one line)
Make python segfault in one line
Infinite prime number generator in Python3
Prime number
CGI server (1) python edition in one line
Project Euler # 7 "1000 1st prime number" in Python
Decompose command arguments in one line in Python
[Python] Invert bool value in one line
Make a rock-paper-scissors game in one line (python)
I made a prime number generation program in Python
How to do zero-padding in one line with OpenCV
I made a prime number generation program in Python 2
Prime numbers in Python
[In one line] Visualize like a lawn with just Pandas
Decrypt one line of code in Python lambda, map, list
[Python 3] Prime factorization in 14 lines
php continuous characters in one
DMD in Python one dimension
Try LINE Notify in Python
I made a prime number table output program in various languages
A program that determines whether a number entered in Python is a prime number