Generate Codes based on start and End values of numbers in a column

Hello All,
Could you please help with this.
This is what I have:
506234.222 2
506234.222 2
506234.222 2
506234.222 2
508212.200 2
508212.200 2
333456.111 2
333456.111 2
333456.111 2
333456.111 2

But this is what I want:
506234.222 1
506234.222 2
506234.222 2
506234.222 3
508212.200 1
508212.200 3
333456.111 1
333456.111 2
333456.111 2
333456.111 3
Such that 1 indicates the begining of a value and 3 the end of same value in a column of different values

What if there is only a single line with a given value? 1 or 3?

It will be 3

Try...

$ cat file1
506234.222 2
506234.222 2
506234.222 2
506234.222 2
508212.200 2
508212.200 2
333456.111 2
333456.111 2
333456.111 2
333456.111 2

$ awk 'NR==FNR{a[NR]=$1;next}a[FNR]!=a[FNR-1]{$2=1}a[FNR]!=a[FNR+1]{$2=3};1' file1 file1
506234.222 1
506234.222 2
506234.222 2
506234.222 3
508212.200 1
508212.200 3
333456.111 1
333456.111 2
333456.111 2
333456.111 3

$

Something like:

awk '
x!=$1 {first=1; print FS x FS 3}
x==$1 {print FS x FS (first?1:2); first=0}
{x=$1}
END {print x FS 3}
' file

(untested!)

The above works fine - just have to edit the last value though ...
Thanks to all of you - great!