From f90349fbd02a4b243f73bcdfc245abfa36df497f Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Mon, 24 Apr 2023 19:00:10 +0200 Subject: Challenge 070 LK --- challenge-070/lubos-kolouch/python/ch-1.py | 16 ++++++++++++++++ challenge-070/lubos-kolouch/python/ch-2.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 challenge-070/lubos-kolouch/python/ch-1.py create mode 100644 challenge-070/lubos-kolouch/python/ch-2.py (limited to 'challenge-070/lubos-kolouch/python') diff --git a/challenge-070/lubos-kolouch/python/ch-1.py b/challenge-070/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..21cbaaff44 --- /dev/null +++ b/challenge-070/lubos-kolouch/python/ch-1.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +S = "perlandraku" +C = 3 +O = 4 +N = len(S) +S = list(S) + +for i in range(1, C + 1): + x = i % N + y = (i + O) % N + S[x], S[y] = S[y], S[x] + +S = "".join(S) +print(S) diff --git a/challenge-070/lubos-kolouch/python/ch-2.py b/challenge-070/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..48ab086970 --- /dev/null +++ b/challenge-070/lubos-kolouch/python/ch-2.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +N = 4 +gray_code = ["0", "1"] + +for i in range(2, N + 1): + rev_gray_code = gray_code[::-1] + gray_code = ["0" + x for x in gray_code] + rev_gray_code = ["1" + x for x in rev_gray_code] + gray_code += rev_gray_code + +gray_code = [int(x, 2) for x in gray_code] +print(gray_code) -- cgit