From ab633608a93a0ab60c27ecdecb55c48b6041e42e Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Tue, 29 Jun 2021 14:39:58 +0200 Subject: NibbleSwap --- challenge-119/frankivo/scala/NibbleSwap | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 challenge-119/frankivo/scala/NibbleSwap diff --git a/challenge-119/frankivo/scala/NibbleSwap b/challenge-119/frankivo/scala/NibbleSwap new file mode 100644 index 0000000000..a39d981f59 --- /dev/null +++ b/challenge-119/frankivo/scala/NibbleSwap @@ -0,0 +1,12 @@ +object NibbleSwap { + def swap(n: Int): Int = { + Integer.parseInt( + "%08d" // Two-nibble limit is here. + .format(n.toBinaryString.toInt) // Don't really like the double cast. + .grouped(4) + .toArray + .reverse + .mkString, + 2) + } +} -- cgit From c0189642396125ac67dd8ccef893d43466a7240f Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Tue, 29 Jun 2021 14:45:11 +0200 Subject: Rename --- challenge-119/frankivo/scala/NibbleSwap | 12 ------------ challenge-119/frankivo/scala/NibbleSwap.scala | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 challenge-119/frankivo/scala/NibbleSwap create mode 100644 challenge-119/frankivo/scala/NibbleSwap.scala diff --git a/challenge-119/frankivo/scala/NibbleSwap b/challenge-119/frankivo/scala/NibbleSwap deleted file mode 100644 index a39d981f59..0000000000 --- a/challenge-119/frankivo/scala/NibbleSwap +++ /dev/null @@ -1,12 +0,0 @@ -object NibbleSwap { - def swap(n: Int): Int = { - Integer.parseInt( - "%08d" // Two-nibble limit is here. - .format(n.toBinaryString.toInt) // Don't really like the double cast. - .grouped(4) - .toArray - .reverse - .mkString, - 2) - } -} diff --git a/challenge-119/frankivo/scala/NibbleSwap.scala b/challenge-119/frankivo/scala/NibbleSwap.scala new file mode 100644 index 0000000000..a39d981f59 --- /dev/null +++ b/challenge-119/frankivo/scala/NibbleSwap.scala @@ -0,0 +1,12 @@ +object NibbleSwap { + def swap(n: Int): Int = { + Integer.parseInt( + "%08d" // Two-nibble limit is here. + .format(n.toBinaryString.toInt) // Don't really like the double cast. + .grouped(4) + .toArray + .reverse + .mkString, + 2) + } +} -- cgit From d1c2168c869c4b84884add9b56c706095463423a Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Wed, 30 Jun 2021 14:24:18 +0200 Subject: Sequencer Not working above 33 :) --- challenge-119/frankivo/scala/Sequencer.scala | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 challenge-119/frankivo/scala/Sequencer.scala diff --git a/challenge-119/frankivo/scala/Sequencer.scala b/challenge-119/frankivo/scala/Sequencer.scala new file mode 100644 index 0000000000..7185318871 --- /dev/null +++ b/challenge-119/frankivo/scala/Sequencer.scala @@ -0,0 +1,8 @@ +object Sequencer { + def sequencer(n: Int): Int = { + (0 to (n / 3)) + .map(x => (1 to 3).map(y => y + x * 10)) + .flatten + .toSeq(n) + } +} \ No newline at end of file -- cgit From 039206dc90cc538bc78500f9105a997389c0fcd3 Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Thu, 1 Jul 2021 14:49:30 +0200 Subject: Better Sequencer --- challenge-119/frankivo/scala/Sequencer.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/challenge-119/frankivo/scala/Sequencer.scala b/challenge-119/frankivo/scala/Sequencer.scala index 7185318871..7fac61b488 100644 --- a/challenge-119/frankivo/scala/Sequencer.scala +++ b/challenge-119/frankivo/scala/Sequencer.scala @@ -1,8 +1,8 @@ object Sequencer { def sequencer(n: Int): Int = { - (0 to (n / 3)) - .map(x => (1 to 3).map(y => y + x * 10)) - .flatten - .toSeq(n) + ((1 to n * n.toString.length * 30) + .filterNot(_.toString exists (((4 to 9).toSeq :+ 0).map(_.toString) contains _.toString)) + .filterNot(_.toString contains "11") + ) (n - 1) } } \ No newline at end of file -- cgit From bea3fdaad02054bc86e585baf38ee6a63a99553f Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Thu, 1 Jul 2021 15:05:58 +0200 Subject: Limitless Sequencer --- challenge-119/frankivo/scala/Sequencer.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/challenge-119/frankivo/scala/Sequencer.scala b/challenge-119/frankivo/scala/Sequencer.scala index 7fac61b488..e0fb73d2cc 100644 --- a/challenge-119/frankivo/scala/Sequencer.scala +++ b/challenge-119/frankivo/scala/Sequencer.scala @@ -1,8 +1,13 @@ object Sequencer { def sequencer(n: Int): Int = { - ((1 to n * n.toString.length * 30) - .filterNot(_.toString exists (((4 to 9).toSeq :+ 0).map(_.toString) contains _.toString)) - .filterNot(_.toString contains "11") - ) (n - 1) + var i = 1 + var ok = 1 + while (ok < n) { + if (!i.toString.exists(((4 to 9).toSeq :+ 0).map(_.toString) contains _.toString)) + if (!i.toString.contains("11")) + ok = ok + 1 + i = i + 1 + } + i } } \ No newline at end of file -- cgit From a2bb6f0c8935612308b42492658f490cf6c05f4f Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Thu, 1 Jul 2021 15:33:17 +0200 Subject: LazyList Sequencer --- challenge-119/frankivo/scala/Sequencer.scala | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/challenge-119/frankivo/scala/Sequencer.scala b/challenge-119/frankivo/scala/Sequencer.scala index e0fb73d2cc..7883b8c2f0 100644 --- a/challenge-119/frankivo/scala/Sequencer.scala +++ b/challenge-119/frankivo/scala/Sequencer.scala @@ -1,13 +1,10 @@ object Sequencer { def sequencer(n: Int): Int = { - var i = 1 - var ok = 1 - while (ok < n) { - if (!i.toString.exists(((4 to 9).toSeq :+ 0).map(_.toString) contains _.toString)) - if (!i.toString.contains("11")) - ok = ok + 1 - i = i + 1 - } - i + LazyList + .iterate(1)(_ + 1) + .filterNot(_.toString exists (((4 to 9).toSeq :+ 0).map(_.toString) contains _.toString)) + .filterNot(_.toString contains "11") + .take(n) + .last } } \ No newline at end of file -- cgit