5 kyu
Consecutive k-Primes
93 of 2,211g964
Description:
A natural number is called k-prime if it has exactly k prime factors, counted with multiplicity. A natural number is thus prime if and only if it is 1-prime.
Examples:
k = 2 -> 4, 6, 9, 10, 14, 15, 21, 22, …
k = 3 -> 8, 12, 18, 20, 27, 28, 30, …
k = 5 -> 32, 48, 72, 80, 108, 112, …
Task:
Given an integer k
and a list arr
of positive integers the function consec_kprimes (or its variants in other languages)
returns
how many times in the sequence arr
numbers come up twice in a row with exactly k
prime factors?
Examples:
arr = [10005, 10030, 10026, 10008, 10016, 10028, 10004]
consec_kprimes(4, arr) => 3 because 10005 and 10030 are consecutive 4-primes, 10030 and 10026 too as well as 10028 and 10004 but 10008 and 10016 are 6-primes.
consec_kprimes(4, [10175, 10185, 10180, 10197]) => 3 because 10175-10185 and 10185- 10180 and 10180-10197 are all consecutive 4-primes.
Note:
It could be interesting to begin with: https://www.codewars.com/kata/k-primes
Fundamentals
Similar Kata:
Stats:
Created | May 10, 2016 |
Published | May 10, 2016 |
Warriors Trained | 14617 |
Total Skips | 6458 |
Total Code Submissions | 10061 |
Total Times Completed | 2211 |
Ruby Completions | 93 |
Python Completions | 541 |
JavaScript Completions | 290 |
CoffeeScript Completions | 11 |
Java Completions | 252 |
C# Completions | 118 |
Haskell Completions | 35 |
Clojure Completions | 20 |
C++ Completions | 263 |
PHP Completions | 58 |
Elixir Completions | 38 |
Crystal Completions | 5 |
F# Completions | 20 |
C Completions | 121 |
TypeScript Completions | 69 |
OCaml Completions | 19 |
Rust Completions | 111 |
Swift Completions | 46 |
Go Completions | 96 |
R Completions | 30 |
Shell Completions | 13 |
Kotlin Completions | 55 |
Groovy Completions | 9 |
Scala Completions | 44 |
Julia Completions | 15 |
PowerShell Completions | 8 |
Nim Completions | 6 |
Racket Completions | 9 |
Reason Completions | 3 |
VB Completions | 4 |
Haxe Completions | 4 |
Pascal Completions | 5 |
Perl Completions | 4 |
D Completions | 5 |
Prolog Completions | 5 |
Total Stars | 245 |
% of votes with a positive feedback rating | 90% of 389 |
Total "Very Satisfied" Votes | 320 |
Total "Somewhat Satisfied" Votes | 58 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |