#!/usr/bin/bc -ql /* Challenge 119 TASK #2 - Sequence without 1-on-1 Submitted by: Cheok-Yin Fung Write a script to generate sequence starting at 1. Consider the increasing sequence of integers which contain only 1's, 2's and 3's, and do not have any doublets of 1's like below. Please accept a positive integer $N and print the $Nth term in the generated sequence. 1, 2, 3, 12, 13, 21, 22, 23, 31, 32, 33, 121, 122, 123, 131, Example Input: $N = 5 Output: 13 Input: $N = 10 Output: 32 Input: $N = 60 Output: 2223 */ scale = 0 num = read() seq = 0 define num_ok(n) { auto last_digit, digit, num num = n if (num <= 0) return 0; while (num > 0) { last_digit = digit digit = num % 10 num = num / 10 if (digit < 1 || digit > 3 || (digit == 1 && last_digit == 1)) return 0; } return 1; } define next_seq() { while (1) { seq = seq+1 if (num_ok(seq)) return seq } } for (i = 1; i <= num; i++) seq = next_seq() seq quit