Skip to content

Instantly share code, notes, and snippets.

View nikhil-RGB's full-sized avatar
:octocat:
Hammering out code

Nikhil Narayanan nikhil-RGB

:octocat:
Hammering out code
View GitHub Profile
List<Checkers> continuedCapture(Point source, List<List<Point>> moves) {
Checkers refBoard = this;
List<Checkers> boards = [];
for (List<Point> capDiagonal in moves) {
Checkers childBoardCap = refBoard.cloneGame();
List<List<Point>> newCaps =
childBoardCap.executeCapture(source, capDiagonal);
newCaps = childBoardCap.kingAfterMove(capDiagonal[1])
? childBoardCap.captureSequences(capDiagonal[1])
: newCaps;
One of Flutter's most efficient tricks is ability to use a build context to look up widget tree for something of interest. The most common of these are MediaQuery of context and theme of context. But popular state management solutions, like Flutter Block and Provider, is the same mechanism. And the pattern really is accustomed to. Because without it, every live widget that cares about the MediaQuery would have to accept it as a parameter from their parent, meaning every one of their ancestors would have to accept it as a parameter. This would couple every widget in your app to the position in a widget tree. Imagine that refactoring pane. But the pattern is even more useful than merely preventing a thick jungle of parameters. Simply having a widget run the line of code, MediaQuery of context ties the widget to the MediaQuery, meaning it will get rebuilt whenever the MediaQuery changes. And this is important. Because if you are laying out a widget based on the screen size, that layout is unlikely to remain valu
@nikhil-RGB
nikhil-RGB / checkers.dart
Last active May 8, 2025 21:56
Simple recursive function, contd captures
//Minimax related functions start from here:
//1- This function clones the current board and returns a copy of it
Checkers cloneGame() {
Checkers cloneBoard = Checkers();
cloneBoard.board =
this.board.map((innerList) => List<Token>.from(innerList)).toList();
return cloneBoard;
}
import 'package:hive_flutter/adapters.dart';
import 'package:turing_machines/models/Behaviour.dart';
import 'package:turing_machines/models/Configuration.dart';
import 'package:turing_machines/models/Tape.dart';
import 'package:turing_machines/models/TuringMachines.dart';
part "TuringMachineModel.g.dart";
@HiveType(typeId: 0)
class TuringMachineModel {
@HiveField(0)
@nikhil-RGB
nikhil-RGB / FirstAndFollow.java
Last active April 20, 2024 06:26
This script will calculate the first and follow of a symbol for a given context free grammar. This currently does not handle left recursion and left factoring. Epsilon is not handled yet.
package compiler_design;
import java.util.*;
public class FirstAndFollow {
public static void main(String[] args)
{
System.out.println("Input number of production rules");
Scanner reader=new Scanner(System.in);
int count=Integer.parseInt(reader.nextLine());
LinkedHashMap<String,String[]> table=new LinkedHashMap<>();
for(int i=0;i<count;++i) {
import java.util.*;
public class CodeGenerationForIf {
public static void main(String[] args) {
// Example input: if (x > 5) { y = x * 2; }
String condition = "x>8";
String action = "y = y / 10;";
// Generate code for the if statement
String generatedCode = generateIfCode(condition, action);
System.out.println("Generated code for if:");
@nikhil-RGB
nikhil-RGB / Actions.dart
Created March 31, 2024 20:43
Parse and store actions for a turing machine with a particular configuration, does not include final state as a part of stored data.
// ignore: file_names
import 'package:flutter/material.dart';
import 'package:turing_machines/exceptions/ActionParserException.dart';
//Represents an Action which can be performed on the tape of a turing machine.
class Actions {
String symbol;
ActionType type;
Actions({required this.type, this.symbol = ""});
//Parses a String containing actions, seperated by a ,(comma)
@nikhil-RGB
nikhil-RGB / PostFix.java
Created March 26, 2024 10:39
Compiler Design Experiment 8, evaluation of a post fix expression
import java.util.*;
public class PostFix {
public static void main(String[] args) {
System.out.println("Input Postix Expression");
@nikhil-RGB
nikhil-RGB / $PROFILE
Created March 22, 2024 20:20
A powershell profile script which can be used to define useful shorthands. Also includes initialization for oh-my-posh and winfetch
oh-my-posh --init --shell pwsh --config ~/AppData/Local/Programs/oh-my-posh/themes/jandedobbeleer.omp.json | Invoke-Expression
function personal {
Set-Location -Path C:\PROJECTS\personal
}
function openPersonal {
$directoryPath = 'C:\PROJECTS\personal'
@nikhil-RGB
nikhil-RGB / Minimax.java
Created March 7, 2024 16:56
Original implementation Minimax tictactoe
public static int[] minMax(TicTacToeMin obj)
{
ArrayList<Integer> scores=new ArrayList<>(0);
ArrayList<TicTacToeMin> arrs=obj.simulate();
ArrayList<Integer> moves=obj.emptySpaces();
//return a list of cloned boards with current token fitted into all empty spaces.
if(arrs.size()==0)
{
return new int[] {0,-1};