Let $(a,b)$ and $(c,d)$ be intervals in $\Bbb R$, and find an injective and surjective function from $(a,b)$ to $(c,d)$

So here is this question I got stuck on:

Let $(a,b)$, $(c,d)$ be intervals (not sure if that's the correct term) on $\Bbb R$, so that $a<b$, $c<d$. Find an injective and surjective function $f:(a,b)\rightarrow(c,d)$.

Thanks in advance!

P.S. I get these question a lot. Is that some way of thinking, or some general method I should follow to make these question easier for me to solve?


Solution 1:

enter image description here

Edit: It's not supposed to be a square.

Solution 2:

Hint

Try a function of the form $x \mapsto sx + t$ with $s,t\in\mathbb R$.