Connected and Compact preserving function is not continuous example?
Solution 1:
If a function $f:X\to Y$, between any topological spaces, has finite image, then it maps any set in $X$ to a compact set in $Y$, and in particular thus it preserves compactness. Further, if $X$ is totally disconnected, so every connected component is a singleton, then the image of $f$ on any connected set in $X$ is a singleton too, and thus connected in $Y$. So, for such $X$, any function preserves connectivity.
So, you now get a huge class of compactness and connectivity preserving functions $f:X\to Y$ which are not continuous. Simply take $X$ to be totally disconnected (e.g., $X=\mathbb Q$ with the usual topology (so in particular, $X$ is Hausdorff)) and take $Y$ to be arbitrary (e.g., $Y=[0,1]$, so it's Hausdorff). Now just let $f:X\to Y$ attain finitely many values, while not being continuous. There are plenty of such functions.