Skip to content

Instantly share code, notes, and snippets.

@EtherDream
Last active October 16, 2020 09:33
Show Gist options
  • Save EtherDream/9af693ad2f079926e02858cb226f086c to your computer and use it in GitHub Desktop.
Save EtherDream/9af693ad2f079926e02858cb226f086c to your computer and use it in GitHub Desktop.
2 to N primes in SCSS
// ----
// 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);
@EtherDream
Copy link
Author

EtherDream commented Oct 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment