From ddb660dac6853e936a9e82213be219fefddee349 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Sun, 27 Jun 2021 15:32:24 +0800 Subject: 1 awk script, 2 blogposts, ch-1.pl, ch-2.pl --- challenge-118/cheok-yin-fung/awk/ch-1.awk | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-118/cheok-yin-fung/awk/ch-1.awk diff --git a/challenge-118/cheok-yin-fung/awk/ch-1.awk b/challenge-118/cheok-yin-fung/awk/ch-1.awk new file mode 100644 index 0000000000..fe7e67c04b --- /dev/null +++ b/challenge-118/cheok-yin-fung/awk/ch-1.awk @@ -0,0 +1,20 @@ +# The Weekly Challenge 118 +# Task 1 Binary Palindrome +# Usage: echo "N" | awk -f 'ch-1.awk' +# or: awk -f 'ch-1.awk' < file_contains_an_integer_on_each_line + +{ + n = $0; + i = 0; + while (n > 0) { + arr[i] = n % 2 + n = int(n / 2) + i++ + } + len = i-1 + i = 0 + while (arr[len-i] == arr[i] && i < len/2) { + i++ + } + print arr[len-i]==arr[i] ? 1 : 0 +} -- cgit