Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
get_middle_f1(Str) = [X,Y,Z] =>
|
||||
append(Pre,[X,Y,Z],Post,Str),
|
||||
length(Pre) = length(Post).
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
get_middle_f2(Str) = Str[Mid-1..Mid+1] =>
|
||||
Mid = 1 + Str.len div 2.
|
||||
26
Task/Middle-three-digits/Picat/middle-three-digits-3.picat
Normal file
26
Task/Middle-three-digits/Picat/middle-three-digits-3.picat
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
go =>
|
||||
Success = [123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345],
|
||||
Fail = [1, 2, -1, -10, 2002, -2002, 0],
|
||||
All = Success ++ Fail,
|
||||
|
||||
test(All, get_middle_f1),
|
||||
test(All, get_middle_f2).
|
||||
|
||||
% Test and check for exceptions
|
||||
test(List,F) =>
|
||||
printf("\nTesting %w:\n", F),
|
||||
foreach(N in List)
|
||||
catch(Middle=apply(get_middle,N,F), E, printf("%d = exception %w\n",N,E)),
|
||||
if E.var() then
|
||||
println([n=N,middle=Middle])
|
||||
end
|
||||
end,
|
||||
nl.
|
||||
|
||||
% Check with the get_middle funcion F
|
||||
get_middle(N,F) = apply(F,Str) =>
|
||||
Str = N.abs().to_string(),
|
||||
Len = length(Str),
|
||||
if Len mod 2 = 0 then throw $not_odd_length(N)
|
||||
elseif Len < 3 then throw $number_too_small(N)
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue