Openai/69508c1f-2064-8012-8f0a-41df99edf034
Appearance
This conversation was exported from ChatGPT[1]
gpt-5-2-thinking[edit | edit source]
User: Give me all 4-digit codes such that the sum of the digits is 17 and at least one digit appears twice.[edit | edit source]
Give me all 4-digit codes such that the sum of the digits is 17 and at least one digit appears twice. Use Python to generate and validate.
Assistant:[edit | edit source]
Assistant: python[edit | edit source]
codes = []
for n in range(10000):
s = f"{n:04d}" # includes leading zeros
digits = [int(ch) for ch in s]
if sum(digits) == 17 and len(set(digits)) < 4: # at least one repeated digit
codes.append(s)
=== validate ===
assert all(sum(int(ch) for ch in c) == 17 for c in codes)
assert all(len(set(c)) < 4 for c in codes)
print(len(codes))
print("\n".join(codes))
Output (276 codes):
0089
0098
0188
0377
0449
0494
0557
0566
0575
0656
0665
0737
0755
0773
0809
0818
0881
0890
0908
0944
0980
1088
1169
1178
1187
1196
1277
1448
1466
1484
1556
1565
1619
1646
1655
1664
1691
1718
1727
1772
1781
1808
1817
1844
1871
1880
1916
1961
2177
2249
2258
2267
2276
2285
2294
2339
2366
2393
2429
2447
2474
2492
2528
2555
2582
2627
2636
2663
2672
2717
2726
2744
2762
2771
2825
2852
2924
2933
2942
3077
3239
3266
3293
3329
3338
3347
3356
3365
3374
3383
3392
3437
3446
3455
3464
3473
3536
3545
3554
3563
3626
3635
3644
3653
3662
3707
3734
3743
3770
3833
3923
3932
4049
4094
4148
4166
4184
4229
4247
4274
4292
4337
4346
4355
4364
4373
4409
4418
4427
4436
4445
4454
4463
4472
4481
4490
4535
4544
4553
4616
4634
4643
4661
4724
4733
4742
4814
4841
4904
4922
4940
5057
5066
5075
5156
5165
5228
5255
5282
5336
5345
5354
5363
5435
5444
5453
5507
5516
5525
5534
5543
5552
5561
5570
5606
5615
5633
5651
5660
5705
5750
5822
6056
6065
6119
6146
6155
6164
6191
6227
6236
6263
6272
6326
6335
6344
6353
6362
6416
6434
6443
6461
6506
6515
6533
6551
6560
6605
6614
6623
6632
6641
6650
6722
6911
7037
7055
7073
7118
7127
7172
7181
7217
7226
7244
7262
7271
7307
7334
7343
7370
7424
7433
7442
7505
7550
7622
7703
7712
7721
7730
7811
8009
8018
8081
8090
8108
8117
8144
8171
8180
8225
8252
8333
8414
8441
8522
8711
8801
8810
8900
9008
9044
9080
9116
9161
9224
9233
9242
9323
9332
9404
9422
9440
9611
9800References[edit | edit source]
- ↑ "4-digit codes sum 17". ChatGPT. Retrieved 2025-12-28.