%I #15 Mar 23 2024 17:44:56
%S 9,81,961,9216,96721,929296,9690769,98525476,987656329,9618509476,
%T 98987632129,987650365636,9890943230169,98987854141696,
%U 987896383010761,9896907878105616,98989096389856929,989894587654967296,9898969096969272961,98985494707696721476
%N Largest n-digit square with property that digits alternate in parity, or 0 if no such number exists.
%H Sean A. Irvine, <a href="/A068881/b068881.txt">Table of n, a(n) for n = 1..53</a> (terms 1..33 from Giovanni Resta)
%e a(4) = 9216 as 9, 2, 1, 6 have alternating parity.
%p alp:= proc(n) local L,d;
%p L:= convert(n,base,10);
%p d:= nops(L);
%p if d::even then L:= L + map(op, [[0,1]$(d/2)]) else L:= L + map(op, [[0,1]$((d-1)/2),[0]]) fi;
%p nops(convert(L mod 2, set))=1
%p end proc:f:= proc(d) local s;
%p for s from floor(sqrt(10^d)) by -1 to ceil(sqrt(10^(d-1))) do
%p if alp(s^2) then return s^2 fi
%p od;
%p 0
%p end proc:map(f, [$1..10]); # _Robert Israel_, Aug 14 2018
%t altQ[n_] := n < 10 || Union[Total /@ Partition[ Mod[ IntegerDigits@ n, 2], 2, 1]] == {1}; a[n_] := Block[{r = Floor@ Sqrt@ FromDigits[8 + Mod[ Range@ n, 2]]}, While[! altQ[r^2], r--]; r^2]; Array[a, 16] (* _Giovanni Resta_, Aug 17 2018 *)
%Y Cf. A068876, A030152, A068880.
%K base,nonn
%O 1,1
%A _Amarnath Murthy_, Mar 19 2002
%E a(5) corrected and more terms from _Robert Israel_, Aug 14 2018
%E a(18)-a(20) from _Giovanni Resta_, Aug 16 2018
|