-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZev Euler.rkt
3074 lines (2538 loc) · 86.2 KB
/
Zev Euler.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#lang racket
(require math/base)
(require math/number-theory)
(require test-engine/racket-tests)
(define (rlist->num l)
(if (empty? l)
0
(+ (car l) (* 10 (rlist->num (cdr l))))))
(define (list->num l)
(rlist->num (reverse l)))
(define (factor fact num)
(integer? (/ num fact)))
(define (p#1h numon lis)
(if (= numon 0)
(sum lis)
(if (or (factor 5 numon) (factor 3 numon))
(p#1h (- numon 1) (cons numon lis))
(p#1h (- numon 1) lis))))
(define (p#1)
(p#1h 999 (list)))
(define (last_list lis)
(if (empty? (cdr lis))
(car lis)
(last_list (cdr lis))))
(define (revh lis newlis)
(if (empty? lis)
newlis
(revh (cdr lis) (cons (car lis) newlis))))
(define (rev lis)
(revh lis (list)))
(define (droph lis newlis)
(if (empty? (cdr lis))
(rev newlis)
(droph (cdr lis) (cons (car lis) newlis))))
(define (drop lis)
(droph lis (list)))
(define (lengthh lis num)
(if (empty? lis)
num
(lengthh (cdr lis) (+ num 1))))
(define (length_lis lis)
(lengthh lis 0))
(define (evensh lis newlis)
(if (empty? lis)
(rev newlis)
(if (integer? (/ (car lis) 2))
(evensh (cdr lis) (cons (car lis) newlis))
(evensh (cdr lis) newlis))))
(define (evens lis)
(evensh lis (list)))
(define (p#2h lis)
(if (> (last_list lis) 4000000)
(sum (evens (drop lis)))
(p#2h (rev (cons (+ (last_list lis) (last_list (drop lis))) (rev lis))))))
(define (p#2)
(p#2h (list 1 2)))
(define (largeh lis big)
(if (empty? lis)
big
(if (> (car lis) big)
(largeh (cdr lis) (car lis))
(largeh (cdr lis) big))))
(define (large_list lis)
(largeh (cdr lis) (car lis)))
(define (p#3h num lis at)
(if (> (* at at) num)
num
(if (factor at num)
(flatten (cons (p#3h at (list 1) 2) (p#3h (/ num at) (list 1) 2)))
(p#3h num lis (+ at 1)))))
(define (pf num)
(p#3h num (list 1) 2))
(define (l-nh lis num on)
(if (empty? lis)
num
(l-nh (drop lis) (+ num (* (last_list lis) (expt 10 on))) (+ on 1))))
(define (list-num lis)
(l-nh lis 0 0))
(define (n-lh num lis)
(if (= num 0)
lis
(n-lh (quotient num 10) (cons (remainder num 10) lis))))
(define (num-list num)
(n-lh num (list)))
(define (pall? lis)
(equal? lis (rev lis)))
(define (pal? num)
(pall? (num-list num)))
(define (p#4h lis num1 num2)
(if (and (= num1 100) (= num2 100))
(length_lis lis)
(if (pal? (* num1 num2))
(if (= num1 100)
(p#4h (cons (* num1 num2) lis) 999 (- num2 1))
(p#4h (cons (* num1 num2) lis) (- num1 1) num2))
(if (= num1 100)
(p#4h lis 999 (- num2 1))
(p#4h lis (- num1 1) num2)))))
(define (p#4)
(p#4h (list) 999 999))
(define (factors? num check)
(if (= num 1)
true
(if (= 0 (remainder check num))
(factors? (- num 1) check)
false)))
(define (p#5h num on)
(if (factors? num on)
on
(p#5h num (+ on num))))
(define (p#5 num)
(p#5h num num))
(define (adduph num su)
(if (= num 1)
(+ su 1)
(adduph (- num 1) (+ su num))))
(define (addup num)
(adduph num 0))
(define (poweruph num su)
(if (= num 1)
(+ su 1)
(poweruph (- num 1) (+ su (expt num 2)))))
(define (powerup num)
(poweruph num 0))
(define (p#6 num)
(- (expt (addup num) 2) (powerup num)))
(define (p#7h end lis on)
(if (= (length_lis lis) end)
(car lis)
(if (prime? on)
(p#7h end (cons on lis) (+ on 1))
(p#7h end lis (+ on 1)))))
(define (p#7 num)
(p#7h num (list) 1))
(define (fronth lis new num on)
(if (< num on)
(rev new)
(fronth (cdr lis) (cons (car lis) new) num (+ on 1))))
(define (front num lis)
(fronth lis (list) num 1))
(define (prodlh lis num)
(if (empty? lis)
num
(prodlh (cdr lis) (* num (car lis)))))
(define (prodl lis)
(prodlh lis 1))
(define (p#8h lis biggest)
(if (= 12 (length_lis lis))
biggest
(if (> (prodl (front 13 lis)) biggest)
(p#8h (cdr lis) (prodl (front 13 lis)))
(p#8h (cdr lis) biggest))))
(define (p#8 num)
(p#8h (num-list num) 0))
(define (poth? a b c)
(and (= (+ (expt a 2) (expt b 2)) (expt c 2)) (> c b a)))
(define (haspo a b)
(if (and (integer? (sqrt (+ (expt a 2) (expt b 2)))) (> b a))
(sqrt (+ (expt a 2) (expt b 2)))
0))
(define (haspo? a b)
(and (integer? (sqrt (+ (expt a 2) (expt b 2)))) (> b a)))
(define (p#9h num1 num2)
(if (and (haspo? num1 num2) (= 1000 (+ num1 num2 (haspo num1 num2))))
(* num1 num2 (haspo num1 num2))
(if (= num1 1)
(p#9h 999 (- num2 1))
(p#9h (- num1 1) num2))))
(define (p#9)
(p#9h 999 999))
(define (p#10h lis on max)
(if (> on max)
(sum lis)
(if (prime? on)
(p#10h (cons on lis) (+ on 2) max)
(p#10h lis (+ on 2) max))))
(define (p#10 max)
(p#10h (list 2) 3 max))
(define (frontd lis amount)
(if (= amount 0)
lis
(frontd (cdr lis) (- amount 1))))
(define (mult4 lis p1 p2 p3 p4)
(* (car (frontd lis p1)) (car (frontd lis p2)) (car (frontd lis p3)) (car (frontd lis p4))))
(define (p#11h lis big)
(if (= (length_lis lis) 3)
big
(if (< (length_lis lis) 58)
(p#11h (cdr lis) (large_list (cons (mult4 lis 0 1 2 3)(cons big (list)))))
(if (< (length_lis lis) 61)
(p#11h (cdr lis) (large_list (cons (mult4 lis 0 19 38 57) (cons (mult4 lis 0 1 2 3)(cons big (list))))))
(if (< (length_lis lis) 64)
(p#11h (cdr lis) (large_list (cons (mult4 lis 0 20 40 60) (cons (mult4 lis 0 19 38 57) (cons (mult4 lis 0 1 2 3)(cons big (list)))))))
(p#11h (cdr lis) (large_list (cons (mult4 lis 0 21 42 53) (cons (mult4 lis 0 20 40 60) (cons (mult4 lis 0 19 38 57) (cons (mult4 lis 0 1 2 3)(cons big (list)))))))))))))
(define (p#11 lis)
(p#11h lis 0))
(define (factor#h num on amount)
(if (= on 1)
amount
(if (factor on num)
(factor#h num (- on 1) (+ amount 1))
(factor#h num (- on 1) amount))))
(define (factor# num)
(factor#h num (- num 1) 2))
(define (splitnh num split new)
(if (empty? num)
new
(splitnh (frontd num split) split (cons (list-num (front split num)) new))))
(define (splitn num split)
(splitnh (num-list num) split (list)))
(define (p#13 num)
(list-num (front 10 (num-list (sum (splitn num 50))))))
(define (collatz_lenh num amount)
(if (= num 1)
amount
(if (even? num)
(collatz_lenh (/ num 2) (+ amount 1))
(collatz_lenh (+ (* num 3) 1) (+ amount 1)))))
(define (collatz_len num)
(collatz_lenh num 1))
(define (p#14h high big biggest on)
(if (= on high)
big
(if (> (collatz_len on) biggest)
(p#14h high on (collatz_len on)(+ on 1))
(p#14h high big biggest (+ on 1)))))
(define (p#14 high)
(p#14h high 0 0 10))
(define (choose num1 num2)
(/ (factorial num1) (* (factorial num2) (factorial (- num1 num2)))))
(define (letter_2h2 num1 num2)
(if (= num1 2)
(+ num2 3)
(if (= num1 3)
(+ num2 5)
(if (= num1 4)
(+ num2 4)
(if (= num1 5)
(+ num2 4)
(if (= num1 6)
(+ num2 3)
(if (= num1 7)
(+ num2 5)
(if (= num1 8)
(+ num2 5)
(if (= num1 9)
(+ num2 4)
(if (= num1 1)
(+ num2 3)
num2))))))))))
(define (letter_2h1 lis)
(if (= (car lis) 2)
(letter_2h2 (car (cdr lis)) 6)
(if (= (car lis) 3)
(letter_2h2 (car (cdr lis)) 6)
(if (= (car lis) 4)
(letter_2h2 (car (cdr lis)) 6)
(if (= (car lis) 5)
(letter_2h2 (car (cdr lis)) 5)
(if (= (car lis) 6)
(letter_2h2 (car (cdr lis)) 5)
(if (= (car lis) 7)
(letter_2h2 (car (cdr lis)) 7)
(if (= (car lis) 8)
(letter_2h2 (car (cdr lis)) 6)
(letter_2h2 (car (cdr lis)) 6)))))))))
(define (letter2 num)
(letter_2h1 (num-list num)))
(define (letter3 num)
(letter_2h2 (car (num-list num)) (+ 10 (letter_2h1 (cdr (num-list num))))))
(define (amounth item lis num)
(if (empty? lis)
num
(if (= (car lis) item)
(amounth item (cdr lis) (+ num 1))
(amounth item (cdr lis) num))))
(define (amount item lis)
(amounth item lis 0))
(define (amountvh item vec num on len)
(if (= len on)
num
(if (= (vector-ref vec on) item)
(amountvh item vec (+ num 1) (+ on 1) len)
(amountvh item vec num (+ on 1) len))))
(define (amountv item vec)
(amountvh item vec 0 0 (vector-length vec)))
#|
(define (removeh item lis new)
(if (empty? lis)
(rev new)
(if (= (car lis) item)
(removeh item (cdr lis) new)
(removeh item (cdr lis) (cons (car lis) new)))))
(define (remove item lis)
(removeh item lis (list)))
|#
(define (remove1h item lis new done?)
(if (empty? lis)
(rev new)
(if (and (= (car lis) item) (= done? 0))
(remove1h item (cdr lis) new 1)
(remove1h item (cdr lis) (cons (car lis) new) done?))))
(define (remove1 item lis)
(remove1h item lis (list) 0))
(define (tri?h num on)
(if (< num 0)
false
(if (= num 0)
true
(tri?h (- num on) (+ on 1)))))
(define (triangle? num)
(tri?h num 1))
(define (triangleh num on new)
(if (= num 0)
new
(triangleh (- num 1) (+ on 1) (+ new on))))
(define (triangle num)
(triangleh num 1 0))
(define (factorer#h pfl found)
(if (empty? pfl)
found
(factorer#h (remove (car pfl) pfl) (* (+ (amount (car pfl) pfl) 1) found))))
(define (factorer# num)
(factorer#h (pf num) 1))
(define (p#12h on)
(if (> (factorer# (triangle on)) 500)
(triangle on)
(p#12h (+ on 1))))
(define (p#12)
(p#12h 3))
(define (p#17h num on)
(if (= on 1000)
num
(if (= 2 (length_lis (num-list on)))
(p#17h (+ num (letter2 on)) (+ on 1))
(p#17h (+ num (letter3 on)) (+ on 1)))))
(define (p#17)
(+ 117 (p#17h 0 20)))
(length_lis (list 'o 'n 'e 't 'w 'o 't 'h 'r 'e 'e 'f 'o 'u 'r 'f 'i 'v 'e 's 'i 'x 's 'e 'v 'e 'n 'e 'i 'g 'h 't 'n 'i 'n 'e 't 'e 'n 'e 'l 'e 'v 'e 'n 't 'w 'e 'l 'v 'e 't 'h 'i 'r 't 'e 'e 'n 'f 'o 'u 'r 't 'e 'e 'n 'f 'i 'f 't 'e 'e 'n 's 'i 'x 't 'e 'e 'n 's 'e 'v 'e 'n 't 'e 'e 'n 'e 'i 'g 'h 't 'e 'e 'n 'n 'i 'n 'e 't 'e 'e 'n 'o 'n 'e 't 'h 'o 'u 's 'a 'n 'd))
(define counts-empty (make-immutable-hash '()))
(define (incr-count counts key)
(hash-set counts key
(+ 1 (hash-ref counts key 0))))
(define (count-listh l counts)
(if (empty? l) counts
(count-listh (cdr l)
(incr-count counts (car l)))))
(define (count-list l)
(count-listh l counts-empty))
(define (p#18h lis has row place)
(if (> (+ 1 row) (length_lis lis))
(car lis)
(if (hash-has-key? has (cons row place))
(hash-ref has (cons row place))
(let*
([left (p#18h (frontd lis (+ 1 row)) has (+ row 1) (+ place 1))]
[right (p#18h (frontd lis row) has (+ row 1) place)]
[answer (+ (car lis) (max left right))]
)
(hash-set! has (cons row place) answer)
answer))))
(define (p#18 lis)
(p#18h lis (make-hash) 1 1))
(define (func2# funcer arg1 arg2 outt outf)
(if (funcer arg1 arg2)
outt
outf))
(define (daymonth leap day)
(if (< day 32)
day
(if (< day (+ leap 60))
(- day 31)
(if (< day (+ leap 91))
(- day (+ leap 59))
(if (< day (+ leap 121))
(- day (+ leap 90))
(if (< day (+ leap 152))
(- day (+ leap 120))
(if (< day (+ leap 182))
(- day (+ leap 151))
(if (< day (+ leap 213))
(- day (+ leap 181))
(if (< day (+ leap 244))
(- day (+ leap 212))
(if (< day (+ leap 274))
(- day (+ leap 243))
(if (< day (+ leap 305))
(- day (+ leap 273))
(if (< day (+ leap 335))
(- day (+ leap 304))
(- day (+ leap 334))))))))))))))
(define (p#19h ony ond endy endd amount day)
(if (and (= ony endy) (= ond endd))
amount
(if (or (and (= (daymonth 1 ond) 1) (or (factor 400 ony) (and (factor 4 ony) (not (factor 100 ony))))) (and (= (daymonth 0 ond) 1) (or (not (factor 4 ony)) (and (not (factor 400 ony)) (factor 100 ony)))))
(if (factor 400 ony)
(if (= ond 366)
(p#19h (+ ony 1) 1 endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1))))
(if (factor 100 ony)
(if (= ond 365)
(p#19h (+ ony 1) 1 endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1))))
(if (= 4 ond)
(if (= ond 366)
(p#19h (+ ony 1) 1 endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1))))
(if (= ond 365)
(p#19h (+ ony 1) 1 endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd (+ amount (func2# = day 7 1 0)) (func2# = day 7 1 (+ day 1)))))))
(if (factor 400 ony)
(if (= ond 366)
(p#19h (+ ony 1) 1 endy endd amount (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd amount (func2# = day 7 1 (+ day 1))))
(if (factor 100 ony)
(if (= ond 365)
(p#19h (+ ony 1) 1 endy endd amount (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd amount (func2# = day 7 1 (+ day 1))))
(if (factor 4 ony)
(if (= ond 366)
(p#19h (+ ony 1) 1 endy endd amount (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd amount (func2# = day 7 1 (+ day 1))))
(if (= ond 365)
(p#19h (+ ony 1) 1 endy endd amount (func2# = day 7 1 (+ day 1)))
(p#19h ony (+ ond 1) endy endd amount (func2# = day 7 1 (+ day 1))))))))))
(define (p#19 starty startd endy endd)
(p#19h starty startd endy endd 0 1))
(define (fibh num on1 on2)
(if (= num 1)
on1
(fibh (- num 1) (+ on1 on2) on1)))
(define (fib num)
(fibh num 1 0))
(define (dfib x)
(cond
[(<= x 0) 1]
[else (+ (dfib (- x 1))
(dfib (- x 2)))]))
(define (contains? lis looking)
(if (empty? lis)
false
(if (= looking (car lis))
true
(contains? (cdr lis) looking))))
(define (containsl? lis looking)
(if (empty? lis)
false
(if (equal? looking (car lis))
true
(containsl? (cdr lis) looking))))
(define (undooph lis new)
(if (empty? lis)
(rev new)
(if (containsl? new (car lis))
(undooph (cdr lis) new)
(undooph (cdr lis) (cons (car lis) new)))))
(define (multlh lis num new)
(if (empty? lis)
(rev new)
(multlh (cdr lis) num (cons (* (car lis) num) new))))
(define (multl lis num)
(multlh lis num (list)))
(define (addlh lis num new)
(if (empty? lis)
(rev new)
(addlh (cdr lis) num (cons (+ (car lis) num) new))))
(define (addl lis num)
(addlh lis num (list)))
(define (addhh has num new keys)
(if (empty? keys)
new
(addhh has num (hash-set new (+ num (car keys)) (hash-ref has (car keys))) (cdr keys))))
(define (addh num has)
(addhh has num (make-immutable-hash) (hash-keys has)))
(define (undoop lis)
(undooph lis (list)))
(define (multallh lis)
(if (= (length_lis lis) 2)
(list (car lis) (car (cdr lis)) (* (car lis) (car (cdr lis))))
(flatten (cons (car lis) (cons (multl (multallh (cdr lis)) (car lis)) (multallh (cdr lis)))))))
(define (multall lis)
(undoop (multallh lis)))
(define (myand thing1 thing2)
(if (and thing1 thing2)
true
false))
(define (factorer num)
(multall (flatten (cons 1 (list (pf num))))))
(define (p#21h on lis)
(if (= on 0)
lis
(p#21h (- on 1) (func2# myand (= (sum (remove (sum (remove on (factorer on))) (factorer (sum (remove on (factorer on)))))) on) (not (= on (sum (remove on (factorer on))))) (cons on lis) lis))))
(define (p#21)
(sum (remove 1 (p#21h 10000 (list)))))
(define (keepmulth lis new)
(if (empty? lis)
new
(if (or (containsl? (cdr lis) (car lis)) (containsl? new (car lis)))
(keepmulth (cdr lis) (cons (car lis) new))
(keepmulth (cdr lis) new))))
(define (keepmult lis)
(keepmulth lis (list)))
(define (keepmultlh lis new)
(if (empty? lis)
new
(if (or (containsl? (cdr lis) (car lis)) (containsl? new (car lis)))
(keepmulth (cdr lis) (cons (car lis) new))
(keepmulth (cdr lis) new))))
(define (keepmultl lis)
(keepmultlh lis (list)))
(define (chimas lis amount things)
(if (= (length_lis lis) (- amount 1))
0
(if (containsl? things (front amount lis))
amount
(chimas (cdr lis) amount (cons (front amount lis) things)))))
(define (imash lis amount tobewins)
(if (= amount 0)
(list)
(begin
(set! tobewins (chimas lis amount (list)))
(if (= tobewins 0)
(imash lis (- amount 1) (list))
tobewins))))
(define (imas lis)
(imash lis (- (length_lis lis) 1) (list)))
(define (randlh amount high rlis)
(if (= (length_lis rlis) amount)
rlis
(randlh amount high (cons (random (+ high 1)) rlis))))
(define (randl amount high)
(randlh amount high (list)))
(define (averegeimahh amount highest times lengths)
(if (= times 0)
lengths
(averegeimahh amount highest (- times 1) (cons (imas (randl amount highest)) lengths))))
(define (averegimah amount highest run lengths bla)
(set! bla (averegeimahh amount highest run (list)))
(/ (sum bla) (length_lis bla)))
(define (averegeima amount highest run)
(averegimah amount highest run (list) 0))
(define (abundent? num)
(> (sum (factorer num)) (* 2 num)))
(define (addpairh lis new on)
(if (= (+ on 1) (length_lis lis))
new
(addpairh lis (flatten (cons (addl (frontd lis (+ on 1)) (car (frontd lis on))) new)) (+ on 1))))
(define (addpair lis)
(addpairh lis (list) 0))
(define (allabh high new on)
(if (= on (+ high 1))
new
(if (abundent? on)
(allabh high (cons on new) (+ on 1))
(allabh high new (+ on 1)))))
(define (allab high)
(allabh high (list) 11))
(define (nth num lis)
(if (= num 1)
(car lis)
(nth (- num 1) (cdr lis))))
(define (mih)
(make-immutable-hash))
(define (mmh)
(make-hash))
(define (addpairhh lis new on len)
(if (= (+ on 1) len)
new
(addpairhh lis)))
(define (addpairl-h lis)
(addpairhh lis (mih) 0 (length_lis lis)))
(define (all-sums-hh n nums hash)
(if (empty? nums)
hash
(let* ([new-sum (+ n (car nums))]
[new-hash (if (> new-sum 28123) hash (hash-set hash new-sum '()))])
(all-sums-hh n (cdr nums) new-hash))))
(define (all-sums-h nums hash)
(if (empty? nums)
hash
(all-sums-h (cdr nums) (all-sums-hh (car nums) nums hash))))
(define (all-sumsh nums)
(all-sums-h nums (make-immutable-hash)))
(define (p#23h on abund new)
(if (= on 28123)
(sum new)
(if (hash-has-key? abund on)
(p#23h (+ on 1) abund new)
(p#23h (+ on 1) abund (cons on new)))))
(define (p#23)
(p#23h 1 (all-sumsh (allab 28123)) (list)))
(define (adde-lh element lis new)
(if (empty? lis)
(rev new)
(adde-lh element (cdr lis) (cons (cons element (car lis)) new))))
(define (adde-l element lis)
(adde-lh element lis (list)))
(define (insert element lis place)
(append (front (- place 1) lis)
(cons element (frontd lis (- place 1)))))
(define (distibh element lis new on high)
(if (> on high)
new
(distibh element lis (cons (flatten (insert element lis on)) new) (+ on 1) high)))
(define (distrib element lis)
(distibh element lis (list) 1 (+ 1 (length_lis lis))))
(define (distribsk amount element lis)
(distibh element lis (list) (+ 1 amount) (+ 1 (length_lis lis))))
(define (applyf-lh func lis new arg)
(if (empty? lis)
(rev new)
(applyf-lh func (cdr lis) (append (func arg lis) new) arg)))
(define (applyf-l1 func lis arg)
(applyf-lh func lis (list) arg))
(define (applyf-l2h func lis new arg arg2)
(if (empty? lis)
(rev new)
(applyf-l2h func (cdr lis) (append (func arg arg2 (car lis)) new) arg arg2)))
(define (applyf-l2 func lis arg arg2)
(applyf-l2h func lis (list) arg arg2))
(define (distribplh lis place element new)
(if (empty? lis)
(rev new)
(distribplh (cdr lis) place element (cons (append (front (- place 1) (car lis)) (cons element (frontd (car lis) (- place 1)))) new))))
(define (distribpl lis element place)
(distribplh lis place element (list)))
(define (23distribh num lis on max new)
(if (= on (+ 2 max))
(rev new)
(23distribh num lis (+ on 1) max (append (distribpl lis num on) new))))
(define (p#23distrib num lis)
(23distribh num lis 1 (length_lis (car lis)) (list)))
;;(define (applyf-l1-aba func lis arg)
;; (map (lambda (x) (func x arg)) lis))
(define (allfirh lis new on)
(if (= on 0)
new
(allfirh lis (cons (cons (nth on lis) (remove on lis)) new) (- on 1))))
(define (allfir lis)
(allfirh lis (list) (length_lis lis)))
;;(define (oneperm lis)
;; (if (= length_lis 2)
;; (list lis (list (cadr lis) (car lis)))
(define (permute lis)
(if (= (length_lis lis) 2)
(list lis (list (cadr lis) (car lis)))
(append
(p#23distrib (car lis) (permute (cdr lis))))))
(check-expect (permute (list 1 2))
'((1 2) (2 1)))
(define (p#23case lis1 lis2)
(if (empty? lis1)
false
(if (> (car lis1) (car lis2))
false
(if (< (car lis1) (car lis2))
true
(p#23case (cdr lis1) (cdr lis2))))))
;(/ (sum (list 7172066 8269263 7284157 6666128 7525122 7013083 6619354 7323310 5757639 6681999 7324069 7267822 7185759 7213099 7235713 7529224 7421067)) 17)
;(/ (sum (list 1290502 7557141 2310230 3161290 6776354 6171961 5056629 3133445 647453 6509999 1858560 6436591 5500821 6171614 1488636 6175351 6431453)) 17)
(define (fibdigh num last twolast on)
(if (= (length_lis (num-list (+ last twolast))) num)
on
(fibdigh num (+ last twolast) last (+ on 1))))
(define (fibdig num)
(fibdigh num 1 1 3))
(define (rept#<1hl num den stored on qout floo digits)
(set! qout (/ (list-num (num-list num)) den))
(set! floo (floor qout))
(if (hash-has-key? stored floo)
(- on (hash-ref stored floo))
(if (= qout 1)
0
(if (= floo 0)
(rept#<1hl (* num 10) den stored (+ on 1) 0 0 (+ digits 1))
(rept#<1hl (* (- num (* den floo)) 10) den (hash-set stored (remainder num den) on) (+ on 1) 0 0 1)))))
(define (rept#<1l num den)
(rept#<1hl num den (mih) 1 0 0 1))
(define (2s5s num)
(empty? (remove 5 (remove 2 (flatten (list (pf num)))))))
(define (fracrepth num den on)
(if (or (2s5s (denominator (- (* (expt 10 on) (/ num den)) (/ num den)))) (integer? (- (* (expt 10 on) (/ num den)) (/ num den))))
on
(fracrepth num den (+ on 1))))
(define (fracrept num den)
(define l (remove 5 (remove 2 (flatten (list (pf den))))))
(if (empty? l)
0
(fracrepth num den 1)))
(define (p#26h on ma ma#)
(if (> on 999)
ma#
(if (> ma (fracrept 1 on))
(p#26h (+ on 1) ma ma#)
(p#26h (+ on 1) (fracrept 1 on) on))))
(define (rtrue x)
true)
(define (p#26)
(p#26h 2 0 1))
(define (true? bool)
(if bool
true
false))
(define (sivhh vec on len add)
(if (> (+ 1 on) len)
'()
(begin
(vector-set! vec on false)
(sivhh vec (+ on add) len add))))
(define (posval x)
(max (- 0 x) x))
(define (sivh vec on ma)
(if (> on (- (/ ma 2) 1))
vec
(if (eq? true (vector-ref vec on))
(begin
(sivhh vec (* 2 on) ma on)
(sivh vec (+ on 1) ma))
(sivh vec (+ on 1) ma))))
(define (siv max)
(let ([vec (build-vector max rtrue)])
(begin
(sivh vec 2 max)
(vector-set! vec 0 false)
(vector-set! vec 1 false)
vec)))
(define (euformh a b on)
(if (eq? (vector-ref p (posval (+ (expt on 2) (* on a) b))) false)
on
(euformh a b (+ on 1))))
(define (euform a b)
(euformh a b 0))
(define (p#27h- a b bigval bigprod nums ans)
(if (and (= a -1000) (< b -997))
bigprod
(begin
(set! ans (euform a b))
(if (< b -997)
(if (> ans bigval)
(p#27h- (- a 1) 997 ans (* a b) (cons a b) 0)
(p#27h- (- a 1) 997 bigval bigprod nums 0))
(if (> ans bigval)
(p#27h- a (- b 1) ans (* a b) (cons a b) 0)
(p#27h- a (- b 1) bigval bigprod nums 0))))))
(define (p#27)
(p#27h- 1000 997 0 0 0 (cons 0 0)))
(define (p#28h maxlay layer accum last)
(if (= layer maxlay)
accum
(p#28h maxlay (+ layer 1) (+ accum (+ (* 4 last) (* layer 20))) (+ last (* 8 layer)))))
(define (p#28 layers)
(p#28h layers 1 1 1))
(define (p#29h has base exp ma)
(if (and (= base ma) (= exp ma))
has
(if (= exp ma)
(p#29h (hash-set has (expt base exp) (list)) (+ base 1) 2 ma)
(p#29h (hash-set has (expt base exp) (list)) base (+ exp 1) ma))))
(define (p#29 ma)
(hash-count (p#29h (mih) 2 2 ma)))
(define (p#30h lis on)
(if (= on 354294)
lis
(if (= (sum (map (lambda (x) (expt x 5)) (num-list on))) on)
(p#30h (cons on lis) (+ on 1))
(p#30h lis (+ on 1)))))
(define (p#30)
(sum (p#30h (list) 10)))
(define (onifh lis cond new)
(if (empty? lis)
(rev new)
(if (cond (car lis))
(onifh (cdr lis) cond (cons (car lis) new))
(onifh (cdr lis) cond new))))
(define (onif lis cond)
(onifh lis cond (list)))
(define (onifvh vec cond new on len)
(if (= len on)
new
(if (cond (vector-ref vec on))
(onifvh vec cond (vector-append (vector (vector-ref vec on)) new) (+ on 1) len)
(onifvh vec cond new (+ on 1) len))))
(define (onifv vec cond)
(onifvh vec cond (vector) 0 (vector-length vec)))
(define (apply2h func lis1 lis2 new)
(if (empty? lis1)
new
(apply2h func (cdr lis1) lis2 (append new (map (lambda (x) (func (car lis1) x)) lis2)))))
(define (apply2 func lis1 lis2)
(apply2h func lis1 lis2 (list)))