Snippets Collections
class Solution
{
	public:
	//Function to find the level of node X.
	using pi = pair<int,int>;
	int nodeLevel(int V, vector<int> adj[], int X) 
	{
	    // code here
	    vector<bool> vis(V, false);
	    queue<pi> q;
	    q.push({0, 0});
	    vis[0] = true;
	    while(!q.empty()){
	        auto curr = q.front();q.pop();
	        if(curr.first == X)
	            return curr.second;
	       for(auto adjV : adj[curr.first]){
	           if(!vis[adjV]){
	               vis[adjV] = true;
	               q.push({adjV , curr.second + 1});
	           }
	       }
	    }
	    return -1;
	}
};
class Solution {
public:
    int minimumTime(int n, vector<vector<int>>& relations, vector<int>& time) {
        vector<vector<int>> gr(n+1);
        vector<int> indegree(n+1, 0), prev_time(n+1, 0);
        for(auto& edge : relations){
            gr[edge[0]].push_back(edge[1]);
            indegree[edge[1]]++;
        }
        time.insert(time.begin(), 0);
        queue<int> q;
        for(int i =1; i <= n; i++)
            if(indegree[i] == 0)
                q.push(i);
        while(!q.empty()){
            int node = q.front();q.pop();
            for(auto adjV : gr[node]){
                prev_time[adjV] = max(prev_time[adjV] , time[node] + prev_time[node]);
                if(--indegree[adjV] == 0)
                    q.push(adjV);
            }
        }
        int ans = 0;
        for(int i =1 ; i < n + 1; ++i){
            ans = max(ans, time[i]+prev_time[i]);
        }
        return ans;
    }
};
import logging

logging.basicConfig(filename='codelogging.log', level=logging.DEBUG,
                format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')

a_variable = 200

# for loop with logging
for i in range(100):
    x = print(i)
    logging.info('Iteriating')

logging.info('Script completed')
Data d1; *fake data*;
   do grp =1 to 2;
   do xx = 1 to 5;
   if grp = 1 then N = 20;
   if grp = 2 then N = abs(x-6)*10;
      do i = 1 to N;
         x = xx + ranuni(0) - .5;
         if grp=1 then y= 5*x/10   + ranuni(0);
         if grp=2 then y= 2*x*x/10 + ranuni(0);
         output;
      end;
   end;
   end;
   keep grp x y;
run;

Data pred; *pretend these are results from PLM*;
   do grp =1 to 2;
   do x = 1 to 5 by .5;
         if grp=1 then pred = 5*x/10   + 0;
         if grp=2 then pred = 2*x*x/10 + 0;
         output;
   end;
   end;
run;

ods trace off;
Proc SQL; Select min(x) into :minx TRIMMED from d1; quit;
Proc SQL; Select max(x) into :maxx TRIMMED from d1; quit;
Proc Univariate Data=d1;
   Class grp;
   Var x;
   Histogram x / outhistogram=histout endpoints=&minx to &maxx by .2;
run;

Proc SQL; Select max(_count_) into :maxn TRIMMED from histout; quit;
Data histout;
   Set histout;
   scale=1;
   l = -1*(grp=1) -2*(grp=2);
   h = scale*(_count_/&maxn) -1*(grp=1) -2*(grp=2);
   myx = _MINPT_ + .2/2; *use a new variable name, different from x*;
run;

Data both2;
   Set pred histout;
run;


Proc SGPlot Data=both2 noautolegend;
   highlow x=myx high=h low=l / type=bar barwidth=0.85 nooutline group=grp;
   series x=x y=pred / group=grp; /*x var in highlow and series MUST be different variables*/
   refline 0;
   yaxis max=6 min=-2 values=(-2 to 6 by 1) VALUESHINT /*allows min/max to differ from values list*/;
run;
quit;





import tkinter as tk
from tkinter import ttk

root = tk.Tk()

# Pack a big frame so, it behaves like the window background
big_frame = ttk.Frame(root)
big_frame.pack(fill="both", expand=True)

# Set the initial theme
root.tk.call("source", "sun-valley.tcl")
root.tk.call("set_theme", "light")

def change_theme():
    # NOTE: The theme's real name is sun-valley-<mode>
    if root.tk.call("ttk::style", "theme", "use") == "sun-valley-dark":
        # Set light theme
        root.tk.call("set_theme", "light")
    else:
        # Set dark theme
        root.tk.call("set_theme", "dark")

# Remember, you have to use ttk widgets
button = ttk.Button(big_frame, text="Change theme!", command=change_theme)
button.pack()

root.mainloop()
#importing Autoviz class
from autoviz.AutoViz_Class import AutoViz_Class#Instantiate the AutoViz class
AV = AutoViz_Class()

df = AV.AutoViz('car_design.csv')
star

Thu Oct 19 2023 07:20:10 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/level-of-nodes-1587115620/1

#bfs #graphs #easy
star

Mon Oct 31 2022 01:30:47 GMT+0000 (Coordinated Universal Time)

#graphs #data #jupyter_notebooks
star

Tue Jun 14 2022 00:52:28 GMT+0000 (Coordinated Universal Time)

#graphs #sgplot #histogram #ticks
star

Mon Aug 23 2021 03:08:13 GMT+0000 (Coordinated Universal Time)

#python #data #visualisation #graphs #plots #charts #dashboards
star

Thu May 27 2021 02:57:45 GMT+0000 (Coordinated Universal Time)

#python #data #visualisation #graphs #plots #charts #dashboards
star

Thu May 27 2021 02:56:24 GMT+0000 (Coordinated Universal Time) https://towardsdatascience.com/autoviz-automatically-visualize-any-dataset-75876a4eede4

#python #data #visualisation #graphs #plots #charts #dashboards

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension