Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. public boolean simulate(){
  2. int distance=0;
  3. int numHops=0;
  4. //hopDistance() tells us how far teh frog hops
  5.  
  6. //if frog reaches target numsteps<maxSteps
  7.  
  8. //if goal reached or passed stop hopipng, if position is negative stop hopping if frog reaches max steps stop hopping
  9.  
  10. while(distance<goalDistance&&distance>=0&&numSteps<maxHops){
  11.     distance+=hopDistance();
  12.     numHops++;
  13. }
  14.  
  15. if(distance>=goalDistance){
  16.     return true;
  17. }
  18. return false;
  19. }
  20.  
  21.  
  22. public class RandomStringChooser{
  23.     private String[] words;
  24.     private ArrayList<String> randomWords;
  25.    
  26.     pbulic RandomStringChooser(String[] arr){
  27.         words=arr;
  28.         randomWords=new ArrayList<>();
  29.         makeCopy();
  30.     }
  31.    
  32.     public String getNext(){
  33.         if(randomWords.size()>0){
  34.             return randomWords.remove((int)(Math.random()*randomWords.size()));
  35.         }
  36.         else{
  37.             return "NONE";
  38.         }
  39.     }
  40.    
  41.     private void makeCopy(){
  42.         for(String s: words){
  43.             randomWords.add(s);
  44.         }
  45.     }
  46.  
  47. }
  48.  
  49. public class HiddenWord{
  50.     private String word;
  51.  
  52.     public HiddenWord(String s){
  53.         word=s;
  54.     }
  55.    
  56.     public String getHint(String guess){
  57.     String hint="";
  58.         for(int i=0; i<guess.length();i++){
  59.             String ch=guess.substring(i, i+1);
  60.             if(word.indexOf(ch)>=0){
  61.                 if(word.indexOf(ch)==i){
  62.                     hint+=ch;
  63.                 }
  64.                 else{
  65.                     hint+="+";
  66.                 }
  67.             }
  68.             else{
  69.                 hint+="*";
  70.             }
  71.         }
  72.     }
  73. }
  74.  
  75.  
  76. public interface NumberGroup{
  77.     boolean contains(int n);
  78. }
  79.  
  80. public class Range impliments NumberGroup{
  81.     private int min, max;
  82.    
  83.     public Range(int min, int max){
  84.         this.min=min;
  85.         this.max=max;
  86.     }
  87.    
  88.     public boolean contains(int n){
  89.         return n>=min&&n<=max;
  90.     }
  91. }
  92. @Override
  93. public boolean contains(int n){
  94.     boolean containsN=false;
  95.     for(NumberGroup g: groupList){
  96.         if(g.contains(n)){
  97.             return true;
  98.         }
  99.     }
  100.    
  101.     return false;
  102. }
  103.  
  104.  
  105. public int getValueAt(int r, int c){
  106.  
  107.     for(SparseArrayEntry e: entries){
  108.         if(e.getRow()==r&&e.getCol()==c){
  109.             return e.getValue();
  110.         }
  111.     }
  112.     return 0;
  113.    
  114. }
  115.  
  116. public void removeColumn(int c){
  117.     for(int i=0; i<entries.size(); i++){
  118.         if(entries.get(i).getCol()==c){
  119.             entries.remove(i);
  120.             i--;
  121.         }
  122.         else if(entries.get(i).getCol()>c){
  123.             entries.set(i, new SparseArrayEntry(entries.get(i).getRow,
  124.                                                 entries.get(i).getCol-1));
  125.         }
  126.     }
  127.     numCols--;
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement