Difference between revisions of "Finite State Machine"

From Progzoo
Jump to: navigation, search
(Even Binary Numbers - Abtsracted)
 
(One intermediate revision by the same user not shown)
Line 53: Line 53:
  
  
==Even Binary Numbers - Abtsracted==
+
==Even Binary Numbers - Abstracted==
  
 
<question className='EvenBinary'>
 
<question className='EvenBinary'>
Line 146: Line 146:
 
   }
 
   }
 
}
 
}
]]></prog>
 
</question>
 
 
==What is the function==
 
 
<question class='P'>
 
<prog><![CDATA[
 
public class P{
 
  public static void main(String argv[])
 
  {
 
    for (int i=0;i<5;i++)
 
      System.out.printf("%d%8d\n",i,f(i));
 
  }
 
 
  static int f(int i){
 
    if (i==0)
 
      return 0;
 
    else
 
      return 2+f(i-1);
 
  }
 
}
 
]]></prog>
 
</question>
 
 
 
==What is the function==
 
 
<question class='P'>
 
<prog><![CDATA[
 
public class P{
 
  public static void main(String argv[])
 
  {
 
    for (int i=0;i<5;i++)
 
      System.out.printf("%d%8d\n",i,f(i));
 
  }
 
 
  static int f(int i){
 
    if (i==0)
 
      return 1;
 
    else
 
      return 2*f(i-1);
 
  }
 
}
 
]]></prog>
 
</question>
 
==What is the function==
 
 
<question class='P'>
 
<prog><![CDATA[
 
public class P{
 
  public static void main(String argv[])
 
  {
 
    for (int i:new int[]{2, 42, 111, 2753})
 
      System.out.printf("%5d%8d\n",i,f(i));
 
  }
 
 
  static int f(int i){
 
    if (i==0)
 
      return 0;
 
    else
 
      return (i%10)+f(i/10);
 
  }
 
}
 
 
 
 
]]></prog>
 
]]></prog>
 
</question>
 
</question>

Latest revision as of 16:03, 1 March 2012

Finite State Machines

Even Binary Numbers


[Font] [Default] [Show] [Resize] [History] [Profile]


Even Binary Numbers - Abstracted


[Font] [Default] [Show] [Resize] [History] [Profile]

Divisible by Three (decimal)


[Font] [Default] [Show] [Resize] [History] [Profile]