ArrayMac > Function display > TEST_rm_2015_APL_Competition_R1

     ∇ r←TEST_rm_2015_APL_Competition_R1;ckFnExists;unless;aOk;aEq;on;chkFeature;ckObExists;chkFeatureLine;tfuuN;tfuu;your_solution;urlV;fileV;ucf;boundingpoints;within;expV
[1]   ⍝∇ 20150605/20150628 ra⌈ --()-- test "rm_2015_APL_Competition_R1"                                                                                                      
[2]    test_start                                                                                                                                                            
[3]    r←0                                                                                                                                                                   
[4]    unless←{(~⍵)/⍺}                                                                                                                                                       
[5]    aOk←#.Assert                                                                                                                                                          
[6]    aEq←#.AssertEq                                                                                                                                                        
[7]    on←{⍺ ⍵}                                                                                                                                                              
[8]   ⍝⍝--------                                                                                                                                                             
[9]    ckObExists←{(⍵ omrepl'missing "⍵"')AssertEq ⍺ on ⍬⍴⎕NC ⍵}                                                                                                             
[10]   ckFnExists←3∘ckObExists                                                                                                                                               
[11]   chkFeature←{⍺←0 ⋄ ('Requirement:',⍵)aEq 1 ⍺}                                                                                                                          
[12]   chkFeatureLine←{⍺←0 ⋄ ⍺ chkFeature'⍝⍝--'{(¯1+(⍬⍴⍴⍺)+⍬⍴where ⍺⍷⍵)↓⍵}(1 atpars 2⌷[1]qSI'')FNline ⍵}                                                                     
[13]   ⍝⍝--                                                                                                                                                                  
[14]   tfuuN←'rm_2015_APL_Competition_R1'                                                                                                                                    
[15]   fileV←⍕'H:\ArrayMax\APL2015 Contest\2015 PhaseI Problems.pdf'                                                                                                         
[16]   :If 'Missing Phase 1 PDF file'aOk qNExists fileV                                                                                                                      
[17]       ⎕←'⍝⍝⍝ fileV←',quote fileV                                                                                                                                        
[18]   :Else                                                                                                                                                                 
[19]       urlV←'https://studentcompetitions-general.s3.amazonaws.com/dyalog2015/apl/2015/2015%20PhaseI%20Problems.pdf'                                                      
[20]       ⎕←APLPmt'urlV←'urlV                                                                                                                                               
[21]       ⎕←APLPmt'MORE_html ''a'' ''href'' urlV httag' 'Phase I document'                                                                                                  
[22]       →XIT                                                                                                                                                              
[23]   :EndIf                                                                                                                                                                
[24]                                                                                                                                                                         
[25]   ⍝.                                                                                                                                                                    
[26]   your_solution←{lc←⎕UCS 32+⎕UCS uc←⎕A ⋄ ≡/{{⍵[⍋⍵]}{(lc,⍵)[(uc,⍵)⍳⍵]}⍵{⍺~⍺~⍵}lc,uc}¨⍺ ⍵} ⍝⍝ #1                                                                          
[27]                                                                                                                                                                         
[28]   →fail unless aEq 1 on'anagram'your_solution'Nag A Ram'                                                                                                                
[29]   →fail unless aEq 1 on'Dyalog APL'your_solution'Dog Pay All'                                                                                                           
[30]   →fail unless aEq 1 on''your_solution' !#!'                                                                                                                            
[31]   →fail unless aEq 0 on'abcde'your_solution'zyxwvu'                                                                                                                     
[32]                                                                                                                                                                         
[33]   →fail unless 1 chkFeature'Problem 1 – Nag A Ram'                                                                                                                      
[34]   ⍝.                                                                                                                                                                    
[35]   your_solution←{1=⍬⍴⍴,⍵:0 ⋄ ⌈/0,{⍬⍴⍴⍵~0}¨{(0 1⍷⍵)⊂⍵}0,2⍝⍝ #2                                                                                                      
[36]                                                                                                                                                                         
[37]   →fail unless aEq 8 on your_solution 1 2 3 4 5 6 7 8 9                                                                                                                 
[38]   →fail unless aEq 0 on your_solution 1                                                                                                                                 
[39]   →fail unless aEq 0 on your_solution 9 8 7 6 5 4                                                                                                                       
[40]   →fail unless aEq 3 on your_solution 1 5 3 4 2 6 7 8                                                                                                                   
[41]                                                                                                                                                                         
[42]   →fail unless 1 chkFeature'Problem 2 – Longest Streak'                                                                                                                 
[43]   ⍝.                                                                                                                                                                    
[44]   your_solution←{0=⍵:1↓''(0 1) ⋄ {÷/⍵}{t←⍵[⍋⍺⍺¨⍵] ⋄ t if{(⍳⍬⍴⍴⍵)=⍵⍳⍵}⍺⍺¨t},{⊃⍺⍺/⍵}{(0,⍳⍵),¨⍵}¨⍳⍵} ⍝⍝ #3                                                                 
[45]                                                                                                                                                                         
[46]   →fail unless aEq quote¨(1↓''(0 1))on your_solution 0                                                                                                                  
[47]   →fail unless aEq quote¨(0 1)(1 1)on your_solution 1                                                                                                                   
[48]   →fail unless aEq quote¨(0 1)(1 5)(1 4)(1 3)(2 5)(1 2)(3 5)(2 3)(3 4)(4 5)(1 1)on your_solution 5                                                                      
[49]                                                                                                                                                                         
[50]   →fail unless 1 chkFeature'Problem 3 – Farey Tale'                                                                                                                     
[51]   ⍝.                                                                                                                                                                    
[52]   your_solution←{ix←⍋⍵ ⋄ ({⍵,¨(⍳⍬⍴⍴⍵)-⍵⍳⍵}⍵[ix])[⍋ix]}{(⍺⍺ ⍺)⍳(⍺⍺ ⍵)} ⍝⍝ #4                                                                                             
[53]                                                                                                                                                                         
[54]   →fail unless aEq 3 8 11 4 10 11 11 on'DYALOG APL'your_solution'AAALLLB'                                                                                               
[55]   →fail unless'should work with empty left argument'aEq 1 1 1 1 on''your_solution'test'                                                                                 
[56]   →fail unless'should work with empty right argument'aEq 1 on ⍬≡'test'your_solution''                                                                                   
[57]                                                                                                                                                                         
[58]   →fail unless 1 chkFeature'Problem 4 – PDI – Progressive Dyadic Iota'                                                                                                  
[59]   ⍝.                                                                                                                                                                    
[60]   your_solution←{(*∘0.5)(+/(*∘2)⍵-{(+/⍵)÷⍬⍴⍴⍵}⍵)÷⍬⍴⍴⍵}∘, ⍝⍝ #5                                                                                                          
[61]   →fail unless aEq quote¨(1.414213562)on your_solution 1 2 3 4 5                                                                                                        
[62]   →fail unless aEq quote¨(28.86607005)on your_solution 10 10⍴⍳100 ⍝ and higher dimensions as well                                                                       
[63]                                                                                                                                                                         
[64]   →fail unless 1 chkFeature'Problem 5 – He''s so mean, he has no standard deviation.'                                                                                   
[65]   ⍝.                                                                                                                                                                    
[66]                                                                                                                                                                         
[67]   within←{∧/⍺{⍺<⍵[1]:0 ⋄ ⍺>⍵[2]:0 ⋄ 1}¨↓⍉↑⍵}                                                                                                                            
[68]   boundingpoints←{0 1⊖↑{⍵(↓(,↑⍵)[2 2⍴3 2 1 4])}(⍺⌊⍵)(⍺⌈⍵)}                                                                                                              
[69]   ⍝ boundingpoints←{↑((topleft)(topright))((bottomleft)(bottomrignt))}                                                                                                  
[70]   your_solution←within{1∊⍺⍺∘(1 1⍉⊃⍵⍵/⍺)¨⊃⍵⍵/⍵}boundingpoints ⍝⍝ #6                                                                                                      
[71]   ⍝ Test cases:                                                                                                                                                         
[72]   →fail unless aEq quote¨1 on(1 1)(5 5)your_solution(3 3)(7 7)                                                                                                          
[73]   →fail unless aEq quote¨1 on(1 1)(5 5)your_solution(5 5)(1 1)                                                                                                          
[74]   →fail unless aEq quote¨0 on(1 1)(3 3)your_solution(4 4)(7 7)                                                                                                          
[75]   →fail unless aEq quote¨1 on(1.1 1.1)(5.5 5.5)your_solution(3.3 3.3)(4.4 4.4)                                                                                          
[76]                                                                                                                                                                         
[77]   →fail unless 1 chkFeature'Problem 6 – Hey! This is My Space'                                                                                                          
[78]   ⍝.                                                                                                                                                                    
[79]                                                                                                                                                                         
[80]   ucf←{lc←⎕UCS 32+⎕UCS uc←⎕A ⋄ (uc,⍵)[(lc,⍵)⍳⍵]}                                                                                                                        
[81]   your_solution←{(⍺⍺ ⍺)⍵⍵ ⍺⍺ ⍵} ⍝⍝ #7                                                                                                                                   
[82]                                                                                                                                                                         
[83]   →fail unless aEq quote¨(3 7 4)on'dyalog'(ucf your_solution⍳)'APL'                                                                                                     
[84]   →fail unless aEq quote¨(0 1 1 1 0 1 0)on'bramley'(ucf your_solution∊)'HAMPSHIRE'                                                                                      
[85]                                                                                                                                                                         
[86]   →fail unless 1 chkFeature'Problem 7 – Just In (Upper) Case'                                                                                                           
[87]   ⍝.                                                                                                                                                                    
[88]   your_solution←{⍵-0.01×13=⍵} ⍝⍝ #8                                                                                                                                     
[89]                                                                                                                                                                         
[90]   ⍝. Test cases:                                                                                                                                                        
[91]   →fail unless aEq quote¨(12.99)on your_solution 13                                                                                                                     
[92]   →fail unless aEq quote¨(1 2 3 4 5 6 7 8 9 10 11 12 12.99 14 15)on your_solution⍳15                                                                                    
[93]   →fail unless aEq quote¨(11 12 12.99 14 15)on your_solution 6+5 6 7 8 9                                                                                                
[94]   →fail unless aEq quote¨(12.99 130 13.13 1300)on your_solution 13 130 13.13 1300 ⍝ we only care about the number 13                                                    
[95]                                                                                                                                                                         
[96]   →fail unless 1 chkFeature'Problem 8 – Unlucky 13'                                                                                                                     
[97]   ⍝.                                                                                                                                                                    
[98]   your_solution←{4>⍬⍴⍴,⍵:⍵ ⋄ ⍵[1],({⊃,/⌽¨((⍬⍴⍴⍵)⍴1 0){⎕ML←1 ⋄ ⍺⊂⍵}⍵}1↓¯1↓⍵),¯1↑⍵} ⍝⍝ #9                                                                                 
[99]   ⍝ Test cases:                                                                                                                                                         
[100]  →fail unless aEq quote¨'a'on your_solution'a'                                                                                                                         
[101]  →fail unless aEq quote¨'ab'on your_solution'ab'                                                                                                                       
[102]  →fail unless aEq quote¨'abc'on your_solution'abc'                                                                                                                     
[103]  →fail unless aEq quote¨'acbd'on your_solution'abcd'                                                                                                                   
[104]  →fail unless aEq quote¨'acbde'on your_solution'abcde'                                                                                                                 
[105]  →fail unless aEq quote¨'acbedf'on your_solution'abcdef'                                                                                                               
[106]                                                                                                                                                                        
[107]  →fail unless aEq quote¨'agrmunet'on your_solution'argument'                                                                                                           
[108]  →fail unless aEq quote¨'tihs' 'is' 'aewosme'on your_solution¨'this' 'is' 'awesome'                                                                                    
[109]                                                                                                                                                                        
[110]  →fail unless 1 chkFeature'Problem 9 – I''d Like Mine Scrambled Please'                                                                                                
[111]  ⍝.                                                                                                                                                                    
[112]                                                                                                                                                                        
[113]  your_solution←{{(2⌷⍴↑⍵)∘{(' '/⍨⌊0.5×⍺-⍬⍴⍴⍵),⍵}{↑⍺⍺¨⍵}⍵}{⍕⍵~0}{⍺⍺¨↓⍵}{∘.(!⍨)⍨0,⍳⍵}⍵} ⍝⍝ #10                                                                            
[114] ⍝ Test cases:                                                                                                                                                          
[115]                                                                                                                                                                        
[116]  expV←''                                                                                                                                                               
[117]  expV,←⊂'                 1'                                                                                                                                           
[118]  expV,←⊂'                1 1'                                                                                                                                          
[119]  expV,←⊂'               1 2 1'                                                                                                                                         
[120]  expV,←⊂'              1 3 3 1'                                                                                                                                        
[121]  expV,←⊂'             1 4 6 4 1'                                                                                                                                       
[122]  expV,←⊂'           1 5 10 10 5 1'                                                                                                                                     
[123]  expV,←⊂'         1 6 15 20 15 6 1'                                                                                                                                    
[124]  expV,←⊂'        1 7 21 35 35 21 7 1'                                                                                                                                  
[125]  expV,←⊂'      1 8 28 56 70 56 28 8 1'                                                                                                                                 
[126]  expV,←⊂'    1 9 36 84 126 126 84 36 9 1'                                                                                                                              
[127]  expV,←⊂'1 10 45 120 210 252 210 120 45 10 1'                                                                                                                          
[128]                                                                                                                                                                        
[129]  →fail unless aEq(↑expV)on your_solution 10                                                                                                                            
[130]                                                                                                                                                                        
[131]  →fail unless aEq quote¨(↑' 1' '1 1')on your_solution 1                                                                                                                
[132]                                                                                                                                                                        
[133]  →fail unless aEq quote¨(1↓[1]↑'' '1')on your_solution 0                                                                                                               
[134]  1                                                                                                                                                                     
[135]                                                                                                                                                                        
[136]  →fail unless 1 chkFeature'Problem 10 – Blaise''ing a Trail'                                                                                                           
[137]                                                                                                                                                                        
[138]  ⍝⍝--                                                                                                                                                                  
[139]  :If ~1 chkFeature tfuuN omrepl'implement "⍵"'                                                                                                                         
[140]      ⎕←APLPmtMFS'TEST_',tfuuN                                                                                                                                          
[141]      →XIT                                                                                                                                                              
[142]  :EndIf                                                                                                                                                                
[143]                                                                                                                                                                        
[144]  ⎕←(ThisFN''){⍺∘{i l←(⍬⍴⍵)(1↓⍵) ⋄ (⍺ at i),('your_','solution','←')'{}←'TEXTREPL ⍺ FNline i}ofE ⍺ FNscanN ⍵}'your_solution','←'                                        
[145]                                                                                                                                                                        
[146]  r←1                                                                                                                                                                   
[147]  →XIT                                                                                                                                                                  
[148]                                                                                                                                                                        
[149]                                                                                                                                                                        
[150] fail:                                                                                                                                                                  
[151]  ⎕←APLPmtMFS ThisFN''                                                                                                                                                  
[152] XIT: ⍝⍝-------                                                                                                                                                         
[153]  test_complete                                                                                                                                                         
     ∇                                                                                                                                                                       

Page served at: Wed, 08 Apr 2020 06:01:19 AST.