Skip to content

Instantly share code, notes, and snippets.

@greymd
Created July 27, 2017 10:20
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 greymd/bb56d453ab6d1d046d007ee195cbd9b2 to your computer and use it in GitHub Desktop.
Save greymd/bb56d453ab6d1d046d007ee195cbd9b2 to your computer and use it in GitHub Desktop.
Filter numbers which has 2 same factors with Egison
#!/usr/bin/env egison
(define $main
(lambda [$args]
(each display
(farray-same2 farray))))
(define $farray
(filter 1#(eq? (length %1) 3)
(map (p-f $) (take 100 nats))))
(define $farray-same2
(match-all-lambda
(list (list integer))
[<join $a <cons (& <cons $g <cons ,g <cons _ <nil>>>> $same) _>> same]))
; {2 2 2}
; {2 2 3}
; {2 2 5}
; {3 3 3}
; {2 2 7}
; {2 2 11}
; {3 3 5}
; {2 2 13}
; {3 3 7}
; {2 2 17}
; {2 2 19}
; {2 2 23}
; {3 3 11}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment