Skip to main content
Commonmark migration
Source Link

#Mathematica, 197 193 chars

Mathematica, 197 193 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n},Reverse@#2]&@@@Tuples[Subsets@Range[3,n=Length[i=FromDigits/@StringSplit@InputString[]]]-1,2],{}⋃#==Sort@#∧And@@Thread[i[[#]]≥Abs[#-Rest@#~Append~1]]&]]/.∞->-1 

#Mathematica, 197 193 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n},Reverse@#2]&@@@Tuples[Subsets@Range[3,n=Length[i=FromDigits/@StringSplit@InputString[]]]-1,2],{}⋃#==Sort@#∧And@@Thread[i[[#]]≥Abs[#-Rest@#~Append~1]]&]]/.∞->-1 

Mathematica, 197 193 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n},Reverse@#2]&@@@Tuples[Subsets@Range[3,n=Length[i=FromDigits/@StringSplit@InputString[]]]-1,2],{}⋃#==Sort@#∧And@@Thread[i[[#]]≥Abs[#-Rest@#~Append~1]]&]]/.∞->-1 
added 7 characters in body
Source Link
alephalpha
  • 50k
  • 7
  • 68
  • 182

#Mathematica, 197197 193 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n+1n},Reverse@#2]&@@@Tuples[Subsets@Range[2Reverse@#2]&@@@Tuples[Subsets@Range[3,n=Length[i=FromDigits/@StringSplit@InputString[]]@StringSplit@InputString[]]]-1]1,2],{}⋃#==Sort@#&&And@@Thread[i[[#]]>=Abs[#⋃#==Sort@#∧And@@Thread[i[[#]]≥Abs[#-Rest@#~Append~1]]&]]/.∞->-1 

#Mathematica, 197 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n+1},Reverse@#2]&@@@Tuples[Subsets@Range[2,n=Length[i=FromDigits/@StringSplit@InputString[]]-1],2],{}⋃#==Sort@#&&And@@Thread[i[[#]]>=Abs[#-Rest@#~Append~1]]&]]/.∞->-1 

#Mathematica, 197 193 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n},Reverse@#2]&@@@Tuples[Subsets@Range[3,n=Length[i=FromDigits/@StringSplit@InputString[]]]-1,2],{}⋃#==Sort@#∧And@@Thread[i[[#]]≥Abs[#-Rest@#~Append~1]]&]]/.∞->-1 
Source Link
alephalpha
  • 50k
  • 7
  • 68
  • 182

#Mathematica, 197 chars

Brute force.

Min[Length/@Select[Join[{1},#,{n+1},Reverse@#2]&@@@Tuples[Subsets@Range[2,n=Length[i=FromDigits/@StringSplit@InputString[]]-1],2],{}⋃#==Sort@#&&And@@Thread[i[[#]]>=Abs[#-Rest@#~Append~1]]&]]/.∞->-1