@@ -309,6 +309,7 @@ public static int classify(char x,char off,char on) {
309
309
310
310
}
311
311
public static long slowfib (long num ){
312
+ //Slow recursion fibonnaci
312
313
if (num <=1 ) {
313
314
return num ;
314
315
}
@@ -317,6 +318,9 @@ public static long slowfib(long num){
317
318
}
318
319
public static ArrayList <Long > fibmem =new ArrayList <Long >();
319
320
public static long ffib (long n ){
321
+ /*
322
+ * Fibonnaci implemented with DP
323
+ */
320
324
if (n <=1 ) {
321
325
return n ;
322
326
}
@@ -335,6 +339,7 @@ public static void setupfib() {
335
339
fibmem .add ((long ) 0 );fibmem .add ((long )1 );fibmem .add ((long )1 );fibmem .add ((long )2 );
336
340
}
337
341
public static void show2Darr (int [][] a ) {
342
+ //Print out a 2D array for you
338
343
for (int [] b :a ) {
339
344
for (int c :b ) {
340
345
print (c +" " ,"" );
@@ -344,6 +349,7 @@ public static void show2Darr(int[][] a) {
344
349
}
345
350
}
346
351
public static void showarr (int [] a ) {
352
+ //Print out a array for you
347
353
for (int x :a ) {print (x +" " );}
348
354
}
349
355
public static int [][] dpcache ;
@@ -366,62 +372,29 @@ public static int ks(int W,int[] wt,int[] val,int n) {
366
372
public static void kssetup (int n ,int W ) {
367
373
dpcache =new int [n +1 ][W +1 ];
368
374
}
369
- public static void main ( String [] args ) throws Exception {
375
+ public static int count ( int [] arr ) {
370
376
/*
371
- * Short demo of stuff
372
- * Making an error would also demo error reporting
373
- *
377
+ * Number of groups of 1s
378
+ * Modify for other purposes if needed
379
+ * Example
380
+ * 1111000111
381
+ * Returns 2
374
382
*
375
383
*/
376
- System .out .println ("Running demo" );
377
- Scanner sc =getsysscan ();
378
- print ("Welcome to the demo" );
379
- print (">" ,"" );
380
- int val ;
381
- /*
382
- int[][] testarray= {
383
- {1,1,2,7,7,1,1,1},
384
- {1,1,4,0,7,1,2,2},
385
- {0,3,6,9,1,0,0,0},
386
- {0,3,0,1,0,0,0,0},
387
- {0,3,0,0,0,0,0,0},
388
- {1,1,5,1,3,1,1,1},
389
- {1,1,1,1,3,1,1,1},
390
- };
391
- */
392
- int [][] testarray = {
393
- {1 ,2 ,3 ,1 },
394
- {4 ,5 ,6 ,2 },
395
- {7 ,8 ,9 ,3 },
396
- {10 ,69 ,1 ,4 }
397
-
398
- };
399
- print ("Roation of 90 degrees\n Before \n " );
400
- show2Darr (testarray );
401
- print ("After \n " );
402
- show2Darr (rotate90cw (testarray ));
403
- print ("BEFORE:" );
404
- int [][] ii = {
405
- {1 ,1 ,2 ,3 },
406
- {1 ,0 ,2 ,1 },
407
- {1 ,1 ,1 ,1 },
408
- {1 ,2 ,3 ,4 }
409
- };
410
- show2Darr (ii );
411
- print ("After H reflect:" );
412
- show2Darr (reverseh (ii ));
413
-
414
- try {
415
- val =sc .nextInt ();
416
- }catch (Exception e ) {
417
- print ("Oops that did not go well please rerun and choose a INTEGER" );
418
- val =-1 ;
419
- report (e );
420
- print ("How about we test error reporting" );
421
- console ();
422
- }
423
- if (1 ==val ) {
424
-
384
+ boolean b =false ;int c =0 ;int temp ;
385
+ for (int i =0 ;i <arr .length ;i ++) {
386
+ temp =arr [i ];
387
+ if (temp ==0 && b ) {
388
+ b =false ;
389
+ c ++;
390
+ }
391
+ if (temp ==1 && b ==false ) {
392
+ b =true ;
393
+ }
425
394
}
395
+ return c ;
396
+ }
397
+ public static void main (String [] args ) throws Exception {
398
+ print ("the demo has been removed do to lack of support. Instead we display info about the library." );
426
399
}
427
400
}
0 commit comments