about | help | code help+videos | done | prefs |
apcsaLoopsCountPattern
Given the start and end of a range, an increment and a String pattern of digits, check every number from start to end (but going up by increment, not just by one) and return how many numbers between start and end include the digits of pattern (could be 0!). Preconditions: 0 < start < end, increment > 1, pattern is only digits. Example: suppose start is 3, end is 1000, increment is 3, pattern is "02". The numbers to check are 3,6,9,12,...,99,102,104,...,999. HINTS: the first three parameters are intended to structure a for loop header. Checking whether a number "includes the digits of pattern" can be done easily, though not efficiently, by using Strings. For example, the String class has a method called contains which could be useful.apcsaLoopsCountPattern(3, 1000, 3, "02") → 3 apcsaLoopsCountPattern(3, 1000, 3, "011") → 0 apcsaLoopsCountPattern(104, 205, 2, "7") → 5 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 250
Copyright Nick Parlante 2017 - privacy