https://kotlinlang.org logo
b

bjonnh

03/19/2021, 7:59 PM
32 it seems: println((0.."100000001".toInt(2)).count { it.toString(2).let { it == it.reversed() } })
1
👌 2
m

mickeelm

03/19/2021, 8:55 PM
Bonus version, now with dates and decimal.
(0..256).filter { it.toString(2).let { it == it.reversed() } }.forEach { println("${LocalDate.of(2021, 12, 1).minusDays(it.toLong())} - $it: ${it.toString(2)}") }
1
Which gives
Nah wait, reverse is better
Copy code
2021-03-21 - 255: 11111111
2021-04-14 - 231: 11100111
2021-04-26 - 219: 11011011
2021-05-20 - 195: 11000011
2021-05-26 - 189: 10111101
2021-06-19 - 165: 10100101
2021-07-01 - 153: 10011001
2021-07-25 - 129: 10000001
2021-07-27 - 127: 1111111
2021-08-04 - 119: 1110111
2021-08-16 - 107: 1101011
2021-08-24 - 99: 1100011
2021-08-30 - 93: 1011101
2021-09-07 - 85: 1010101
2021-09-19 - 73: 1001001
2021-09-27 - 65: 1000001
2021-09-29 - 63: 111111
2021-10-11 - 51: 110011
2021-10-17 - 45: 101101
2021-10-29 - 33: 100001
2021-10-31 - 31: 11111
2021-11-04 - 27: 11011
2021-11-10 - 21: 10101
2021-11-14 - 17: 10001
2021-11-16 - 15: 1111
2021-11-22 - 9: 1001
2021-11-24 - 7: 111
2021-11-26 - 5: 101
2021-11-28 - 3: 11
2021-11-30 - 1: 1
2021-12-01 - 0: 0
(so
256 downTo 0
instead)
b

bjonnh

03/19/2021, 9:46 PM
I knew someone would do that 🤣
m

mickeelm

03/19/2021, 9:56 PM
Couldn't resist 😄
e

ephemient

03/20/2021, 12:45 AM
without code: binary palindrome can only be of the from 1{xyz}{zyx}1 or 1{xy}z{yx}1, so there's 2^⌊(n-1)/2⌋ n-bit palindromes
❤️ 1
1
well since "0" counts as a palindrome as well, ⌈⌉ around that
m

mickeelm

03/20/2021, 9:18 AM
That's AoC-spirit right there. Always evolving the solutions 😃
5 Views