Last active
October 16, 2020 09:33
-
-
Save EtherDream/9af693ad2f079926e02858cb226f086c to your computer and use it in GitHub Desktop.
2 to N primes in SCSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.4.21) | |
// Compass (v1.0.3) | |
// ---- | |
@function is_prime($num, $sqrt) { | |
@for $i from 3 through $sqrt { | |
@if $num % $i == 0 { | |
@return false; | |
} | |
} | |
@return true; | |
} | |
@mixin list_prime($max) { | |
.No_1 { value: 2; } | |
.No_2 { value: 3; } | |
$index: 2; | |
$sqrt: 3; | |
@for $num from 5 through $max { | |
@while $sqrt * $sqrt <= $num { | |
$sqrt: $sqrt + 1; | |
} | |
@if $num % 2 != 0 { | |
@if is_prime($num, $sqrt) { | |
$index: $index + 1; | |
.No_#{$index} { value: $num; } | |
} | |
} | |
} | |
} | |
@include list_prime(1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.sassmeister.com/gist/9af693ad2f079926e02858cb226f086c