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

More By Author:

Check out these other kata created by g964

Stats:

CreatedMay 10, 2016
PublishedMay 10, 2016
Warriors Trained14617
Total Skips6458
Total Code Submissions10061
Total Times Completed2211
Ruby Completions93
Python Completions541
JavaScript Completions290
CoffeeScript Completions11
Java Completions252
C# Completions118
Haskell Completions35
Clojure Completions20
C++ Completions263
PHP Completions58
Elixir Completions38
Crystal Completions5
F# Completions20
C Completions121
TypeScript Completions69
OCaml Completions19
Rust Completions111
Swift Completions46
Go Completions96
R Completions30
Shell Completions13
Kotlin Completions55
Groovy Completions9
Scala Completions44
Julia Completions15
PowerShell Completions8
Nim Completions6
Racket Completions9
Reason Completions3
VB Completions4
Haxe Completions4
Pascal Completions5
Perl Completions4
D Completions5
Prolog Completions5
Total Stars245
% of votes with a positive feedback rating90% of 389
Total "Very Satisfied" Votes320
Total "Somewhat Satisfied" Votes58
Total "Not Satisfied" Votes11
Total Rank Assessments8
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • g964 Avatar
  • raulbc777 Avatar
  • kazk Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad