aboutsummaryrefslogtreecommitdiff
path: root/challenge-258/bruce-gray/java/ch-1.java
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-03-04 00:21:07 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-03-04 00:21:07 +0000
commit6047ae2284ecc043eadaf4ccbd11d16ac0dd27e1 (patch)
tree73c2632aab4a14833a0094441c1ee66be1ef0459 /challenge-258/bruce-gray/java/ch-1.java
parent40d47c8ead708860c4e3f21bae091506a42807f4 (diff)
parent4597936d06c260bebd4f5922abc56c1067fc504f (diff)
downloadperlweeklychallenge-club-6047ae2284ecc043eadaf4ccbd11d16ac0dd27e1.tar.gz
perlweeklychallenge-club-6047ae2284ecc043eadaf4ccbd11d16ac0dd27e1.tar.bz2
perlweeklychallenge-club-6047ae2284ecc043eadaf4ccbd11d16ac0dd27e1.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-258/bruce-gray/java/ch-1.java')
-rw-r--r--challenge-258/bruce-gray/java/ch-1.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-258/bruce-gray/java/ch-1.java b/challenge-258/bruce-gray/java/ch-1.java
new file mode 100644
index 0000000000..b60b8fcdf4
--- /dev/null
+++ b/challenge-258/bruce-gray/java/ch-1.java
@@ -0,0 +1,34 @@
+// java java/ch-1.java
+import java.util.List;
+public class ch_1 {
+
+
+ static long task1 ( List<Integer> ns ) {
+ return ns.stream()
+ .filter(n -> n.toString().length() % 2 == 0)
+ .count();
+ }
+
+
+ // Test harness
+ static int test_number = 1;
+ static void plan ( Integer count ) { System.out.printf("1..%d\n", count); }
+ static boolean is ( long got, long expected, String desc ) {
+ boolean ret = got == expected;
+ System.out.printf("%s %d - %s\n", (ret ? "ok" : "not ok"), test_number++, desc);
+ return ret;
+ }
+ public static void main(String[] args) {
+ record Testcase ( int expected, List<Integer> inputs ) {}
+
+ List<Testcase> tst = List.of(
+ new Testcase( 3, List.of( 10, 1, 111, 24, 1000 ) ),
+ new Testcase( 0, List.of( 111, 1, 11111 ) ),
+ new Testcase( 1, List.of( 2, 8, 1024, 256 ) )
+ );
+ plan(tst.size());
+ for (Testcase t : tst) {
+ is( task1(t.inputs), t.expected, t.inputs.toString() );
+ }
+ }
+}