in reply to Newbie question
Yet another inevitable TMTOWTDI:
#!/usr/bin/env perl use strict; use warnings; use feature qw(say); use Math::Prime::Util qw(sumdigits); use Data::Dump; my @input = (-222, -221, -21, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144); my @ans = map { (sumdigits($_) % 2) ? $_ : () } @input; dd \@ans; __END__ Karls-Mac-mini:monks karl$ ./11146306.pl [-221, -21, 1, 1, 3, 5, 21, 34, 89, 144]
See also map, Data::Dump, Math::Prime::Util and ntheory.
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Newbie question
by LanX (Saint) on Aug 23, 2022 at 19:40 UTC | |
by AnomalousMonk (Archbishop) on Aug 23, 2022 at 20:30 UTC | |
by karlgoethebier (Abbot) on Aug 23, 2022 at 20:17 UTC | |
by roho (Bishop) on Aug 24, 2022 at 03:04 UTC | |
|
Re^2: Newbie question
by oldB51 (Sexton) on Aug 25, 2022 at 06:52 UTC | |
by karlgoethebier (Abbot) on Aug 26, 2022 at 10:38 UTC |