1 kyu

Regular Expression for Binary Numbers Divisible by n

599 of 1,214hufftheweevil

Description:

Regular Expression for Binary Numbers Divisible by n

Create a function that will return a regular expression string that is capable of evaluating binary strings (which consist of only 1s and 0s) and determining whether the given string represents a number divisible by n.

Tests

Inputs 1 <= n <= 18 will be tested

Each n will be tested against random invalid tests and random valid tests (which may or may not pass the regex test itself, accordingly).

Notes

  • Strings that are not binary numbers should be rejected.
  • Keep your solution under 5000 characters. This means you can't hard-code the answers.
  • Only these characters may be included in your returned string:

    01?:*+^$()[]|

Javascript Notes

  • Do not include the regex caps /.../. Your string will be used as such: RegExp(regexDivisibleBy(3)) in the tests.
  • No funny business! There should be no need for prototyping, so don't even think about it.
Algorithms
Puzzles
Regular Expressions
Strings

More By Author:

Check out these other kata created by hufftheweevil

Stats:

CreatedAug 16, 2017
PublishedAug 17, 2017
Warriors Trained18845
Total Skips1527
Total Code Submissions38870
Total Times Completed1214
JavaScript Completions599
Python Completions456
Java Completions119
Kotlin Completions19
Groovy Completions5
Scala Completions23
F# Completions5
Ruby Completions21
C Completions25
Rust Completions24
C++ Completions10
Total Stars485
% of votes with a positive feedback rating96% of 256
Total "Very Satisfied" Votes237
Total "Somewhat Satisfied" Votes15
Total "Not Satisfied" Votes4
Total Rank Assessments5
Average Assessed Rank
1 kyu
Highest Assessed Rank
1 kyu
Lowest Assessed Rank
2 kyu
Ad
Contributors
  • hufftheweevil Avatar
  • dramforever Avatar
  • kazk Avatar
  • docgunthrop Avatar
  • Blind4Basics Avatar
  • mjpieters Avatar
  • nomennescio Avatar
  • gullymiles Avatar
  • Voile Avatar
  • Madjosz Avatar
  • ice1000 Avatar
  • Bubbler Avatar
  • C-V Avatar
  • Awesome A.D. Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • Kacarott Avatar
Ad