************************************

TO PLOT THE CANTOR FUNCTION:
(this takes a while)

thepoints={{0,0},{1,1}};
levels=10;
Do[number=(n/(3^levels));nterms=25;a=Table[0,{i,1,25}];leftover=Table[0,{i,1,25}];a[[1]]=Floor[3 number];leftover[[1]]=number-((a[[1]])/3);Do[a[[k]]=Floor[(3^k) leftover[[k-1]]];leftover[[k]]=leftover[[k-1]]-((a[[k]])/(3^k)),{k,2,nterms}];nlast=nterms;Do[If[a[[nterms+1-k]]==1,nlast=nterms+1-k],{k,1,nterms}];fun[number]=N[(∑_(k=1)^(nlast-1))((a[[k]])/(2 (2^k)))+(1/(2^nlast))];thepoints=Append[thepoints,{number,fun[number]}],{n,1,(3^levels)-1}];
fred=thepoints[[Ordering[thepoints]]];
cantorgraph=ListPlot[fred,Joined->True]

Show[cantorgraph,PlotRange->{{0,1},{0,1}}]

Show[cantorgraph,PlotRange->{{0,(1/3)},{0,(1/2)}}]

Show[cantorgraph,PlotRange->{{0,(1/9)},{0,(1/4)}}]

Show[cantorgraph,PlotRange->{{0,(1/27)},{0,(1/8)}}]

Clear[n];
Do[Print[Show[cantorgraph,PlotRange->{{0,((((1/3)))^n)},{0,((((1/2)))^n)}},Ticks->{{(1/3) ((((1/3)))^n),(2/3) ((((1/3)))^n),((((1/3)))^n)},{((((1/2)))^(n+1)),((((1/2)))^n)}}]],{n,1,4}];

Clear[n];
Do[Print[Show[cantorgraph,PlotRange->{{0,((((1/3)))^n)},{0,((((1/2)))^n)}},Ticks->{{(1/3) ((((1/3)))^n),(2/3) ((((1/3)))^n),((((1/3)))^n)},{((((1/2)))^(n+1)),((((1/2)))^n)}}]],{n,1,4}];

Show[cantorgraph,PlotRange->{{0,1},{0,1}},AspectRatio->Automatic]
Show[cantorgraph,PlotRange->{{0,(1/3)},{0,(1/2)}},AspectRatio->Automatic]
Show[cantorgraph,PlotRange->{{0,(1/9)},{0,(1/4)}},AspectRatio->Automatic]
Show[cantorgraph,PlotRange->{{0,(1/27)},{0,(1/8)}},AspectRatio->Automatic]

************Older Stuff*******************

number=3/5;

nterms=25;
a=Table[0,{i,1,25}];
leftover=Table[0,{i,1,25}];

a[[1]]=Floor[3*number];
leftover[[1]]=number-a[[1]]/3;
Do[
a[[k]]=Floor[3^k*leftover[[k-1]]];
leftover[[k]]=leftover[[k-1]]-a[[k]]/3^k
,{k,2,nterms}];

nlast=nterms;
Do[If[a[[nterms+1-k]]==1,nlast=nterms+1-k]
,{k,1,nterms}];

Print[number," is the sum of"];
Print[Table[a[[i]]/3^i,{i,1,10}],"..."];

fun[number]=N[Sum[1/2*a[[k]]/2^k,{k,1,nlast-1}]+1/2^nlast];

Print["The Cantor function F(",number,") ≈ ",fun[number]];

****************************************

dd={{0,0},{1/3,1/2},{1,1},{2/3,1/2},{1/9,1/4},{2/9,1/4},{7/9,3/4},{8/9,3/4},{1/27,1/8},{2/27,1/8},
{7/27,3/8},{8/27,3/8},
{19/27,5/8},{20/27,5/8},
{25/27,7/8},{26/27,7/8},{1/81,1/16},{2/81,1/16},{7/81,3/16},{8/81,3/16},
{19/81,5/16},{20/81,5/16},
{25/81,7/16},{26/81,7/16},
{56/81,9/16},{55/81,9/16},
{62/81,11/16},{61/81,11/16},
{74/81,13/16},{73/81,13/16},
{80/81,15/16},{79/81,15/16}
};
thelist=dd[[Ordering[dd]]];
ListPlot[thelist,PlotJoined->True];