aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-173/laurent-rosenfeld/d/ch-1.d22
-rw-r--r--challenge-173/laurent-rosenfeld/d/ch-2.d11
-rw-r--r--challenge-173/laurent-rosenfeld/dart/ch-2.dart1
-rw-r--r--challenge-173/laurent-rosenfeld/dc/ch-2.dc19
-rw-r--r--challenge-173/laurent-rosenfeld/go/ch-1.go26
-rw-r--r--challenge-173/laurent-rosenfeld/go/ch-2.go17
-rw-r--r--challenge-173/laurent-rosenfeld/javascript/ch-2.js7
-rw-r--r--challenge-173/laurent-rosenfeld/kotlin/ch-1.kt20
-rw-r--r--challenge-173/laurent-rosenfeld/kotlin/ch-2.kt10
-rw-r--r--challenge-173/laurent-rosenfeld/lua/ch-2.lua7
-rw-r--r--challenge-173/laurent-rosenfeld/nim/ch-1.nim15
-rw-r--r--challenge-173/laurent-rosenfeld/nim/ch-2.nim7
-rw-r--r--challenge-173/laurent-rosenfeld/tcl/ch-2.tcl6
13 files changed, 168 insertions, 0 deletions
diff --git a/challenge-173/laurent-rosenfeld/d/ch-1.d b/challenge-173/laurent-rosenfeld/d/ch-1.d
new file mode 100644
index 0000000000..0d9450bc60
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/d/ch-1.d
@@ -0,0 +1,22 @@
+import std.stdio;
+import std.math;
+import std.conv;
+
+bool is_esthetic(int num) {
+ auto s = to!string(num, 10);
+ foreach (i; 1 .. s.length) {
+ if (abs(s[i] - s[i-1]) != 1) return false;
+ }
+ return true;
+}
+void main() {
+ int[] tests = [ 5456, 120, 121, 23456, 2346, 7654567, 765467 ];
+ foreach(test; tests) {
+ printf("%-9d ", test);
+ if (is_esthetic(test)) {
+ writeln("is esthetic");
+ } else {
+ writeln("is not esthetic");
+ }
+ }
+}
diff --git a/challenge-173/laurent-rosenfeld/d/ch-2.d b/challenge-173/laurent-rosenfeld/d/ch-2.d
new file mode 100644
index 0000000000..c4bd7e68ec
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/d/ch-2.d
@@ -0,0 +1,11 @@
+import std.stdio;
+import std.bigint;
+
+void main() {
+ BigInt s = "2";
+ writeln(s);
+ for (int i = 1; i <= 9; i++) {
+ s = s * (s - 1) + 1;
+ writeln(s);
+ }
+}
diff --git a/challenge-173/laurent-rosenfeld/dart/ch-2.dart b/challenge-173/laurent-rosenfeld/dart/ch-2.dart
new file mode 100644
index 0000000000..1311463a6b
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/dart/ch-2.dart
@@ -0,0 +1 @@
+void main() { var s = BigInt.from(2); print(s); var one = BigInt.from(1); for (int i = 1; i <= 9; i++) { s = s * (s - one) + one; print(s); } }
diff --git a/challenge-173/laurent-rosenfeld/dc/ch-2.dc b/challenge-173/laurent-rosenfeld/dc/ch-2.dc
new file mode 100644
index 0000000000..9e93709ebc
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/dc/ch-2.dc
@@ -0,0 +1,19 @@
+2sn # push 2 on the stack, pop 2 off the top of the stack
+ # and store it into register n
+lnp # copy the value back on the stack and print it
+9sc # give counter c an initial value of 9
+[ # start of macro
+ 1- # subtract 1 from stack (value n-1)
+ ln # load n to stack
+ *1+p # compute product n * n-1, add 1 and print
+ sn # pop new value and store it in register n
+ ln # copy new value in n to stack
+ lc # copy counter to stack
+ 1- # decrement counter (subtract 1 from c)
+ sc # store decremented counter in c
+ 0 lc # store 0 and counter on stack
+ >m # compare c to 0 and, if c > 0, run recursively macro in m
+] # end of macro
+d # duplicate macro on stack
+sm # store macro in register m
+x # execute first iteration of macro
diff --git a/challenge-173/laurent-rosenfeld/go/ch-1.go b/challenge-173/laurent-rosenfeld/go/ch-1.go
new file mode 100644
index 0000000000..897699b88f
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/go/ch-1.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+)
+
+func is_esthetic(n int) bool {
+ s := strconv.Itoa(n)
+ for i := 1; i < len(s); i++ {
+ if s[i]-s[i-1] != 1 && s[i-1]-s[i] != 1 {
+ return false
+ }
+ }
+ return true
+}
+func main() {
+ tests := []int{5456, 120, 121, 23456, 2346, 7654567, 765467}
+ for _, test := range tests {
+ if is_esthetic(test) {
+ fmt.Printf("%-9d is esthetic\n", test)
+ } else {
+ fmt.Printf("%-9d is not esthetic\n", test)
+ }
+ }
+}
diff --git a/challenge-173/laurent-rosenfeld/go/ch-2.go b/challenge-173/laurent-rosenfeld/go/ch-2.go
new file mode 100644
index 0000000000..c5d6735298
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/go/ch-2.go
@@ -0,0 +1,17 @@
+// Go big int syntax really sucks
+package main
+
+import (
+ "fmt"
+ "math/big"
+)
+
+func main() {
+ s := big.NewInt(2)
+ fmt.Println(0, ": ", s)
+ one := big.NewInt(1)
+ for i := 1; i <= 9; i++ {
+ s.Add(new(big.Int).Mul(s, s), new(big.Int).Sub(one, s))
+ fmt.Println(i, ": ", s)
+ }
+}
diff --git a/challenge-173/laurent-rosenfeld/javascript/ch-2.js b/challenge-173/laurent-rosenfeld/javascript/ch-2.js
new file mode 100644
index 0000000000..12fa6e4a53
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/javascript/ch-2.js
@@ -0,0 +1,7 @@
+let s = BigInt (2)
+let one = BigInt (1)
+console.log(s + " ");
+for (let i = 1; i <= 9; i++) {
+ s = s * (s - one) + one
+ console.log(s + " ");
+}
diff --git a/challenge-173/laurent-rosenfeld/kotlin/ch-1.kt b/challenge-173/laurent-rosenfeld/kotlin/ch-1.kt
new file mode 100644
index 0000000000..a2e8404838
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/kotlin/ch-1.kt
@@ -0,0 +1,20 @@
+import kotlin.math.abs
+
+fun is_esthetic(num: Int): Boolean {
+ val n = num.toString()
+ for (i in 1..n.length - 1) {
+ if (abs(n[i] - n[i-1]) != 1) {
+ return false
+ }
+ }
+ return true
+}
+fun main() {
+ for (test in arrayOf(5456, 120, 121, 23456, 2346, 7654567, 765467)) {
+ if (is_esthetic(test)) {
+ println("$test is esthetic")
+ } else {
+ println("$test is not esthetic")
+ }
+ }
+}
diff --git a/challenge-173/laurent-rosenfeld/kotlin/ch-2.kt b/challenge-173/laurent-rosenfeld/kotlin/ch-2.kt
new file mode 100644
index 0000000000..0b95436d03
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/kotlin/ch-2.kt
@@ -0,0 +1,10 @@
+import java.math.BigInteger
+
+fun main () {
+ var n = BigInteger("2")
+ val one = BigInteger("1")
+ for (i in 1..9) {
+ n = n * (n - one) + one
+ println(n)
+ }
+}
diff --git a/challenge-173/laurent-rosenfeld/lua/ch-2.lua b/challenge-173/laurent-rosenfeld/lua/ch-2.lua
new file mode 100644
index 0000000000..7387f975b2
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/lua/ch-2.lua
@@ -0,0 +1,7 @@
+-- Does not work properly
+s = 2
+print(s)
+for i = 1, 9 do
+ s = s * (s - 1) + 1
+ print(s)
+end
diff --git a/challenge-173/laurent-rosenfeld/nim/ch-1.nim b/challenge-173/laurent-rosenfeld/nim/ch-1.nim
new file mode 100644
index 0000000000..dc25e9e58f
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/nim/ch-1.nim
@@ -0,0 +1,15 @@
+import strutils
+import std/strformat
+
+proc is_esthetic(num: int): bool =
+ let n = intToStr(num)
+ for i in 1..len(n)-1:
+ if abs(int(n[i]) - int(n[i-1])) != 1:
+ return false
+ return true
+
+for test in [5456, 120, 121, 23456, 2346, 7654567, 765467]:
+ if is_esthetic(test):
+ echo fmt("{test:<9}"), " is esthetic"
+ else:
+ echo fmt("{test:<9}"), " is not esthetic"
diff --git a/challenge-173/laurent-rosenfeld/nim/ch-2.nim b/challenge-173/laurent-rosenfeld/nim/ch-2.nim
new file mode 100644
index 0000000000..f7bde8d44c
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/nim/ch-2.nim
@@ -0,0 +1,7 @@
+import bigints
+
+var s = 2.initBigInt
+echo s
+for i in 1..9:
+ s = s * (s - 1) + 1
+ echo s
diff --git a/challenge-173/laurent-rosenfeld/tcl/ch-2.tcl b/challenge-173/laurent-rosenfeld/tcl/ch-2.tcl
new file mode 100644
index 0000000000..5e2c59ef9c
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/tcl/ch-2.tcl
@@ -0,0 +1,6 @@
+set s 2
+puts $s
+for {set i 1} {$i <= 9} {incr i} {
+ set s [expr ($s * ($s - 1) + 1)]
+ puts $s
+}