Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Liste de départements limitrophes français
01:38,39,69,71,73,74
02:08,51,59,60,77,80
03:18,23,42,58,63,71
04:05,06,26,83,84
05:04,26,38,73
06:04,83
07:26,30,38,42,43,48,84
08:02,51,55
09:11,31,66
10:21,51,52,77,89
11:09,31,34,66,81
12:15,30,34,46,48,81,82
13:30,83,84
14:27,50,61,76
15:12,19,43,46,48,63
16:17,24,79,86,87
17:16,24,33,79,85
18:03,23,36,41,45,58
19:15,23,24,46,63,87
2A:2B
2B:2A
21:10,39,52,58,70,71,89
22:29,35,56
23:03,18,19,36,63,87
24:16,17,19,33,46,47,87
25:39,70,90
26:04,05,07,38,84
27:14,28,60,61,76,78,95
28:27,41,45,61,72,78,91
29:22,56
30:07,12,13,34,48,84
31:09,11,32,65,81,82
32:31,40,47,64,65,82
33:17,24,40,47
34:11,12,30,81
35:22,44,49,50,53,56
36:18,23,37,41,86,87
37:36,41,49,72,86
38:01,05,07,26,42,69,73
39:01,21,25,70,71
40:32,33,47,64
41:18,28,36,37,45,72
42:03,07,38,43,63,69,71
43:07,15,42,48,63
44:35,49,56,85
45:18,28,41,58,77,89,91
46:12,15,19,24,47,82
47:24,32,33,40,46,82
48:07,12,15,30,43
49:35,37,44,53,72,79,85,86
50:14,35,53,61
51:02,08,10,52,55,77
52:10,21,51,55,70,88
53:35,49,50,61,72
54:55,57,67,88
55:08,51,52,54,88
56:22,29,35,44
57:54,67
58:03,18,21,45,71,89
59:02,62,80
60:02,27,76,77,80,95
61:14,27,28,50,53,72
62:59,80
63:03,15,19,23,42,43
64:32,40,65
65:31,32,64
66:09,11
67:54,57,68,88
68:67,88,90
69:01,38,42,71
70:21,25,39,52,88,90
71:01,03,21,39,42,58,69
72:28,37,41,49,53,61
73:01,05,38,74
74:01,73
75:92,93,94
76:14,27,60,80
77:02,10,45,51,60,89,91,93,94,95
78:27,28,91,92,95
79:16,17,49,85,86
80:02,59,60,62,76
81:11,12,31,34,82
82:12,31,32,46,47,81
83:04,06,13,84
84:04,07,13,26,30,83
85:17,44,49,79
86:16,36,37,49,79,87
87:16,19,23,24,36,86
88:52,54,55,67,68,70,90
89:10,21,45,58,77
90:25,68,70,88
91:28,45,77,78,92,94
92:75,78,91,93,94,95
93:75,77,92,94,95
94:75,77,91,92,93
95:27,60,77,78,92,93
#!/usr/bin/env ruby
# Build a hash from the text file
deps = {}
File.open("liste-de-departements-limitrophes-francais.txt").each_line do |line|
line, ending = line.split(/\n/)
next if !line
dep, links = line.split(":")
next if !links
links = links.split(",")
deps[dep] = links
end
# Microscopic testing lib
def assert(assertion, message = nil)
raise "FAIL #{message}" unless assertion
print "."
end
puts "Testing"
deps.each do |dep, links|
assert links == links.uniq, "should not have duplicate links in department '#{dep}'"
assert links == links.sort, "should have sorted links in department '#{dep}'"
assert !links.include?(dep), "departement '#{dep}' should not reference itself"
links.each do |link|
assert deps[link], "departement '#{link}' does not exist in departement '#{dep}'"
assert deps[link].include?(dep), "departement '#{dep}' does not exist in departement '#{link}'"
end
end
puts
puts "Tests pass!"
@fcamblor
Copy link

fcamblor commented Apr 30, 2012

Est-il bien utile de référencer le département 20 alors que 2A et 2B sont définis ?

Autre question, plus problématique : est-il normal que lorsqu'on compte le nombre de départements limitrophes (par ex, 01 a 6 départements limitrophes ; ce compte est facile à obtenir : il suffit de compter le nombre de ":" et de ","), on obtienne un nombre impair (479 occurrences si on enlève la ligne "20:" qui ne sert a rien) alors que la liste est bijective ?
N'y a-t-il pas une erreur quelque part ?

@sunny
Copy link
Author

sunny commented Apr 30, 2012

@fcamblor Pour l'erreur ça vaudrait le coup en effet de trouver quelles relations ne sont pas symétriques. (Et 20 on peut s'en passer, en effet.)

@fcamblor
Copy link

fcamblor commented Apr 30, 2012

Ok le 92 se référence lui-même ... c'était là le pb !

@sunny
Copy link
Author

sunny commented Apr 30, 2012

Merci @fcamblor ! J'ai ajouté un petit bout de code pour s'assurer qu'on ait pas ce genre de régressions dans le futur.

@lagenceoueb
Copy link

lagenceoueb commented Feb 2, 2022

Hello @sunny,
merci pour le taf qui m'a bien aidé pour un projet PHP.
Je partage ici :
https://gist.github.com/lagenceoueb/246bcd0441620aeac5f8f7f97efdd710

@fcamblor
Copy link

fcamblor commented Jun 29, 2022

J'ai trouvé une erreur : 04 & 13 sont limitrophes (source: wikipedia)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment