Break out of loop in scala while iterating on list - algorithm

I am trying to solve a problem.
Problem :
You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the following conditions are true:
There are as many red balls as green balls.
There are as many yellow balls as blue balls.
Difference between the number of red balls and green balls in every prefix of the sequence is at most 1.
Difference between the number of yellow balls and blue balls in every prefix of the sequence is at most 1.
Your task is to write a program, which for a given sequence prints True if it is full of colors, otherwise it prints False.
My solution : for each string, i am generating all possible prefixes and suffixes to validate the condition number 3 and 4. But it is taking more time.
instead of generating prefix and validating conditions every time, we can iterate over the string and validate the condition. I want to break out of loop when condition is not met. I am not able to get that in functional style. Can someone help me how to achieve it.
My solution :
object Test {
def main(args: Array[String]) {
def isValidSequence(str: String) = {
def isValidCondition(ch1:Char, ch2:Char, m:Map[Char, Int]):Boolean = m.getOrElse(ch1, 0) - m.getOrElse(ch2, 0) > 1
def groupByChars(s:String) = s.groupBy(ch => ch).map(x => (x._1, x._2.length))
def isValidPrefix(s:String):Boolean = (1 to s.length).exists(x => isValidCondition('R', 'G', groupByChars(s.take(x))))
val x = groupByChars(str)
lazy val cond1 = x.get('R') == x.get('G')
lazy val cond2 = x.get('B') == x.get('Y')
lazy val cond3 = isValidPrefix(str)
lazy val cond4 = isValidPrefix(str.reverse)
cond1 && cond2 && !cond3 && !cond4
}
def printBoolValue(b:Boolean) = if(b) println("True") else println("False")
val in = io.Source.stdin.getLines()
val inSize = in.take(1).next().toInt
val strs = in.take(inSize)
strs.map(isValidSequence(_)).foreach(printBoolValue)
}
}

As another answer, here's a more straightforward solution, that does short-circuit the differences check.
val valid = List("RGYBRGYB")
val invalid = List("RGYBR", "RGYBY", "RGYBY", "RGYYB")
def checkBalls(s:String) = {
def differences(s:String, a:Char, b:Char) = {
def differenceHelp(s:String, a:Char, b:Char, current:Int):Boolean = {
if (current < -1 || current > 1) false
else if (s.length == 0) true
else differenceHelp(s.tail, a, b,
if (s.head == a) current + 1 else if (s.head == b) current - 1 else current)
}
differenceHelp(s, a, b, 0)
}
lazy val cond1 = s.count('R'==) == s.count('G'==)
lazy val cond2 = s.count('Y'==) == s.count('B'==)
lazy val cond3 = differences(s, 'R', 'G')
lazy val cond4 = differences(s, 'Y', 'B')
cond1 && cond2 && cond3 && cond4
}
valid.forall(checkBalls(_)) //> res0: Boolean = true
invalid.forall(!checkBalls(_)) //> res1: Boolean = true
EDIT: as an optimisation, we can do cond1 as part of cond3 (and cond2 as part of cond4). There are equal numbers of each if and only if the count is 0 at the end of the string. We can check that in differences and return true only if that's the case. So that gives
def checkBalls(s:String) = {
def differences(s:String, a:Char, b:Char) = {
def differenceHelp(s:String, a:Char, b:Char, current:Int):Boolean = {
if (current < -1 || current > 1) false
else if (s.length == 0) (count == 0) // <- this line changed
else differenceHelp(s.tail, a, b,
if (s.head == a) current + 1 else if (s.head == b) current - 1 else current)
}
differenceHelp(s, a, b, 0)
}
lazy val cond3 = differences(s, 'R', 'G')
lazy val cond4 = differences(s, 'Y', 'B')
cond3 && cond4
}
which passes the tests just like the previous version. It could be made slightly faster by doing the R/G and Y/B checks in one call to differences, but that's looking a bit overspecialised.

Here is a solution using streams if you need.
code :-
object RGYB extends App {
val validPattern = List(
"RG","RYBG","RYGB","RBGY",
"GR","GYBR","GYRB","GBRY",
"YB","YRGB","YRBG","YGRB",
"BY","BRGY","BRYG","BGYR"
)
val pattern ="RGRG"
pattern.sliding(4).foreach { x1 =>
val count = validPattern.filter { p1 => {
x1.equalsIgnoreCase(p1)
}
}.size
if(count<1)
{
x1.sliding(2).foreach {
x2=>
val counter = validPattern.filter { p2 => {
x2.equalsIgnoreCase(p2)
}
}.size
if(counter<1)
{
println("false !! not valid due to "+x2);
System.exit(0)
}
}
println("false !! not valid due to "+x1);
System.exit(0)
}
}
println("True !!"+pattern+" Is a valid string pattern")
}

So, the trick is to check the longest prefix first. If that fails, we're done. Otherwise, we take the next longest prefix and recurse. If we get to the empty string, it passed for all prefixes, and therefore it's valid.
def isValidPrefix(s: String): Boolean =
if (s.length == 0)
true
else if (!isValidCondition('R', 'G', groupByChars(s)))
false
else isValidPrefix(s.init)

Related

Is there a known algorithm for simplifying a boolean expression with number comparisons?

For example, if I have the expression (A > 5) && (A == 6),
that expression can be simplified to just (A == 6), and still have the same behavior for A ∈ ℤ.
I also need it to work with multiple variables, so for instance ((B > 2) && (C == 2)) || ((B > 2) && (C < 2)) should simplify to (B > 2) && (C < 3).
I won't need to compare two unknowns, only unknowns and numbers, and I only need it to work with the operators <, >, and == for numbers, and && and || for expressions (&& being AND and || being OR, of course). All unknowns are integers.
Is there any algorithm that takes such an expression and returns an expression with equal behavior and a minimal amount of operators?
(in my specific case, || operators are preferred over &&)
Here's a slow dynamic programming algorithm along the lines that you were thinking of.
from collections import defaultdict, namedtuple
from heapq import heappop, heappush
from itertools import product
from math import inf
# Constructors for Boolean expressions. False and True are also accepted.
Lt = namedtuple("Lt", ["lhs", "rhs"])
Eq = namedtuple("Eq", ["lhs", "rhs"])
Gt = namedtuple("Gt", ["lhs", "rhs"])
And = namedtuple("And", ["lhs", "rhs"])
Or = namedtuple("Or", ["lhs", "rhs"])
# Variable names. Arbitrary strings are accepted.
A = "A"
B = "B"
C = "C"
# Example formulas.
first_example = And(Gt(A, 5), Eq(A, 6))
second_example = Or(And(Gt(B, 2), Eq(C, 2)), And(Gt(B, 2), Lt(C, 2)))
third_example = Or(And(Gt(A, 1), Gt(B, 1)), And(Gt(A, 0), Gt(B, 2)))
fourth_example = Or(Lt(A, 6), Gt(A, 5))
fifth_example = Or(And(Eq(A, 2), Gt(C, 2)), And(Eq(B, 2), Lt(C, 2)))
# Returns a map from each variable to the set of values such that the formula
# might evaluate differently for variable = value-1 versus variable = value.
def get_critical_value_sets(formula, result=None):
if result is None:
result = defaultdict(set)
if isinstance(formula, bool):
pass
elif isinstance(formula, Lt):
result[formula.lhs].add(formula.rhs)
elif isinstance(formula, Eq):
result[formula.lhs].add(formula.rhs)
result[formula.lhs].add(formula.rhs + 1)
elif isinstance(formula, Gt):
result[formula.lhs].add(formula.rhs + 1)
elif isinstance(formula, (And, Or)):
get_critical_value_sets(formula.lhs, result)
get_critical_value_sets(formula.rhs, result)
else:
assert False, str(formula)
return result
# Returns a list of inputs sufficient to compare Boolean combinations of the
# primitives returned by enumerate_useful_primitives.
def enumerate_truth_table_inputs(critical_value_sets):
variables, value_sets = zip(*critical_value_sets.items())
return [
dict(zip(variables, values))
for values in product(*({-inf} | value_set for value_set in value_sets))
]
# Returns both constants and all single comparisons whose critical value set is
# a subset of the given ones.
def enumerate_useful_primitives(critical_value_sets):
yield False
yield True
for variable, value_set in critical_value_sets.items():
for value in value_set:
yield Lt(variable, value)
if value + 1 in value_set:
yield Eq(variable, value)
yield Gt(variable, value - 1)
# Evaluates the formula recursively on the given input.
def evaluate(formula, input):
if isinstance(formula, bool):
return formula
elif isinstance(formula, Lt):
return input[formula.lhs] < formula.rhs
elif isinstance(formula, Eq):
return input[formula.lhs] == formula.rhs
elif isinstance(formula, Gt):
return input[formula.lhs] > formula.rhs
elif isinstance(formula, And):
return evaluate(formula.lhs, input) and evaluate(formula.rhs, input)
elif isinstance(formula, Or):
return evaluate(formula.lhs, input) or evaluate(formula.rhs, input)
else:
assert False, str(formula)
# Evaluates the formula on the many inputs, packing the values into an integer.
def get_truth_table(formula, inputs):
truth_table = 0
for input in inputs:
truth_table = (truth_table << 1) + evaluate(formula, input)
return truth_table
# Returns (the number of operations in the formula, the number of Ands).
def get_complexity(formula):
if isinstance(formula, bool):
return (0, 0)
elif isinstance(formula, (Lt, Eq, Gt)):
return (1, 0)
elif isinstance(formula, And):
ops_lhs, ands_lhs = get_complexity(formula.lhs)
ops_rhs, ands_rhs = get_complexity(formula.rhs)
return (ops_lhs + 1 + ops_rhs, ands_lhs + 1 + ands_rhs)
elif isinstance(formula, Or):
ops_lhs, ands_lhs = get_complexity(formula.lhs)
ops_rhs, ands_rhs = get_complexity(formula.rhs)
return (ops_lhs + 1 + ops_rhs, ands_lhs + ands_rhs)
else:
assert False, str(formula)
# Formula compared by complexity.
class HeapItem:
__slots__ = ["_complexity", "formula"]
def __init__(self, formula):
self._complexity = get_complexity(formula)
self.formula = formula
def __lt__(self, other):
return self._complexity < other._complexity
def __le__(self, other):
return self._complexity <= other._complexity
def __eq__(self, other):
return self._complexity == other._complexity
def __ne__(self, other):
return self._complexity != other._complexity
def __ge__(self, other):
return self._complexity >= other._complexity
def __gt__(self, other):
return self._complexity > other._complexity
# Like heapq.merge except we can add iterables dynamically.
class Merge:
__slots__ = ["_heap", "_iterable_count"]
def __init__(self):
self._heap = []
self._iterable_count = 0
def update(self, iterable):
iterable = iter(iterable)
try:
value = next(iterable)
except StopIteration:
return
heappush(self._heap, (value, self._iterable_count, iterable))
self._iterable_count += 1
def __iter__(self):
return self
def __next__(self):
if not self._heap:
raise StopIteration
value, index, iterable = heappop(self._heap)
try:
next_value = next(iterable)
except StopIteration:
return value
heappush(self._heap, (next_value, index, iterable))
return value
class Combinations:
__slots__ = ["_op", "_formula", "_best_formulas", "_i", "_n"]
def __init__(self, op, formula, best_formulas):
self._op = op
self._formula = formula
self._best_formulas = best_formulas
self._i = 0
self._n = len(best_formulas)
def __iter__(self):
return self
def __next__(self):
if self._i >= self._n:
raise StopIteration
formula = self._op(self._formula, self._best_formulas[self._i])
self._i += 1
return HeapItem(formula)
# Returns the simplest equivalent formula, breaking ties in favor of fewer Ands.
def simplify(target_formula):
critical_value_sets = get_critical_value_sets(target_formula)
inputs = enumerate_truth_table_inputs(critical_value_sets)
target_truth_table = get_truth_table(target_formula, inputs)
best = {}
merge = Merge()
for formula in enumerate_useful_primitives(critical_value_sets):
merge.update([HeapItem(formula)])
best_formulas = []
for item in merge:
if target_truth_table in best:
return best[target_truth_table]
formula = item.formula
truth_table = get_truth_table(formula, inputs)
if truth_table in best:
continue
n = len(best_formulas)
for op in [And, Or]:
merge.update(Combinations(op, formula, best_formulas))
best[truth_table] = formula
best_formulas.append(formula)
print(simplify(first_example))
print(simplify(second_example))
print(simplify(third_example))
print(simplify(fourth_example))
print(simplify(fifth_example))
Output:
Eq(lhs='A', rhs=6)
And(lhs=Lt(lhs='C', rhs=3), rhs=Gt(lhs='B', rhs=2))
And(lhs=And(lhs=Gt(lhs='B', rhs=1), rhs=Gt(lhs='A', rhs=0)), rhs=Or(lhs=Gt(lhs='B', rhs=2), rhs=Gt(lhs='A', rhs=1)))
True
Or(lhs=And(lhs=Eq(lhs='B', rhs=2), rhs=Lt(lhs='C', rhs=2)), rhs=And(lhs=Gt(lhs='C', rhs=2), rhs=Eq(lhs='A', rhs=2)))
Maybe you can consider intervals for your variables, for example:
(A > 5) && (A == 6)
Given you have a variable A, set an initial interval for it: A: [-∞, ∞].
Each condition that you read, you can reduce your interval:
(A > 5) sets the interval for A: [6, ∞]
(A == 6) sets the interval for A: [6, 6]
For each update on the interval, check if the new condition is possible, for example:
(A > 5) sets the interval for A: [6, ∞]
(A == 5) out of the interval, impossible condition.
Just another example:
((B > 2) && (C == 2)) || ((B > 2) && (C < 2))
Initially: B: [-∞, ∞] and C: [-∞, ∞].
((B > 2) && (C == 2))
(B > 2) sets the interval for B: [3, ∞]
(C == 2) sets the interval for C: [2, 2]
The next condition is attached with ||, so you add intervals:
((B > 2) && (C < 2))
(B > 2) sets the interval for B: [3, ∞]
(C < 2) sets the interval for C: [2, 2] U [-∞, 1] = [-∞, 2]

How to create a Minimax algorithm comparing arrays

I'm trying to code a "minimax" algorithm for Tic Tac Toe.
Each node of the tree is of the form [nil/Int, String] where the last element is a nine character string describing the board, and the first is an Integer ranking the node, or nil by default.
If the value is nil, it tries to inherit the appropriate value from child nodes.
This is where I get an error, when comparing an array with an array failed.
class Scene_TicTacToe #Script 2/2
def initialize
#Boardstate as a str from top left corner to bottom right corner.
#boardstate = "---------"
#1 = player, -1 = comp
#active_player = 1
end
def wincheck(boardstate=#boardstate)
#should return -1 for loss, 0 for draw, 1 for win
["OOO","XXX"].each do |f|
for i in 0..2
if (boardstate[i]+boardstate[i+3]+boardstate[i+6]).chr == f || boardstate[(3*i)..(3*i)+2] == f
return f == "OOO" ? 1 : -1
end
end
if (boardstate[0]+boardstate[4]+boardstate[8]).chr == f || (boardstate[2]+boardstate[4]+boardstate[6]).chr == f
return f == "OOO" ? 1 : -1
end
end
return 0
end
def computer_play
#Sets depth,and alpha/beta for pruning, so far so good
depth = 3
alpha = -100
beta = 100
##boardstate starts as "---------"
##active_player: 1=player, -1=computer
play(minimax(#boardstate, depth, alpha, beta, #active_player))
end
def play(array)
#Check actual boardside with parameter boardside to see what move has been
#selected and plays that move
for i in 0...array[1].length
if #boardstate[i] != array[1][i]
#color = array[1][i].chr == "X" ? #ai : #player
##cursor.y = (i / 3) * #side
##cursor.x = (i % 3) * #side
##board.bitmap.fill_rect(#cursor.x,#cursor.y,#side,#side,color)
#boardstate = array[1].dup
end
end
end
def minimax(boardstate, depth, alpha, beta, active_player)
#If bottom node reached, returns [boardstate_score, boardstate]
#wincheck returns 1 if player wins, -1 if computer wins, and 0 otherwise
if depth == 0 or wincheck(boardstate) != 0 or (/-/ =~ boardstate) == nil
return [wincheck(boardstate),boardstate]
end
if active_player == 1 #if player's turn
#Gets an array of all the next possible boardstates and return the one with
#the best eval.
child = generate_child(boardstate, active_player)
child.each do |f| #f = [Int/nil, String]
if f[0] == nil
#This should turn all the nil wincheck values to the best value of children nodes
f[0] = minimax(f[1], depth-1, alpha, beta, -active_player).last[0]
end
alpha = [f[0], alpha].max
if beta <= alpha
break
end
end
return child.sort_by{|c| c[0]}
end
if active_player == -1 #if computer's turn
#Same as above but with worst eval.
child = generate_child(boardstate, active_player)
child.each do |f|
if f[0] == nil
f[0] = minimax(f[1], depth-1, alpha, beta, -active_player).first[0]
end
beta = [f[0], beta].min
if beta <= alpha
break
end
end
#Following line raises "comparison of array with array failed" error :
return child.sort_by{|c| c[0]}
end
end
def generate_child(boardstate, active_player)
#returns boardstate string with one X or O more than current boardstate
#and sets nil as a default wincheck value
c = active_player == 1 ? "O" : "X"
a = []
for i in 0...boardstate.length
if boardstate[i].chr == "-"
s = boardstate.dup
s[i]= c
a << [nil, s]
end
end
return a
end
end
Error: comparison of array with array failed

While loop through a string in Ruby

I am entering "901000" as an argument to the following method, and I expect it to remove the last three zeros and return "901".
def zeros(x)
str = x.to_s
i = str.length-1
while str[i] == "0"
str = str.delete(str[i])
i = i-1
end
return str
end
But it returns "91" instead. I cannot understand why my code does not work. Can someone help please?
At first, str is "901000", i = str.length-1 is 5, and str[i] is "0". Hence,
str = str.delete(str[i])
is equivalent to
str = "901000".delete("0")
That gives you "91".
Then, by i = i-1, i becomes 4, and str[i] (which is equivalent to "91"[4]) becomes nil, and str[i] == 0 (which is equivalent to nil == 0) becomes false. So the loop ends, returning the value str, which is "91".
To do what you want, some simple ways are:
"901000".sub(/0+\z/, "") # => "901"
"901000"[/.*?(?=0+\z)/] # => "901"

How to do a conditioned for loop in Ruby

I'm amazed with Ruby's syntax, I can only describe it in one word: comfortable.
EDIT: I think I wasn't clear. I want an easy way to exit loops with conditions.
Sadly, I can't find how to do this Java code in Ruby:
Assume:
array = [1,2,3,4]
array2 = [1,2,3,4]
boolean condition = false;
for(int i = 0; i < array.length && !condition; i++)
{
for(int j = 0; j < array2.length && !condition; j++)
{
condition = (array[i] + array2[j] + 1 == 7);
}
}
if(condition)
{
System.out.println("Two elements of the arrays + 1 sum 7")
}
I love Ruby's one liners... But I can't even do this with full open loops...
I'm looking for something like this (each_while is made up):
array.each_while(condition && condition2) { SomeAction }
Which is the simplest way to do this in Ruby?
Most of the loops I work with have exiting conditions to optimize them. Everything I find on the internet is not acceptable for Ruby's beautiful syntax because it is even worse than Java, and we all know Java ain't pretty.
Some solution I found in the web:
catch "BreakOuterLoop" do
for i in 1..10
print "out #{i}\n"
for j in 1..10
print "in #{j}\n"
throw "BreakOuterLoop" if i+j > 16
end
end
end
Just awful...
require 'matrix'
Matrix[0...rows, 0...cols].each_with_index do |e, row, col|
next unless [cond1, cond2, cond3].reduce :&
# code
end
array1.each.with_index.lazy.take_while { cond1 }.each do |e1, i1|
array2.each.with_index.lazy.take_while { cond2 }.each do |e2, i2|
# do some stuff
end
end
Loop with condition
You could use break :
array1.each do |x|
break unless condition && condition2
array2.each do |y|
break unless condition3
# do_something
end
end
end
If you need the indices in your conditions :
array1.each_with_index do |x,i|
break unless condition && condition2
array2.each_with_index do |y,j|
break unless condition3
# do_something
end
end
end
Specific problem
Boolean
For your updated problem, you can use any?. It is exactly what you wanted to do. It iterates as long as a condition isn't true, and returns a value ASAP :
array = [1,2,3,4]
array2 = [1,2,3,4]
puts array.product(array2).any?{|a,b| a + b + 1 == 7 }
#=> true
Or :
puts array.any?{|a| array2.any?{ |b| a + b + 1 == 7 } }
#=> true
puts array.any?{|a| array2.any?{ |b| a + b + 1 == 12 } }
#=> false
The second example should be faster, because not every pair is created : As soon as one is found, true is returned.
Pair
If you want to know for which pair the condition is true, you can use find:
p array.product(array2).find { |a, b| a + b + 1 == 7 }
#=> [2,4]
p array.product(array2).find { |a, b| a + b + 1 == 12 }
#=> nil
Optimization for huge arrays
The above code will run slow for huge arrays.
You could convert the biggest array to a Set, and use a direct lookup :
require 'set'
array = [1, 2, 3, 4]
array2 = [1, 2, 3, 4]
set2 = array2.to_set
sum = 7 - 1
x1 = array.find { |x| set2.include?(sum - x) }
if x1
puts "#{x1} + #{sum - x1} + 1 = #{sum + 1}"
end
#=> 2 + 4 + 1 = 7
array.length.times do |i|
break unless condition_1 && condition_2
# some action
end
break will stop the loop as soon as the conditions are no longer met
Regarding the loop matrix
Of course you can nest a loop within a loops within a loop, but that is definitely not the ruby way. I'm sure there is a nicer solution to whatever problem may arise.
As stated before, there is a prettier functional solution for probably any specific use case you can think of. I will try to answer the more general question, which is how to convert this java code:
int somethingYouWillMutate = 0; // any types or values or number of things
for(int i = 0; i < array.length && condition && condition2; i++) {
for(int j = 0; j < array2.length && condition; j++) {
someAction(array[i], array2[j], somethingYouWillMutate);
}
}
To ruby:
something_you_will_mutate = 0
array.product(array2).each do |e1, e2|
break unless condition && condition2
some_action(e1, e2)
end
Note:
while c1 && c2 =:=
while true; break if !(c1 && c2) =:=
while true; break unless c1 && c2
If you want the indices as well:
array_indexed = array.each_with_index.to_a
array2_indexed = array2.each_with_index.to_a
array_indexed.product(array2_indexed).each do |(e1, i1), (e2, i2)|
break unless condition && condition2
some_action(e1, e2, i1, i2, something_you_will_mutate)
end
Note: If you want an even more generic solution (with 3 or more arrays for example):
[array, array2, array3...].
map(&:each_with_index).
map(&:to_a).
reduce(:product).
map(&:flatten).
each do |e1, i1, e2, i2, e3, i3...|
break unless condition && condition2 && condition3...
some_action(e1, e2, i1, i2, e3, i3..., something_you_will_mutate)
end

Use for statement with array to find next true

Im trying to use the code below to find the biggest number that's not true; however, if a true variable comes before the biggest number I want it to give me the number below that one. How can I change my code to accomplish this?
var firstRow = [1: false, 2: false, 3: false, 4: false, 5: true, 6: false]
var smallest = Int.max
var largest = 0
var playerLoc = "3"
for (number, bool) in firstRow {
if playerLoc != "1" && playerLoc != "30"{
if bool == false && number < smallest {
smallest = number
var smallString = ("\(smallest)")
if smallString == playerLoc {
smallest = Int.max
}
else {
smallest = number
}
}
}
else {
smallest = Int.max
}
if playerLoc != "6" && playerLoc != "36" {
if bool == false && number > largest {
largest = number
}
}
else {
largest = 0
}
}
println(smallest)
println(largest)
So for example this code would set largest equal to 4 if it worked correctly and smallest equal to 1
UPDATE:
When using this line of code I get the error Array Index Out of Range
var firstRow = [(1, false), (2, false), (3, false), (4, false), (5, false), (6, false)]
However, if I use it in the playground it works fine.
I've narrowed the problem down to this code.
if two.contains(player.position) || two.contains(opponent.position) || two.contains(block3.position) {
firstRow[2].1 = true
} else {
firstRow[2].1 = false
}
You should use an array instead of a dictionary if the order matters.
var firstRow = [(1, false), (2, false), (3, false), (4, false), (5, true), (6, false)]
Then you can iterate like this:
for var i = 0; i < firstRow.count; ++i){
if (firstRow[i].1){
if (i == 0){
// handle this condition
} else {
smallest = firstRow[i-1].0
break
}
}
}
I figured it out. When I switched to the array it started at 0 instead of 1 so if I called 6 it gave the error. So I had to start at 0 and go to 5.

Resources