Abundant odd numbers: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 29:
{{trans|Python}}
 
<syntaxhighlight lang="11l">V oddNumber = 1
V aCount = 0
V dSum = 0
Line 108:
 
=={{header|360 Assembly}}==
<syntaxhighlight lang="360asm">* Abundant odd numbers 18/09/2019
ABUNODDS CSECT
USING ABUNODDS,R13 base register
Line 226:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program abundant64.s */
Line 815:
[[http://rosettacode.org/wiki/Proper_divisors#Ada]].
 
<syntaxhighlight lang=Ada"ada">with Ada.Text_IO, Generic_Divisors;
 
procedure Odd_Abundant is
Line 907:
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">BEGIN
# find some abundant odd numbers - numbers where the sum of the proper #
# divisors is bigger than the number #
Line 1,020:
{{Trans|ALGOL 68}}
Using the divisor_sum procedure from the [[Sum_of_divisors#ALGOL_W]] task.
<syntaxhighlight lang="algolw">begin
% find some abundant odd numbers - numbers where the sum of the proper %
% divisors is bigger than the number %
Line 1,131:
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">on aliquotSum(n)
if (n < 2) then return 0
set sum to 1
Line 1,187:
{{output}}
 
<syntaxhighlight lang="applescript">"The first 25 abundant odd numbers:
945 (proper divisor sum: 975)
1575 (proper divisor sum: 1649)
Line 1,220:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=ARM"arm Assemblyassembly">
/* ARM assembly Raspberry PI */
/* program abundant.s */
Line 1,775:
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">abundant?: function [n]-> (2*n) < sum factors n
 
print "the first 25 abundant odd numbers:"
Line 1,837:
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"autohotkey">Abundant(num){
sum := 0, str := ""
for n, bool in proper_divisors(num)
Line 1,857:
return Array
}</syntaxhighlight>
Examples:<syntaxhighlight lang=AutoHotkey"autohotkey">output := "First 25 abundant odd numbers:`n"
while (count<1000)
{
Line 1,922:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f ABUNDANT_ODD_NUMBERS.AWK
# converted from C
Line 1,992:
=={{header|BASIC256}}==
{{trans|Visual Basic .NET}}
<syntaxhighlight lang=BASIC256"basic256">
numimpar = 1
contar = 0
Line 2,049:
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
#include <math.h>
 
Line 2,103:
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using static System.Console;
using System.Collections.Generic;
using System.Linq;
Line 2,165:
=={{header|C++}}==
{{trans|Go}}
<syntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <numeric>
Line 2,282:
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">% Integer square root
isqrt = proc (s: int) returns (int)
x0: int := s / 2
Line 2,381:
Using the ''iterate'' library instead of the standard ''loop'' or ''do''.
 
<syntaxhighlight lang="lisp">;; * Loading the external libraries
(eval-when (:compile-toplevel :load-toplevel)
(ql:quickload '("cl-annot" "iterate" "alexandria")))
Line 2,493:
=={{header|D}}==
{{trans|C++}}
<syntaxhighlight lang="d">import std.stdio;
 
int[] divisors(int n) {
Line 2,588:
=={{header|Delphi}}==
{{trans|C}}
<syntaxhighlight lang="delphi">program AbundantOddNumbers;
 
{$APPTYPE CONSOLE}
Line 2,667:
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Abundant odd numbers. Nigel Galloway: August 1st., 2021
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
Line 2,709:
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
Line 2,773:
A basic direct solution. A more robust alternative would be to find
the prime factors and then use a formulaic approach.
<syntaxhighlight lang="fortran">
program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
Line 2,857:
=={{header|FreeBASIC}}==
{{trans|Visual Basic .NET}}
<syntaxhighlight lang="freebasic">
Declare Function SumaDivisores(n As Integer) As Integer
 
Line 2,954:
=={{header|Frink}}==
Frink has efficient functions for factoring numbers that use trial division, wheel factoring, and Pollard rho factoring.
<syntaxhighlight lang="frink">isAbundantOdd[n] := sum[allFactors[n, true, false]] > n
 
n = 3
Line 3,035:
=={{header|FutureBasic}}==
{{trans|C}}
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
Line 3,089:
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import (
Line 3,201:
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
Line 3,301:
 
=={{header|Haskell}}==
<syntaxhighlight lang=Haskell"haskell">import Data.List (nub)
 
divisorSum :: Integral a => a -> a
Line 3,364:
 
Or, importing Data.Numbers.Primes (and significantly faster):
<syntaxhighlight lang="haskell">import Data.List (group, sort)
import Data.Numbers.Primes
 
Line 3,479:
 
=={{header|Java}}==
<syntaxhighlight lang="java">import java.util.ArrayList;
import java.util.List;
 
Line 3,566:
Composing reusable functions and generators:
{{Trans|Python}}
<syntaxhighlight lang="javascript">(() => {
'use strict';
const main = () => {
Line 3,812:
 
=={{header|jq}}==
<syntaxhighlight lang="jq">
# The factors, unsorted
def factors:
Line 3,831:
 
Computing the first abundant number greater than 10^9 is presently impractical using jq, but for the other tasks:
<syntaxhighlight lang="text">( ["n", "sum of divisors"],
limit(25; abundant_odd_numbers)),
[],
Line 3,871:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Primes
 
function propfact(n)
Line 3,944:
=={{header|Kotlin}}==
{{trans|D}}
<syntaxhighlight lang="scala">fun divisors(n: Int): List<Int> {
val divs = mutableListOf(1)
val divs2 = mutableListOf<Int>()
Line 4,038:
=={{header|Lobster}}==
{{trans|C}}
<syntaxhighlight lang=Lobster"lobster">
// Note that the following function is for odd numbers only
// Use "for (unsigned i = 2; i*i <= n; i++)" for even and odd numbers
Line 4,114:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">-- Return the sum of the proper divisors of x
function sumDivs (x)
local sum, sqr = 1, math.sqrt(x)
Line 4,182:
=={{header|MAD}}==
 
<syntaxhighlight lang=MAD"mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(ND)
Line 4,252:
=={{header|Maple}}==
 
<syntaxhighlight lang=Maple"maple">
with(NumberTheory):
 
Line 4,354:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
 
<syntaxhighlight lang=Mathematica"mathematica">ClearAll[AbundantQ]
AbundantQ[n_] := TrueQ[Greater[Total @ Most @ Divisors @ n, n]]
res = {};
Line 4,391:
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">block([k: 0, n: 1, l: []],
while k < 25 do (
n: n+2,
Line 4,404:
<pre>[[945,1920],[1575,3224],[2205,4446],[2835,5808],[3465,7488],[4095,8736],[4725,9920],[5355,11232],[5775,11904],[5985,12480],[6435,13104],[6615,13680],[6825,13888],[7245,14976],[7425,14880],[7875,16224],[8085,16416],[8415,16848],[8505,17472],[8925,17856],[9135,18720],[9555,19152],[9765,19968],[10395,23040],[11025,22971]]</pre>
 
<syntaxhighlight lang="maxima">block([k: 0, n: 1],
while k < 1000 do (
n: n+2,
Line 4,414:
<pre>[492975,1012336]</pre>
 
<syntaxhighlight lang="maxima">block([n: 5, l: [5], r: divsum(n,-1)],
while n < 10^8 do (
if not mod(n,3)=0 then (
Line 4,428:
 
=={{header|Nim}}==
<syntaxhighlight lang=Nim"nim">
from math import sqrt
import strformat
Line 4,572:
=={{header|Pascal}}==
{{works with|Free Pascal}} {{works with|Delphi}}
<syntaxhighlight lang="pascal">
program AbundantOddNumbers;
{$IFDEF FPC}
Line 4,793:
{{trans|Raku}}
{{libheader|ntheory}}
<syntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 4,852:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">abundantOdd</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">done</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">printAll</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">done</span><span style="color: #0000FF;"><</span><span style="color: #000000;">lim</span> <span style="color: #008080;">do</span>
Line 4,910:
 
=={{header|PicoLisp}}==
<syntaxhighlight lang=PicoLisp"picolisp">(de accud (Var Key)
(if (assoc Key (val Var))
(con @ (inc (cdr @)))
Line 4,988:
 
=={{header|Processing}}==
<syntaxhighlight lang="processing">void setup() {
println("First 25 abundant odd numbers: ");
int abundant = 0;
Line 5,065:
=={{header|PureBasic}}==
{{trans|C}}
<syntaxhighlight lang=PureBasic"purebasic">NewList l_sum.i()
 
 
Line 5,171:
===Procedural===
{{trans|Visual Basic .NET}}
<syntaxhighlight lang=Python"python">#!/usr/bin/python
# Abundant odd numbers - Python
 
Line 5,254:
 
===Functional===
<syntaxhighlight lang="python">'''Odd abundant numbers'''
 
from math import sqrt
Line 5,390:
 
=={{header|q}}==
<syntaxhighlight lang="q">s:{c where 0=x mod c:1+til x div 2} / proper divisors
sd:sum s@ / sum of proper divisors
abundant:{x<sd x}
Line 5,397:
The definition here is naïve. It suffices for the first two items in this task, but takes minutes to execute the third item on a 2018 Mac with 64GB memory.
{{out}}
<syntaxhighlight lang="q">q)count A:Filter[abundant] 1+2*til 260000 / a batch of abundant odd numbers; 1000+ is enough
1054
 
Line 5,417:
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
 
<syntaxhighlight lang=Quackery"quackery"> [ 0 swap factors witheach + ] is sigmasum ( n --> n )
 
0 -1 [ 2 +
Line 5,475:
 
=={{header|R}}==
<syntaxhighlight lang=R"r"># Abundant Odd Numbers
 
find_div_sum <- function(x){
Line 5,553:
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">#lang racket
 
(require math/number-theory
Line 5,603:
{{works with|Rakudo|2019.03}}
 
<syntaxhighlight lang=perl6"raku" line>sub odd-abundant (\x) {
my @l = x.is-prime ?? 1 !! flat
1, (3 .. x.sqrt.floor).map: -> \d {
Line 5,668:
 
The &nbsp; '''sigO''' &nbsp; function is a specialized version of the &nbsp; '''sigma''' &nbsp; function optimized just for &nbsp; ''odd'' &nbsp; numbers.
<syntaxhighlight lang="rexx">/*REXX pgm displays abundant odd numbers: 1st 25, one─thousandth, first > 1 billion. */
parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/
if Nlow=='' | Nlow=="," then Nlow= 25 /*Not specified? Then use the default.*/
Line 5,742:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
#Project: Anbundant odd numbers
 
Line 5,874:
=={{header|Ruby}}==
proper_divisors method taken from http://rosettacode.org/wiki/Proper_divisors#Ruby
<syntaxhighlight lang="ruby">require "prime"
class Integer
Line 5,903:
=={{header|Rust}}==
{{trans|Go}}
<syntaxhighlight lang="rust">fn divisors(n: u64) -> Vec<u64> {
let mut divs = vec![1];
let mut divs2 = Vec::new();
Line 5,992:
=={{header|Scala}}==
{{trans|D}}
<syntaxhighlight lang="scala">import scala.collection.mutable.ListBuffer
 
object Abundant {
Line 6,087:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func is_abundant(n) {
n.sigma > 2*n
}
Line 6,150:
 
=={{header|Smalltalk}}==
<syntaxhighlight lang="smalltalk">divisors :=
[:nr |
|divs|
Line 6,236:
=={{header|Swift}}==
 
<syntaxhighlight lang="swift">extension BinaryInteger {
@inlinable
public func factors(sorted: Bool = true) -> [Self] {
Line 6,304:
=={{header|uBasic/4tH}}==
{{trans|C}}
<syntaxhighlight lang="text">c = 0
For n = 1 Step 2 While c < 25
Line 6,395:
=={{header|Visual Basic .NET}}==
{{Trans|ALGOL 68}}
<syntaxhighlight lang="vbnet">Module AbundantOddNumbers
' find some abundant odd numbers - numbers where the sum of the proper
' divisors is bigger than the number
Line 6,490:
=={{header|Vlang}}==
{{trans|go}}
<syntaxhighlight lang="vlang">fn divisors(n i64) []i64 {
mut divs := [i64(1)]
mut divs2 := []i64{}
Line 6,568:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt
import "/math" for Int, Nums
Line 6,643:
=={{header|X86 Assembly}}==
Assemble with tasm and tlink /t
<syntaxhighlight lang="asm"> .model tiny
.code
.486
Line 6,747:
 
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0"xpl0">int Cnt, Num, Div, Sum, Quot;
[Cnt:= 0;
Num:= 3; \find odd abundant numbers
Line 6,805:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn oddAbundants(startAt=3){ //--> iterator
Walker.zero().tweak(fcn(rn){
n:=rn.value;
Line 6,819:
}.fp(Ref(startAt.isOdd and startAt or startAt+1)))
}</syntaxhighlight>
<syntaxhighlight lang="zkl">fcn oddDivisors(n){ // -->sorted List
[3.. n.toFloat().sqrt().toInt(), 2].pump(List(1),'wrap(d){
if( (y:=n/d) *d != n) return(Void.Skip);
Line 6,831:
}
}</syntaxhighlight>
<syntaxhighlight lang="zkl">oaw:=oddAbundants();
 
println("First 25 abundant odd numbers:");
10,327

edits