Function for three equal consecutive digits P37257


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

thehtml

Write a recursive function that, given two natural numbers n and b, returns true if and only if n has three or more equal consecutive digits when expressed in base b.

For example, the number 44344 does not have three equal consecutive digits in base 10. By contrast, 159 in ternary is 12220, so it does have three equal consecutive digits in base 3.

Precondition

It holds 0 ≤ n ≤ 109 and 2 ≤ b ≤ 100.

Interface

C++
bool three_equal_consecutive_digits(int n, int b);
C
int three_equal_consecutive_digits(int n, int b);
Java
public static boolean three_equal_consecutive_digits(int n, int b);
Python
three_equal_consecutive_digits(n, b) # returns bool
 
three_equal_consecutive_digits(n: int, b: int) -> bool

Observation You only need to submit the required procedure; your main program will be ignored.

Information
Author
Salvador Roura
Language
English
Translator
Salvador Roura
Original language
Catalan
Other languages
Catalan
Official solutions
C C++ Java Python
User solutions
C C++ Python