lambdaway
::
semiprime
7
|
list
|
login
|
load
|
|
_h1 semiprime _p Following [[rosettacode|https://rosettacode.org/wiki/Semiprime]] {b semiprime numbers} are natural numbers that are products of exactly two (possibly equal) prime numbers. For instance: {prewrap 4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95 106 111 115 118 119 121 122 123 129 133 134 141 142 143 145 146 155 158 159 161 166 169 177 178 183 185 187 194 201 202 203 205 206´209 213 214 215 217 218 219 221 226 235 237 247 249 253 254 259 262 265 267 274 278 287 289 291 295 298 299 301 302 303 305 309 314 319 321 323 326 327 329 334 335 339 341 346 355 358 361 362 365 371 377 381 382 386 391 393 394 395 398 403 407 411 413 415 417 422 427 437 445 446 447 451 453 454 458 466 469 471 473 478 481 482 485 489 493 497 } _p Just compute the factors of a number. {prewrap '{def factors {def factors.r {lambda {:n :i} {if {> :i :n} then else {if {= {% :n :i} 0} then :i {factors.r {/ :n :i} :i} else {factors.r :n {+ :i 1}} }}}} {lambda {:n} {A.new {factors.r :n 2}} }} -> {def factors {def factors.r {lambda {:n :i} {if {> :i :n} then else {if {= {% :n :i} 0} then :i {factors.r {/ :n :i} :i} else {factors.r :n {+ :i 1}} }}}} {lambda {:n} {A.new {factors.r :n 2} }}} '{factors 491} -> {factors 491} // prime '{factors 492} -> {factors 492} '{factors 493} -> {factors 493} // semiprime '{factors 494} -> {factors 494} '{factors 495} -> {factors 495} '{factors 496} -> {factors 496} '{factors 497} -> {factors 497} // semiprime '{factors 498} -> {factors 498} '{factors 499} -> {factors 499} // prime '{factors 500} -> {factors 500} '{S.replace \s by space in {S.map {lambda {:i} {let { {:i :i} {:f {factors :i}} } {if {= {A.length :f} 2} then :i={A.first :f}*{A.last :f} else}} } {S.serie 1 100}}} -> {S.replace \s by space in {S.map {lambda {:i} {let { {:i :i} {:f {factors :i}} } {if {= {A.length :f} 2} then {div}:i = {A.first :f}*{A.last :f} else}} } {S.serie 1 100}}} '{S.replace \s by space in {S.map {lambda {:i} {let { {:i :i} {:f {factors :i}} } {if {= {A.length :f} 2} then :i else}} } {S.serie 1 500}}} -> {S.replace \s by space in {S.map {lambda {:i} {let { {:i :i} {:f {factors :i}} } {if {= {A.length :f} 2} then :i else}} } {S.serie 1 500}}} }
lambdaway v.20211111