Skip to content

Instantly share code, notes, and snippets.

@panchishin
panchishin / call_groq.py
Created May 16, 2024 18:08
Simple utility script to call Groq and save/retrieve history
import os
import sys
from groq import Groq
import json
import time
SAVE_FILE = ".groq_chat_history.json"
model = "8"
args = sys.argv[1:]
@panchishin
panchishin / using_pipes.py
Created April 16, 2024 15:33
Using the Pipe in python as an operator
# Example of using custom | operations
# Lets say we want to emulate LCEL, a language that uses | as a pipe operator
# For this example we will start with an input which is a dictionary
# and we want our operator object to read the 'input' key and add a new key 'output'
# Our starting data
input_data = {'input': "Hello World"}
# Our operator object that reverses the input and stores it in the 'output' key
@panchishin
panchishin / tictactoe.py
Last active March 23, 2023 08:14
Tic Tac Toe for CodinGame using MCTS in Python
import sys
import math
import random
from copy import deepcopy
from datetime import datetime
winning_states = ( # use tuple instead of list for speed
0b111_000_000, 0b000_111_000, 0b000_000_111,
0b100_100_100, 0b010_010_010, 0b001_001_001,
@panchishin
panchishin / tictactoe.cpp
Created July 30, 2021 14:32
Basic tic tac tow with random move unless the next move could win
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;
int main() {
@panchishin
panchishin / textadventure.py
Created July 29, 2021 17:09
Very simple text adventure example
def getChoice(choices):
message = "Pick one of : " + ", ".join(choices) + " > "
choice = ""
while choice not in choices:
choice = input(message)
print()
return choice
if __name__ == "__main__":
@panchishin
panchishin / explore.py
Last active August 4, 2021 15:51
A very short text game
import random
# Some fun flavour text to start off
character_descriptions = ["tall", "short", "sly", "lanky", "blue"]
character_gender = ["male","female"]
character_race = ["human","goblin"]
description = random.choice(character_descriptions) + " " + random.choice(character_gender) + " " + random.choice(character_race)
@panchishin
panchishin / gist:a0a6bd3b9119aba6818e95908c54aa49
Last active May 21, 2021 12:00
experiment_for_msmits.py
# -- imports --
import numpy as np
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
# np.set_printoptions(precision=2) reduces np precision output to 2 digit
np.set_printoptions(precision=2, suppress=True)
# -- constant data --
x = [[0., 0.], [1., 1.], [1., 0.], [0., 1.], [-1., -1.], [-1., 0.], [0., -1.]]
@panchishin
panchishin / testharness.py
Created February 24, 2021 19:07
A test harness for uttt
from subprocess import Popen, PIPE
import sys
player1 = sys.argv[1]
player2 = sys.argv[2]
def sendReceive(proc, message):
proc.stdin.write(message)
proc.stdin.flush()
return proc.stdout.readline()
@panchishin
panchishin / mcts.py
Last active December 19, 2020 23:15
MCTS in python from pypi.org/project/mcts/ with unit test example
import time
import math
import random
def randomPolicy(state):
while not state.isTerminal():
try:
action = random.choice(state.getPossibleActions())
except IndexError:
@panchishin
panchishin / subscript_floats.py
Created December 9, 2020 17:46
Python change decimal places to unicode subscript
def asSubstring(number):
result = []
decimal = False
for n in str(number):
if n == '.':
decimal = True
else:
result.append(chr(int(n) + 48 + 8272 * decimal))
return u''.join(result)
asSubstring(123.456)