5
1
From Wikipedia:
PESEL is the national identification number used in Poland since 1979. It always has 11 digits, identifies just one person and cannot be changed to another one.
It has the form of YYMMDDZZZXQ, where YYMMDD is the date of birth (with century encoded in month field), ZZZ is the personal identification number, X denotes sex (even number for females, odd number for males) and Q is a control digit, which is used to verify whether a given PESEL is correct or not.
Having a PESEL in the form of ABCDEF GHIJK, one can check the vailidity of the number by computing the following expression:
A*1 + B*3 + C*7 + D*9 + E*1 + F*3 + G*7 + H*9 + I*1 + J*3
Then the last digit of the result should be subtracted from 10. If the result of the last operation is not equal to the last digit of a given PESEL, the PESEL is incorrect. This system works reliably well for catching one-digit mistakes and digit swaps.
Provide a short program to generate random, valid PESEL number:
- It has to be a PESEL a person born in either 20th or 21st century
- The birth birth date has to be random but doesn't have to validate leap years or number of days in a month (i.e. the numbers representing the day number have to be between
01
and31
) - All valid PESELs in this date range (01.01.1990-31.12.2099) must be possible
- The shortest code (i.e. complete program code), in bytes, wins.
2How random? eg, must all digits vary, must eg all 20th century birthdays be possible, and no others? Seems like this can be subverted by solutions that just coin toss between male and female. – bazzargh – 2014-04-13T09:29:06.553
@bazzargh, good point - let it be a PESEL for a person born in either 20th or 21st century. – syntagma – 2014-04-13T09:37:25.063
2Actually my point is more that 'random' can mean 'one of a fixed set of choices'. If you pick a PESEL of A001100000Q then Q=10-A, it's still 'random', with a random date, but way less code. Saying that all valid PESELs for your date range must be possible blocks tricks like this. – bazzargh – 2014-04-13T09:44:10.430
@bazzargh Changed the question once again. – syntagma – 2014-04-13T09:47:13.527
1
Please correct the algorithm: The current version allows the last digit to be
– Heiko Oberdiek – 2014-04-13T12:20:59.22710
. The Polish Wikipedia version uses a modulo 10 operation to get 0 in this case.1The gender entry uses the full range
0
to9
to encode male and female (1 bit). What's the purpose of this "random noise"? Or are there further specification on the gender field that I have missed? – Heiko Oberdiek – 2014-04-13T12:24:00.1703
The century is encoded in the month field. This is neither specified in the question or links. For example, it is explained in the Polish Wikipedia article.
– Heiko Oberdiek – 2014-04-13T12:26:13.4031Please clarify the restrictions on the date. The question says, that all dates of the 20th and 21st century must be possible. It is unclear, if invalid dates are allowed. It makes a huge difference in a code golf competition, if the date has to be validated, e.g. excluding YYYY-02-29 with YYYY not being a leap year. – Heiko Oberdiek – 2014-04-13T12:34:41.007
See http://en.wikipedia.org/wiki/PESEL for an explanation, in English, of the PESEL encoding.
– DavidC – 2014-04-13T14:24:55.380The control digit is found by taking the remainder of the number modulus 10. It is not found by subtraction. – DavidC – 2014-04-13T14:57:03.930
@DavidCarraher: Missed that, the Polish version has a nice table instead. – Heiko Oberdiek – 2014-04-13T16:15:22.430
@DavidCarraher: The result of the expression in the question is subtracted from 10 and then the control digit is the remainder of the number modulus 10. – Heiko Oberdiek – 2014-04-13T16:19:51.673
Isn't that the same as finding the remainder of division by 10. (I.e. the subtraction is unnecessary.) – DavidC – 2014-04-13T16:51:43.867
@DavidCarraher: 136 % 10 = 7 is different from (10 - (137 % 10)) % 10 = 3. (Of course there is room for optimization in the calculation of the control digit.) – Heiko Oberdiek – 2014-04-13T17:31:23.000
you are correct (of course)! – DavidC – 2014-04-13T19:01:04.653