day 6, AWK solution
This commit is contained in:
		
							
								
								
									
										17
									
								
								d06/exec.awk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								d06/exec.awk
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					BEGIN { W = 14 }
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						for (i=1; i<=length($1); i++) {
 | 
				
			||||||
 | 
							window = substr($1,i,W)
 | 
				
			||||||
 | 
							# compare each char of window to all char of window
 | 
				
			||||||
 | 
							S = 0  # to count match
 | 
				
			||||||
 | 
							for (j=1; j<=W; j++) {
 | 
				
			||||||
 | 
								for (k=1; k<=W; k++) {
 | 
				
			||||||
 | 
									S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (S == W) {  # if each char match only with itsef
 | 
				
			||||||
 | 
								print i + W - 1
 | 
				
			||||||
 | 
								next  # finish
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user