Friday 26 September 2014

Pattern Machine (Mesin deret bilangan)

1. Machine that alternatively multiply by 2 and then substract by 2
Mesin yang mengali dengan 2 dan mengurang dengan 2 secara bergantian.

Code:
a = 3
TextWindow.WriteLine(a)
For i = 0 To 10
  a = a * 2
  TextWindow.WriteLine(a)
  a = a - 2
  TextWindow.WriteLine(a)
EndFor

Output:
3, 6, 4, 8, 6, 12, 10, 20, 18, ...

Screenshot:


2. Machine that add preceeding term with 1, 2, 3, 4


3. Machine that add increasing even number to the preceding term.
Pattern: 1, 3, 7, 13, 21


No comments:

Post a Comment