4 kyu

Regular expression for binary numbers divisible by 5

722 of 2,260aswitalski

Description:

Define a regular expression which tests if a given string representing a binary number is divisible by 5.

Examples:

// 5 divisable by 5
Regex.IsMatch('101', DivisibleByFive) == true

// 135 divisable by 5
Regex.IsMatch('10000111', DivisibleByFive) == true

// 666 not divisable by 5
Regex.IsMatch('0000001010011010', DivisibleByFive) == false
// 5 divisable by 5
divisibleByFive.test('101') === true

// 135 divisable by 5
divisibleByFive.test('10000111') === true

// 666 not divisable by 5
divisibleByFive.test('0000001010011010') === false
// 5 is divisible by 5
preg_match($pattern, '101'); // => 1
// 135 is divisible by 5
preg_match($pattern, '10000111'); // => 1
// 666 is not divisible by 5
preg_match($pattern, '0000001010011010'); // => 0
# 5 divisible by 5
PATTERN.match('101') == true

# 135 divisible by 5
PATTERN.match('10000111') == true

# 666 not divisible by 5
PATTERN.match('0000001010011010') == false
// 5 divisible by 5
DivisibleByFive.pattern().matcher('101').matches() == true

// 135 divisible by 5
DivisibleByFive.pattern().matcher('10000111').matches() == true

// 666 not divisible by 5
DivisibleByFive.pattern().matcher('0000001010011010').matches() == false

Note:

This can be solved by creating a Finite State Machine that evaluates if a string representing a number in binary base is divisible by given number.

The detailed explanation for dividing by 3 is here

The FSM diagram for dividing by 5 is here

Binary
Algorithms
Regular Expressions

Stats:

CreatedNov 14, 2015
PublishedNov 15, 2015
Warriors Trained13935
Total Skips5194
Total Code Submissions14180
Total Times Completed2260
JavaScript Completions722
Python Completions797
Java Completions450
TypeScript Completions238
PHP Completions180
C# Completions245
Total Stars361
% of votes with a positive feedback rating91% of 394
Total "Very Satisfied" Votes342
Total "Somewhat Satisfied" Votes35
Total "Not Satisfied" Votes17
Total Rank Assessments8
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • aswitalski Avatar
  • Unnamed Avatar
  • Unihedron Avatar
  • rubs33 Avatar
  • smile67 Avatar
  • donaldsebleung Avatar
  • vguzev Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • RobsonMoon Avatar
Ad