Skip to content

Instantly share code, notes, and snippets.

@jgrimes
Created June 15, 2013 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgrimes/5788973 to your computer and use it in GitHub Desktop.
Save jgrimes/5788973 to your computer and use it in GitHub Desktop.
module Main where
import Control.Monad
import Data.List
import Data.Char (intToDigit)
perms xs n = do
l <- replicateM n xs
guard (length l <= n)
let z = do x <- [0..(n - 1)]
y <- [1..(n - 1)]
if (x < y)
then return (l!!x <= l!!y || l!!y == 0 || l!!y `elem` (take (y - 1) l))
else return True
guard (and z)
return l
main = mapM (putStrLn . (map intToDigit)) (perms [0..9] 3)
@jgrimes
Copy link
Author

jgrimes commented Jun 15, 2013

000
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
022
023
024
025
026
027
028
029
030
033
034
035
036
037
038
039
040
044
045
046
047
048
049
050
055
056
057
058
059
060
066
067
068
069
070
077
078
079
080
088
089
090
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
133
134
135
136
137
138
139
140
141
144
145
146
147
148
149
150
151
155
156
157
158
159
160
161
166
167
168
169
170
171
177
178
179
180
181
188
189
190
191
199
200
202
203
204
205
206
207
208
209
220
222
223
224
225
226
227
228
229
230
232
233
234
235
236
237
238
239
240
242
244
245
246
247
248
249
250
252
255
256
257
258
259
260
262
266
267
268
269
270
272
277
278
279
280
282
288
289
290
292
299
300
303
304
305
306
307
308
309
330
333
334
335
336
337
338
339
340
343
344
345
346
347
348
349
350
353
355
356
357
358
359
360
363
366
367
368
369
370
373
377
378
379
380
383
388
389
390
393
399
400
404
405
406
407
408
409
440
444
445
446
447
448
449
450
454
455
456
457
458
459
460
464
466
467
468
469
470
474
477
478
479
480
484
488
489
490
494
499
500
505
506
507
508
509
550
555
556
557
558
559
560
565
566
567
568
569
570
575
577
578
579
580
585
588
589
590
595
599
600
606
607
608
609
660
666
667
668
669
670
676
677
678
679
680
686
688
689
690
696
699
700
707
708
709
770
777
778
779
780
787
788
789
790
797
799
800
808
809
880
888
889
890
898
899
900
909
990
999

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