Generate Demlo Numbers diamond. A Demlo number is like 123…n-1nn-1…321 For ex – 12345654321
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 285
Challenge Difficulty: ⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Generate Demlo Numbers diamond with Power Query
Power Query solution 1 for Generate Demlo Numbers diamond, proposed by Bo Rydobon 🇹🇭:
let
n = 9,
ab = (x) => List.Transform({1 .. x * 2 - 1}, (i) => x - Number.Abs(x - i)),
Ans = List.Transform(ab(9), (j) => Text.Combine(List.Transform(ab(j), Text.From)))
in
Ans
Power Query solution 2 for Generate Demlo Numbers diamond, proposed by Zoran Milokanović:
let
Source = List.Accumulate(
{1 .. 16},
{1},
(s, c) => s & {List.Last(s) + Number.Sign(Number.From(c < 9) - .1)}
),
S = List.Transform(
Source,
each
let
n = Text.Repeat("1", _),
s = Text.Repeat(" ", 2 * (9 - _))
in
s & Text.Replace(Text.From(Expression.Evaluate(n & "*" & n)), "0", "1") & s
)
in
S
Power Query solution 3 for Generate Demlo Numbers diamond, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
Sol = List.Transform({1..9} &List.Reverse({1..8}), each Text.Combine(List.Transform({1.._}& List.Reverse(List.RemoveLastN({1.._})), Text.From)))
in
Sol
Una vez cargado al excel, se centran las celdas y queda como en la imagen. Espero que esto cumpla con las condiciones del reto.
Aqui hay otro query, un poco forzado pero también funciona...
let
Sol = List.Transform({1..9} &List.Reverse({1..8}), each
let
a = Text.Combine(List.Transform({1.._}& List.Reverse(List.RemoveLastN({1.._})), Text.From)),
b = 17-Text.Length(a),
c = Text.Repeat(" ", b),
d = c&a
in d)
in
Sol
Show translation
Show translation of this comment
Power Query solution 4 for Generate Demlo Numbers diamond, proposed by Luan Rodrigues:
let
Fonte = 9,
fx = (n) => {1 .. n} & List.Reverse({1 .. n - 1}),
res = Table.TransformRows(
Table.FromColumns({{1 .. Fonte} & List.Reverse({1 .. Fonte - 1})}),
each Text.Combine(List.Transform(fx([Column1]), Text.From))
)
in
res
Power Query solution 5 for Generate Demlo Numbers diamond, proposed by Alexis Olson:
let
R = (N) => {1 .. N} & List.Reverse({1 .. N - 1})
in
List.Transform(R(9), (i) => Text.Combine(List.Transform(R(i), Number.ToText)))
Power Query solution 6 for Generate Demlo Numbers diamond, proposed by Ramiro Ayala Chávez:
let
Origen = List.Transform({1 .. 17}, each _ - 9),
a = List.Transform(Origen, each Number.Abs(_)),
b = List.Transform(a, each 9 - _),
c = List.Transform(b, each Text.Repeat("1", _)),
d = Table.FromList(c, Splitter.SplitByNothing()),
e = Table.TransformColumnTypes(d, {{"Column1", Int64.Type}}),
f = Table.TransformColumns(e, {{"Column1", each Number.Power(_, 2)}}),
g = Table.TransformColumnTypes(f, {{"Column1", type text}}),
Sol = Table.ReplaceValue(g, "0", "1", Replacer.ReplaceText, {"Column1"})
in
Sol
Power Query solution 7 for Generate Demlo Numbers diamond, proposed by Szabolcs Phraner:
let
Demlo =
List.Transform( {1..9}, each [a = Text.Combine(List.FirstN({"1".."9"},_)), b = Text.Reverse(Text.Start(a,_-1)) , c = a&b] )
)
in
List.Transform(Demlo, each [c] )
Solving the challenge of Generate Demlo Numbers diamond with Excel
Excel solution 1 for Generate Demlo Numbers diamond, proposed by Bo Rydobon 🇹🇭:
=9
[(c:=''.join(
str(
j
) for j in range(
1,
n-abs(
i-n
)+1
)
))+c[-2::-1] for i in range(
1,
n*2
)
Excel solution 2 for Generate Demlo Numbers diamond, proposed by Bo Rydobon 🇹🇭:
=LET(
n,
9,
ab,
LAMBDA(
x,
x-ABS(
x-SEQUENCE(
x*2-1
)
)
),
MAP(
ab(
n
),
LAMBDA(
i,
CONCAT(
ab(
i
)
)
)
)
)
Excel solution 3 for Generate Demlo Numbers diamond, proposed by Rick Rothstein:
=VSTACK(
SUBSTITUTE(
REPT(
1,
SEQUENCE(
9
)
)^2,
"00",
21
),
REPT(
1,
SEQUENCE(
8,
,
8,
-1
)
)^2
)
Excel solution 4 for Generate Demlo Numbers diamond, proposed by Rick Rothstein:
=SUBSTITUTE(REPT(1,9-ABS(SEQUENCE(17)-9))^2,"00",21)
Excel solution 5 for Generate Demlo Numbers diamond, proposed by John V.:
=LET(
r,
ROW(
1:8
),
p,
VSTACK(
r,
9,
9-r
),
b,
CONCAT(
p
),
LEFT(
b,
p
)&RIGHT(
b,
p-1
)
)
Excel solution 6 for Generate Demlo Numbers diamond, proposed by John V.:
= list(range(1, 9))
p = n + [9] + [9 - i for i in n]
s = ''.join(str(i) for i in p)
Excel solution 7 for Generate Demlo Numbers diamond, proposed by محمد حلمي:
=LET(
v,
SCAN(
"123456789987654321",
SEQUENCE(
9
),
LAMBDA(
a,
d,
LEFT(
a,
LEN(
a
)/2-1
)&RIGHT(
a,
LEN(
a
)/2
)
)
),
VSTACK(
SORT(
v
),
DROP(
v,
1
)
)
)
Excel solution 8 for Generate Demlo Numbers diamond, proposed by Kris Jaganah:
=MAP(VSTACK(SEQUENCE(9),SEQUENCE(8,,8,-1)),LAMBDA(x,IFERROR(CONCAT(HSTACK(SEQUENCE(,x),SEQUENCE(,x-1,x-1,-1))),1)))
Excel solution 9 for Generate Demlo Numbers diamond, proposed by Timothée BLIOT:
=MAP(
VSTACK(
SEQUENCE(
9
),
SEQUENCE(
9,
,
9,
-1
)
),
LAMBDA(
v,
CONCAT(
VSTACK(
SEQUENCE(
v
),
IFERROR(
SEQUENCE(
v-1
),
""
)
)
)
)
)
Excel solution 10 for Generate Demlo Numbers diamond, proposed by Hussein SATOUR:
=BYROW(
VSTACK(
SEQUENCE(
9
),
SEQUENCE(
8,
,
8,
-1
)
),
LAMBDA(
x,
LEFT(
123456789,
x
)&RIGHT(
87654321,
x-1
)
)
)
Excel solution 11 for Generate Demlo Numbers diamond, proposed by Oscar Mendez Roca Farell:
=LET(_f, LAMBDA(i, SEQUENCE(i, , i, -1)), SCAN( , MOD(VSTACK(SEQUENCE(9),_f(8))-1, 9)+1, LAMBDA(a, v, CONCAT(SEQUENCE(v))&IFERROR(CONCAT(_f(v-1)), ""))))
Excel solution 12 for Generate Demlo Numbers diamond, proposed by Sunny Baggu:
=LET(
_rows,
9,
_num,
2 * _rows,
_seq,
VSTACK(
SEQUENCE(
_num / 2
),
SEQUENCE(
_num / 2 - 1,
,
_num / 2 - 1,
-1
)
),
_col1,
MAP(
_seq,
LAMBDA(
a,
CONCAT(
SEQUENCE(
a
)
)
)
),
_col2,
IFERROR(
MAP(
_seq,
LAMBDA(
a,
CONCAT(
SEQUENCE(
a - 1,
,
a - 1,
-1
)
)
)
),
""
),
MAP(
_col1,
_col2,
LAMBDA(
a,
b,
a & b
)
)
)
Excel solution 13 for Generate Demlo Numbers diamond, proposed by LEONARD OCHEA 🇷🇴:
=LET(
F,
LAMBDA(
x,
x-ABS(
SEQUENCE(
2*x-1
)-x
)
),
MAP(
F(
9
),
LAMBDA(
a,
CONCAT(
F(
a
)
)
)
)
)
Excel solution 14 for Generate Demlo Numbers diamond, proposed by LEONARD OCHEA 🇷🇴:
=LET(
n,
SEQUENCE(
9
),
MAP(
VSTACK(
n,
DROP(
9-n,
-1
)
),
LAMBDA(
a,
LET(
s,
SEQUENCE(
a
),
IFERROR(
CONCAT(
s,
DROP(
a-s,
-1
)
),
1&""
)
)
)
)
)
Excel solution 15 for Generate Demlo Numbers diamond, proposed by Abdallah Ally:
=LET(n,9,f,LAMBDA(v,REDUCE("1",SEQUENCE(v-1,,2),LAMBDA(x,y,VSTACK(x,IF(y=1,x,CONCAT(SEQUENCE(y),SEQUENCE(y-1,,y-1,-1))))))),VSTACK(f(n),SORTBY(f(n-1),LEN(f(n-1)),-1)))
Excel solution 16 for Generate Demlo Numbers diamond, proposed by Charles Roldan:
=LAMBDA(
n,
REDUCE(
,
SORT(
SEQUENCE(
n
),
,
-1
),
LAMBDA(
a,
b,
"" & VSTACK(
b,
b & a & b,
b
)
)
)
)(9)
Excel solution 17 for Generate Demlo Numbers diamond, proposed by Tolga Demirci, PMP, PMI-ACP, MOS-Expert:
=sharing
=LET(
w;
SEQUENCE(
9;
;
1;
1
);
e;
LEN(
TEXTJOIN(
;
;
SEQUENCE(
9;
;
1;
1
)
)
)+1-SEQUENCE(
9;
;
1;
1
);
VSTACK(
HSTACK(
MAP(
w;
LAMBDA(
x;
TEXTJOIN(
;
;
SEQUENCE(
x;
;
1;
1
)
)
)
);
SUBSTITUTE(
MAP(
w;
LAMBDA(
y;
TEXTJOIN(
;
;
LEN(
TEXTJOIN(
;
;
SEQUENCE(
y;
;
1;
1
)
)
)+1-SEQUENCE(
y;
;
1;
1
)
)
)
);
w;
"";
1
)
);
HSTACK(
MAP(
e;
LAMBDA(
q;
TEXTJOIN(
;
;
SEQUENCE(
q;
;
1;
1
)
)
)
);
SUBSTITUTE(
MAP(
e;
LAMBDA(
z;
TEXTJOIN(
;
;
LEN(
TEXTJOIN(
;
;
SEQUENCE(
z;
;
1;
1
)
)
)+1-SEQUENCE(
z;
;
1;
1
)
)
)
);
e;
"&";
1
)
)
)
)
Excel solution 18 for Generate Demlo Numbers diamond, proposed by Julien Lacaze:
=MAP(
VSTACK(
SEQUENCE(
9
),
SEQUENCE(
8,
,
8,
-1
)
),
LAMBDA(
a,
CONCAT(
SEQUENCE(
a,
,
1
),
IFERROR(
SEQUENCE(
a-1,
,
a-1,
-1
),
""
)
)
)
)
Excel solution 19 for Generate Demlo Numbers diamond, proposed by Pieter de Bruijn:
=DROP(
LET(
n,
8,
REDUCE(
0,
VSTACK(
SEQUENCE(
n
),
SEQUENCE(
n-1,
,
n-1,
-1
)
),
LAMBDA(
x,
y,
VSTACK(
x,
CONCAT(
SEQUENCE(
,
y
)
)&CONCAT(
IFERROR(
SEQUENCE(
,
y-1,
y-1,
-1
),
""
)
)
)
)
)
),
1
)
Excel solution 20 for Generate Demlo Numbers diamond, proposed by Giorgi Goderdzishvili:
=LET(
seq,
SEQUENCE(
9
),
mp,
MAP(
seq,
LAMBDA(
x,
CONCAT(
HSTACK(
SEQUENCE(
,
x
),
SEQUENCE(
,
MAX(
x-1,
1
),
x-1,
-1
)
)
)
)
),
srt,
SORT(
--TAKE(
mp,
8
),
1,
-1
),
SUBSTITUTE(
VSTACK(
mp,
srt
),
"0",
""
)
)
Excel solution 21 for Generate Demlo Numbers diamond, proposed by samir tobeil:
=DROP(
LET(
s,
SEQUENCE(
9
),
d,
SCAN(
,
s,
LAMBDA(
a,
x,
a&x
)
)&RIGHT(
SCAN(
,
s,
LAMBDA(
a,
x,
x&a
)
),
s-1
),
VSTACK(
d,
INDEX(
d,
9-s
)
)
),
-1
)
Excel solution 22 for Generate Demlo Numbers diamond, proposed by Andres Rojas Moncada:
=LET(
_sec,
SECUENCIA(
9
),
_m1,
SCAN(
"",
_sec,
LAMBDA(
_acu,
_val,
LET(
_esc,
TOMAR(
_sec,
_val-1
),
CONCAT(
_esc,
_val,
_val-_esc
)
)
)
),
SI.ERROR(
APILARV(
_m1,
INDICE(
_m1,
9-EXCLUIR(
_sec,
-1
)
)
),
"1"
)
)
Excel solution 23 for Generate Demlo Numbers diamond, proposed by Hazem Hassan:
=LET(
a,
REPT(
1,
SEQUENCE(
9
)
)^2,
VSTACK(
SUBSTITUTE(
a,
"00",
21
),
SORT(
DROP(
a,
-1
),
,
-1
)
)
)
Excel solution 24 for Generate Demlo Numbers diamond, proposed by Jeremy Freelove:
=LET(
n,
9,
dLen,
ABS(
ABS(
SEQUENCE(
2*n-1,
,
1-n
)
)-n
),
MAP(
dLen,
LAMBDA(
a,
CONCAT(
ABS(
ABS(
SEQUENCE(
,
a*2-1,
1-a
)
)-a
)
)
)
)
)
Solving the challenge of Generate Demlo Numbers diamond with Python in Excel
Python in Excel solution 1 for Generate Demlo Numbers diamond, proposed by Abdallah Ally:
import pandas as pd
def demlo_numbers(n):
numbers = ["".join([str(x) for x in
(list(range(1, num + 1)) + list(range(1, num))[::-1])])
for num in range(1, n +1)]
df = pd.DataFrame(numbers + numbers[:-1][::-1],
columns=['DemloNumbers'])
return df
Python in Excel solution 2 for Generate Demlo Numbers diamond, proposed by JvdV -:
=LET(s,"12345678987654321",n,9-ABS(ROW(1:17)-9),LEFT(s,n)&RIGHT(s,n-1))
[(lambda x,y:x[:y+1]+x[::-1][9-y:])('123456789',8-abs(n-8)) for n in range(17)]
I hope that clears things up for those starting with Python.
Python in Excel solution 3 for Generate Demlo Numbers diamond, proposed by Diarmuid Early:
["".join([str(size-abs(i)-abs(j)) for j in range(abs(i)-size+1,size-abs(i))]) for i in range(-size+1,size)]
I'm saving all my Python solutions to these challenges here if anyone wants to explore:
bit.ly/PythonLearningFolder
Solving the challenge of Generate Demlo Numbers diamond with R
R solution 1 for Generate Demlo Numbers diamond, proposed by Konrad Gryczan, PhD:
library(purrr)
generateDemloNumber <- function(length) {
number <- as.numeric(paste0(rep(1, length), collapse = ""))
return(number^2)
}
demlo_sequence <- c(1:9, 8:1) %>%
map_dbl(~generateDemloNumber(.))
R solution 2 for Generate Demlo Numbers diamond, proposed by Konrad Gryczan, PhD:
library(purrr)
library(tidyverse)
library(gmp)
generateDemloNumber <- function(length) {
number <- as.bigz(paste0(rep(1, length), collapse = ""))
result <- as.character(number^2)
return(result)
}
demlo_sequence <- c(1:9, 8:1) %>%
map(~generateDemloNumber(.)) %>%
unlist() %>%
as.data.frame(number = list(.))
&&
