# Gentic Algoirthms | Hello World

My Projects
My Profile
Logout
Undo
Redo
Cut
Copy
Paste
Delete
Select All
Find
Find and Replace
Editor Theme
Crimson
Eclipse
Github
Solarized
Cobalt
krTheme
Monokai
Terminal
Textmate
Twilight
Vibrant Ink
Font Size
8px
9px
10px
11px
12px
13px
14px
15px
16px
17px
18px
20px
22px
24px
Tab Size
1
2
3
4
5
6
7
8
Show Invisible
Hide Invisible
Show Line Numbers
Hide Line Numbers
Ace Editor (Default)
Vim Editor
Emacs Editor
Open New Project
Save Project
Save As New Project
Share Project
Search Project
from random import randint goal = "Hello, World!" allowed_characters = list("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ,!") def get_random_entity(n, string_length): entities = [] for _ in range(0, n): entity = "" for _ in range(0, string_length): entity += allowed_characters[randint(0, len(allowed_characters)-1)] entities.append(entity) return entities def get_fitness(entity): points = 0 for i in range(0, len(entity)): if goal[i] == entity[i]: points += 1 return points # Get offspring from two parents. # First, we choose random division point. Genes # before the division point come from first parent and # genes after the division point come from second parent. # If the gene is to be mutated, random character is selected instead. def get_offspring(first_parent, second_parent, mutation_chance): new_entity = "" for i in range(0, len(first_parent)): if randint(0, 100) < mutation_chance: new_entity += allowed_characters[randint(0, len(allowed_characters)-1)] else: if randint(0, 1) == 0: new_entity += first_parent[i] else: new_entity += second_parent[i] return new_entity entities = get_random_entity(100, 13) generation = 0 while True: generation += 1 # Fitness score = [] for e in entities: score.append(get_fitness(e)) print(f"Generation {generation}, best score: {max(score)} ::: {entities[0]}") if entities[0] == goal: print(f"SOLUTION FOUND IN {generation} GENERATIONS") break # Get 90 offsprings. # Chance to be selected as parent is increased for entities with higher score total_chance = sum(score) offsprings = [] while len(offsprings) < 90: parent1_random = randint(0, total_chance - 1) parent2_random = randint(0, total_chance - 1) parent1 = -1 parent2 = -1 for i in range(0, len(score)): parent1_random -= score[i] parent2_random -= score[i] if parent1_random <= 0 and parent1 == -1: parent1 = i if parent2_random <= 0 and parent2 == -1: parent2 = i offsprings.append(get_offspring(entities[parent1], entities[parent2], 5)) # Kill 90 worst entities # sort entities based on score entities_sorted = [entities for _,entities in sorted(zip(score,entities))] entities_sorted.reverse() entities = entities_sorted[:10] entities += offsprings

# Gentic Algoirthms | Hello World (Python v3.6.2) : August 2023

The most user friendly and intuitive Gentic Algoirthms | Hello World (version Python v3.6.2) helps you to Edit, Run and Share your Python3 Code directly from your browser. This development environment provides you the latest version Python v3.6.2 as of August 2023.

## How to give program Input?

The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.

## Keyboard Shortcuts

ShortcutDescription
⌘ + EnterRun the program
⌘ + SSave Project (Login Required)
⇧ + ⌘ + SSave As Project
⌘ + PNew Project
⌘ + GShare Project
⌘ + ZUndo Editing
⌘ + YRedo Editing
⌘ + ASelect All Text
⌘ + XCut Selected Text
⌘ + CCopy Selected Text
⌘ + VPaste Copied Text
⌘ + FSearch Text
⌘ + ⌥ + FReplace Text
ShortcutDescription
Ctrl + EnterRun the program
Ctrl + SSave Project
Shift + Ctrl + SSave As Project
Ctrl + GShare Project
Ctrl + ZUndo Editing
Ctrl + YRedo Editing
Ctrl + ASelect All Text
Ctrl + XCut Selected Text
Ctrl + CCopy Selected Text
Ctrl + VPaste Copied Text
Ctrl + FSearch Text
Ctrl + HReplace Text

## How to Save Python3 Project

You can save your Python3 Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.

## How to Share Python3 Project

You can use this feature to share your Python3 Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.