blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 5 117 | path stringlengths 3 268 | src_encoding stringclasses 34
values | length_bytes int64 6 4.23M | score float64 2.52 5.19 | int_score int64 3 5 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | text stringlengths 13 4.23M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
e40c3c0d402f994feb1d94b775a544091edf7863 | C++ | donRumata03/Literature | /src/Vocab_research.cpp | UTF-8 | 1,726 | 2.890625 | 3 | [
"MIT"
] | permissive | #include "pch.h"
#include "Vocab_research.h"
vector<pair<double, double>> make_author_vocab(author_books* author)
{
common_word_top author_top;
for (auto& artwork : author->artworks) author_top.merge(artwork.top);
cout << "Got merged top!" << endl;
size_t all_diff_words = author_top.different_words();
auto max_freq = author_top.most_frequent_word().second;
cout << "All different words: " << all_diff_words << "; Max frequency: " << max_freq << endl;
vector<pair<double, double>> res = { /*{ 0., double(all_diff_words) }*/ };
for(size_t cutting_number = 1; cutting_number < max_freq; cutting_number++)
{
author_top.cut(cutting_number);
if (author_top.different_words() == 0) break;
if (!res.empty() && author_top.different_words() == res.back().second) continue;
res.emplace_back(double(cutting_number), double(author_top.different_words()));
}
return res;
}
vector<pair<double, double>> make_log_author_vocab(author_books* author, const bool log_x, const bool log_y)
{
cout << "Got result!" << endl;
auto not_logged = make_author_vocab(author);
if (!log_x && !log_y) return not_logged;
vector<pair<double, double>> answer;
for (auto& p : not_logged)
{
if (log_x) p.first = log(p.first);
if (log_y) p.second = log(p.second);
if (p.first != p.first || p.second != p.second)
{
cout << "Number error!" << endl;
continue;
}
answer.emplace_back(p);
}
return answer;
}
void reduce_line(vector<pair<double, double>>& graph)
{
pair<double, double> first(graph.front()), last(graph.back());
double k = (first.second - last.second) / (first.first - last.first);
double b = first.second - first.first * k;
for (auto& pnt : graph)
{
pnt.second -= pnt.first * k + b;
}
}
| true |
3dd1ea4080210baffddb9d82ca51affa45537cba | C++ | paulojuniore/advanced-algorithms | /LISTA 3/05 - Teclado quebrado.cpp | UTF-8 | 584 | 3.265625 | 3 | [] | no_license | // 1451 - Teclado Quebrado. 25/04/2018
#include <iostream>
#include <list>
using namespace std;
int main()
{
int i;
string frase;
list<char> restos;
list<char>::iterator it;
while(cin >> frase)
{
restos.clear();
it = restos.begin();
for(i = 0; i < frase.length(); i++)
{
if(frase[i] == ']')
it = restos.end();
else if(frase[i] == '[')
it = restos.begin();
if(frase[i] != '[' && frase[i] != ']')
restos.insert(it, frase[i]);
}
for(it = restos.begin(); it != restos.end(); it++)
cout << *it;
cout << endl;
}
return 0;
}
| true |
1e63ca0725f05f44a8d97c37e31beb129ac99512 | C++ | LukeMaher98/ZorkGUI | /hero.h | UTF-8 | 1,248 | 3.09375 | 3 | [] | no_license | #ifndef HERO_H
#define HERO_H
#include "item.h"
#include "Character.h"
#include <string>
#include <vector>
using namespace std;
class Hero : public Character
{
friend class MainWindow;
friend void setStamina(Hero &c, int stam){
c.stamina = stam;
}
private:
bool Sword;
vector<Item> itemsInCharacter;
int killcount;
bool canFight;
int stamina;
public:
Hero();
string longDescription();
bool victory();
bool attack(Character *target);
bool take(Item *taken);
vector<Item> getItems();
void setDead();
int getStamina();
bool checkStamina();
template < class T >
bool fightResult(const T a, const T b){
if(a > b){
return true;
}
else {
return false;
}
}
void operator++ (int) {
killcount++;
}
void operator + (Item *item) {
itemsInCharacter.push_back(*item);
delete item;
}
void operator - (int i) {
vector<Item>::iterator it = itemsInCharacter.begin();
for(int z = 0; z < i; z++){
it++;
}
this->itemsInCharacter.erase(it);
}
};
#endif // HERO_H
| true |
58ea2e325daba55dba6c0b2ff9ed05934f589518 | C++ | sasqwatch/ANBU | /importer.h | UTF-8 | 2,759 | 2.75 | 3 | [] | no_license | #pragma once
#ifndef IMPORTER_H
#define IMPORTER_H
#include "common.h"
#include "dos_header.h"
#include "nt_header.h"
#include "optional_header.h"
#include "data_directory_header.h"
#include "section_header.h"
class Importer
/***
* Class used to fix the import address table of an
* unpacked file, with this class will be easier to
* create the necessary structures for the new IAT.
*/
{
public:
enum name_or_ordinal_enum_t
{
function_is_name = 0,
function_is_ordinal = 1
};
struct import_directory_names_struct_t
{
std::string dll_name;
uint32_t first_thunk;
std::vector<name_or_ordinal_enum_t> name_or_ordinal;
std::vector<std::string> function_names;
std::vector<uint16_t> function_ordinals;
bool operator<(const import_directory_names_struct_t& a) const
{
return first_thunk < a.first_thunk;
}
};
#pragma pack(1)
struct import_directory_struct_t {
uint32_t originalFirstThunk;
uint32_t timeDateStamp;
uint32_t forwarderChain;
uint32_t nameRVA;
uint32_t firstThunk;
};
#pragma pack()
static const uint64_t ordinal_constant_64_binary = 0x8000000000000000;
static const uint32_t ordinal_constant_32_binary = 0x80000000;
Importer(pe_parser::dos_header_t *dos_header,
pe_parser::nt_header_t *nt_coff_header,
pe_parser::optional_header_t *optional_header,
pe_parser::data_directory_header_t *data_directory_header,
pe_parser::section_header_t *section_table_header);
~Importer() = default;
void ImporterAddNewDll(const char* dll_name);
void ImporterAddNewDll(const wchar_t* dll_name);
void ImporterAddNewAPI(const char* function_name);
void ImporterAddNewAPIOrdinal(uint16_t function_ordinal);
void ImporterSetNewFirstThunk(uint32_t first_thunk);
std::vector<uint8_t> ImporterDumpToFile(uint32_t& rva_of_import_directory);
std::vector<uintptr_t> get_original_first_thunk();
uint32_t get_rva_first_thunk();
private:
void copy_name_to_buffer(std::vector<uint8_t>& buffer, std::string name);
bool compare_by_first_thunk(const import_directory_names_struct_t& a, const import_directory_names_struct_t& b);
void clean_list();
/****** HEADER DATA ******/
pe_parser::dos_header_t* dos_header;
pe_parser::nt_header_t* nt_coff_header;
pe_parser::optional_header_t* optional_header;
pe_parser::data_directory_header_t* data_directory_header;
pe_parser::section_header_t* section_table_header;
/****** Importer DATA ******/
std::vector<import_directory_names_struct_t> dlls_and_functions;
import_directory_names_struct_t* import_aux;
std::vector<uint8_t> raw_strings_dlls_and_functions;
std::vector<uintptr_t> new_original_first_thunk;
std::vector<import_directory_struct_t> imports_directories;
};
#endif // !IMPORTER_H
| true |
5e950cfba064875377eff7bea8b9ca5d3187c245 | C++ | JureHudoklin/AGV_warehouse | /catkin_ws/src/robot/include/robot.h | UTF-8 | 601 | 3.328125 | 3 | [] | no_license |
template <class T>
T getSign(T number) {
if (number < 0) {
return -1;
} else if(number > 0){
return 1;
} else {
return 0;
}
}
template <class T>
T limitNumber(T number, T max) {
if (number > max) {
return max;
} else if (number < -max) {
return -max;
} else {
return number;
}
}
template <class T>
int getMinIndex(T* number, int size) {
int index = 0;
T a = number[0];
for(int i = 1; i<size; i++) {
if (number[i]<a) {
a = number[i];
index = i;
}
}
return index;
}
| true |
479edc2c2385595e82b97e689f344d57e7175b09 | C++ | a-gavriel/Remote-Memory | /rmlibserver/encryption/encryption.cpp | UTF-8 | 548 | 3.234375 | 3 | [] | no_license | #include "encryption.h"
std::string encrypt(std::string text)
{
char key = 'x';
std::string encrypted;
std::string original = text;
for (int i = 0; i < original.size(); i++)
{
encrypted += original[i] ^ (int(key) + i) % 20;
}
return encrypted;
}
std::string decrypt(std::string text)
{
char key = 'x';
std::string decrypted;
std::string encrypted = text;
for (int i = 0; i < encrypted.size(); i++)
{
decrypted += encrypted[i] ^ (int(key) + i) % 20;
}
return decrypted;
} | true |
5e5a5e5c6a9b2d941d3d0823dc859b68e7ebcfa8 | C++ | FelixOON/MeteoFMClock | /setupMode.ino | UTF-8 | 6,115 | 2.53125 | 3 | [] | no_license | SetupMode::SetupMode(uint32_t timeInterval) : Mode()
{
timer.setInterval(timeInterval);
}
void SetupMode::init(uint8_t param)
{
_param = param;
if (_param == 0) // time set mode
{
_changeHrs = hrs;
_changeMins = mins;
DateTime now = rtc.getTime();
_changeDay = now.day;
_changeMonth = now.month;
_changeYear = now.year;
_set = &btnLeft;
_left = &btnMiddle;
_right = &btnRight;
}
else if (_param == 1) // alarm set mode
{
_changeHrs = alarmHrs;
_changeMins = alarmMins;
_set = &btnMiddle;
_left = &btnLeft;
_right = &btnRight;
}
else if (_param == 2) // night mode set mode
{
_changeHrs = nightHrStart;
_changeMins = nightHrEnd;
_set = &btnRight;
_left = &btnLeft;
_right = &btnMiddle;
}
_setupStage = 0;
_isHoursSelected = true;
_lampState = true;
}
void SetupMode::loop()
{
Mode::loop();
if (!timer.isReady()) return;
_lampState = !_lampState;
anodeStates[4] = false;
anodeStates[5] = false;
if (!_isHoursSelected)
{
anodeStates[0] = true;
anodeStates[1] = true;
anodeStates[2] = _lampState;
anodeStates[3] = _lampState;
}
else
{
anodeStates[0] = _lampState;
anodeStates[1] = _lampState;
anodeStates[2] = true;
anodeStates[3] = true;
}
if (_param == 0) // date-time setup
{
if (_setupStage == 0) // time setup
{
sendToIndicators(_changeHrs, _changeMins, 0, false);
}
else if (_setupStage == 1) // year setup
{
sendToIndicators((uint8_t)(_changeYear / 100), (uint8_t)(_changeYear % 100), 0, true); // year
anodeStates[0] = _lampState;
anodeStates[1] = _lampState;
anodeStates[2] = _lampState;
anodeStates[3] = _lampState;
}
else if (_setupStage == 2) // day, month
sendToIndicators(_changeDay, _changeMonth, 0, true);
}
else if (_param == 1) // alarm setup
{
if (_setupStage == 0) // setup alarm mode
{
sendToIndicators(alarmMode, 0, 0, true);
anodeStates[0] = _lampState;
anodeStates[1] = _lampState;
anodeStates[2] = false;
anodeStates[3] = false;
}
else if (_setupStage == 1) // setup time
{
sendToIndicators(_changeHrs, _changeMins, 0, false);
}
}
}
void SetupMode::buttonsLoop()
{
if ((_setupStage == 0 && _param != 1) || (_setupStage == 1 && _param == 1) ) { // time setup
if (_left->isClick())
{
if (_isHoursSelected)
{
_changeHrs--;
if (_changeHrs < 0) _changeHrs = 23;
}
else
{
_changeMins--;
if (_param == 0 || _param == 1)
{
if (_changeMins < 0) _changeMins = 59; // time set or alarm time set
}
else
if (_changeMins < 0) _changeMins = 23; // day-night
}
}
if (_right->isClick())
{
if (_isHoursSelected)
{
_changeHrs++;
if (_changeHrs > 23) _changeHrs = 0;
}
else
{
_changeMins++;
if (_param == 0 || _param == 1)
{
if (_changeMins > 59) _changeMins = 0; // time set or alarm time set
}
else
if (_changeMins > 23) _changeMins = 0; // day-night
}
}
}
if (_setupStage == 0 && _param == 1) // setup alarm mode
{
if (_left->isClick())
{
if (alarmMode > 0) alarmMode--;
}
if (_right->isClick())
{
if (alarmMode < 3) alarmMode++;
}
}
if (_param == 0 && _setupStage == 2) // setup day-month
{
if (_left->isClick())
{
if (_isHoursSelected) _changeDay--; else _changeMonth--;
}
if (_right->isClick())
{
if (_isHoursSelected) _changeDay++; else _changeMonth++;
}
uint8_t maxDay = getNumberOfDays(_changeYear, _changeMonth);
if (_changeMonth > 12) _changeMonth = 1;
if (_changeMonth < 1 ) _changeMonth = 12;
if (_changeDay > maxDay) _changeDay = 1;
if (_changeDay < 1) _changeDay= maxDay;
}
if (_param == 0 && _setupStage == 1) // setup year
{
if (_left->isClick()) _changeYear--;
if (_right->isClick()) _changeYear++;
if (_changeYear < 2000) _changeYear = 2000;
if (_changeYear > 3000) _changeYear = 3000;
}
if (_right->isHolded() || _left->isHolded()) {} // reset events
if (_set->isHolded())
{
if (_param == 0) // datetime setup
{
if (_setupStage < 2)
{
_isHoursSelected = true;
_setupStage++;
return;
}
hrs = _changeHrs;
mins = _changeMins;
secs = 0;
rtc.setTime(0, mins, hrs, _changeDay, _changeMonth, _changeYear);
}
else if (_param == 1) // alarm
{
if (_setupStage == 0)
{
if (alarmMode > 0)
{
_setupStage++;
return;
}
}
alarmHrs = _changeHrs;
alarmMins = _changeMins;
EEPROM.put(EEPROM_CELL_ALARM_HOURS, alarmHrs);
EEPROM.put(EEPROM_CELL_ALARM_MINUTES, alarmMins);
EEPROM.put(EEPROM_CELL_ALARM_MODE, alarmMode);
setPin(PIEZO_PIN, HIGH);
delay(300);
setPin(PIEZO_PIN, LOW);
}
modeSelector.setMode(Modes::Main, 0);
}
if (_set->isClick()) _isHoursSelected = !_isHoursSelected;
}
| true |
f2cf6c0e962607e67529eb6e82b7594e913c13a4 | C++ | joastbg/art-raytracer | /matrix.h | UTF-8 | 1,581 | 2.75 | 3 | [] | no_license | /*
* =====================================================================================
*
* Filename: matrix.h
*
* Description:
*
* Version: 1.0
* Created: 01/11/2012 18:36:30
* Revision: none
* Compiler: g++
*
* Author: Johan Astborg (ja), into@avantimedev.net
* Company: avantimedev
*
* =====================================================================================
*/
#ifndef MATRIX_H
#define MATRIX_H
#include "vector3.h"
#include <iostream>
class Matrix {
public:
Matrix(); // Empty constructor sets all elements to 0
void identity(); // set elements to identity matrix
bool invert();
void transpose();
void zero(); // zero out matrix
double getXY(int x, int y);
void setXY(int x, int y, double value);
void set(int i, double value);
void set(double (&arr)[16]);
void set(const Matrix& matrix);
// overloaded operators +, -, *, /, (x,y)
// matrix * vector
// matrix * scalar
Vector3 transform(Vector3& v);
friend Matrix operator+(const Matrix& lhs, const Matrix& rhs);
friend Matrix operator-(const Matrix& lhs, const Matrix& rhs);
friend Matrix operator*(const Matrix& lhs, const Matrix& rhs);
friend Matrix operator*(const Matrix& lhs, const double scalar);
double operator()(const int col, const int row);
void operator()(); // zero out matrix
void operator=(const Matrix& matrix);
bool operator==(const Matrix& matrix);
// determinant?
friend std::ostream &operator<<(std::ostream& out, const Matrix& matrix);
double elems[16]; // or row major order
private:
};
#endif
| true |
3726726cb26aa3143d9bccfcd53aacc332bc3e25 | C++ | btobrien/chessworm | /src/cpp/chess/graph/Parse.h | UTF-8 | 1,460 | 2.578125 | 3 | [] | no_license |
#pragma once
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <fstream>
#include <cassert>
#include <algorithm>
#include "Glyph.h"
#include "Log.h"
//class Parser {
// Game* CreateGame(std::ifstream& pgn);
//
//private:
// std::string pgn;
// int index;
// static void next(std::string &text, int &i, char delim);
// bool parse(std::string &text, int &i);
// std::string parseMove();
//
// template <class PgnNode>
// void createNode(PgnNode* parent)
//};
struct Game;
struct GameNode {
std::string move;
int glyph;
std::string comment;
std::string precomment; //don't like
Game* game;
GameNode* parent;
GameNode* child;
std::vector<GameNode*> variations;
GameNode(GameNode* p, std::string m, const std::string& text, int& i, std::string pre);
~GameNode();
std::string ToString(); //delete
//private:
static void next(const std::string &text, int &i, char delim);
bool parse(const std::string &text, int &i);
static std::string parseMove(const std::string &text, int &i);
};
struct Tags {
std::string name; //event tag
std::string white;
std::string black;
std::string date;
std::string opening;
std::string annotator;
std::string result;
};
struct Game {
GameNode* root;
std::vector<GameNode*> varRoots;
Tags tags;
std::string intro;
Game(std::ifstream& pgn);
~Game();
private:
void addTag(std::string tname, const std::string& tval);
};
| true |
17bda4211cfce214cb1ddbc0309b60433594425c | C++ | chen0040/cpp-ogre-mllab | /paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeQueue.h | UTF-8 | 8,263 | 2.671875 | 3 | [
"MIT"
] | permissive | /***************************************************************************
OgrePagingLandScapeQueue.h - description
-------------------
begin : Mon Aug 04 2003
copyright : (C) 2003 by Jose A. Milan
email : spoke2@supercable.es
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
#ifndef PAGINGLANDSCAPEQUEUE_H
#define PAGINGLANDSCAPEQUEUE_H
#include <queue>
#include <list>
#include "Ogre.h"
#include "OgreSceneNode.h"
#include "OgreVector3.h"
namespace Ogre
{
//-----------------------------------------------------------------------
inline Real vectorToBoxDistance(const AxisAlignedBox &bbox, const Vector3& point)
{
const Vector3 &boxMin = bbox.getMinimum ();
const Vector3 halfSize ((bbox.getMaximum () - boxMin) * 0.5);
// work in the box's coordinate system
const Vector3 kDiff (point - (halfSize + boxMin));
// compute squared distance and closest point on box
Real fSqrDistance (0.0);
for (unsigned int i = 0; i < 3; i++)
{
const Real kClosest = kDiff[i];
const Real khalfSize = halfSize[i];
if (kClosest < -khalfSize)
{
const Real fDelta = kClosest + khalfSize;
fSqrDistance += fDelta * fDelta;
}
else if (kClosest > khalfSize)
{
const Real fDelta = kClosest - khalfSize;
fSqrDistance += fDelta * fDelta;
}
}
return fSqrDistance;
}
//-----------------------------------------------------------------------
template <class T>
class distanceToBoxSort
{
public:
//-----------------------------------------------------------------------
distanceToBoxSort(const Vector3 &camPos) : mCamPos(camPos)
{};
//-----------------------------------------------------------------------
bool operator()(T* x, T* y)
{
return (x->getCenter() - mCamPos).squaredLength() <
(y->getCenter() - mCamPos).squaredLength();
//return vectorToBoxDistance (x->getWorldBbox(), mCamPos) <
// vectorToBoxDistance (y->getWorldBbox(), mCamPos);
}
private:
const Vector3 mCamPos;
};
//-----------------------------------------------------------------------
/** This class holds classes T given to it by the plugin in a FIFO queue. */
template<class T>
class PagingLandScapeQueue
{
public:
//typedef std::queue<T *, std::list<T *> > MsgQueType;
typedef std::list<T *> MsgQueType;
//-----------------------------------------------------------------------
PagingLandScapeQueue( )
{
};
//-----------------------------------------------------------------------
virtual ~PagingLandScapeQueue( )
{
mQueue.clear ();
};
//-----------------------------------------------------------------------
void clear ()
{
mQueue.clear ();
};
//-----------------------------------------------------------------------
void push( T* e )
{
PLSM2_ASSERT ( std::find(mQueue.begin(), mQueue.end(), e) == mQueue.end());
// Insert the element at the end of the queue
mQueue.push_back ( e );
};
//-----------------------------------------------------------------------
typename MsgQueType::iterator begin()
{
return mQueue.begin ();
};
//-----------------------------------------------------------------------
typename MsgQueType::iterator end()
{
return mQueue.end ();
};
//-----------------------------------------------------------------------
typename MsgQueType::iterator erase(typename MsgQueType::iterator it)
{
return mQueue.erase (it);
};
//-----------------------------------------------------------------------
void remove (T* e)
{
mQueue.remove (e);
};
//-----------------------------------------------------------------------
void sortNearest(const Vector3 &pos)
{
mQueue.sort (distanceToBoxSort <T>(pos));
};
//-----------------------------------------------------------------------
T *find_nearest(const Vector3 &pos)
{
T *p = 0;
Real mindist = std::numeric_limits<Real>::max ();
typename MsgQueType::iterator q, qend = mQueue.end ();
for (q = mQueue.begin ();
q != qend;
++q)
{
const Real res = (pos - (*q)->getCenter()).squaredLength();
//const Real res = vectorToBoxDistance ((*q)->getSceneNode()->_getWorldAABB(), pos);
if (res < mindist)
{
mindist = res;
p = (*q);
}
}
if (p)
mQueue.remove (p);
return p;
};
//-----------------------------------------------------------------------
T *find_nearest(const unsigned int x, const unsigned int z)
{
T *p = 0;
unsigned int mindist = 0;
typename MsgQueType::iterator q, qend = mQueue.end ();
for (q = mQueue.begin ();
q != qend;
++q)
{
unsigned int lx, lz;
(*q)->getCoordinates(lx, lz);
const unsigned int res = abs (static_cast <int> (lx - x)) + abs (static_cast <int> (lz - z));
if (res < mindist)
{
mindist = res;
p = (*q);
}
}
if (p)
mQueue.remove (p);
return p;
};
//-----------------------------------------------------------------------
T *find_farest(const unsigned int x, const unsigned int z)
{
T *p = 0;
unsigned int maxdist = -1;
typename MsgQueType::iterator q, qend = mQueue.end ();
for (q = mQueue.begin ();
q != qend;
++q)
{
unsigned int lx, lz;
(*q)->getCoordinates(lx, lz);
const unsigned int res = abs ((int)(lx - x)) + abs ((int)(lz - z));
if (res > maxdist)
{
maxdist = res;
p = (*q);
}
}
if (p)
mQueue.remove (p);
return p;
};
//-----------------------------------------------------------------------
T* pop( )
{
T* tmp = 0;
if ( !mQueue.empty () )
{
// Queue is not empty so get a pointer to the
// first message in the queue
tmp = mQueue.front( );
// Now remove the pointer from the message queue
mQueue.pop_front( );
}
return tmp;
};
//-----------------------------------------------------------------------
size_t getSize() const
{
return mQueue.size ();
};
//-----------------------------------------------------------------------
bool empty() const
{
return mQueue.empty( );
};
//-----------------------------------------------------------------------
MsgQueType *getQueue()
{
return &mQueue;
}
protected:
MsgQueType mQueue;
};
} //namespace
#endif //PAGINGLANDSCAPEQUEUE_H
| true |
a6490ae9389605edf0113937e78d54c38dbeeb69 | C++ | CrazyIEEE/algorithm | /OnlineJudge/蓝桥杯/算法训练/字串统计.cpp | UTF-8 | 2,893 | 3.765625 | 4 | [] | no_license | /*
问题描述
给定一个长度为n的字符串S,还有一个数字L,统计长度大于等于L的出现次数最多的子串(不同的出现可以相交),如果有多个,输出最长的,如果仍然有多个,输出第一次出现最早的。
输入格式
第一行一个数字L。
第二行是字符串S。
L大于0,且不超过S的长度。
输出格式
一行,题目要求的字符串。
输入样例1:
4
bbaabbaaaaa
输出样例1:
bbaa
输入样例2:
2
bbaabbaaaaa
输出样例2:
aa
数据规模和约定
n<=60
S中所有字符都是小写英文字母。
提示
枚举所有可能的子串,统计出现次数,找出符合条件的那个
*/
#include "iostream"
#include "string"
#include "map"
#include "vector"
#include "algorithm"
bool paixu(const std::pair<std::string, int> &p1, const std::pair<std::string, int> &p2)
{
return p1.second > p2.second;
}
bool paixu1(const std::pair<std::string, int> &p1, const std::pair<std::string, int> &p2)
{
return p1.first.size() > p2.first.size();
}
int main()
{
int L = 0;
std::string str;
std::cin >> L >> str;
std::map<std::string, int> map;
while (L <= str.size())
{
int index = 0;
while (true)
{
std::string t = str.substr(index, L);
if (t.size() < L)
{
break;
}
else
{
if (map.count(t) == 0)
{
map.insert({t, 1});
}
else
{
map.at(t)++;
}
}
index++;
}
L++;
}
std::vector<std::pair<std::string, int>> vec;
for (std::map<std::string, int>::iterator it = map.begin(); it != map.end(); it++)
{
vec.push_back({it->first, it->second});
}
std::sort(vec.begin(), vec.end(), paixu);
std::vector<std::pair<std::string, int>>::iterator it = vec.begin() + 1;
while (it->second == vec.begin()->second)
{
it++;
}
vec.erase(it, vec.end());
if (vec.size() > 1)
{
std::sort(vec.begin(), vec.end(), paixu1);
it = vec.begin() + 1;
while (it->first.size() == vec.begin()->first.size())
{
it++;
}
vec.erase(it, vec.end());
if (vec.size() > 1)
{
int index = str.find(vec[0].first);
it = vec.begin() + 1;
while (it < vec.end())
{
if (str.find(it->first) < index)
{
index = str.find(it->first);
vec[0] = *it;
}
it++;
}
}
}
std::cout << vec[0].first;
return 0;
} | true |
1c73c136406e78d2963cb6e379d0a6f372a6264a | C++ | fezrestia/hello-world | /windows-game-program/PuzzleGame/PuzzleGame/util.h | UTF-8 | 1,413 | 3.109375 | 3 | [] | no_license | #ifndef FEZRESTIA_UTIL
#define FEZRESTIA_UTIL
using namespace std;
namespace fezrestia {
/**
* File buffer class.
*/
class FileBuffer {
private:
const int mSize;
const char* mBuffer;
public:
/**
* CONSTRUCTOR.
*
* @param size
* @param buffer
*/
FileBuffer(int size, char* buffer) :
mSize(size),
mBuffer(buffer) {
// NOP.
}
/**
* DESTRUCTOR.
*/
~FileBuffer() {
// Fail safe.
release();
}
/**
* Get buffer size.
*
* @return
*/
int getSize() {
return mSize;
}
/**
* Get buffer.
*
* @return
*/
const char* getBuffer() {
return mBuffer;
}
/**
* Release all internal resources.
*/
void release() {
if (mBuffer != NULL) {
delete mBuffer;
mBuffer = NULL;
}
}
};
/**
* Load file and return FileBuffer. FileBuffer must be deleted by client.
*
* @param fileName [IN]
* @return FileBuffer
*/
FileBuffer* loadFile(const char* fileName);
} // namespace fezrestia
#endif // FEZRESTIA_UTIL
| true |
db9678649b4dadb3e803c7467a56005a2cf1893d | C++ | amraboelkher/CompetitiveProgramming | /CodeForces/Codeforces Round #451/C.cpp | UTF-8 | 1,019 | 2.59375 | 3 | [
"MIT"
] | permissive | #include<bits/stdc++.h>
using namespace std;
int main(){
freopen("in.in" , "r" , stdin);
int n ;
cin >> n;
map<string , set< string > > mp;
map<string , vector< string > > ret;
for(int i = 0 ;i < n ;i ++){
int no;
string per;
cin >> per >> no;
while(no --){
string ss;
cin >> ss;
mp[per].insert(ss);
}
}
for(auto &mm : mp){
vector< string > vec(mm.second.begin() , mm.second.end());
vector< bool > yes(vec.size() );
for(int i = 0 ; i < vec.size() ;i ++){
for(int ii = 0 ; ii < vec.size() ;ii ++) if(i != ii && vec[ii].size() >= vec[i].size()){
string nn = vec[ii].substr(vec[ii].size() - vec[i].size() );
if(nn == vec[i]){
yes[i] = 1;
break;
}
}
}
for(int i = 0 ;i < vec.size() ;i ++){
if(!yes[i]){
ret[mm.first].push_back(vec[i]);
}
}
}
cout << ret.size() << "\n";
for(auto &mm : ret){
cout << mm.first << " " << mm.second.size() ;
for(int i = 0 ;i < mm.second.size() ;i ++)
cout << " " << mm.second[i] ;
cout << "\n";
}
}
| true |
c625df61bae16fc4647cb96e89dab914ddb5c5f9 | C++ | jacketsj/numcal | /vec.h | UTF-8 | 1,324 | 3.171875 | 3 | [] | no_license | #ifndef vec_h
#define vec_h
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define num double
struct vec
{
vec();
vec(int d);
vec(vector<num> vals);
vec(const vec &oth);
void operator=(const vec &oth);
bool operator==(const vec &oth) const;
vec operator+(num oth) const;
vec operator-(num oth) const;
vec operator*(num oth) const;
vec operator/(num oth) const;
vec operator^(num oth) const;
void operator+=(num oth);
void operator-=(num oth);
void operator*=(num oth);
void operator/=(num oth);
void operator^=(num oth);
vec operator+(const vec &oth) const;
vec operator-(const vec &oth) const;
void operator+=(const vec &oth);
void operator-=(const vec &oth);
num operator*(const vec &oth) const; // dot product
num norm() const; // l2 norm
num norm2() const; // l2 norm squared
num norm1() const; // l1 norm
num norm_inf() const; // l-inf norm
string to_string() const;
num& operator[](int i);
const num& roa(int i) const;
int dim() const;
static vec same(int d, num val);
static vec one(int d);
static vec zero(int d);
static vec card(int d, int i); //cardinal vector in direction i
private:
int d;
vector<num> vals;
};
vec operator+(num oth, const vec &v);
vec operator-(num oth, const vec &v);
vec operator*(num oth, const vec &v);
#endif
| true |
7cbff2bf2fc2d372aa84efad4060e94c8f690287 | C++ | SFMLCoBra/CBLib | /src/TextDocument.cpp | UTF-8 | 12,439 | 2.84375 | 3 | [] | no_license | #include "TextDocument.hpp"
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include "Data.hpp"
namespace cb
{
TextDocument::TextDocument()
: lines(0), sect(0), writetosection(false)
{
}
TextDocument::TextDocument(const std::string& currentFilePath)
: currentFilePath(currentFilePath), lines(0), sect(0), writetosection(false)
{
}
TextDocument::~TextDocument()
{
}
bool TextDocument::dirExists(const std::string& path)
{
boost::filesystem::path temppath(path);
if (boost::filesystem::exists(temppath))
{
// can normal io apply to the file?
if (boost::filesystem::is_directory(temppath))
{
return true;
}
else
{
CB_DEFAULT_ERROR_MSG("file " + path + " is no directory.");
return false;
}
}
CB_DEFAULT_ERROR_MSG("file " + path + " doesn't exist.");
// else: directory does not exist
return false;
// native c++ | <sys/stat>
/*
if (access(path.c_str(), 0) != -1)
{
return true;
}
*/
}
bool TextDocument::fileExists(const std::string & path)
{
boost::filesystem::path temppath(path);
if (boost::filesystem::exists(temppath))
{
// can normal io apply to the file?
if (boost::filesystem::is_regular_file(temppath))
{
return true;
}
else
{
CB_DEFAULT_ERROR_MSG("file " + path + " is not a regular file.");
return false;
}
}
CB_DEFAULT_ERROR_MSG("file " + path + " doesn't exist.");
// else: directory does not exist
return false;
}
bool TextDocument::createDirectory(const std::string& path)
{
boost::filesystem::path dir(path);
if (boost::filesystem::create_directory(dir))
{
return true;
}
CB_DEFAULT_ERROR_MSG("couldn't create file: " + path);
return false;
}
void TextDocument::write(const std::string& var, const std::string& content)
{
if (writetosection)
{
section += "<" + var + ":" + content + ">\n";
linesbtw++;
}
else
{
this->content += "<" + var + ":" + content + ">\n";
}
lines++;
}
void TextDocument::writeLineToContent(const std::string& content)
{
this->content += content;
}
void TextDocument::writeToContent(const std::string& content, bool lineBreak)
{
this->content += content;
if (lineBreak)
this->content += "\n";
}
void TextDocument::writeTruncToContent(const std::string& content)
{
this->content = content;
}
bool TextDocument::writeContentToFile(const std::string ¤tFilePath)
{
if (currentFilePath == "")
{
if (this->currentFilePath == "")
{
CB_DEFAULT_ERROR_MSG("this->currentFilePath is not a file");
return false;
}
open.open(this->currentFilePath, std::ofstream::out | std::ofstream::app);
}
else
{
open.open(currentFilePath, std::ofstream::out | std::ofstream::app);
}
open << content;
open.close();
return true;
}
void TextDocument::writeContentTruncToFile(const std::string ¤tFilePath)
{
if (currentFilePath == "")
{
if (this->currentFilePath == "")
{
CB_DEFAULT_ERROR_MSG("this->currentFilePath is not a file");
return;
}
open.open(this->currentFilePath, std::ofstream::out | std::ofstream::trunc);
}
else
{
open.open(currentFilePath, std::ofstream::out | std::ofstream::trunc);
}
open << content;
open.close();
}
void TextDocument::writeSectionToFile()
{
open.open(currentFilePath, std::ofstream::out | std::ofstream::app);
open << section;
open.close();
}
void TextDocument::clearContent()
{
section.clear();
content.clear();
lines = 0;
sect = 0;
}
void TextDocument::clearSection()
{
section.clear();
sect = 0;
linesbtw = 0;
}
void TextDocument::clearToUseNewFile(const std::string& filename)
{
clearContent();
sect = 0;
if (!filename.empty())
{
setFileName(filename);
}
}
bool TextDocument::deleteFile(const std::string& filename)
{
try
{
boost::filesystem::remove_all(filename.c_str());
}
catch (boost::filesystem::filesystem_error e)
{
CB_DEFAULT_ERROR_MSG("couldn't clear file: " + filename);
}
return true;
}
void TextDocument::addSectionToContent()
{
content += section;
}
bool TextDocument::loadFile(const std::string& filename, bool var)
{
if (!(fileExists(filename)))
{
CB_DEFAULT_ERROR_MSG("Couldn't open file: " + filename);
return false;
}
clearContent();
read.open(filename);
if (var)
{
std::pair<std::string, std::string> p;
std::vector<std::pair<std::string, std::string>> vp;
std::string temp;
while (!read.eof())
{
getline(read, temp);
content += temp;
lines++;
fir = temp.find("<");
sec = temp.find(":");
p.first = temp.substr(fir + 1, sec - fir - 1);
fir = temp.find(":");
sec = temp.find(">");
p.second = temp.substr(fir + 1, sec - fir - 1);
addVar(p.first, p.second);
}
}
else
{
content.assign((std::istreambuf_iterator<char>(read)),
(std::istreambuf_iterator<char>()));
}
read.close();
return true;
}
bool TextDocument::loadSection(int section)
{
std::string temp;
fir = content.find("|b" + std::to_string(section) + "b|");
// if the position is the end of the file (std::string::npos = -1)
// return false because it couldn't find the beginning of the section.
if (fir == std::string::npos)
{
CB_DEFAULT_ERROR_MSG(
"Couldn't load section " +
std::to_string(section) + " in " + currentFilePath);
return false;
}
sec = content.find("|e" + std::to_string(section) + "e|");
temp = content.substr(fir + 1, sec - fir - 1);
fir = content.find(section + "e|");
std::string s = content.substr(sec + 1, fir - sec - 1);
std::pair<std::string, std::string> pair;
int l = stoi(s);
for (int i = 0; i < l; i++)
{
fir = temp.find("<");
sec = temp.find(":");
pair.first = temp.substr(fir + 1, sec - fir - 1);
fir = temp.find(":");
sec = temp.find(">");
pair.second = temp.substr(fir + 1, sec - fir - 1);
addVar(pair.first, pair.second);
}
return true;
}
void TextDocument::beginSection()
{
section.clear();
writetosection = true;
linesbtw = 0;
section += "|b" + std::to_string(sect) + "b|\n";
lines++;
}
void TextDocument::endSection()
{
section += "|e" + std::to_string(linesbtw) + "e|\n";
content += section;
writetosection = false;
lines++;
sect++;
}
void TextDocument::addVar(const std::string& var, const std::string& content)
{
bool addnew = true;
int id = -1;
// checks if variable container already exists
for (std::size_t i = 0; i < vvar.size(); i++)
{
if (vvar[i].begin()->first == var)
{
id = i;
if (addnew != false)
addnew = false;
}
}
// add new container for the new variable
if (addnew)
{
vpair.clear();
vpair.push_back(std::make_pair(var, content));
vvar.push_back(vpair);
}
else
{
if (id >= 0)
{
vvar[id].push_back(std::make_pair(var, content));
}
}
}
// SETTER
void TextDocument::setFileName(const std::string& currentFilePath)
{
this->currentFilePath = currentFilePath;
}
// GETTER
std::string TextDocument::getContent(const std::string& var, unsigned int count)
{
for (std::size_t i = 0; i < vvar.size(); i++)
{
if (vvar[i].begin()->first == var)
{
if (vvar[i].size() > count)
{
return vvar[i].at(count).second;
}
}
}
CB_DEFAULT_ERROR_MSG("probably couldn't find variable name.");
return "";
}
int TextDocument::getContentAsInt(const std::string& var, unsigned int count)
{
for (std::size_t i = 0; i < vvar.size(); i++)
{
if (vvar[i].begin()->first == var)
{
if (vvar[i].size() > count)
{
return stoi(vvar[i].at(count).second);
}
}
}
return -666;
}
std::string TextDocument::getCurrentDirectory() const
{
std::wstring s = boost::filesystem::current_path().c_str();
return std::string(s.begin(), s.end());
}
int TextDocument::getLinesFromFile(const std::string& currentFilePath)
{
read.open(currentFilePath);
std::string s;
while (!read.eof())
{
std::getline(read, s);
lines++;
}
read.close();
return lines;
}
int TextDocument::getLinesFromActualFile() const
{
return lines;
}
const std::string& TextDocument::getFileContent() const
{
//std::ifstream ifs(currentFilePath);
//std::string content((std::istreambuf_iterator<char>(ifs)),
// (std::istreambuf_iterator<char>()));
return content;
}
std::vector<std::string> TextDocument::getFilenamesInDir(const std::string& path)
{
std::vector<std::string> vfiles;
if (!dirExists(path))
{
CB_DEFAULT_ERROR_MSG("Path " + path + " is not a directory");
return std::vector<std::string>{};
}
auto files = boost::make_iterator_range(boost::filesystem::directory_iterator(path), {});
for (auto& i : files)
{
vfiles.push_back(i.path().filename().string());
}
return vfiles;
}
std::vector<std::string> TextDocument::getFilenamesInDirWithExt(const std::string& path, const std::string& ext)
{
std::vector<std::string> vfiles;
if (!dirExists(path))
{
CB_DEFAULT_ERROR_MSG("Path " + path + " is not a directory");
return std::vector<std::string>{};
}
auto files = boost::make_iterator_range(boost::filesystem::directory_iterator(path), {});
for (auto& i : files)
{
if (i.path().extension() == ext)
{
vfiles.push_back(i.path().filename().string());
}
}
return vfiles;
}
std::vector<std::string> TextDocument::getFilenamesInDirWithoutExt(const std::string& path)
{
std::vector<std::string> vfiles;
if (!dirExists(path))
{
CB_DEFAULT_ERROR_MSG("Path " + path + " is not a directory");
return std::vector<std::string>{};
}
auto files = boost::make_iterator_range(boost::filesystem::directory_iterator(path), {});
for (auto& i : files)
{
if (i.status().type() == boost::filesystem::file_type::regular_file)
{
if (i.path().has_extension())
{
vfiles.push_back(i.path().stem().string());
}
else
{
vfiles.push_back(i.path().filename().string());
}
}
}
return vfiles;
}
void TextDocument::lowerString(std::string& data)
{
std::locale loc;
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
}
std::string TextDocument::getStringBetween(const std::string & text, const std::string & first, const std::string & second, std::size_t offset)
{
std::size_t f = text.find(first, offset);
std::size_t s;
if (second == first)
s = text.find(second, f + 1);
else
s = text.find(second, offset);
if (first == "") return text.substr(0, s);
if (second == "") return text.substr(f + first.size(), text.size() - f - first.size());
return text.substr(f + first.size(), s - f - first.size());
}
int TextDocument::removeAllOccurencesAndInsert(std::string & str, const std::string & deleteThis, const std::string & insert, bool deleteBorder)
{
// 1. find substring to delete
// 2. delete substring from string
// 3. insert replacement
int amount = 0;
std::size_t pos;
while ((pos = str.find(deleteThis)) != std::string::npos)
{
if (deleteBorder)
{
str.erase(pos - 1, deleteThis.size() + 2);
str.insert(pos - 1, insert);
}
else
{
str.erase(pos, deleteThis.size());
str.insert(pos, insert);
}
amount++;
}
return amount;
}
std::size_t TextDocument::removeOccurenceAndInsert(std::string & str, const std::string & deleteThis, const std::string & insert, std::size_t offset, bool deleteBorder)
{
std::size_t pos;
if ((pos = str.find(deleteThis, offset)) != std::string::npos)
{
if (deleteBorder)
{
str.erase(pos - 1, deleteThis.size() + 2);
str.insert(pos - 1, insert);
}
else
{
str.erase(pos, deleteThis.size());
str.insert(pos, insert);
}
}
return pos;
}
std::vector<std::string> TextDocument::getAllStringsBetween(const std::string& content, const std::string & first, const std::string & second)
{
std::vector<std::string> occurrence;
std::size_t start, end = 0;
while ((start = content.find(first, end)) != std::string::npos)
{
end = content.find(second, start + 1);
if (end == std::string::npos)
{
break;
}
occurrence.push_back(getStringBetween(content, first, second));
}
return occurrence;
}
std::vector<std::string> TextDocument::splitInLines(const std::string & text, bool deleteEmpty)
{
std::size_t p = 0;
std::size_t cur = 0;
std::vector<std::string> lines;
while (true)
{
cur = p;
if ((p = text.find('\n', p + 1)) == std::string::npos)
break;
std::string str = text.substr(cur, text.find('\n', cur + 1) - cur);
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
if (!str.empty())
lines.push_back(str);
}
if (cur < text.size())
{
std::string str = text.substr(cur, text.size() - cur);
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
if (!str.empty())
lines.push_back(str);
}
return lines;
}
} | true |
6e163cf627020d950c03e23bfbbfd488cb954fa0 | C++ | JonathanStine/Programming-Practice | /C++/JCPSRational.h | UTF-8 | 3,002 | 3.59375 | 4 | [] | no_license | /* The header file for assignment 11
* Edward G. Kovach
* December 6, 2014
* defines the class JCPSRational which models fractions.
*/
#ifndef JCPSRATIONAL
#define JCPSRATIONAL
using namespace std;
#include <iostream>
#include <string>
class JCPSRational
{
public:
// The instructions for assignment 11, did not require the return type to be Rational &. I made them Rational & because
// it makes the program run more efficiently. It would work with return types of just Rational/
JCPSRational(int = 0, int = 1);
JCPSRational(JCPSRational&);// constructor
JCPSRational& add(JCPSRational &); // add two fractions
JCPSRational& subtract(JCPSRational &); // subtract two fractions
JCPSRational& multiply(JCPSRational &); // multiply two fractions
JCPSRational& divide(JCPSRational &); // divide two fractions
void printFract(); // prints the fraction
void printDecimal(); // prints the decimal value of the fraction
JCPSRational& operator+(JCPSRational&);
JCPSRational& operator*(JCPSRational&);
JCPSRational& operator-(JCPSRational&);
JCPSRational& operator/(JCPSRational&);
JCPSRational &operator+=(JCPSRational&);
void operator=(JCPSRational&);
bool operator==(JCPSRational&);
bool operator!=(JCPSRational&);
bool operator>(JCPSRational&);
bool operator<=(JCPSRational&);
friend ostream& operator<< (ostream &, JCPSRational const&);
friend istream& operator>> (istream &, JCPSRational &);
private:
int numerator; // numerator of fraction
int denominator; // denominator of fraction
void reduce(); // reduces fractions
int gcd(int, int); // finds the greatest common denominator
};
#endif
/*
---------------------------------------------
| JCPSRational |
|-------------------------------------------|
| -numerator : int |
| -denominator : int |
|-------------------------------------------|
|+<constructor>JCPSRational(n:int=0, d:int=1)|
|+add(n:JCPSRational&):JCPSRational& |
|+subtract(n:JCPSRational&):JCPSRational& |
|+multiply(n:JCPSRational&):JCPSRational& |
|+divide(n:JCPSRational&):JCPSRational& |
|+printFract() |
|+printDecimal() |
|-reduce() |
|-gcd():int |
---------------------------------------------
*/
/* Pseudocode for JCPSRational.h
class for Rationals {
public:
constructor with int num and int denom {
call reduce();
}
copy constructor with JCPSRational &
Add, subtract, multiply, divide methods
Print methods
Arithmetic operator overloads
+= Operator overload
Assignment operator overload
Comparison operators overload (> <=)
Stream operators overload
private:
int numerator, denominator
GCD method
reduce method called on initialization
}
*/
| true |
ba0eb13900996b8bd1b927830759fc97c90dbda9 | C++ | zhangxin8105/EVO | /EVOMotor/Platform/Include/Platform/Leak.h | UTF-8 | 483 | 2.75 | 3 | [] | no_license | #ifndef LEAK_H_
#define LEAK_H_
//fix name later
#include <map>
class Leak
{
public:
Leak();
~Leak();
static void addPointer(void* pointer, const char* file, const unsigned int line);
static void removePointer(void* pointer);
private:
struct PointerInfo
{
const char* file;
unsigned int line;
};
typedef std::map<void*, PointerInfo> Pointers;
static Leak* _instance;
Pointers _pointers;
Leak(const Leak& leak);
Leak& operator =(const Leak& leak);
};
#endif | true |
ac7b8b5473cfecde9cbdb8f02ef1661a7036825c | C++ | haoboxuxu/leetcode-algorithm | /c++/120_Triangle.cpp | UTF-8 | 277 | 2.546875 | 3 | [] | no_license | class Solution {
public:
int minimumTotal(vector<vector<int>>& f) {
for (int i = f.size() - 2; i >= 0; i--) {
for (int j = 0; j <= i; j++) {
f[i][j] += min(f[i+1][j], f[i+1][j+1]);
}
}
return f[0][0];
}
}; | true |
63b6cd48aa1dac9144aeaa0589ab24a539d21e0c | C++ | ltcltc/COMP2123PROJECT | /printboard.cpp | UTF-8 | 457 | 3.640625 | 4 | [] | no_license | // printboard.cpp
// print the game board
#include <iostream>
#include <string>
using namespace std;
void printboard(int size, string ** map)
{
cout << " ";
for (int i = 0; i < size; i++)
{
cout << i << " ";
}
cout << endl;
// output gameboard in formate
for (int row = 0; row < size; row++)
{
cout << row << " ";
for (int col = 0; col < size; col++)
{
cout << map[row][col] << " ";
}
cout << endl;
}
}
| true |
fea3dbc3a5b5418e5145a2cb41de66dfa21f8e6f | C++ | mayank93/Moving-in-3D-World | /camera.h | UTF-8 | 518 | 2.65625 | 3 | [] | no_license | #ifndef camera_H
#define camera_H
#include "headerFiles.h"
class GLCamera{
public:
float eyeX;
float eyeY;
float eyeZ;
float refX;
float refY;
float refZ;
float upX;
float upY;
float upZ;
GLCamera(){
}
void set(float eX,float eY,float eZ,float rX,float rY,float rZ,float uX,float uY,float uZ){
eyeX=eX;
eyeY=eY;
eyeZ=eZ;
refX=rX;
refY=rY;
refZ=rZ;
upX=uX;
upY=uY;
upZ=uZ;
}
~GLCamera(){
}
void lookAt(){
gluLookAt(eyeX,eyeY,eyeZ,refX,refY,refZ,upX,upY,upZ);
}
};
#endif
| true |
4b58247fb318fff6e1b525f0758decab4260702e | C++ | thverney-dozo/Piscine-CPP | /C08/ex02/mutantstack.hpp | UTF-8 | 1,550 | 2.796875 | 3 | [] | no_license | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mutantstack.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aeoithd <aeoithd@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/11 11:21:59 by aeoithd #+# #+# */
/* Updated: 2021/01/14 19:50:15 by aeoithd ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MUTANTSTACK_HPP
# define MUTANTSTACK_HPP
#include <iostream>
#include <algorithm>
#include <stack>
template <typename T>
class MutantStack: public std::stack<T>
{
public:
MutantStack(): std::stack<T>(){};
MutantStack(MutantStack const & cpy): std::stack<T>(cpy){};
virtual ~MutantStack(){};
MutantStack &operator=(MutantStack const &affect)
{
this->c = affect.c;
return (*this);
};
typedef typename std::stack<T>::container_type::iterator iterator;
iterator begin()
{
return std::stack<T>::c.begin();
};
iterator end()
{
return std::stack<T>::c.end();
};
};
#endif
| true |
0aadb41abc1b67c30a5a5c41cd8a9f8c682ad112 | C++ | PlenkinAv/LeetCode | /133. Clone Graph.cpp | UTF-8 | 709 | 3.375 | 3 | [] | no_license | //https://leetcode.com/problems/clone-graph/
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> neighbors;
Node() {}
Node(int _val, vector<Node*> _neighbors) {
val = _val;
neighbors = _neighbors;
}
};
*/
class Solution {
public:
unordered_map<Node*, Node*> table;
Node* cloneGraph(Node* node) {
if(!node) return NULL;
if (table.find(node) == table.end()){
table[node] = new Node(node->val);
for(auto n: node->neighbors)
table[node]->neighbors.push_back(cloneGraph(n));
}
return table[node];
}
}; | true |
f64dfcf08b6002b08c55d29cfee75df3047627c2 | C++ | semihsahin1990/StreamWithCoroutines | /code/StreamWithCoroutines/core/src/streamc/topology/ReverseTree.cpp | UTF-8 | 3,445 | 2.5625 | 3 | [] | no_license | #include <string>
#include "streamc/topology/ReverseTree.h"
#include "streamc/operators/FileSource.h"
#include "streamc/operators/TupleGenerator.h"
#include "streamc/operators/Timestamper.h"
#include "streamc/operators/Selective.h"
#include "streamc/operators/Busy.h"
#include "streamc/operators/Union.h"
#include "streamc/operators/ResultCollector.h"
#include "streamc/operators/FileSink.h"
using namespace std;
using namespace streamc;
using namespace streamc::operators;
using namespace streamc::connectors;
// | n^depth-1 x (source+timestamper+selective+busy) + | n^depth-2 x (union+selective+busy) + ... + | 1 x (union+selective+busy) + (resultcollector + sink)
ReverseTree::ReverseTree(size_t depth, uint64_t cost, double selectivity, size_t n)
: depth_(depth), cost_(cost), selectivity_(selectivity), n_(n), flow_("reverseTree")
{
// create sources
int numberOfSources = pow(n_, depth_-1);
for(size_t i=0; i<numberOfSources; i++) {
/*
Operator & src = flow_.createOperator<FileSource>("src"+to_string(i))
.set_fileName("data/in.dat")
.set_fileFormat({{"name",Type::String}, {"grade",Type::String}, {"lineNo", Type::Integer}});
*/
Operator & src = flow_.createOperator<TupleGenerator>("src"+to_string(i), 100800);
sourceOps_.push_back(&src);
Operator & timestamper = flow_.createOperator<Timestamper>("timestamper"+to_string(i));
timestamperOps_.push_back(×tamper);
}
// create nodes (selective & cost)
int numberOfNodes = (pow(n_, depth_)-1) / (n_-1) ;
for(size_t i=0; i<numberOfNodes; i++) {
Operator & selective = flow_.createOperator<Selective>("selective"+to_string(i), selectivity_);
selectiveOps_.push_back(&selective);
Operator & busy = flow_.createOperator<Busy>("busy"+to_string(i), cost_);
busyOps_.push_back(&busy);
}
// create unions
for(size_t i=numberOfSources; i<numberOfNodes; i++) {
Operator & myUnion = flow_.createOperator<Union>("union"+to_string(i-numberOfSources), n_);
unionOps_.push_back(&myUnion);
}
// create result collector
Operator & resultCollector = flow_.createOperator<ResultCollector>("resultCollector", "expData/result.dat");
// create sink
Operator & snk = flow_.createOperator<FileSink>("snk")
.set_fileName("data/out.dat")
.set_fileFormat({{"name",Type::String}, {"grade",Type::String}});
// connect operators
for(size_t i=0; i<numberOfSources; i++) {
flow_.addConnection((*sourceOps_[i], 0) >> (0, *timestamperOps_[i]));
flow_.addConnection((*timestamperOps_[i], 0) >> (0, *selectiveOps_[i]));
flow_.addConnection((*selectiveOps_[i], 0) >> (0, *busyOps_[i]));
//cout<<"source "<<i<<"\t timestamper "<<i<<endl;
//cout<<"timestamper "<<i<<"\t selective "<<i<<endl;
//cout<<"selective "<<i<<"\t busy "<<i<<endl;
}
for(size_t i=numberOfSources; i<numberOfNodes; i++) {
flow_.addConnection((*unionOps_[i-numberOfSources], 0) >> (0, *selectiveOps_[i]));
flow_.addConnection((*selectiveOps_[i], 0) >> (0, *busyOps_[i]));
//cout<<"union "<<i-numberOfSources<<"\t selective "<<i<<endl;
//cout<<"selective "<<i<<"\t busy "<<i<<endl;
}
for(size_t i=0; i<numberOfNodes-1; i++) {
flow_.addConnection((*busyOps_[i], 0) >> (i%n_, *unionOps_[i/n_]));
//cout<<"busy "<<i<<"\t union"<<(i/n)<<" port "<<i%n_<<endl;
}
flow_.addConnection((*busyOps_[numberOfNodes-1],0) >> (0,resultCollector));
flow_.addConnection((resultCollector, 0) >> (0, snk));
} | true |
5ae3345ed6e2cfa82cc740ee93cacd1c8d19126a | C++ | azabrod1/CStuff3 | /C_Random/C_Random/blockedList.hpp | UTF-8 | 3,853 | 2.984375 | 3 | [] | no_license | //
// blockedList.hpp
// Tarjan
//
// Created by Alex Zabrodskiy on 5/28/17.
// Copyright © 2017 Alex Zabrodskiy. All rights reserved.
//
#ifndef blockedList_hpp
#define blockedList_hpp
#include <stdio.h>
#include <atomic>
template <class S, int P = 3, int L = 8>
class BlockedListIt;
template <class S, int P = 3, int L = 8>
class BlockedList{
friend class BlockedListIt<S,P,L>;
private:
public:
static int sums[L];
static int powers[L];
const static int base;
std::atomic<int> head;
std::atomic<S*> masterList[L];
BlockedList(): head(0), masterList{}{}
~BlockedList(){
for(int arr = 0; arr < L; ++arr)
if(masterList[arr])
delete[] masterList[arr].load();
}
inline int findLocation(int num){
int loc{0};
while(num >= sums[loc]){++loc;}
return loc;
}
inline void push_back(const S& item){
int idx(head++);
if(idx < base){
if(!*masterList){ //If we are adding the first element of the array, we must make sure it is initilized
S* toInsert(new S[base]()); S* null(nullptr);
//If another thread has already added a buffer, we delete the one we created
if(!masterList[0].compare_exchange_strong(null, toInsert))
delete[] toInsert;
}
masterList[0][idx] = item;
return;
}
int location {findLocation(idx)};
int pos(idx - sums[location-1]);
if(!masterList[location]){
//Create a new buffer b
S* toInsert(new S[powers[location]]()); S* null(nullptr);
//If another thread has already added a buffer, we delete the one we created
if(!masterList[location].compare_exchange_strong(null, toInsert))
delete[] toInsert;
}
masterList[location][pos] = item;
}
static int initSums(){
int _base = 1 << P;
sums[0] = _base;
powers[0] = _base;
for(int i = 1; i < L; ++i){
powers[i] = powers[i-1] << P;
sums[i] = sums[i-1] + powers[i];
}
return _base;
}
inline int size(){
return head.load();
}
inline bool smallList(const int& _size){
return _size < base;
}
inline S& getFromSmallList(const int idx){
return masterList[0][idx];
}
BlockedListIt<S,P,L> getIt(){
return BlockedListIt<S,P,L>(*this, this->head);
}
BlockedListIt<S,P,L> getIt(int size){
return BlockedListIt<S,P,L>(*this, size);
}
};
template <class S, int P, int L>
struct BlockedListIt{
private:
int idx, arr, ttl;
const int last;
BlockedList<S,P,L>& list;
public:
BlockedListIt(BlockedList<S,P,L>& _list, int _last): idx{-1}, arr{0}, last{_last}, list(_list), ttl{-1}{}
inline S& getNext(){
return list.masterList[arr][idx];
}
inline bool increment(){
if(++ttl == last)
return false;
if(BlockedList<S,P,L>::sums[arr] == ttl){
++arr; idx = 0;
}
else
++idx;
return true;
}
};
template<class S, int P, int L>
int BlockedList<S,P,L>::sums[L];
template<class S, int P, int L>
int BlockedList<S,P,L>::powers[L];
template<class S, int P, int L>
const int BlockedList<S,P,L>::base = BlockedList<S,P,L>::initSums();
#endif /* blockedList_hpp */
| true |
7ba711c8f3d2ea8ac4dc951e63a53eea611d9ef8 | C++ | akashc110/Cplusplus | /3_Exercises_1.cpp | UTF-8 | 2,667 | 3.40625 | 3 | [] | no_license | #include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<iomanip>
#include<ios>
using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::string;
using std::streamsize;
using std::sort;
using std::vector;
double getMedian();
int main()
{
cout << "Enter the integers: " << endl;
double number;
vector<double> num_array, q1_array, q3_array;
typedef vector<double>::size_type vecSize;
while(cin >> number){
//cout << "Hello Akash! You Rock!" << endl;
num_array.push_back(number);
}
sort(num_array.begin(),num_array.end());
vecSize size = num_array.size();
if(size == 0){
cout << "You must enter at least one number. Try again." << endl;
return 1;
}
vecSize mid = size/2;
cout << "Mid is " << mid << endl;
double median;
median = size % 2 == 0 ? (num_array[mid] + num_array[mid - 1]) / 2
: num_array[mid];
cout << "The median is " << median << endl;
//if size of vector is even, split in two halves
if(size % 2 == 0){
for(int i = 0; i < mid; ++i){
q1_array.push_back(num_array[i]);
}
sort(q1_array.begin(),q1_array.end());
vecSize length = q1_array.size();
vecSize quart = length/2;
double quartile1;
quartile1 = length % 2 == 0 ? (q1_array[quart] + q1_array[quart - 1]) / 2
: q1_array[quart];
cout << "The first quartile is " << quartile1 << endl;
for(int i = mid; i < size; ++i){
q3_array.push_back(num_array[i]);
}
sort(q3_array.begin(),q3_array.end());
vecSize length_2 = q3_array.size();
vecSize quart3 = length_2/2;
double quartile3;
quartile3 = length_2 % 2 == 0 ? (q3_array[quart3] + q3_array[quart3 - 1]) / 2
: q3_array[quart3];
cout << "The third quartile is " << quartile3 << endl;
}
//if size of vector is odd, make two halves excluding median
else{
for(int i = 0; i < mid; ++i){
q1_array.push_back(num_array[i]);
}
sort(q1_array.begin(),q1_array.end());
vecSize length = q1_array.size();
vecSize quart = length/2;
double quartile1;
quartile1 = length % 2 == 0 ? (q1_array[quart] + q1_array[quart - 1]) / 2
: q1_array[quart];
cout << "The first quartile is " << quartile1 << endl;
for(int i = mid+1; i < size; ++i){
q3_array.push_back(num_array[i]);
}
sort(q3_array.begin(),q3_array.end());
vecSize length_2 = q3_array.size();
vecSize quart3 = length_2/2;
double quartile3;
quartile3 = length_2 % 2 == 0 ? (q3_array[quart3] + q3_array[quart3 - 1]) / 2
: q3_array[quart3];
cout << "The third quartile is " << quartile3 << endl;
}
return 0;
}
double getMedian(void){
cout << "Akash, you are doing really well!" << endl;
return 0;
}
| true |
5fca0594e457dee4dca0c191b1bd7b17d12edae5 | C++ | NotBjoggisAtAll/Tomato-Engine | /src/app.h | UTF-8 | 5,820 | 2.71875 | 3 | [
"MIT"
] | permissive | #ifndef APP_H
#define APP_H
#include <memory>
#include <QObject>
#include <QTimer>
#include <QElapsedTimer>
#include "types.h"
#include "mainwindow.h"
#include "GSL/vector3d.h"
#include "GSL/vector2d.h"
class RenderWindow;
class EventHandler;
/** \mainpage Welcome to the Tomato Engine documentation!
* This engine was created as a project in Game Engine Architecture at the Inland Norway University of Applied Sciences.
* @author <a href="https://github.com/NotBjoggisAtAll">NotBjoggisAtAll</a> on GitHub.
* @date Fall of 2019.*/
/**
* The App class is the main class that connects everything together.
* It's here you create and connect everything together.
* The App is creating the MainWindow which is the editor itself.
* App contains the actual gameloop while the program is running.
*/
class App : public QObject
{
Q_OBJECT
public:
/**
* Default constructor.
* The constructor registers and sets up all the components and systems.
* It also creates the MainWindow and connect a bunch of signals and slots together.
* The constructor starts the gameloop aswell.
*/
App();
/**
* Default deconstructor.
* Cleans up SoundManager.
*/
~App();
private slots:
/**
* postInit is run after the MainWindow and the RenderWindow is created and finished initalizing.
* Here you typically creates entities to show in the world, now that everything is set up correctly.
*/
void postInit();
/**
* Tick runs every frame (16ms).
* It runs all the different systems tick function in a specific order to make it work properly.
*/
void tick();
/**
* playGame is called from the MainWindow when the user pressed the Playbutton.
* It runs the beginPlay function in different systems.
*/
void playGame();
/**
* stopGame is called from the MainWindow when the user pressed the Stopbutton.
* It runs the endPlay function in different systems.
*/
void stopGame();
/**
* Deletes all entities and makes a new clean scene.
*/
void newScene();
/**
* Clears the scene and makes a prompt of loading a new one.
* Opens a filedialog so the user can choose a JSON file to open.
*/
void loadScene();
/**
* Saves the scene to a JSON file.
* Opens a filedialog so the user can choose a JSON file to save to.
*/
void saveScene();
/**
* Called when the button Create->Empty Entity is pressed.
* Creates a new entity, gives it a default name and shows it in the world outliner.
* @return the Entity created.
*/
Entity createEntity();
/**
* Called when the buttons under the Create menu is pressed (Except Empty Entity).
* Creates a new entity and gives its components based on what type of object you want to create.
* @param name - the object name.
* @param path - the mesh path for the object.
* @return the Entity created.
*/
Entity spawnObject(std::string name, std::string path);
/**
* Updates all the cameras perspective matrices.
* Run whenever the RenderWindow is resized.
* @param aspectRatio - The RenderWindow's aspect ratio.
*/
void updateCameraPerspectives(float aspectRatio);
/**
* Called whenever the user presses the left mouse button.
* Called from the EventHandler.
* Mainly used for mousepicking to select object. And when playing the game.
*/
void mouseLeftClick();
/**
* Called when the collision system detects two entities that collided.
* This function runs custom logic for the game to work.
* Deletes the projectile and the npc if they hit eachother.
* @param entity1 - Entity.
* @param entity2 - Entity.
*/
void entitiesCollided(Entity entity1, Entity entity2);
private:
/// A unique pointer to the MainWindow.
std::unique_ptr<MainWindow> mainWindow_;
/// A shared pointer to the RenderWindow.
std::shared_ptr<RenderWindow> renderWindow_;
/// A shared pointer to the EventHandler.
std::shared_ptr<EventHandler> eventHandler_;
/// The tick timer. Makes the tick function run in a loop.
QTimer tickTimer_;
/// Stores the current deltaTime.
float deltaTime_ = 0;
/// At the beginning of each frame the deltaTime is added to this. Used to print the deltaTime more accurately on the statusbar. Reset when printed.
float totalDeltaTime_ = 0;
/// A timer that resets every 100 frames. It's job is to update the statusbar every 100 frame. No need to update it every frame.
QElapsedTimer frameTimer_;
/// A timer that holds the current deltaTime. At the beginning of each frame this is reset and its value is set to the deltaTime.
QElapsedTimer deltaTimer_;
/// A counter that increases everyframe. Used to display the deltatime more accurately. Reset every time its printed to the statusbar.
int frameCounter = 0;
/**
* Calculates the framerate and prints it to the statusbar.
*/
void calculateFramerate();
/**
* Custom game logic.
* Called whenever the user plays the game and presses left click.
* Spawns a tower that shoots at enemies.
* @param hitPosition - The position the turret is going to spawn.
*/
void spawnTower(gsl::Vector3D hitPosition);
/**
* Registers all the components. Must be called before any component is used.
*/
void registerComponents();
/**
* Registers all the systems. Must be called before any system is used.
*/
void registerSystems();
/**
* Gives all the systems different signatures based on what components they need. Must be called before any system is used.
*/
void setSystemSignatures();
};
#endif // APP_H
| true |
a49c070d64154f2524cc4347eacda52580bd27d2 | C++ | ed765super/Simulation-of-an-OS | /ncogbonnafilesystemsrepository/startShell.cc | UTF-8 | 19,143 | 3.671875 | 4 | [] | no_license | #include "startShell.h"
#include "evaluate.h"
#include <iostream>
#include <fstream>
using namespace std;
//PRE:
//POST: RV = what the user typed into the terminal in
//LinkeList<MyString> form where every relevant piece of the user's
//input is broken up into nodes
LinkedList<MyString> tokenize(char* userinput){
LinkedList<MyString> userCMD;//will hold the list of tokens from the
//user's input
int user_index = 0;
bool done = false;
while (!done){
MyString token; //Will hold a word from the user's input
while ((userinput[user_index] != aSpace) &&
(userinput[user_index] != EOS)){
//we have not read a word
char ch = userinput[user_index];//will hold a letter from the userinput
token.addchar(ch);
user_index++;
}
//ASSERT: we have a full word to put in the userCMD
//Collorary: user index is either a space or a newline
userCMD.append(token);
//ASSERT: token has been added to userCMD
if (userinput[user_index] == EOS){
//ASSERT: we have read the entire user input
done = true;
}
else{
//ASSERT: userinput[user_index] is a space
user_index++;
//read past space
}
}
//ASSERT: userCMD contains all tokens from the user
return (userCMD);
}
//PRE: path must be a char* created in the checkToken function. This
//function cannat be used for rm.
//POST: RV = true iff the path is valid according to the assumptions
//made in the README
bool checkPath(char* pathString){
bool alphaNumeric = true;
char ch;//will hold a character from pathString
int index;
while (ch != EOS){
ch = pathString[index];
if(((ch >= CHAR0) && (ch <= CHAR9)) || ((ch >= UPPERA) && (ch <= UPPERZ))
|| ((ch <= LOWERA) && (ch >= LOWERZ)) || (ch == FWDSLASH) ||
(ch == PERIOD)){
//ASSERT: ch is alpha numeric or the '/' chartacter OR THE '.'
//character
}
else{
alphaNumeric = false;
}
}
//ASSERT: If all characters in the string were alpha numeric or the
//'/' chartacter OR THE '.' character, alphaNumeric is true.
//otherwise, alphaNumeric is false.
return alphaNumeric;
}
//PRE: path must be a char* created in the checkToken function. This
//function can ONLY be used for rm.
//POST: RV = true iff the path is valid according to the assumptions
//made in the README
bool checkPathRM(char* pathString){
bool alphaNumeric = true;
char ch;//will hold a character from pathString
int index;
while (ch != EOS){
ch = pathString[index];
if(((ch >= CHAR0) && (ch <= CHAR9)) || ((ch >= UPPERA) && (ch <= UPPERZ))
|| ((ch <= LOWERA) && (ch >= LOWERZ)) || (ch == FWDSLASH) ||
(ch == PERIOD) || (ch == STAR)){
//ASSERT: ch is alpha numeric or the '/' chartacter OR THE '.'
//or the '*' character
}
else{
alphaNumeric = false;
}
}
//ASSERT: If all characters in the string were alpha numeric or the
//'/' chartacter OR THE '.' or the '*' character, alphaNumeric is true.
//otherwise, alphaNumeric is false.
return alphaNumeric;
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateFormat(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if(tokenList.getSize() == 1){
validToken = true;
}
else{
//user put an invalid number of parameters
cout << "invalid # of parameters" << endl;
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateDefrag(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if(tokenList.getSize() == 1){
validToken = true;
}
else{
//user put an invalid number of parameters
cout << "invalid # of parameters" << endl;
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validatePWD(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if(tokenList.getSize() == 1){
validToken = true;
}
else{
//user put an invalid number of parameters
cout << "invalid # of parameters" << endl;
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateLS(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if(tokenList.getSize() == 1){
validToken = true;
}
else{
if (tokenList.getSize() == 2){
//ASSERT: a path was given with the cmd
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPath(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for LS was invalid" << endl;
}
}
else{
//ASSERT: user put in more than 2 tokens
cout << "invalid # of parameters" << endl;
}
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateCD(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if(tokenList.getSize() == 1){
validToken = true;
}
else{
if (tokenList.getSize() == 2){
//ASSERT: a path was given with the cmd
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPath(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for CD was invalid" << endl;
}
}
else{
//ASSERT: user put in more than 2 tokens
cout << "invalid # of parameters" << endl;
}
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateMKDIR(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if (tokenList.getSize() == 2){
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPath(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for MKDIR was invalid" << endl;
}
}
else{
//ASSERT: user put in more than 2 tokens
cout << "invalid # of parameters" << endl;
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateRM(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: a path was given with the cmd
if (tokenList.getSize() == 2){
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPathRM(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for RM was invalid" << endl;
}
}
else{
//ASSERT: user put in more than 2 tokens
cout << "invalid # of parameters" << endl;
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateRMDIR(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPath(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for RMDIR was invalid" << endl;
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateCP(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if ((tokenList.getSize() != 3) || (tokenList.getSize() != 4)){
//ASSERT: user typed in too many or too little number of
//parameters
cout << "invalid # of parameters" << endl;
}
else{
if (tokenList.getSize() == 3){
//ASSERT: user gave no optional parameters
MyString* path1 = tokenList.getNth(1);
char* path1String = path1->getstring();
validToken = checkPath(path1String);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path1 for CP was invalid" << endl;
}
//ASSERT: source modification parameter is correct
MyString* path2 = tokenList.getNth(2);
char* path2String = path2->getstring();
validToken = checkPath(path2String);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path2 for CP was invalid" << endl;
}
}
else if (tokenList.getSize() == 4){
//ASSERT: the optional parameter was given
MyString* sourceModifier = tokenList.getNth(1);
char* sourceString = sourceModifier->getstring();
if ((isEqualString(sourceString, lessThanString)) ||
(isEqualString(sourceString, greaterThanString))){
//ASSERT: source modification parameter is correct
MyString* path1 = tokenList.getNth(2);
char* path1String = path1->getstring();
validToken = checkPath(path1String);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path1 for CP was invalid" << endl;
}
//ASSERT: source modification parameter is correct
MyString* path2 = tokenList.getNth(3);
char* path2String = path2->getstring();
validToken = checkPath(path2String);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path2 for CP was invalid" << endl;
}
}
}
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateCAT(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if ((tokenList.getSize() != 2) || (tokenList.getSize() != 3)){
//ASSERT: user typed in too many or too little number of
//parameters
cout << "invalid # of parameters" << endl;
}
else{
if (tokenList.getSize() == 2){
//ASSERT: only a path was given with the cmd
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPath(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for CAT was invalid" << endl;
}
}
else if (tokenList.getSize() == 3){
//ASSERT: the optional parameter was given
MyString* Flag = tokenList.getNth(1);
char* flagString = Flag->getstring();
if (isEqualString(flagString, LOWERH)){
//ASSERT: flag parameter is correct
MyString* path = tokenList.getNth(2);
char* path1String = path->getstring();
validToken = checkPath(path1String);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for CAT was invalid" << endl;
}
}
}
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateDISPLAYINODE(LinkedList<MyString> tokenList, bool & validToken,
char* commandString, fileSys & myFileSys){
//ASSERT: user typed in a valid cmd
if((tokenList.getSize() != 1) && (tokenList.getSize() != 3)){
//user put an invalid number of parameters
cout << "invalid # of parameters" << endl;
}
else{
if(tokenList.getSize() == 1){
//user wants the default call of this cmd
validToken = true;
}
else{
//ASSERT: tokenList must be of size 3
//COLLORARY: the user typed in bounds for their content to be
//outputted
MyString* myN = tokenList.getNth(1);
char* nString = myN->getstring();
int n = strToInt(nString);
MyString* myM = tokenList.getNth(2);
char* mString = myN->getstring();
int m = strToInt(mString);
int MAXM = myFileSys.getDiskSize();
if ((n >= 0) && (m <= MAXM) && (n <= m)){
validToken = true;
}
}
}
}
//PRE: validToken must be initialized to false. commandString must be
//a representation of the head of the tokenList
//POST: validToken is true iff user typed in all valid parameters for
//the cmd associated with this function (cmd is located after the word
//validate in this fuction's name)
void validateDU(LinkedList<MyString> tokenList, bool & validToken,
char* commandString){
//ASSERT: user typed in a valid cmd
if(tokenList.getSize() == 1){
validToken = true;
}
else{
if (tokenList.getSize() == 2){
//ASSERT: a path was given with the cmd
MyString* path = tokenList.getNth(1);
char* pathString = path->getstring();
validToken = checkPath(pathString);
//ASSERT: validToken is true iff the path is valid according to
//the README
if(!validToken){
cout << "path for DU was invalid" << endl;
}
}
else{
//ASSERT: user put in more than 2 tokens
cout << "invalid # of parameters" << endl;
}
}
}
//PRE: tokenList must be non NULL.
//POST: RV = true iff there are no inValidities within the tokenList
bool checkToken(LinkedList<MyString> tokenList, fileSys & myFileSys){
//Validity check for every cmd to ensure they follow the assumptions
//made in the readme
bool validToken = false;
MyString* command = tokenList.getHead();
char* commandString = command->getstring();
if (isEqualString(commandString, FORMAT)){
validateFormat(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, DEFRAG)){
validateDefrag(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, PWD)){
validatePWD(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, LS)){
validateLS(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, CD)){
validateCD(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, MKDIR)){
validateMKDIR(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, RM)){
validateRM(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, RMDIR)){
validateRMDIR(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, CP)){
validateCP(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, CAT)){
validateCAT(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, DISPLAYINODE)){
validateDISPLAYINODE(tokenList, validToken, commandString, myFileSys);
}
else if (isEqualString(commandString, DU)){
validateDU(tokenList, validToken, commandString);
}
else if (isEqualString(commandString, EXIT)){
validToken == true;
}
}
//PRE:
//POST: puts the user's command into userCommand
void createCommand(char curr_ch, MyString & userCommand){
cout << "F>";
curr_ch = cin.get();
while(curr_ch != newLine){
userCommand.addchar(curr_ch);
curr_ch = cin.get();
}
}
//PRE:
//POST: Prompts the user for a cmd and if it is a valid comand, passes
//it to evaluate
void startShell(int diskSize){
char curr_ch;
MyString userCommand;
bool done = false; //represents when the main while loop is done
fileSys myFileSys(diskSize);
createCommand(curr_ch, userCommand);
//ASSERT: curr_ch == '\n' => we have read everything that the user typed
// into the terminal
while (!done){
char* curr_command = userCommand.getstring();
//ASSERT: user has not typed in the exit cmd into the terminal
LinkedList<MyString> tokenList = tokenize(curr_command);
//ASSERT: tokenList is a linked list of MyString characters that
//represent the user's command
bool validToken = checkToken(tokenList, myFileSys);
//assert: validToken true iff the entirety of the token is valid
if (validToken){
//ASERT: the cmd the user typed in (curr_command) was valid
//along with the possible
//operands that could accomany those cmds.
if(isEqualString(curr_command, EXIT)){
//ASSERT: the user wants to be finished
done = true;
fstream* diskFile = myFileSys.getDiskFile();
diskFile->close();
}
else{
//ASSERT: the user is not finished with his/her/it's
//simulation
evaluate_command(tokenList, myFileSys);
}
//ASSERT: We've done SOMETHING regarding the current command the
//user typed
}
else{
//ASSERT: user typed in something nonvalid
cout << "ERROR: User typed something invalid" << endl;
}
if (!done){
//ASSERT: the user has not typed in exit
MyString nextCMD;
createCommand(curr_ch, nextCMD);
userCommand = nextCMD;
}
}
//ASSERT: we are finished with our simulation of the fileSystem
}
| true |
826c83df9449c0008832b0f7f44e1ce0267fd742 | C++ | wolfjagger/coopnet | /src/coopnet/graph/mutable/reversable_graph.inl | UTF-8 | 6,068 | 2.59375 | 3 | [
"MIT"
] | permissive |
template<typename SatProp>
ReversableSatGraph<SatProp>::ReversableSatGraph(
const BaseSatGraph& original, const SatGraphTranslator& origTranslator) :
graph(graph_util::create_default_concrete_graph<SatProp>(
original, origTranslator)),
reverseStack() {
connectedComponentEntryPts
= graph_util::calculate_connected_components(graph.graph);
numConnectedComponents = connectedComponentEntryPts.size();
}
template<typename SatProp>
PruneStatus ReversableSatGraph<SatProp>::get_vert_status(VertDescriptor v) const {
auto& prop = graph.graph[vert];
switch (prop.kind()) {
case VertKind::Node:
return prop.node().pruneStatus = status;
case VertKind::Node:
return prop.clause().pruneStatus = status;
}
}
template<typename SatProp>
void ReversableSatGraph<SatProp>::set_vert_status(VertDescriptor v, PruneStatus newStatus) {
PruneStatus* oldStatus;
auto& prop = graph.graph[vert];
switch (prop.kind()) {
case VertKind::Node:
oldStatus = &prop.node().pruneStatus;
break;
case VertKind::Node:
oldStatus = &prop.clause().pruneStatus;
break;
}
if (*oldStatus != newStatus) {
if (DEBUG) std::cout << "Set status for vert " << v << " to " << newStatus << "\n";
reverseStack.emplace(std::make_pair(v, *oldStatus));
*oldStatus = newStatus;
}
}
template<typename SatProp>
PruneStatus ReversableSatGraph<SatProp>::get_edge_status(EdgeDescriptor e) const {
return graph.graph[e].pruneStatus;
}
template<typename SatProp>
void ReversableSatGraph<SatProp>::set_edge_status(EdgeDescriptor e, PruneStatus newStatus) {
auto& oldStatus = graph.graph[e].pruneStatus;
if (oldStatus != newStatus) {
if (DEBUG) std::cout << "Set status for edge " << e << " to " << newStatus << "\n";
reverseStack.emplace(std::make_pair(e, oldStatus));
oldStatus = newStatus;
}
}
template<typename SatProp>
boost::tribool ReversableSatGraph<SatProp>::get_assignment(VertDescriptor v) const {
return graph.graph[v].node().assignment;
}
template<typename SatProp>
void ReversableSatGraph<SatProp>::set_assignment(VertDescriptor v, boost::tribool newValue) {
auto& oldValue = graph.graph[v].node().assignment;
if (oldValue != newValue ||
(!boost::indeterminate(oldValue) && boost::indeterminate(newValue)) ||
(boost::indeterminate(oldValue) && !boost::indeterminate(newValue))) {
if (DEBUG) std::cout << "Set assignment for vert " << v << " to " << newValue << "\n";
reverseStack.emplace(std::make_pair(v, oldValue));
oldValue = newValue;
}
}
template<typename SatProp>
bool ReversableSatGraph<SatProp>::is_indeterminate_node(VertDescriptor v) const {
return (graph.graph[v].kind() == VertKind::Node)
&& (boost::indeterminate(graph.graph[v].node().assignment));
}
template<typename SatProp>
bool ReversableSatGraph<SatProp>::is_indeterminate() const {
auto vPair = boost::vertices(graph.graph);
return std::any_of(vPair.first, vPair.second, [this](VertDescriptor v) {
return is_indeterminate_node(v);
});
}
template<typename SatProp>
void ReversableSatGraph<SatProp>::reverse_to_vert(VertDescriptor v) {
auto done = false;
while (!done && !reverseStack.empty()) {
auto& action = reverseStack.top();
using reverseObject = ReversableAction::ReverseCategory;
switch (action.type) {
case reverseObject::Vertex: {
auto& vertexData =
boost::get<VertStatusPair>(action.suppData);
auto vert = vertexData.first;
auto status = vertexData.second;
if (DEBUG)
std::cout << "Prune vert status " << vert << " " << status << "\n";
auto& prop = graph.graph[vert];
switch (prop.kind()) {
case VertKind::Node:
prop.node().pruneStatus = status;
break;
case VertKind::Clause:
prop.clause().pruneStatus = status;
break;
}
// If vert is prune-to vert, set to done (status is set first, not assignment)
if (vert == v && status == PruneStatus::Active) done = true;
break;
}
case reverseObject::Edge: {
auto& edgeData =
boost::get<EdgeStatusPair>(action.suppData);
auto edge = edgeData.first;
auto status = edgeData.second;
if (DEBUG)
std::cout << "Prune edge status " << edge << " " << status << "\n";
graph.graph[edge].pruneStatus = status;
break;
}
case reverseObject::Assignment: {
auto& incompleteAssignmentData =
boost::get<IncompleteAssignmentPair>(action.suppData);
auto vert = incompleteAssignmentData.first;
auto value = incompleteAssignmentData.second;
if (DEBUG)
std::cout << "Prune assignment " << vert << " " << value << "\n";
graph.graph[vert].node().assignment = value;
break;
}
}
reverseStack.pop();
}
}
template<typename SatProp>
void ReversableSatGraph<SatProp>::reset_all() {
auto vPair = boost::vertices(graph.graph);
auto ePair = boost::edges(graph.graph);
std::for_each(vPair.first, vPair.second, [this](VertDescriptor v) {
auto& prop = graph.graph[v];
switch(prop.kind()) {
case VertKind::Node:
prop.node().pruneStatus = PruneStatus::Active;
prop.node().assignment = boost::indeterminate;
break;
case VertKind::Clause:
prop.clause().pruneStatus = PruneStatus::Active;
break;
}
});
std::for_each(ePair.first, ePair.second, [this](EdgeDescriptor e) {
graph.graph[e].pruneStatus = PruneStatus::Active;
});
reverseStack = ReverseStack();
}
template<typename SatProp>
size_t ReversableSatGraph<SatProp>::num_connected_components() const {
return numConnectedComponents;
}
template<typename SatProp>
const std::vector<VertDescriptor>&
ReversableSatGraph<SatProp>::connected_component_entry_pts() const {
return connectedComponentEntryPts;
}
template<typename SatProp>
template<typename PruneVisitor>
void ReversableSatGraph<SatProp>::visit(PruneVisitor& v) {
visit_sat_graph(graph.graph, v,
connectedComponentEntryPts.begin(), connectedComponentEntryPts.end());
}
template<typename SatProp>
template<typename PruneVisitor>
void ReversableSatGraph<SatProp>::visit(PruneVisitor& v) const {
visit_sat_graph(graph.graph, v,
connectedComponentEntryPts.begin(), connectedComponentEntryPts.end());
}
| true |
69927371db458333220cda4b97fd9c04ada469ff | C++ | 2416390994/helloword- | /4_6.cpp | UTF-8 | 1,636 | 3.359375 | 3 | [] | no_license | #include<iostream>
#include<string>
#include<vector>
using namespace std;
/*
class Solution {
public:
vector<int> printMatrix(vector<vector<int> > matrix) {
size_t size = matrix.size();
int row = size;
int col = matrix[0].size();
int top = 0,left = 0,bottom = row - 1,right = col - 1;
vector<int> vec;
while(top <= bottom && left <= right)
{
for(int i = left;i <= right; ++i)
vec.push_back(matrix[top][i]);
for(int i = top + 1;i <= bottom;++i)
vec.push_back(matrix[i][right]);
for(int i = right - 1; i >= left && top < bottom; --i)
vec.push_back(matrix[bottom][i]);
for(int i = bottom - 1;i > top && left < right; --i)
vec.push_back(matrix[i][left]);
top++;left++;bottom--;right--;
}
}
};
*/
class Solution {
public:
vector<int> printMatrix(vector<vector<int> > matrix)
{
vector<int> vec;
int row = matrix.size();
int col = matrix[0].size();
int top = 0, left = 0, bottom = row - 1, right = col - 1;
while (left <= right && top <= bottom)
{
for (int i = left; i <= right; ++i)
vec.push_back(matrix[top][i]);
for (int i = top + 1; i <= bottom; ++i)
vec.push_back(matrix[i][right]);
for (int i = right - 1; i >= left&&top < bottom; --i)
vec.push_back(matrix[bottom][i]);
for (int i = bottom - 1; i > top&&left < right; --i)
vec.push_back(matrix[i][left]);
top++; left++; bottom--; right--;
}
return vec;
}
};
int main()
{
return 0;
} | true |
035877cac827dffc41820990d0f75f58c909f62f | C++ | Shossain97/School | /Data Structures/Lab12/eecs_560_fall_2017_lab12_avl.tar/avl-lab-12/catalog.cpp | UTF-8 | 1,476 | 3.28125 | 3 | [] | no_license | #include "catalog.hpp"
#include "util.hpp"
#include <iostream>
Catalog::Catalog(){
tree=new AVL();
}
Catalog::~Catalog(){
delete tree;
}
void print(Book* aBook){
std::cout<<"id: "<<aBook->getId();
std::cout<<" name: "<<aBook->getName();
std::cout<<" count: "<<aBook->getCurrentCount();
std::cout<<" / "<<aBook->getTotalCount();
std::cout<<" publisher: "<<aBook->getPublisher();
std::cout<<"\n";
}
void Catalog::addBook(int id, std::string bookName, std::string publisherName, int copyCount){
Book* newBook=new Book(id, bookName, publisherName, copyCount);
tree->addBook(newBook);
//std::cout<<"New book\n";
//printTree();
}
Book* Catalog::checkoutBook(int id){
Book* checkedBook=tree->search(id);
if(checkedBook==nullptr){
std::cout<<"Book does not exist in this Library!\n";
return nullptr;
}
else{
if(checkedBook->getCurrentCount()==0){
std::cout<<"We are out of that book!\n";
return nullptr;
}
else{
checkedBook->setCurrentCount(checkedBook->getCurrentCount()-1);
std::cout<<"Book details:\n";
print(checkedBook);
return checkedBook;
}
}
}
void Catalog::returnBook(int id){
Book* checkedBook=tree->search(id);
if(checkedBook==nullptr){
std::cout<<"Book does not exist in this Library!\n";
}
else{
checkedBook->setCurrentCount(checkedBook->getCurrentCount()+1);
}
}
void Catalog::printTree(){
tree->levelorderTraverse(&print);
std::cout<<"\n\n\n";
}
| true |
da3b907373e4e9d32c4b2228b2db5a4c47e2dddd | C++ | juanpablocruz/adventure_game | /adventureshire/character.cpp | UTF-8 | 2,217 | 2.640625 | 3 | [] | no_license | #include "adventureshire.h"
#include "objects.h"
void initCharacter(Character &ch, ALLEGRO_BITMAP *tile) {
ch.x = 185;
ch.y = 218;
ch.imgx = 0;
ch.imgy = 0;
ch.sizex = 32;
ch.sizey = 64;
ch.sizex2 = 70;
ch.sizey2 = 152;
ch.npc_id = 0;
ch.speed = 2;
ch.maxFrame = 7;
ch.currFrame = 0;
ch.frameCount = 0;
ch.frameDelay = 12;
ch.frameWidth = 31;
ch.frameHeight = 64;
ch.animationColumns = 7;
ch.animationDirection = 1;
ch.offsetx = -4;
ch.offsety = 0;
ch.animationRow = 1;
ch.tile = tile;
}
void ResetCharacterAnimation(Character &ch, int position) {
if (position == 1)
ch.animationRow = 1;
else
ch.currFrame = 0;
}
void drawCharacter(Character &ch) {
int fx = (ch.currFrame % ch.animationColumns) * ch.frameWidth;
int fy = ch.animationRow * ch.frameHeight;
al_draw_scaled_bitmap(ch.tile, fx + ch.offsetx, fy + ch.offsety,
ch.sizex - 5, ch.sizey,
ch.x, ch.y, ch.sizex2, ch.sizey2, 0);
if (ch.currFrame == 0 && ch.animationRow == 1)
al_draw_scaled_bitmap(ch.tile, 250, 64,
10, 18,
ch.x + 37, ch.y - 8, 25, 47, 0);
}
void drawSprite(struct Sprite &ch) {
int fx = (ch.currFrame % ch.animationColumns) * ch.frameWidth;
int fy = ch.animationRow * ch.frameHeight;
al_draw_scaled_bitmap(ch.tile, fx + ch.offsetx, fy + ch.offsety,
ch.frameWidth - 5, ch.frameHeight,
ch.imgx, ch.imgy, ch.sizex2, ch.sizey2, 0);
}
void animateSprite(struct Sprite &ch){
ch.frameCount++;
if (ch.frameCount == ch.frameDelay) {
ch.frameCount = 0;
ch.currFrame++;
if (ch.currFrame == ch.maxFrame)
ch.currFrame = 0;
}
}
void animateSprite(Character &ch){
ch.frameCount++;
if (ch.frameCount == ch.frameDelay) {
ch.frameCount = 0;
ch.currFrame++;
if (ch.currFrame == ch.maxFrame)
ch.currFrame = 0;
}
}
void moveCharacter(Character &ch, int destX, int destY) {
ch.animationRow = 1;
ch.frameCount++;
if (ch.frameCount == ch.frameDelay) {
ch.frameCount = 0;
ch.currFrame++;
if (ch.currFrame == ch.maxFrame)
ch.currFrame = 1;
}
if ((destX - ch.x) > ch.speed){
ch.x += ch.speed;
}
else if ((ch.x - destX) > ch.speed){
ch.x -= ch.speed;
}
else {
ch.movement = false;
ch.currFrame = 0;
}
if (ch.x > WIDTH - ch.sizex2)
ch.x = WIDTH - ch.sizex2;
} | true |
3bcf72f115998efaea9e82ea1fd37cbc7b2fce27 | C++ | srkprasad1995/files | /palindrome_2000.cpp | UTF-8 | 728 | 2.734375 | 3 | [] | no_license | #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstring>
using namespace std;
int dp[5001][5001];
int min(int a,int b,int c)
{
return ((a<b)? (a<c?a:c) : (b<c?b:c));
}
int check(char str[],int n)
{
for(int i=0;i<n;i++)
dp[i][i] = 0;
for(int len = 2;len<=n;len++)
{
for(int i=0;i<n-len+1;i++)
{
int j=i+len-1;
if(str[i] == str[j]) dp[i][j] = (j-i)>1?dp[i+1][j-1]:0;
else dp[i][j] = min(dp[i][j-1],dp[i+1][j]) +1;
}
}
/* for(int i=0;i<n;i++) {
for(int j=0;j<n;j++)
printf("%d ",dp[i][j]);
printf("\n");
}*/
return dp[0][n-1];
}
int main()
{
int n;
scanf("%d",&n);
char str[5001];
scanf("%s",str);
int temp = check(str,n);
printf("%d\n",temp);
return 0;
}
| true |
8708d43c4a1a816e5c2202db991228b075c9de79 | C++ | arthuuuur/L3_Projet_PPIL_Client_Cpp | /PPIL_v1.0/Test_Circle.cpp | UTF-8 | 230 | 2.828125 | 3 | [] | no_license | #include "Circle.h"
int main() {
Vector2D v1(3, 9);
Shape * s1 = new Circle(Color::BLUE, v1, 4.5);
cout << *s1 << endl;
cout << s1->getGravity() << endl; // (3,9)
cout << s1->getArea() << endl; // 63.62 find with geogebra
} | true |
d3a8020e46e9bc84db14d04703053b44e0895d05 | C++ | praveensonare/Leetcode | /source/239_SlidingWindowMaximum.cpp | UTF-8 | 2,015 | 3.46875 | 3 | [] | no_license | #include "Header.h"
// 239. Sliding Window Maximum
// Level - Hard
// You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.
// Return the max sliding window.
//
// Example 1:
// Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
// Output: [3,3,5,5,6,7]
// Explanation:
// Window position Max
// --------------- -----
// [1 3 -1] -3 5 3 6 7 3
// 1 [3 -1 -3] 5 3 6 7 3
// 1 3 [-1 -3 5] 3 6 7 5
// 1 3 -1 [-3 5 3] 6 7 5
// 1 3 -1 -3 [5 3 6] 7 6
// 1 3 -1 -3 5 [3 6 7] 7
//
// Example 2:
// Input: nums = [1], k = 1
// Output: [1]
//
// Example 3:
// Input: nums = [1,-1], k = 1
// Output: [1,-1]
//
// Example 4:
// Input: nums = [9,11], k = 2
// Output: [11]
//
// Example 5:
// Input: nums = [4,-2], k = 2
// Output: [4]
//
// Constraints:
// 1 <= nums.length <= 105
// -104 <= nums[i] <= 104
// 1 <= k <= nums.length
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
int len = nums.size();
deque<pair<int, int>> dQ; // val, idx
vector<int> result;
for (int i = 0; i < len; ++i)
{
if (!dQ.empty() && dQ.front().second <= i - k) dQ.pop_front();
while (!dQ.empty() && dQ.back().first <= nums[i])
{
dQ.pop_back();
}
dQ.push_back(pair<int, int>(nums[i], i));
if (i >= k-1) result.push_back(dQ.front().first);
}
return result;
}
#define PAIR pair<vector<int>, int>
void test_maxSlidingWindow()
{
vector<PAIR> tc = {PAIR({1,3,-1,-3,5,3,6,7}, 3), PAIR({1},1), PAIR({1,-1}, 1), PAIR({9,11},2), PAIR({4,-2},2)};
vector<vector<int>> answers = {{3,3,5,5,6,7}, {1}, {1,-1}, {11}, {4}};
for (unsigned i = 0; i < tc.size(); ++i)
{
if (maxSlidingWindow(tc[i].first, tc[i].second) != answers[i]) ERROR_LOG;
}
}
| true |
9b4b8bd26945d19ef69d7ae48088f4ad1cb99544 | C++ | JacobRBlomquist/MinUnit | /example.cpp | UTF-8 | 618 | 2.71875 | 3 | [] | no_license | #include <stdio.h>
#include "minunit.h"
int tests_run = 0;
int foo = 7;
int bar = 4;
static char *test_foo()
{
mu_assert("error, foo != 7", foo == 7);
return 0;
}
static char *test_bar()
{
mu_assert("error, bar != 5", bar == 5);
return 0;
}
static char *all_tests()
{
mu_run_test(test_foo);
mu_run_test(test_bar);
return 0;
}
int main(int argc, char **argv)
{
char *result = all_tests();
if (result != 0)
{
printf("%s\n", result);
}
else
{
printf("ALL TESTS PASSED\n");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
} | true |
87ef89009b92884965cd919fa30f67d03005c883 | C++ | Natalia9Ramirez/Poo | /Buscar.cpp | UTF-8 | 760 | 3.046875 | 3 | [] | no_license | #include <conio.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class buscarCar{
private:
string datos;
string car;
public:
buscarCar(string datos, string car){
this->car= car;
this->datos=datos;
}
void buscar(){
int encontrado=0;
for(int i=0;i<datos.length();i++){
for(int j=0; j<car.length();j++)
{
if(datos.at(i)==car.at(j)){
//printf("%c fue encontrado en la posicion %d\n");
encontrado = j;
int k = i;
printf("posicion %d i %d \n",j,k,encontrado);
}
}
}
}
}
;
int main() {
buscarCar b("HostName:localhost","localhost");
b.buscar();
return 0;
}
| true |
e5238e1810b154a04f04b9a86c2e338a107e7041 | C++ | gxmc/book-Generative_Programming | /GMCL/dictionaries.h | ISO-8859-1 | 10,758 | 2.5625 | 3 | [] | no_license | /******************************************************************************/
/* */
/* Generative Matrix Package - File "Dictionaries.h" */
/* */
/* */
/* Category: ICCL Components */
/* */
/* Classes: */
/* - HashDictionary */
/* - ListDictionary */
/* */
/* */
/* These classes are used as dictionary data structures for the sparse */
/* matrix format COO. For both dictionary structures there exist read */
/* iterators. */
/* HashDictionary takes a horizontal container, a vertical container and a */
/* hash function as parameters to build the hash structure. The horizontal */
/* container has to be a dictionary itself. */
/* */
/* */
/* */
/* (c) Copyright 1998 by Tobias Neubert, Krzysztof Czarnecki, */
/* Ulrich Eisenecker, Johannes Knaupp */
/* */
/******************************************************************************/
#ifndef DB_MATRIX_DICTIONARIES_H
#define DB_MATRIX_DICTIONARIES_H
#include <stdlib.h>
#include <math.h>
#include "HashFunctions.h"
namespace MatrixICCL{
template<class HashFormat_>
class HashIterator
{
public:
typedef HashFormat_ Format;
typedef Format::Config Config;
typedef Config::ElementType ElementType;
typedef Config::IndexType IndexType;
typedef Config::MallocErrorChecker MallocErrorChecker;
private:
typedef Format::SecondaryVectorType ScndFormat;
typedef ScndFormat::IteratorType ScndIteratorType;
public:
HashIterator(const Format& c) :format_(c), scndIter(NULL)
{
reset();
}
~HashIterator()
{
delete scndIter;
}
void getNext(IndexType& i, IndexType& j, ElementType& v)
{
assert(!end());
scndIter->getNext(i, j, v);
if (scndIter->end()) nextScndIter();
}
void reset()
{
indx= 0;
nextScndIter();
}
bool end() const
{
return indx >= format_.hashVector.count() && scndIter==NULL;
}
protected:
void nextScndIter()
{
delete scndIter;
ScndFormat* pntr= NULL;
while (pntr==NULL && indx<format_.hashVector.count())
pntr= format_.hashVector.getElement(indx++);
if (pntr==NULL)
scndIter= NULL;
else
{
scndIter= new ScndIteratorType(*pntr);
MallocErrorChecker::ensure(scndIter!=NULL); assert(scndIter!=NULL);
}
if (scndIter!=NULL && scndIter->end()) nextScndIter();
}
private:
const Format& format_;
IndexType indx;
ScndIteratorType* scndIter;
};
template<class VerticalContainer, class HorizontalContainer, class HashFunction_>
class HashDictionary
{
public:
typedef HorizontalContainer::Config Config;
typedef Config::IndexType IndexType;
typedef Config::SignedIndexType SignedIndexType;
typedef Config::ElementType ElementType;
typedef HashFunction_ HashFunction;
typedef HashFunction::HashWidth HashWidth;
typedef Config::MallocErrorChecker MallocErrorChecker;
typedef VerticalContainer PrimaryVectorType;
typedef HorizontalContainer SecondaryVectorType;
typedef HashIterator<HashDictionary<VerticalContainer,
HorizontalContainer, HashFunction_> > IteratorType;
friend IteratorType;
public:
HashDictionary(const IndexType& size) : size_(size), hashVector(hashWidth())
{
hashVector.initElements();
}
~HashDictionary()
{
for (IndexType i= 0; i<hashVector.count(); i++)
delete hashVector.getElement(i);
}
static IndexType hashWidth() {return HashWidth::value;}
void setElement(const IndexType& i, const IndexType& j,
const ElementType& v)
{
IndexType primIndx= getIndex(i, j);
if (!validIndex(primIndx))
{
SecondaryVectorType* pntr=
new SecondaryVectorType(size_ / hashWidth());
MallocErrorChecker::ensure(pntr != NULL);
assert(pntr != NULL);
pntr->initElements();
hashVector.setElement(primIndx, pntr);
}
hashVector.getElement(primIndx)->setElement(i, j, v);
}
ElementType getElement(const IndexType & i, const IndexType & j) const
{
IndexType primIndx= getIndex(i, j);
return validIndex(primIndx)
? hashVector.getElement(primIndx)->getElement(i, j)
: zero();
}
void initElements()
{
for (IndexType i= 0; i<hashVector.count(); i++)
delete hashVector.getElement(i);
hashVector.initElements();
}
static const ElementType & zero() {return eNull;}
protected:
bool validIndex(const IndexType& i) const
{
assert(i>=0); assert(i<hashVector.count());
return hashVector.getElement(i) != NULL;
}
IndexType getIndex(const IndexType& i, const IndexType& j) const
{
return HashFunction::getHashValue(i, j);
}
private:
const IndexType size_;
PrimaryVectorType hashVector;
static const ElementType eNull;
};
template<class VerticalContainer, class HorizontalContainer, class HashFunction_>
HashDictionary<VerticalContainer, HorizontalContainer, HashFunction_>::
ElementType const
HashDictionary<VerticalContainer, HorizontalContainer, HashFunction_>::eNull=
HashDictionary<VerticalContainer, HorizontalContainer, HashFunction_>::
ElementType(0);
template<class ListFormat_>
class ListIterator
{
public:
typedef ListFormat_ Format;
typedef Format::ElementType ElementType;
typedef Format::IndexType IndexType;
ListIterator(const Format& c) :_format(c), indx(0) {}
void getNext(IndexType& i, IndexType& j, ElementType& v)
{
assert(!end());
v= format_.m_Val. getElement(indx);
i= format_.m_Indx.getElement(indx);
j= format_.m_Jndx.getElement(indx);
++indx;
}
void reset()
{
indx= 0;
}
bool end() const {return indx >= format_.m_Val.count();}
private:
const Format& format_;
IndexType indx;
};
template<class IndexVector, class ElementVector>
class ListDictionary
{
public:
typedef ElementVector::Config Config;
typedef Config::ElementType ElementType;
typedef Config::IndexType IndexType;
typedef Config::SignedIndexType SignedIndexType;
typedef ListIterator<ListDictionary<IndexVector, ElementVector> >
IteratorType;
friend IteratorType;
ListDictionary(const IndexType& size)
: m_Val(0, size), m_Indx(0, size), m_Jndx(0, size)
{}
void setElement( const IndexType & i, const IndexType & j,
const ElementType & v )
{
IndexType indx= getIndex(i, j);
if (v == zero())
if (validIndex(indx))
{ // Element lschen
for (IndexType ii= indx; ii<m_Val.count(); ++ii)
{
m_Val. setElement(ii, m_Val. getElement(ii+1));
m_Indx.setElement(ii, m_Indx.getElement(ii+1));
m_Jndx.setElement(ii, m_Jndx.getElement(ii+1));
}
m_Val. removeLastElement();
m_Indx.removeLastElement();
m_Jndx.removeLastElement();
}
else;
else if (validIndex(indx))
{ // Element ndern
m_Val. setElement(indx, v);
m_Indx.setElement(indx, i);
m_Jndx.setElement(indx, j);
}
else
{ // insert element
assert(!m_Val. full());
assert(!m_Jndx.full());
m_Val. addElement(v);
m_Indx.addElement(i);
m_Jndx.addElement(j);
}
}
ElementType getElement( const IndexType & i, const IndexType & j ) const
{
IndexType indx= getIndex(i, j);
return validIndex(indx) ? m_Val.getElement(indx) : zero();
}
void initElements()
{
m_Val. clear();
m_Indx.clear();
m_Jndx.clear();
}
static const ElementType & zero() {return eNull;}
protected:
bool validIndex(const IndexType& i) const
{
return i<m_Val.count();
}
IndexType getIndex(const IndexType& i, const IndexType& j) const
{
for (IndexType indx= 0; indx<m_Val.count(); ++indx)
if (m_Indx.getElement(indx)==i && m_Jndx.getElement(indx)==j)
return indx;
return m_Val.count();
}
private:
ElementVector m_Val;// values
IndexVector m_Indx; // m_Indx[pos] holds the column index of m_Val[pos]
IndexVector m_Jndx; // m_Jndx[pos] holds the column index of m_Val[pos]
static const ElementType eNull;
};
template<class IndexVector, class ElementVector>
ListDictionary<IndexVector, ElementVector>::ElementType const
ListDictionary<IndexVector, ElementVector>::eNull=
ListDictionary<IndexVector, ElementVector>::ElementType(0);
} // namespace MatrixICCL
#endif // DB_MATRIX_DICTIONARIES_H
| true |
169bb73d80bfd77e579d09ae5d73d44368e6ebbd | C++ | takapamu/-playing-cards-game | /playing card game/playing_card_game.cc | UTF-8 | 1,368 | 3.46875 | 3 | [] | no_license | #include<iostream> //標準出力
#include<random> //乱数生成
#define DECK 52
#define MIN_DECK 1
#define MAX_DECK 10
class Deck_Pcard
{
private:
int deck_num; //デッキ数
int card_num; //カード枚数
int *deck; //格納配列
int *p_deck;//配列戦闘ポインタ
public:
Deck_Pcard(int input_deck_num = MIN_DECK)
{
if(input_deck_num < MAX_DECK)
{
deck_num = MIN_DECK; //最小値
}
else if(input_deck_num > MAX_DECK)
{
deck_num = MAX_DECK; //最大値
}
else
{
deck_num = input_deck_num; //入力値
}
card_num = deck_num * DECK;
deck = new int [card_num];
p_deck = &deck[0];
//配列初期化
for(int i = 0; i < card_num; i++)
{
deck[i] = -1;
}
std::random_device rnd; //乱数生成
for(int i = 0; i < card_num; i++)
{
while(true)
{
int place = rnd()%(card_num);
if(deck[place] == -1)
{
deck[place] = i%DECK;
break; //ループを抜ける
}
}
}
}
~Deck_Pcard()
{
delete[] deck;
}
int hand_card()
{
int hand = p_deck[0];
p_deck++;
card_num--;
return hand;
}
void show_card()
{
for(int i = 0; i < deck_num*DECK; i++)
{
std::cout << deck[i] << "";
}
std::cout << std::endl;
}
}; | true |
e23ebfa70daa492fae9144c4057f301fd20cd87f | C++ | MohamedKharaev/UCI | /ICS 45C/hw/hw2/coins_main.cpp | UTF-8 | 908 | 3.28125 | 3 | [] | no_license | #include <iostream>
using namespace std;
#include "Coins.h"
int main()
{
Coins pocket(5, 3, 6, 8);
Coins piggyBank(50, 50, 50, 50);
cout << "I have " << pocket << " in my pocket." << endl;
pocket = pocket.extract_exact_change( coins_required_for_cents( 68 ) );
cout << "I bought chips for 68 cents and now I have " << pocket << " in my pocket " << endl;
cout << "I have " << piggyBank << " in my piggy bank" << endl;
Coins temp = coins_required_for_cents( 205 );
piggyBank.extract_exact_change(temp);
pocket.deposit_coins(temp);
cout <<"I transferred $2.05 from my piggy back into my pocket. Now I have " << pocket << " in my pocket and " << piggyBank << " in my piggy bank" << endl;
Coins couch(10, 10, 10, 10);
piggyBank.deposit_coins(couch);
cout << "I found change in the sofa and added it to my piggy bank. Now my piggy bank has ";
piggyBank.print_dollar(cout);
return 0;
}
| true |
252a2b4f904b997e149f5fc0345c89cc89f3765c | C++ | EtBLh/hw_dungeon | /src/util.hpp | UTF-8 | 2,130 | 2.859375 | 3 | [] | no_license | #ifndef UTIL_H
#define UTIL_H
#include <nlohmann/json.hpp>
#include <fstream>
#include <streambuf>
#include <cstring>
#include <functional>
#include "const.h"
#include <cmath>
using namespace nlohmann;
using namespace std;
namespace Dungeon{
typedef struct _vector_d
{
float x = 0, y = 0;
_vector_d(float x, float y): x(x), y(y) {};
_vector_d() {};
_vector_d operator=(const _vector_d& a){
x = a.x;
y = a.y;
return *this;
}
_vector_d operator+(const _vector_d& a){
return _vector_d(x+a.x,y+a.y);
}
_vector_d operator-(const _vector_d& a){
return _vector_d(x-a.x,y-a.y);
}
} vector_d;
inline vector_d conv_real_pos(vector_d virtual_pos){
return vector_d(virtual_pos.x*SCALER*BLOCK_WIDTH, virtual_pos.y*SCALER*BLOCK_WIDTH);
}
typedef struct _rect{
float x = 0, y = 0, width = 0, height = 0;
_rect(float x, float y, float width, float height):
x(x),y(y),width(width),height(height){};
_rect(vector_d pos, float width, float height):
x(pos.x), y(pos.y), width(width), height(height) {};
_rect operator+(const _vector_d& a){
return _rect(a.x+x,a.y+y,width,height);
}
} rect;
const auto is_collide = [](rect rect1, rect rect2) -> bool{
return (rect1.x < rect2.x + rect2.width &&
rect1.x + rect1.width > rect2.x &&
rect1.y < rect2.y + rect2.height &&
rect1.y + rect1.height > rect2.y);
};
const auto distance = [](rect rect1, rect rect2) -> float{
vector_d pos1((rect1.x+rect1.width)/2,
(rect1.y+rect1.height)/2);
vector_d pos2((rect2.x+rect2.width)/2,
(rect2.y+rect2.height)/2);
return sqrt(pow(pos1.x-pos2.x,2) + pow(pos1.y-pos2.y,2));
};
const auto load_json_file = [](string path) -> json{
ifstream input(path);
if (!input) return json();
json __json;
input >> __json;
return __json;
};
}
#endif | true |
4aaebca155473e78a87f367b4467d7d664b2e2f5 | C++ | zhangmneg/zhangmeng | /作业/6-20/main.cpp | GB18030 | 227 | 2.640625 | 3 | [] | no_license | #include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout<<"һ";
int x=0;
int y=0;
cin>>x>>y;
if(fmod(y,x)==0)
cout<<"ture";
else
cout<<"false";
}
| true |
060f439087ac333163c45ae97163e03014e87a07 | C++ | CMMayer/Toolkit-for-Ring-LWE-v1.0 | /include/Efficient DFT.h | UTF-8 | 3,339 | 2.65625 | 3 | [] | no_license | #pragma once
#ifndef EDFT_H
#define EDFT_H
#include <complex>
#include <vector>
#include "Data_Type_Settings.h"
typedef std::complex<real_type> complex_type;
typedef std::vector<complex_type> complex_vec;
namespace RLWE_Toolkit {
namespace DFT {
/*
Cooley-Tukey FFT for power of two input.size() = N = 2^k.
Calls cooley_tukey_fft(output, input, N)
*/
void cooley_tukey_fft(complex_vec& output, complex_vec const& input);
/*
Cooley-Tukey IFFT for power of two input.size() = N = 2^k.
Calls cooley_tukey_ifft(output, input, N)
*/
void cooley_tukey_ifft(complex_vec& output, complex_vec const& input);
/*
Recursive implementation of Cooley-Tukey FFT for powers of two N = 2^k.
The whole recursion works on the input vector. The values @param start and @param step
are used to traverse through certain sub vectors throughout the recursion.
*/
void cooley_tukey_fft(complex_vec& output, complex_vec const& input, int N, int start = 0, int step = 1);
/*
Recursive implementation of Cooley-Tukey IFFT for powers of two N = 2^k.
The whole recursion works on the input vector. The values @param start and @param step
are used to traverse through certain sub vectors throughout the recursion.
*/
void cooley_tukey_ifft(complex_vec& output, complex_vec const& input, int N, int start = 0, int step = 1);
/*
Implementation of Rader's DFT for prime length input. For a detailed explanation see:
http://www.skybluetrades.net/blog/posts/2013/12/31/data-analysis-fft-9.html
*/
void rader_dft_for_primes(complex_vec& output, complex_vec const& input, complex_vec const& precomp_DFT_omega_p, int generator);
/*
Slightly adjusted implementation of Rader's DFT to fit an application of the Chinese remainder transform.
*/
void rader_crt_for_primes(complex_vec& output, complex_vec const& input, complex_vec const& precomp_DFT_omega_p, int generator);
/*
Slightly adjusted implementation of Rader's DFT to fit an application of the adjoint Chinese remainder transform.
*/
void rader_crt_star_for_primes(complex_vec& output, complex_vec const& input, complex_vec const& precomp_DFT_omega_p, int generator);
/*
Applies the permutation induced by the generator @param generator of the unit group of ZZ_p.
Input might have size p or (p-1), output must have size (p-1).
*/
void unitsGeneratorPermutation(complex_vec& output, complex_vec const& input, int generator, int p);
/*
Applies the permutation induced by the inverse of the generator @param generator of the unit group of ZZ_p.
Input must have size (p-1), Output might have size p or (p-1).
*/
void unitsGeneratorPermutationInverse(complex_vec& output, complex_vec const& input, int generator, int p);
/*
Zero pads the input vector to the new size. @param newSize must be >= 2*input.size() - 3.
zeroPadding inserts the needed amount of zeros between the first and second entry of the input vector.
*/
void zeroPadding(complex_vec& output, complex_vec const& input, int newSize);
/*
Creates the output vector of size @param newSize, whose entries are a cyclic padding of the input.
For example, (a b c) -> (a b c a b c a b). @param newSize must be >= 2*input.size() - 3.
*/
void cyclicPadding(complex_vec& output, complex_vec const& input, int newSize);
}
}
#endif // !EDFT_H
| true |
ca263714c4cceac7c849f47c7911da3bb1a78d21 | C++ | nisiscau/Object-Oriented-Programming-C- | /C++ Object Oriented Programming/W2/puzzle.cpp | UTF-8 | 380 | 3.296875 | 3 | [] | no_license | #include <iostream>
int main() {
using std::cout,std::endl;
/* code */
int num = 7;
cout<<"num: "<<num<<endl;
cout<<"&num: "<<&num<<endl;
int *p = #
cout<<"p: "<<p<<endl;
cout<<"*p: "<<*p<<endl;
cout<<"&p: "<<&p<<endl;
*p = 42;
cout<<"*p changed to 42"<<endl;
cout<<"&num: "<<&num<<endl;
return 0;
}
| true |
15d56fee3d4a0627d16a8bc8e2a3ca68baadf4d9 | C++ | elaxcc/Formulas | /Formulas/Errors.cpp | UTF-8 | 557 | 2.53125 | 3 | [] | no_license | #include "stdafx.h"
#include "Errors.h"
namespace Formula
{
const std::string ErrorList::c_err_invalid_operator_ = "Error A1: Unknown operator ";
ErrorList::ErrorList()
{
}
ErrorList::~ErrorList()
{
errors_.clear();
}
void ErrorList::add(const std::string& err, unsigned line, unsigned column)
{
errors_.push_back(Error(err, line, column));
}
void ErrorList::add_unknown_operator(std::string _operator, unsigned line, unsigned column)
{
errors_.push_back(Error(c_err_invalid_operator_ + _operator, line, column));
}
} // Formulas
| true |
79586c628abc8625510d27d3e63ddca9a9c58003 | C++ | jordanbonaldi/Nanotekspice | /src/Component/Clock.cpp | UTF-8 | 813 | 3.09375 | 3 | [] | no_license | /*
** EPITECH PROJECT, 2018
** Clock
** File description:
** Implementation of Clock
*/
#include "Clock.hpp"
Clock::Clock(const std::string &s) : AComponent(s, 1, "clock")
{
}
nts::Tristate Clock::compute(std::size_t pin)
{
if (pin - 1 > 0)
throw nts::PinUnknown("error");
return this->value;
}
void Clock::setLink(std::size_t pin, nts::IComponent &other,
std::size_t otherPin)
{
if (pin - 1 < this->numberOfPins && !this->pins.at(pin - 1)) {
this->pins[pin - 1] = &other;
other.setLink(otherPin, *this, pin);
} else if (pin > this->numberOfPins)
throw nts::PinUnknown("error");
}
void Clock::dump() const
{
std::cout << "clock : " << name << std::endl;
std::cout << "clock value : " << this->value << std::endl;
std::cout << "linked : " << (this->pins.at(0) ? "yes" : "no") << std::endl;
}
| true |
5cc88a9a0f3ffb30acbf9cadd5b77e40ac8157e9 | C++ | alvinalvord/CPL | /codeforces/div3/494/A/a.cpp | UTF-8 | 351 | 2.890625 | 3 | [] | no_license | #include <iostream>
#include <cstdio>
int
main ()
{
int arr[101];
for (int i = 0; i < 101; i++)
arr[i] = 0;
int n, temp;
scanf ("%d", &n);
for (int i = 0; i < n; i++) {
scanf ("%d", &temp);
arr[temp] ++;
}
int max = 1;
for (int i = 0; i < 101; i++)
if (arr[i] > max)
max = arr[i];
printf ("%d\n", max);
return 0;
}
| true |
ce2a916d31c35b31163f8c5d565f9da437f058eb | C++ | Hitoshy/Maratona-de-Programacao | /URI-Exercicios/1020/1020.cpp | UTF-8 | 237 | 2.6875 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, ano, mes, dia;
scanf("%d", &n);
ano = n/365;
mes = (n-ano*365)/30;
dia = n-ano*365-mes*30;
printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n", ano, mes, dia);
return 0;
} | true |
f29cc4440c812a93073d672083832bd1146a2d76 | C++ | mir-group/flare | /src/flare_pp/descriptors/wigner3j.cpp | UTF-8 | 87,017 | 2.5625 | 3 | [
"MIT"
] | permissive | #include "wigner3j.h"
#include <iostream>
// See compute_wigner.py for the calculation of these coefficients.
Eigen::VectorXd compute_coeffs(int lmax) {
Eigen::VectorXd wigner3j_coeffs = Eigen::VectorXd::Zero(pow((lmax + 1), 6));
if (lmax == 0) {
wigner3j_coeffs(0) = 1;
} else if (lmax == 1) {
wigner3j_coeffs(0) = 1;
wigner3j_coeffs(9) = sqrt(3) / 3;
wigner3j_coeffs(11) = -sqrt(3) / 3;
wigner3j_coeffs(13) = sqrt(3) / 3;
wigner3j_coeffs(21) = sqrt(3) / 3;
wigner3j_coeffs(23) = -sqrt(3) / 3;
wigner3j_coeffs(25) = sqrt(3) / 3;
wigner3j_coeffs(30) = sqrt(3) / 3;
wigner3j_coeffs(32) = -sqrt(3) / 3;
wigner3j_coeffs(34) = sqrt(3) / 3;
wigner3j_coeffs(42) = sqrt(6) / 6;
wigner3j_coeffs(44) = -sqrt(6) / 6;
wigner3j_coeffs(48) = -sqrt(6) / 6;
wigner3j_coeffs(52) = sqrt(6) / 6;
wigner3j_coeffs(56) = sqrt(6) / 6;
wigner3j_coeffs(58) = -sqrt(6) / 6;
} else if (lmax == 2) {
wigner3j_coeffs(0) = 1;
wigner3j_coeffs(14) = sqrt(3) / 3;
wigner3j_coeffs(16) = -sqrt(3) / 3;
wigner3j_coeffs(18) = sqrt(3) / 3;
wigner3j_coeffs(60) = sqrt(5) / 5;
wigner3j_coeffs(64) = -sqrt(5) / 5;
wigner3j_coeffs(68) = sqrt(5) / 5;
wigner3j_coeffs(72) = -sqrt(5) / 5;
wigner3j_coeffs(76) = sqrt(5) / 5;
wigner3j_coeffs(86) = sqrt(3) / 3;
wigner3j_coeffs(88) = -sqrt(3) / 3;
wigner3j_coeffs(90) = sqrt(3) / 3;
wigner3j_coeffs(110) = sqrt(3) / 3;
wigner3j_coeffs(112) = -sqrt(3) / 3;
wigner3j_coeffs(114) = sqrt(3) / 3;
wigner3j_coeffs(122) = sqrt(6) / 6;
wigner3j_coeffs(124) = -sqrt(6) / 6;
wigner3j_coeffs(128) = -sqrt(6) / 6;
wigner3j_coeffs(132) = sqrt(6) / 6;
wigner3j_coeffs(136) = sqrt(6) / 6;
wigner3j_coeffs(138) = -sqrt(6) / 6;
wigner3j_coeffs(148) = sqrt(5) / 5;
wigner3j_coeffs(152) = -sqrt(10) / 10;
wigner3j_coeffs(156) = sqrt(30) / 30;
wigner3j_coeffs(162) = -sqrt(10) / 10;
wigner3j_coeffs(166) = sqrt(30) / 15;
wigner3j_coeffs(170) = -sqrt(10) / 10;
wigner3j_coeffs(176) = sqrt(30) / 30;
wigner3j_coeffs(180) = -sqrt(10) / 10;
wigner3j_coeffs(184) = sqrt(5) / 5;
wigner3j_coeffs(212) = sqrt(30) / 30;
wigner3j_coeffs(214) = -sqrt(10) / 10;
wigner3j_coeffs(216) = sqrt(5) / 5;
wigner3j_coeffs(224) = -sqrt(10) / 10;
wigner3j_coeffs(226) = sqrt(30) / 15;
wigner3j_coeffs(228) = -sqrt(10) / 10;
wigner3j_coeffs(236) = sqrt(5) / 5;
wigner3j_coeffs(238) = -sqrt(10) / 10;
wigner3j_coeffs(240) = sqrt(30) / 30;
wigner3j_coeffs(258) = sqrt(15) / 15;
wigner3j_coeffs(262) = -sqrt(10) / 10;
wigner3j_coeffs(266) = sqrt(10) / 10;
wigner3j_coeffs(270) = -sqrt(15) / 15;
wigner3j_coeffs(278) = -sqrt(30) / 15;
wigner3j_coeffs(282) = sqrt(30) / 30;
wigner3j_coeffs(290) = -sqrt(30) / 30;
wigner3j_coeffs(294) = sqrt(30) / 15;
wigner3j_coeffs(302) = sqrt(15) / 15;
wigner3j_coeffs(306) = -sqrt(10) / 10;
wigner3j_coeffs(310) = sqrt(10) / 10;
wigner3j_coeffs(314) = -sqrt(15) / 15;
wigner3j_coeffs(348) = sqrt(5) / 5;
wigner3j_coeffs(352) = -sqrt(5) / 5;
wigner3j_coeffs(356) = sqrt(5) / 5;
wigner3j_coeffs(360) = -sqrt(5) / 5;
wigner3j_coeffs(364) = sqrt(5) / 5;
wigner3j_coeffs(392) = sqrt(5) / 5;
wigner3j_coeffs(398) = -sqrt(10) / 10;
wigner3j_coeffs(400) = -sqrt(10) / 10;
wigner3j_coeffs(404) = sqrt(30) / 30;
wigner3j_coeffs(406) = sqrt(30) / 15;
wigner3j_coeffs(408) = sqrt(30) / 30;
wigner3j_coeffs(412) = -sqrt(10) / 10;
wigner3j_coeffs(414) = -sqrt(10) / 10;
wigner3j_coeffs(420) = sqrt(5) / 5;
wigner3j_coeffs(438) = sqrt(30) / 15;
wigner3j_coeffs(442) = -sqrt(15) / 15;
wigner3j_coeffs(448) = -sqrt(15) / 15;
wigner3j_coeffs(452) = -sqrt(30) / 30;
wigner3j_coeffs(456) = sqrt(10) / 10;
wigner3j_coeffs(462) = sqrt(10) / 10;
wigner3j_coeffs(470) = -sqrt(10) / 10;
wigner3j_coeffs(476) = -sqrt(10) / 10;
wigner3j_coeffs(480) = sqrt(30) / 30;
wigner3j_coeffs(484) = sqrt(15) / 15;
wigner3j_coeffs(490) = sqrt(15) / 15;
wigner3j_coeffs(494) = -sqrt(30) / 15;
wigner3j_coeffs(508) = sqrt(5) / 5;
wigner3j_coeffs(512) = -sqrt(5) / 5;
wigner3j_coeffs(516) = sqrt(5) / 5;
wigner3j_coeffs(520) = -sqrt(5) / 5;
wigner3j_coeffs(524) = sqrt(5) / 5;
wigner3j_coeffs(540) = sqrt(15) / 15;
wigner3j_coeffs(542) = -sqrt(30) / 15;
wigner3j_coeffs(552) = -sqrt(10) / 10;
wigner3j_coeffs(554) = sqrt(30) / 30;
wigner3j_coeffs(556) = sqrt(15) / 15;
wigner3j_coeffs(564) = sqrt(10) / 10;
wigner3j_coeffs(568) = -sqrt(10) / 10;
wigner3j_coeffs(576) = -sqrt(15) / 15;
wigner3j_coeffs(578) = -sqrt(30) / 30;
wigner3j_coeffs(580) = sqrt(10) / 10;
wigner3j_coeffs(590) = sqrt(30) / 15;
wigner3j_coeffs(592) = -sqrt(15) / 15;
wigner3j_coeffs(618) = sqrt(70) / 35;
wigner3j_coeffs(622) = -sqrt(105) / 35;
wigner3j_coeffs(626) = sqrt(70) / 35;
wigner3j_coeffs(638) = -sqrt(105) / 35;
wigner3j_coeffs(642) = sqrt(70) / 70;
wigner3j_coeffs(646) = sqrt(70) / 70;
wigner3j_coeffs(650) = -sqrt(105) / 35;
wigner3j_coeffs(658) = sqrt(70) / 35;
wigner3j_coeffs(662) = sqrt(70) / 70;
wigner3j_coeffs(666) = -sqrt(70) / 35;
wigner3j_coeffs(670) = sqrt(70) / 70;
wigner3j_coeffs(674) = sqrt(70) / 35;
wigner3j_coeffs(682) = -sqrt(105) / 35;
wigner3j_coeffs(686) = sqrt(70) / 70;
wigner3j_coeffs(690) = sqrt(70) / 70;
wigner3j_coeffs(694) = -sqrt(105) / 35;
wigner3j_coeffs(706) = sqrt(70) / 35;
wigner3j_coeffs(710) = -sqrt(105) / 35;
wigner3j_coeffs(714) = sqrt(70) / 35;
} else if (lmax == 3) {
wigner3j_coeffs(0) = 1;
wigner3j_coeffs(21) = sqrt(3) / 3;
wigner3j_coeffs(23) = -sqrt(3) / 3;
wigner3j_coeffs(25) = sqrt(3) / 3;
wigner3j_coeffs(88) = sqrt(5) / 5;
wigner3j_coeffs(92) = -sqrt(5) / 5;
wigner3j_coeffs(96) = sqrt(5) / 5;
wigner3j_coeffs(100) = -sqrt(5) / 5;
wigner3j_coeffs(104) = sqrt(5) / 5;
wigner3j_coeffs(213) = sqrt(7) / 7;
wigner3j_coeffs(219) = -sqrt(7) / 7;
wigner3j_coeffs(225) = sqrt(7) / 7;
wigner3j_coeffs(231) = -sqrt(7) / 7;
wigner3j_coeffs(237) = sqrt(7) / 7;
wigner3j_coeffs(243) = -sqrt(7) / 7;
wigner3j_coeffs(249) = sqrt(7) / 7;
wigner3j_coeffs(261) = sqrt(3) / 3;
wigner3j_coeffs(263) = -sqrt(3) / 3;
wigner3j_coeffs(265) = sqrt(3) / 3;
wigner3j_coeffs(306) = sqrt(3) / 3;
wigner3j_coeffs(308) = -sqrt(3) / 3;
wigner3j_coeffs(310) = sqrt(3) / 3;
wigner3j_coeffs(318) = sqrt(6) / 6;
wigner3j_coeffs(320) = -sqrt(6) / 6;
wigner3j_coeffs(324) = -sqrt(6) / 6;
wigner3j_coeffs(328) = sqrt(6) / 6;
wigner3j_coeffs(332) = sqrt(6) / 6;
wigner3j_coeffs(334) = -sqrt(6) / 6;
wigner3j_coeffs(344) = sqrt(5) / 5;
wigner3j_coeffs(348) = -sqrt(10) / 10;
wigner3j_coeffs(352) = sqrt(30) / 30;
wigner3j_coeffs(358) = -sqrt(10) / 10;
wigner3j_coeffs(362) = sqrt(30) / 15;
wigner3j_coeffs(366) = -sqrt(10) / 10;
wigner3j_coeffs(372) = sqrt(30) / 30;
wigner3j_coeffs(376) = -sqrt(10) / 10;
wigner3j_coeffs(380) = sqrt(5) / 5;
wigner3j_coeffs(471) = sqrt(30) / 30;
wigner3j_coeffs(473) = -sqrt(10) / 10;
wigner3j_coeffs(475) = sqrt(5) / 5;
wigner3j_coeffs(483) = -sqrt(10) / 10;
wigner3j_coeffs(485) = sqrt(30) / 15;
wigner3j_coeffs(487) = -sqrt(10) / 10;
wigner3j_coeffs(495) = sqrt(5) / 5;
wigner3j_coeffs(497) = -sqrt(10) / 10;
wigner3j_coeffs(499) = sqrt(30) / 30;
wigner3j_coeffs(517) = sqrt(15) / 15;
wigner3j_coeffs(521) = -sqrt(10) / 10;
wigner3j_coeffs(525) = sqrt(10) / 10;
wigner3j_coeffs(529) = -sqrt(15) / 15;
wigner3j_coeffs(537) = -sqrt(30) / 15;
wigner3j_coeffs(541) = sqrt(30) / 30;
wigner3j_coeffs(549) = -sqrt(30) / 30;
wigner3j_coeffs(553) = sqrt(30) / 15;
wigner3j_coeffs(561) = sqrt(15) / 15;
wigner3j_coeffs(565) = -sqrt(10) / 10;
wigner3j_coeffs(569) = sqrt(10) / 10;
wigner3j_coeffs(573) = -sqrt(15) / 15;
wigner3j_coeffs(589) = sqrt(7) / 7;
wigner3j_coeffs(595) = -sqrt(42) / 21;
wigner3j_coeffs(601) = sqrt(70) / 35;
wigner3j_coeffs(607) = -sqrt(35) / 35;
wigner3j_coeffs(613) = sqrt(105) / 105;
wigner3j_coeffs(623) = -sqrt(21) / 21;
wigner3j_coeffs(629) = 2 * sqrt(210) / 105;
wigner3j_coeffs(635) = -sqrt(105) / 35;
wigner3j_coeffs(641) = 2 * sqrt(210) / 105;
wigner3j_coeffs(647) = -sqrt(21) / 21;
wigner3j_coeffs(657) = sqrt(105) / 105;
wigner3j_coeffs(663) = -sqrt(35) / 35;
wigner3j_coeffs(669) = sqrt(70) / 35;
wigner3j_coeffs(675) = -sqrt(42) / 21;
wigner3j_coeffs(681) = sqrt(7) / 7;
wigner3j_coeffs(786) = sqrt(105) / 105;
wigner3j_coeffs(790) = -sqrt(35) / 35;
wigner3j_coeffs(794) = sqrt(70) / 35;
wigner3j_coeffs(798) = -sqrt(42) / 21;
wigner3j_coeffs(802) = sqrt(7) / 7;
wigner3j_coeffs(816) = -sqrt(21) / 21;
wigner3j_coeffs(820) = 2 * sqrt(210) / 105;
wigner3j_coeffs(824) = -sqrt(105) / 35;
wigner3j_coeffs(828) = 2 * sqrt(210) / 105;
wigner3j_coeffs(832) = -sqrt(21) / 21;
wigner3j_coeffs(846) = sqrt(7) / 7;
wigner3j_coeffs(850) = -sqrt(42) / 21;
wigner3j_coeffs(854) = sqrt(70) / 35;
wigner3j_coeffs(858) = -sqrt(35) / 35;
wigner3j_coeffs(862) = sqrt(105) / 105;
wigner3j_coeffs(890) = sqrt(7) / 14;
wigner3j_coeffs(896) = -sqrt(105) / 42;
wigner3j_coeffs(902) = sqrt(14) / 14;
wigner3j_coeffs(908) = -sqrt(14) / 14;
wigner3j_coeffs(914) = sqrt(105) / 42;
wigner3j_coeffs(920) = -sqrt(7) / 14;
wigner3j_coeffs(932) = -sqrt(21) / 14;
wigner3j_coeffs(938) = sqrt(21) / 21;
wigner3j_coeffs(944) = -sqrt(21) / 42;
wigner3j_coeffs(956) = sqrt(21) / 42;
wigner3j_coeffs(962) = -sqrt(21) / 21;
wigner3j_coeffs(968) = sqrt(21) / 14;
wigner3j_coeffs(980) = sqrt(7) / 14;
wigner3j_coeffs(986) = -sqrt(105) / 42;
wigner3j_coeffs(992) = sqrt(14) / 14;
wigner3j_coeffs(998) = -sqrt(14) / 14;
wigner3j_coeffs(1004) = sqrt(105) / 42;
wigner3j_coeffs(1010) = -sqrt(7) / 14;
wigner3j_coeffs(1048) = sqrt(5) / 5;
wigner3j_coeffs(1052) = -sqrt(5) / 5;
wigner3j_coeffs(1056) = sqrt(5) / 5;
wigner3j_coeffs(1060) = -sqrt(5) / 5;
wigner3j_coeffs(1064) = sqrt(5) / 5;
wigner3j_coeffs(1127) = sqrt(5) / 5;
wigner3j_coeffs(1133) = -sqrt(10) / 10;
wigner3j_coeffs(1135) = -sqrt(10) / 10;
wigner3j_coeffs(1139) = sqrt(30) / 30;
wigner3j_coeffs(1141) = sqrt(30) / 15;
wigner3j_coeffs(1143) = sqrt(30) / 30;
wigner3j_coeffs(1147) = -sqrt(10) / 10;
wigner3j_coeffs(1149) = -sqrt(10) / 10;
wigner3j_coeffs(1155) = sqrt(5) / 5;
wigner3j_coeffs(1173) = sqrt(30) / 15;
wigner3j_coeffs(1177) = -sqrt(15) / 15;
wigner3j_coeffs(1183) = -sqrt(15) / 15;
wigner3j_coeffs(1187) = -sqrt(30) / 30;
wigner3j_coeffs(1191) = sqrt(10) / 10;
wigner3j_coeffs(1197) = sqrt(10) / 10;
wigner3j_coeffs(1205) = -sqrt(10) / 10;
wigner3j_coeffs(1211) = -sqrt(10) / 10;
wigner3j_coeffs(1215) = sqrt(30) / 30;
wigner3j_coeffs(1219) = sqrt(15) / 15;
wigner3j_coeffs(1225) = sqrt(15) / 15;
wigner3j_coeffs(1229) = -sqrt(30) / 15;
wigner3j_coeffs(1245) = sqrt(7) / 7;
wigner3j_coeffs(1251) = -sqrt(21) / 21;
wigner3j_coeffs(1257) = sqrt(105) / 105;
wigner3j_coeffs(1265) = -sqrt(42) / 21;
wigner3j_coeffs(1271) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1277) = -sqrt(35) / 35;
wigner3j_coeffs(1285) = sqrt(70) / 35;
wigner3j_coeffs(1291) = -sqrt(105) / 35;
wigner3j_coeffs(1297) = sqrt(70) / 35;
wigner3j_coeffs(1305) = -sqrt(35) / 35;
wigner3j_coeffs(1311) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1317) = -sqrt(42) / 21;
wigner3j_coeffs(1325) = sqrt(105) / 105;
wigner3j_coeffs(1331) = -sqrt(21) / 21;
wigner3j_coeffs(1337) = sqrt(7) / 7;
wigner3j_coeffs(1348) = sqrt(5) / 5;
wigner3j_coeffs(1352) = -sqrt(5) / 5;
wigner3j_coeffs(1356) = sqrt(5) / 5;
wigner3j_coeffs(1360) = -sqrt(5) / 5;
wigner3j_coeffs(1364) = sqrt(5) / 5;
wigner3j_coeffs(1380) = sqrt(15) / 15;
wigner3j_coeffs(1382) = -sqrt(30) / 15;
wigner3j_coeffs(1392) = -sqrt(10) / 10;
wigner3j_coeffs(1394) = sqrt(30) / 30;
wigner3j_coeffs(1396) = sqrt(15) / 15;
wigner3j_coeffs(1404) = sqrt(10) / 10;
wigner3j_coeffs(1408) = -sqrt(10) / 10;
wigner3j_coeffs(1416) = -sqrt(15) / 15;
wigner3j_coeffs(1418) = -sqrt(30) / 30;
wigner3j_coeffs(1420) = sqrt(10) / 10;
wigner3j_coeffs(1430) = sqrt(30) / 15;
wigner3j_coeffs(1432) = -sqrt(15) / 15;
wigner3j_coeffs(1458) = sqrt(70) / 35;
wigner3j_coeffs(1462) = -sqrt(105) / 35;
wigner3j_coeffs(1466) = sqrt(70) / 35;
wigner3j_coeffs(1478) = -sqrt(105) / 35;
wigner3j_coeffs(1482) = sqrt(70) / 70;
wigner3j_coeffs(1486) = sqrt(70) / 70;
wigner3j_coeffs(1490) = -sqrt(105) / 35;
wigner3j_coeffs(1498) = sqrt(70) / 35;
wigner3j_coeffs(1502) = sqrt(70) / 70;
wigner3j_coeffs(1506) = -sqrt(70) / 35;
wigner3j_coeffs(1510) = sqrt(70) / 70;
wigner3j_coeffs(1514) = sqrt(70) / 35;
wigner3j_coeffs(1522) = -sqrt(105) / 35;
wigner3j_coeffs(1526) = sqrt(70) / 70;
wigner3j_coeffs(1530) = sqrt(70) / 70;
wigner3j_coeffs(1534) = -sqrt(105) / 35;
wigner3j_coeffs(1546) = sqrt(70) / 35;
wigner3j_coeffs(1550) = -sqrt(105) / 35;
wigner3j_coeffs(1554) = sqrt(70) / 35;
wigner3j_coeffs(1582) = sqrt(14) / 14;
wigner3j_coeffs(1588) = -sqrt(14) / 14;
wigner3j_coeffs(1594) = sqrt(210) / 70;
wigner3j_coeffs(1600) = -sqrt(70) / 70;
wigner3j_coeffs(1610) = -sqrt(14) / 14;
wigner3j_coeffs(1622) = sqrt(35) / 35;
wigner3j_coeffs(1628) = -sqrt(70) / 35;
wigner3j_coeffs(1634) = sqrt(210) / 70;
wigner3j_coeffs(1644) = sqrt(14) / 14;
wigner3j_coeffs(1650) = -sqrt(35) / 35;
wigner3j_coeffs(1662) = sqrt(35) / 35;
wigner3j_coeffs(1668) = -sqrt(14) / 14;
wigner3j_coeffs(1678) = -sqrt(210) / 70;
wigner3j_coeffs(1684) = sqrt(70) / 35;
wigner3j_coeffs(1690) = -sqrt(35) / 35;
wigner3j_coeffs(1702) = sqrt(14) / 14;
wigner3j_coeffs(1712) = sqrt(70) / 70;
wigner3j_coeffs(1718) = -sqrt(210) / 70;
wigner3j_coeffs(1724) = sqrt(14) / 14;
wigner3j_coeffs(1730) = -sqrt(14) / 14;
wigner3j_coeffs(1793) = sqrt(105) / 105;
wigner3j_coeffs(1795) = -sqrt(21) / 21;
wigner3j_coeffs(1797) = sqrt(7) / 7;
wigner3j_coeffs(1811) = -sqrt(35) / 35;
wigner3j_coeffs(1813) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1815) = -sqrt(42) / 21;
wigner3j_coeffs(1829) = sqrt(70) / 35;
wigner3j_coeffs(1831) = -sqrt(105) / 35;
wigner3j_coeffs(1833) = sqrt(70) / 35;
wigner3j_coeffs(1847) = -sqrt(42) / 21;
wigner3j_coeffs(1849) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1851) = -sqrt(35) / 35;
wigner3j_coeffs(1865) = sqrt(7) / 7;
wigner3j_coeffs(1867) = -sqrt(21) / 21;
wigner3j_coeffs(1869) = sqrt(105) / 105;
wigner3j_coeffs(1903) = sqrt(70) / 70;
wigner3j_coeffs(1907) = -sqrt(210) / 70;
wigner3j_coeffs(1911) = sqrt(14) / 14;
wigner3j_coeffs(1915) = -sqrt(14) / 14;
wigner3j_coeffs(1933) = -sqrt(210) / 70;
wigner3j_coeffs(1937) = sqrt(70) / 35;
wigner3j_coeffs(1941) = -sqrt(35) / 35;
wigner3j_coeffs(1949) = sqrt(14) / 14;
wigner3j_coeffs(1963) = sqrt(14) / 14;
wigner3j_coeffs(1967) = -sqrt(35) / 35;
wigner3j_coeffs(1975) = sqrt(35) / 35;
wigner3j_coeffs(1979) = -sqrt(14) / 14;
wigner3j_coeffs(1993) = -sqrt(14) / 14;
wigner3j_coeffs(2001) = sqrt(35) / 35;
wigner3j_coeffs(2005) = -sqrt(70) / 35;
wigner3j_coeffs(2009) = sqrt(210) / 70;
wigner3j_coeffs(2027) = sqrt(14) / 14;
wigner3j_coeffs(2031) = -sqrt(14) / 14;
wigner3j_coeffs(2035) = sqrt(210) / 70;
wigner3j_coeffs(2039) = -sqrt(70) / 70;
wigner3j_coeffs(2079) = sqrt(42) / 42;
wigner3j_coeffs(2085) = -sqrt(21) / 21;
wigner3j_coeffs(2091) = sqrt(70) / 35;
wigner3j_coeffs(2097) = -sqrt(21) / 21;
wigner3j_coeffs(2103) = sqrt(42) / 42;
wigner3j_coeffs(2121) = -sqrt(105) / 42;
wigner3j_coeffs(2127) = sqrt(7) / 14;
wigner3j_coeffs(2133) = -sqrt(210) / 210;
wigner3j_coeffs(2139) = -sqrt(210) / 210;
wigner3j_coeffs(2145) = sqrt(7) / 14;
wigner3j_coeffs(2151) = -sqrt(105) / 42;
wigner3j_coeffs(2163) = sqrt(105) / 42;
wigner3j_coeffs(2175) = -sqrt(105) / 70;
wigner3j_coeffs(2181) = 2 * sqrt(105) / 105;
wigner3j_coeffs(2187) = -sqrt(105) / 70;
wigner3j_coeffs(2199) = sqrt(105) / 42;
wigner3j_coeffs(2211) = -sqrt(105) / 42;
wigner3j_coeffs(2217) = sqrt(7) / 14;
wigner3j_coeffs(2223) = -sqrt(210) / 210;
wigner3j_coeffs(2229) = -sqrt(210) / 210;
wigner3j_coeffs(2235) = sqrt(7) / 14;
wigner3j_coeffs(2241) = -sqrt(105) / 42;
wigner3j_coeffs(2259) = sqrt(42) / 42;
wigner3j_coeffs(2265) = -sqrt(21) / 21;
wigner3j_coeffs(2271) = sqrt(70) / 35;
wigner3j_coeffs(2277) = -sqrt(21) / 21;
wigner3j_coeffs(2283) = sqrt(42) / 42;
wigner3j_coeffs(2373) = sqrt(7) / 7;
wigner3j_coeffs(2379) = -sqrt(7) / 7;
wigner3j_coeffs(2385) = sqrt(7) / 7;
wigner3j_coeffs(2391) = -sqrt(7) / 7;
wigner3j_coeffs(2397) = sqrt(7) / 7;
wigner3j_coeffs(2403) = -sqrt(7) / 7;
wigner3j_coeffs(2409) = sqrt(7) / 7;
wigner3j_coeffs(2514) = sqrt(7) / 7;
wigner3j_coeffs(2524) = -sqrt(21) / 21;
wigner3j_coeffs(2528) = -sqrt(42) / 21;
wigner3j_coeffs(2534) = sqrt(105) / 105;
wigner3j_coeffs(2538) = 2 * sqrt(210) / 105;
wigner3j_coeffs(2542) = sqrt(70) / 35;
wigner3j_coeffs(2548) = -sqrt(35) / 35;
wigner3j_coeffs(2552) = -sqrt(105) / 35;
wigner3j_coeffs(2556) = -sqrt(35) / 35;
wigner3j_coeffs(2562) = sqrt(70) / 35;
wigner3j_coeffs(2566) = 2 * sqrt(210) / 105;
wigner3j_coeffs(2570) = sqrt(105) / 105;
wigner3j_coeffs(2576) = -sqrt(42) / 21;
wigner3j_coeffs(2580) = -sqrt(21) / 21;
wigner3j_coeffs(2590) = sqrt(7) / 7;
wigner3j_coeffs(2618) = sqrt(21) / 14;
wigner3j_coeffs(2624) = -sqrt(7) / 14;
wigner3j_coeffs(2632) = -sqrt(7) / 14;
wigner3j_coeffs(2638) = -sqrt(21) / 21;
wigner3j_coeffs(2644) = sqrt(105) / 42;
wigner3j_coeffs(2652) = sqrt(105) / 42;
wigner3j_coeffs(2658) = sqrt(21) / 42;
wigner3j_coeffs(2664) = -sqrt(14) / 14;
wigner3j_coeffs(2672) = -sqrt(14) / 14;
wigner3j_coeffs(2684) = sqrt(14) / 14;
wigner3j_coeffs(2692) = sqrt(14) / 14;
wigner3j_coeffs(2698) = -sqrt(21) / 42;
wigner3j_coeffs(2704) = -sqrt(105) / 42;
wigner3j_coeffs(2712) = -sqrt(105) / 42;
wigner3j_coeffs(2718) = sqrt(21) / 21;
wigner3j_coeffs(2724) = sqrt(7) / 14;
wigner3j_coeffs(2732) = sqrt(7) / 14;
wigner3j_coeffs(2738) = -sqrt(21) / 14;
wigner3j_coeffs(2801) = sqrt(7) / 7;
wigner3j_coeffs(2813) = -sqrt(42) / 21;
wigner3j_coeffs(2815) = -sqrt(21) / 21;
wigner3j_coeffs(2825) = sqrt(70) / 35;
wigner3j_coeffs(2827) = 2 * sqrt(210) / 105;
wigner3j_coeffs(2829) = sqrt(105) / 105;
wigner3j_coeffs(2837) = -sqrt(35) / 35;
wigner3j_coeffs(2839) = -sqrt(105) / 35;
wigner3j_coeffs(2841) = -sqrt(35) / 35;
wigner3j_coeffs(2849) = sqrt(105) / 105;
wigner3j_coeffs(2851) = 2 * sqrt(210) / 105;
wigner3j_coeffs(2853) = sqrt(70) / 35;
wigner3j_coeffs(2863) = -sqrt(21) / 21;
wigner3j_coeffs(2865) = -sqrt(42) / 21;
wigner3j_coeffs(2877) = sqrt(7) / 7;
wigner3j_coeffs(2911) = sqrt(14) / 14;
wigner3j_coeffs(2915) = -sqrt(14) / 14;
wigner3j_coeffs(2931) = -sqrt(14) / 14;
wigner3j_coeffs(2939) = sqrt(14) / 14;
wigner3j_coeffs(2951) = sqrt(210) / 70;
wigner3j_coeffs(2955) = sqrt(35) / 35;
wigner3j_coeffs(2959) = -sqrt(35) / 35;
wigner3j_coeffs(2963) = -sqrt(210) / 70;
wigner3j_coeffs(2971) = -sqrt(70) / 70;
wigner3j_coeffs(2975) = -sqrt(70) / 35;
wigner3j_coeffs(2983) = sqrt(70) / 35;
wigner3j_coeffs(2987) = sqrt(70) / 70;
wigner3j_coeffs(2995) = sqrt(210) / 70;
wigner3j_coeffs(2999) = sqrt(35) / 35;
wigner3j_coeffs(3003) = -sqrt(35) / 35;
wigner3j_coeffs(3007) = -sqrt(210) / 70;
wigner3j_coeffs(3019) = -sqrt(14) / 14;
wigner3j_coeffs(3027) = sqrt(14) / 14;
wigner3j_coeffs(3043) = sqrt(14) / 14;
wigner3j_coeffs(3047) = -sqrt(14) / 14;
wigner3j_coeffs(3087) = sqrt(105) / 42;
wigner3j_coeffs(3093) = -sqrt(105) / 42;
wigner3j_coeffs(3099) = sqrt(42) / 42;
wigner3j_coeffs(3115) = -sqrt(105) / 42;
wigner3j_coeffs(3127) = sqrt(7) / 14;
wigner3j_coeffs(3133) = -sqrt(21) / 21;
wigner3j_coeffs(3143) = sqrt(42) / 42;
wigner3j_coeffs(3149) = sqrt(7) / 14;
wigner3j_coeffs(3155) = -sqrt(105) / 70;
wigner3j_coeffs(3161) = -sqrt(210) / 210;
wigner3j_coeffs(3167) = sqrt(70) / 35;
wigner3j_coeffs(3177) = -sqrt(21) / 21;
wigner3j_coeffs(3183) = -sqrt(210) / 210;
wigner3j_coeffs(3189) = 2 * sqrt(105) / 105;
wigner3j_coeffs(3195) = -sqrt(210) / 210;
wigner3j_coeffs(3201) = -sqrt(21) / 21;
wigner3j_coeffs(3211) = sqrt(70) / 35;
wigner3j_coeffs(3217) = -sqrt(210) / 210;
wigner3j_coeffs(3223) = -sqrt(105) / 70;
wigner3j_coeffs(3229) = sqrt(7) / 14;
wigner3j_coeffs(3235) = sqrt(42) / 42;
wigner3j_coeffs(3245) = -sqrt(21) / 21;
wigner3j_coeffs(3251) = sqrt(7) / 14;
wigner3j_coeffs(3263) = -sqrt(105) / 42;
wigner3j_coeffs(3279) = sqrt(42) / 42;
wigner3j_coeffs(3285) = -sqrt(105) / 42;
wigner3j_coeffs(3291) = sqrt(105) / 42;
wigner3j_coeffs(3318) = sqrt(7) / 7;
wigner3j_coeffs(3324) = -sqrt(7) / 7;
wigner3j_coeffs(3330) = sqrt(7) / 7;
wigner3j_coeffs(3336) = -sqrt(7) / 7;
wigner3j_coeffs(3342) = sqrt(7) / 7;
wigner3j_coeffs(3348) = -sqrt(7) / 7;
wigner3j_coeffs(3354) = sqrt(7) / 7;
wigner3j_coeffs(3378) = sqrt(7) / 14;
wigner3j_coeffs(3380) = -sqrt(21) / 14;
wigner3j_coeffs(3396) = -sqrt(105) / 42;
wigner3j_coeffs(3398) = sqrt(21) / 21;
wigner3j_coeffs(3400) = sqrt(7) / 14;
wigner3j_coeffs(3414) = sqrt(14) / 14;
wigner3j_coeffs(3416) = -sqrt(21) / 42;
wigner3j_coeffs(3418) = -sqrt(105) / 42;
wigner3j_coeffs(3432) = -sqrt(14) / 14;
wigner3j_coeffs(3436) = sqrt(14) / 14;
wigner3j_coeffs(3450) = sqrt(105) / 42;
wigner3j_coeffs(3452) = sqrt(21) / 42;
wigner3j_coeffs(3454) = -sqrt(14) / 14;
wigner3j_coeffs(3468) = -sqrt(7) / 14;
wigner3j_coeffs(3470) = -sqrt(21) / 21;
wigner3j_coeffs(3472) = sqrt(105) / 42;
wigner3j_coeffs(3488) = sqrt(21) / 14;
wigner3j_coeffs(3490) = -sqrt(7) / 14;
wigner3j_coeffs(3532) = sqrt(42) / 42;
wigner3j_coeffs(3536) = -sqrt(105) / 42;
wigner3j_coeffs(3540) = sqrt(105) / 42;
wigner3j_coeffs(3562) = -sqrt(21) / 21;
wigner3j_coeffs(3566) = sqrt(7) / 14;
wigner3j_coeffs(3574) = -sqrt(105) / 42;
wigner3j_coeffs(3592) = sqrt(70) / 35;
wigner3j_coeffs(3596) = -sqrt(210) / 210;
wigner3j_coeffs(3600) = -sqrt(105) / 70;
wigner3j_coeffs(3604) = sqrt(7) / 14;
wigner3j_coeffs(3608) = sqrt(42) / 42;
wigner3j_coeffs(3622) = -sqrt(21) / 21;
wigner3j_coeffs(3626) = -sqrt(210) / 210;
wigner3j_coeffs(3630) = 2 * sqrt(105) / 105;
wigner3j_coeffs(3634) = -sqrt(210) / 210;
wigner3j_coeffs(3638) = -sqrt(21) / 21;
wigner3j_coeffs(3652) = sqrt(42) / 42;
wigner3j_coeffs(3656) = sqrt(7) / 14;
wigner3j_coeffs(3660) = -sqrt(105) / 70;
wigner3j_coeffs(3664) = -sqrt(210) / 210;
wigner3j_coeffs(3668) = sqrt(70) / 35;
wigner3j_coeffs(3686) = -sqrt(105) / 42;
wigner3j_coeffs(3694) = sqrt(7) / 14;
wigner3j_coeffs(3698) = -sqrt(21) / 21;
wigner3j_coeffs(3720) = sqrt(105) / 42;
wigner3j_coeffs(3724) = -sqrt(105) / 42;
wigner3j_coeffs(3728) = sqrt(42) / 42;
wigner3j_coeffs(3780) = sqrt(42) / 42;
wigner3j_coeffs(3786) = -sqrt(21) / 21;
wigner3j_coeffs(3792) = sqrt(21) / 21;
wigner3j_coeffs(3798) = -sqrt(42) / 42;
wigner3j_coeffs(3822) = -sqrt(21) / 21;
wigner3j_coeffs(3828) = sqrt(42) / 42;
wigner3j_coeffs(3840) = -sqrt(42) / 42;
wigner3j_coeffs(3846) = sqrt(21) / 21;
wigner3j_coeffs(3864) = sqrt(21) / 21;
wigner3j_coeffs(3876) = -sqrt(42) / 42;
wigner3j_coeffs(3882) = sqrt(42) / 42;
wigner3j_coeffs(3894) = -sqrt(21) / 21;
wigner3j_coeffs(3906) = -sqrt(42) / 42;
wigner3j_coeffs(3912) = -sqrt(42) / 42;
wigner3j_coeffs(3918) = sqrt(42) / 42;
wigner3j_coeffs(3930) = -sqrt(42) / 42;
wigner3j_coeffs(3936) = sqrt(42) / 42;
wigner3j_coeffs(3942) = sqrt(42) / 42;
wigner3j_coeffs(3954) = sqrt(21) / 21;
wigner3j_coeffs(3966) = -sqrt(42) / 42;
wigner3j_coeffs(3972) = sqrt(42) / 42;
wigner3j_coeffs(3984) = -sqrt(21) / 21;
wigner3j_coeffs(4002) = -sqrt(21) / 21;
wigner3j_coeffs(4008) = sqrt(42) / 42;
wigner3j_coeffs(4020) = -sqrt(42) / 42;
wigner3j_coeffs(4026) = sqrt(21) / 21;
wigner3j_coeffs(4050) = sqrt(42) / 42;
wigner3j_coeffs(4056) = -sqrt(21) / 21;
wigner3j_coeffs(4062) = sqrt(21) / 21;
wigner3j_coeffs(4068) = -sqrt(42) / 42;
} else if (lmax == 4) {
wigner3j_coeffs(0) = 1;
wigner3j_coeffs(30) = sqrt(3) / 3;
wigner3j_coeffs(32) = -sqrt(3) / 3;
wigner3j_coeffs(34) = sqrt(3) / 3;
wigner3j_coeffs(124) = sqrt(5) / 5;
wigner3j_coeffs(128) = -sqrt(5) / 5;
wigner3j_coeffs(132) = sqrt(5) / 5;
wigner3j_coeffs(136) = -sqrt(5) / 5;
wigner3j_coeffs(140) = sqrt(5) / 5;
wigner3j_coeffs(294) = sqrt(7) / 7;
wigner3j_coeffs(300) = -sqrt(7) / 7;
wigner3j_coeffs(306) = sqrt(7) / 7;
wigner3j_coeffs(312) = -sqrt(7) / 7;
wigner3j_coeffs(318) = sqrt(7) / 7;
wigner3j_coeffs(324) = -sqrt(7) / 7;
wigner3j_coeffs(330) = sqrt(7) / 7;
wigner3j_coeffs(552) = 1 / 3;
wigner3j_coeffs(560) = -1 / 3;
wigner3j_coeffs(568) = 1 / 3;
wigner3j_coeffs(576) = -1 / 3;
wigner3j_coeffs(584) = 1 / 3;
wigner3j_coeffs(592) = -1 / 3;
wigner3j_coeffs(600) = 1 / 3;
wigner3j_coeffs(608) = -1 / 3;
wigner3j_coeffs(616) = 1 / 3;
wigner3j_coeffs(630) = sqrt(3) / 3;
wigner3j_coeffs(632) = -sqrt(3) / 3;
wigner3j_coeffs(634) = sqrt(3) / 3;
wigner3j_coeffs(702) = sqrt(3) / 3;
wigner3j_coeffs(704) = -sqrt(3) / 3;
wigner3j_coeffs(706) = sqrt(3) / 3;
wigner3j_coeffs(714) = sqrt(6) / 6;
wigner3j_coeffs(716) = -sqrt(6) / 6;
wigner3j_coeffs(720) = -sqrt(6) / 6;
wigner3j_coeffs(724) = sqrt(6) / 6;
wigner3j_coeffs(728) = sqrt(6) / 6;
wigner3j_coeffs(730) = -sqrt(6) / 6;
wigner3j_coeffs(740) = sqrt(5) / 5;
wigner3j_coeffs(744) = -sqrt(10) / 10;
wigner3j_coeffs(748) = sqrt(30) / 30;
wigner3j_coeffs(754) = -sqrt(10) / 10;
wigner3j_coeffs(758) = sqrt(30) / 15;
wigner3j_coeffs(762) = -sqrt(10) / 10;
wigner3j_coeffs(768) = sqrt(30) / 30;
wigner3j_coeffs(772) = -sqrt(10) / 10;
wigner3j_coeffs(776) = sqrt(5) / 5;
wigner3j_coeffs(948) = sqrt(30) / 30;
wigner3j_coeffs(950) = -sqrt(10) / 10;
wigner3j_coeffs(952) = sqrt(5) / 5;
wigner3j_coeffs(960) = -sqrt(10) / 10;
wigner3j_coeffs(962) = sqrt(30) / 15;
wigner3j_coeffs(964) = -sqrt(10) / 10;
wigner3j_coeffs(972) = sqrt(5) / 5;
wigner3j_coeffs(974) = -sqrt(10) / 10;
wigner3j_coeffs(976) = sqrt(30) / 30;
wigner3j_coeffs(994) = sqrt(15) / 15;
wigner3j_coeffs(998) = -sqrt(10) / 10;
wigner3j_coeffs(1002) = sqrt(10) / 10;
wigner3j_coeffs(1006) = -sqrt(15) / 15;
wigner3j_coeffs(1014) = -sqrt(30) / 15;
wigner3j_coeffs(1018) = sqrt(30) / 30;
wigner3j_coeffs(1026) = -sqrt(30) / 30;
wigner3j_coeffs(1030) = sqrt(30) / 15;
wigner3j_coeffs(1038) = sqrt(15) / 15;
wigner3j_coeffs(1042) = -sqrt(10) / 10;
wigner3j_coeffs(1046) = sqrt(10) / 10;
wigner3j_coeffs(1050) = -sqrt(15) / 15;
wigner3j_coeffs(1066) = sqrt(7) / 7;
wigner3j_coeffs(1072) = -sqrt(42) / 21;
wigner3j_coeffs(1078) = sqrt(70) / 35;
wigner3j_coeffs(1084) = -sqrt(35) / 35;
wigner3j_coeffs(1090) = sqrt(105) / 105;
wigner3j_coeffs(1100) = -sqrt(21) / 21;
wigner3j_coeffs(1106) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1112) = -sqrt(105) / 35;
wigner3j_coeffs(1118) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1124) = -sqrt(21) / 21;
wigner3j_coeffs(1134) = sqrt(105) / 105;
wigner3j_coeffs(1140) = -sqrt(35) / 35;
wigner3j_coeffs(1146) = sqrt(70) / 35;
wigner3j_coeffs(1152) = -sqrt(42) / 21;
wigner3j_coeffs(1158) = sqrt(7) / 7;
wigner3j_coeffs(1398) = sqrt(105) / 105;
wigner3j_coeffs(1402) = -sqrt(35) / 35;
wigner3j_coeffs(1406) = sqrt(70) / 35;
wigner3j_coeffs(1410) = -sqrt(42) / 21;
wigner3j_coeffs(1414) = sqrt(7) / 7;
wigner3j_coeffs(1428) = -sqrt(21) / 21;
wigner3j_coeffs(1432) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1436) = -sqrt(105) / 35;
wigner3j_coeffs(1440) = 2 * sqrt(210) / 105;
wigner3j_coeffs(1444) = -sqrt(21) / 21;
wigner3j_coeffs(1458) = sqrt(7) / 7;
wigner3j_coeffs(1462) = -sqrt(42) / 21;
wigner3j_coeffs(1466) = sqrt(70) / 35;
wigner3j_coeffs(1470) = -sqrt(35) / 35;
wigner3j_coeffs(1474) = sqrt(105) / 105;
wigner3j_coeffs(1502) = sqrt(7) / 14;
wigner3j_coeffs(1508) = -sqrt(105) / 42;
wigner3j_coeffs(1514) = sqrt(14) / 14;
wigner3j_coeffs(1520) = -sqrt(14) / 14;
wigner3j_coeffs(1526) = sqrt(105) / 42;
wigner3j_coeffs(1532) = -sqrt(7) / 14;
wigner3j_coeffs(1544) = -sqrt(21) / 14;
wigner3j_coeffs(1550) = sqrt(21) / 21;
wigner3j_coeffs(1556) = -sqrt(21) / 42;
wigner3j_coeffs(1568) = sqrt(21) / 42;
wigner3j_coeffs(1574) = -sqrt(21) / 21;
wigner3j_coeffs(1580) = sqrt(21) / 14;
wigner3j_coeffs(1592) = sqrt(7) / 14;
wigner3j_coeffs(1598) = -sqrt(105) / 42;
wigner3j_coeffs(1604) = sqrt(14) / 14;
wigner3j_coeffs(1610) = -sqrt(14) / 14;
wigner3j_coeffs(1616) = sqrt(105) / 42;
wigner3j_coeffs(1622) = -sqrt(7) / 14;
wigner3j_coeffs(1644) = 1 / 3;
wigner3j_coeffs(1652) = -sqrt(3) / 6;
wigner3j_coeffs(1660) = sqrt(105) / 42;
wigner3j_coeffs(1668) = -sqrt(70) / 42;
wigner3j_coeffs(1676) = sqrt(42) / 42;
wigner3j_coeffs(1684) = -sqrt(21) / 42;
wigner3j_coeffs(1692) = sqrt(7) / 42;
wigner3j_coeffs(1706) = -1 / 6;
wigner3j_coeffs(1714) = sqrt(21) / 21;
wigner3j_coeffs(1722) = -sqrt(105) / 42;
wigner3j_coeffs(1730) = 2 * sqrt(7) / 21;
wigner3j_coeffs(1738) = -sqrt(105) / 42;
wigner3j_coeffs(1746) = sqrt(21) / 21;
wigner3j_coeffs(1754) = -1 / 6;
wigner3j_coeffs(1768) = sqrt(7) / 42;
wigner3j_coeffs(1776) = -sqrt(21) / 42;
wigner3j_coeffs(1784) = sqrt(42) / 42;
wigner3j_coeffs(1792) = -sqrt(70) / 42;
wigner3j_coeffs(1800) = sqrt(105) / 42;
wigner3j_coeffs(1808) = -sqrt(3) / 6;
wigner3j_coeffs(1816) = 1 / 3;
wigner3j_coeffs(2088) = sqrt(7) / 42;
wigner3j_coeffs(2094) = -sqrt(21) / 42;
wigner3j_coeffs(2100) = sqrt(42) / 42;
wigner3j_coeffs(2106) = -sqrt(70) / 42;
wigner3j_coeffs(2112) = sqrt(105) / 42;
wigner3j_coeffs(2118) = -sqrt(3) / 6;
wigner3j_coeffs(2124) = 1 / 3;
wigner3j_coeffs(2144) = -1 / 6;
wigner3j_coeffs(2150) = sqrt(21) / 21;
wigner3j_coeffs(2156) = -sqrt(105) / 42;
wigner3j_coeffs(2162) = 2 * sqrt(7) / 21;
wigner3j_coeffs(2168) = -sqrt(105) / 42;
wigner3j_coeffs(2174) = sqrt(21) / 21;
wigner3j_coeffs(2180) = -1 / 6;
wigner3j_coeffs(2200) = 1 / 3;
wigner3j_coeffs(2206) = -sqrt(3) / 6;
wigner3j_coeffs(2212) = sqrt(105) / 42;
wigner3j_coeffs(2218) = -sqrt(70) / 42;
wigner3j_coeffs(2224) = sqrt(42) / 42;
wigner3j_coeffs(2230) = -sqrt(21) / 42;
wigner3j_coeffs(2236) = sqrt(7) / 42;
wigner3j_coeffs(2274) = sqrt(5) / 15;
wigner3j_coeffs(2282) = -sqrt(35) / 30;
wigner3j_coeffs(2290) = sqrt(5) / 10;
wigner3j_coeffs(2298) = -sqrt(2) / 6;
wigner3j_coeffs(2306) = sqrt(2) / 6;
wigner3j_coeffs(2314) = -sqrt(5) / 10;
wigner3j_coeffs(2322) = sqrt(35) / 30;
wigner3j_coeffs(2330) = -sqrt(5) / 15;
wigner3j_coeffs(2346) = -2 * sqrt(5) / 15;
wigner3j_coeffs(2354) = sqrt(5) / 10;
wigner3j_coeffs(2362) = -sqrt(5) / 15;
wigner3j_coeffs(2370) = sqrt(5) / 30;
wigner3j_coeffs(2386) = -sqrt(5) / 30;
wigner3j_coeffs(2394) = sqrt(5) / 15;
wigner3j_coeffs(2402) = -sqrt(5) / 10;
wigner3j_coeffs(2410) = 2 * sqrt(5) / 15;
wigner3j_coeffs(2426) = sqrt(5) / 15;
wigner3j_coeffs(2434) = -sqrt(35) / 30;
wigner3j_coeffs(2442) = sqrt(5) / 10;
wigner3j_coeffs(2450) = -sqrt(2) / 6;
wigner3j_coeffs(2458) = sqrt(2) / 6;
wigner3j_coeffs(2466) = -sqrt(5) / 10;
wigner3j_coeffs(2474) = sqrt(35) / 30;
wigner3j_coeffs(2482) = -sqrt(5) / 15;
wigner3j_coeffs(2524) = sqrt(5) / 5;
wigner3j_coeffs(2528) = -sqrt(5) / 5;
wigner3j_coeffs(2532) = sqrt(5) / 5;
wigner3j_coeffs(2536) = -sqrt(5) / 5;
wigner3j_coeffs(2540) = sqrt(5) / 5;
wigner3j_coeffs(2648) = sqrt(5) / 5;
wigner3j_coeffs(2654) = -sqrt(10) / 10;
wigner3j_coeffs(2656) = -sqrt(10) / 10;
wigner3j_coeffs(2660) = sqrt(30) / 30;
wigner3j_coeffs(2662) = sqrt(30) / 15;
wigner3j_coeffs(2664) = sqrt(30) / 30;
wigner3j_coeffs(2668) = -sqrt(10) / 10;
wigner3j_coeffs(2670) = -sqrt(10) / 10;
wigner3j_coeffs(2676) = sqrt(5) / 5;
wigner3j_coeffs(2694) = sqrt(30) / 15;
wigner3j_coeffs(2698) = -sqrt(15) / 15;
wigner3j_coeffs(2704) = -sqrt(15) / 15;
wigner3j_coeffs(2708) = -sqrt(30) / 30;
wigner3j_coeffs(2712) = sqrt(10) / 10;
wigner3j_coeffs(2718) = sqrt(10) / 10;
wigner3j_coeffs(2726) = -sqrt(10) / 10;
wigner3j_coeffs(2732) = -sqrt(10) / 10;
wigner3j_coeffs(2736) = sqrt(30) / 30;
wigner3j_coeffs(2740) = sqrt(15) / 15;
wigner3j_coeffs(2746) = sqrt(15) / 15;
wigner3j_coeffs(2750) = -sqrt(30) / 15;
wigner3j_coeffs(2766) = sqrt(7) / 7;
wigner3j_coeffs(2772) = -sqrt(21) / 21;
wigner3j_coeffs(2778) = sqrt(105) / 105;
wigner3j_coeffs(2786) = -sqrt(42) / 21;
wigner3j_coeffs(2792) = 2 * sqrt(210) / 105;
wigner3j_coeffs(2798) = -sqrt(35) / 35;
wigner3j_coeffs(2806) = sqrt(70) / 35;
wigner3j_coeffs(2812) = -sqrt(105) / 35;
wigner3j_coeffs(2818) = sqrt(70) / 35;
wigner3j_coeffs(2826) = -sqrt(35) / 35;
wigner3j_coeffs(2832) = 2 * sqrt(210) / 105;
wigner3j_coeffs(2838) = -sqrt(42) / 21;
wigner3j_coeffs(2846) = sqrt(105) / 105;
wigner3j_coeffs(2852) = -sqrt(21) / 21;
wigner3j_coeffs(2858) = sqrt(7) / 7;
wigner3j_coeffs(3004) = sqrt(5) / 5;
wigner3j_coeffs(3008) = -sqrt(5) / 5;
wigner3j_coeffs(3012) = sqrt(5) / 5;
wigner3j_coeffs(3016) = -sqrt(5) / 5;
wigner3j_coeffs(3020) = sqrt(5) / 5;
wigner3j_coeffs(3036) = sqrt(15) / 15;
wigner3j_coeffs(3038) = -sqrt(30) / 15;
wigner3j_coeffs(3048) = -sqrt(10) / 10;
wigner3j_coeffs(3050) = sqrt(30) / 30;
wigner3j_coeffs(3052) = sqrt(15) / 15;
wigner3j_coeffs(3060) = sqrt(10) / 10;
wigner3j_coeffs(3064) = -sqrt(10) / 10;
wigner3j_coeffs(3072) = -sqrt(15) / 15;
wigner3j_coeffs(3074) = -sqrt(30) / 30;
wigner3j_coeffs(3076) = sqrt(10) / 10;
wigner3j_coeffs(3086) = sqrt(30) / 15;
wigner3j_coeffs(3088) = -sqrt(15) / 15;
wigner3j_coeffs(3114) = sqrt(70) / 35;
wigner3j_coeffs(3118) = -sqrt(105) / 35;
wigner3j_coeffs(3122) = sqrt(70) / 35;
wigner3j_coeffs(3134) = -sqrt(105) / 35;
wigner3j_coeffs(3138) = sqrt(70) / 70;
wigner3j_coeffs(3142) = sqrt(70) / 70;
wigner3j_coeffs(3146) = -sqrt(105) / 35;
wigner3j_coeffs(3154) = sqrt(70) / 35;
wigner3j_coeffs(3158) = sqrt(70) / 70;
wigner3j_coeffs(3162) = -sqrt(70) / 35;
wigner3j_coeffs(3166) = sqrt(70) / 70;
wigner3j_coeffs(3170) = sqrt(70) / 35;
wigner3j_coeffs(3178) = -sqrt(105) / 35;
wigner3j_coeffs(3182) = sqrt(70) / 70;
wigner3j_coeffs(3186) = sqrt(70) / 70;
wigner3j_coeffs(3190) = -sqrt(105) / 35;
wigner3j_coeffs(3202) = sqrt(70) / 35;
wigner3j_coeffs(3206) = -sqrt(105) / 35;
wigner3j_coeffs(3210) = sqrt(70) / 35;
wigner3j_coeffs(3238) = sqrt(14) / 14;
wigner3j_coeffs(3244) = -sqrt(14) / 14;
wigner3j_coeffs(3250) = sqrt(210) / 70;
wigner3j_coeffs(3256) = -sqrt(70) / 70;
wigner3j_coeffs(3266) = -sqrt(14) / 14;
wigner3j_coeffs(3278) = sqrt(35) / 35;
wigner3j_coeffs(3284) = -sqrt(70) / 35;
wigner3j_coeffs(3290) = sqrt(210) / 70;
wigner3j_coeffs(3300) = sqrt(14) / 14;
wigner3j_coeffs(3306) = -sqrt(35) / 35;
wigner3j_coeffs(3318) = sqrt(35) / 35;
wigner3j_coeffs(3324) = -sqrt(14) / 14;
wigner3j_coeffs(3334) = -sqrt(210) / 70;
wigner3j_coeffs(3340) = sqrt(70) / 35;
wigner3j_coeffs(3346) = -sqrt(35) / 35;
wigner3j_coeffs(3358) = sqrt(14) / 14;
wigner3j_coeffs(3368) = sqrt(70) / 70;
wigner3j_coeffs(3374) = -sqrt(210) / 70;
wigner3j_coeffs(3380) = sqrt(14) / 14;
wigner3j_coeffs(3386) = -sqrt(14) / 14;
wigner3j_coeffs(3408) = 1 / 3;
wigner3j_coeffs(3416) = -sqrt(2) / 6;
wigner3j_coeffs(3424) = sqrt(42) / 42;
wigner3j_coeffs(3432) = -sqrt(14) / 42;
wigner3j_coeffs(3440) = sqrt(70) / 210;
wigner3j_coeffs(3452) = -sqrt(2) / 6;
wigner3j_coeffs(3460) = 2 * sqrt(7) / 21;
wigner3j_coeffs(3468) = -sqrt(21) / 21;
wigner3j_coeffs(3476) = 2 * sqrt(70) / 105;
wigner3j_coeffs(3484) = -sqrt(14) / 42;
wigner3j_coeffs(3496) = sqrt(42) / 42;
wigner3j_coeffs(3504) = -sqrt(21) / 21;
wigner3j_coeffs(3512) = sqrt(70) / 35;
wigner3j_coeffs(3520) = -sqrt(21) / 21;
wigner3j_coeffs(3528) = sqrt(42) / 42;
wigner3j_coeffs(3540) = -sqrt(14) / 42;
wigner3j_coeffs(3548) = 2 * sqrt(70) / 105;
wigner3j_coeffs(3556) = -sqrt(21) / 21;
wigner3j_coeffs(3564) = 2 * sqrt(7) / 21;
wigner3j_coeffs(3572) = -sqrt(2) / 6;
wigner3j_coeffs(3584) = sqrt(70) / 210;
wigner3j_coeffs(3592) = -sqrt(14) / 42;
wigner3j_coeffs(3600) = sqrt(42) / 42;
wigner3j_coeffs(3608) = -sqrt(2) / 6;
wigner3j_coeffs(3616) = 1 / 3;
wigner3j_coeffs(3674) = sqrt(105) / 105;
wigner3j_coeffs(3676) = -sqrt(21) / 21;
wigner3j_coeffs(3678) = sqrt(7) / 7;
wigner3j_coeffs(3692) = -sqrt(35) / 35;
wigner3j_coeffs(3694) = 2 * sqrt(210) / 105;
wigner3j_coeffs(3696) = -sqrt(42) / 21;
wigner3j_coeffs(3710) = sqrt(70) / 35;
wigner3j_coeffs(3712) = -sqrt(105) / 35;
wigner3j_coeffs(3714) = sqrt(70) / 35;
wigner3j_coeffs(3728) = -sqrt(42) / 21;
wigner3j_coeffs(3730) = 2 * sqrt(210) / 105;
wigner3j_coeffs(3732) = -sqrt(35) / 35;
wigner3j_coeffs(3746) = sqrt(7) / 7;
wigner3j_coeffs(3748) = -sqrt(21) / 21;
wigner3j_coeffs(3750) = sqrt(105) / 105;
wigner3j_coeffs(3784) = sqrt(70) / 70;
wigner3j_coeffs(3788) = -sqrt(210) / 70;
wigner3j_coeffs(3792) = sqrt(14) / 14;
wigner3j_coeffs(3796) = -sqrt(14) / 14;
wigner3j_coeffs(3814) = -sqrt(210) / 70;
wigner3j_coeffs(3818) = sqrt(70) / 35;
wigner3j_coeffs(3822) = -sqrt(35) / 35;
wigner3j_coeffs(3830) = sqrt(14) / 14;
wigner3j_coeffs(3844) = sqrt(14) / 14;
wigner3j_coeffs(3848) = -sqrt(35) / 35;
wigner3j_coeffs(3856) = sqrt(35) / 35;
wigner3j_coeffs(3860) = -sqrt(14) / 14;
wigner3j_coeffs(3874) = -sqrt(14) / 14;
wigner3j_coeffs(3882) = sqrt(35) / 35;
wigner3j_coeffs(3886) = -sqrt(70) / 35;
wigner3j_coeffs(3890) = sqrt(210) / 70;
wigner3j_coeffs(3908) = sqrt(14) / 14;
wigner3j_coeffs(3912) = -sqrt(14) / 14;
wigner3j_coeffs(3916) = sqrt(210) / 70;
wigner3j_coeffs(3920) = -sqrt(70) / 70;
wigner3j_coeffs(3960) = sqrt(42) / 42;
wigner3j_coeffs(3966) = -sqrt(21) / 21;
wigner3j_coeffs(3972) = sqrt(70) / 35;
wigner3j_coeffs(3978) = -sqrt(21) / 21;
wigner3j_coeffs(3984) = sqrt(42) / 42;
wigner3j_coeffs(4002) = -sqrt(105) / 42;
wigner3j_coeffs(4008) = sqrt(7) / 14;
wigner3j_coeffs(4014) = -sqrt(210) / 210;
wigner3j_coeffs(4020) = -sqrt(210) / 210;
wigner3j_coeffs(4026) = sqrt(7) / 14;
wigner3j_coeffs(4032) = -sqrt(105) / 42;
wigner3j_coeffs(4044) = sqrt(105) / 42;
wigner3j_coeffs(4056) = -sqrt(105) / 70;
wigner3j_coeffs(4062) = 2 * sqrt(105) / 105;
wigner3j_coeffs(4068) = -sqrt(105) / 70;
wigner3j_coeffs(4080) = sqrt(105) / 42;
wigner3j_coeffs(4092) = -sqrt(105) / 42;
wigner3j_coeffs(4098) = sqrt(7) / 14;
wigner3j_coeffs(4104) = -sqrt(210) / 210;
wigner3j_coeffs(4110) = -sqrt(210) / 210;
wigner3j_coeffs(4116) = sqrt(7) / 14;
wigner3j_coeffs(4122) = -sqrt(105) / 42;
wigner3j_coeffs(4140) = sqrt(42) / 42;
wigner3j_coeffs(4146) = -sqrt(21) / 21;
wigner3j_coeffs(4152) = sqrt(70) / 35;
wigner3j_coeffs(4158) = -sqrt(21) / 21;
wigner3j_coeffs(4164) = sqrt(42) / 42;
wigner3j_coeffs(4202) = sqrt(10) / 15;
wigner3j_coeffs(4210) = -sqrt(2) / 6;
wigner3j_coeffs(4218) = sqrt(21) / 21;
wigner3j_coeffs(4226) = -sqrt(14) / 21;
wigner3j_coeffs(4234) = sqrt(7) / 21;
wigner3j_coeffs(4242) = -sqrt(210) / 210;
wigner3j_coeffs(4256) = -sqrt(15) / 15;
wigner3j_coeffs(4264) = sqrt(5) / 30;
wigner3j_coeffs(4272) = sqrt(7) / 42;
wigner3j_coeffs(4280) = -sqrt(42) / 42;
wigner3j_coeffs(4288) = sqrt(70) / 42;
wigner3j_coeffs(4296) = -sqrt(35) / 30;
wigner3j_coeffs(4304) = sqrt(105) / 70;
wigner3j_coeffs(4318) = sqrt(5) / 10;
wigner3j_coeffs(4326) = -2 * sqrt(105) / 105;
wigner3j_coeffs(4334) = sqrt(21) / 42;
wigner3j_coeffs(4350) = -sqrt(21) / 42;
wigner3j_coeffs(4358) = 2 * sqrt(105) / 105;
wigner3j_coeffs(4366) = -sqrt(5) / 10;
wigner3j_coeffs(4380) = -sqrt(105) / 70;
wigner3j_coeffs(4388) = sqrt(35) / 30;
wigner3j_coeffs(4396) = -sqrt(70) / 42;
wigner3j_coeffs(4404) = sqrt(42) / 42;
wigner3j_coeffs(4412) = -sqrt(7) / 42;
wigner3j_coeffs(4420) = -sqrt(5) / 30;
wigner3j_coeffs(4428) = sqrt(15) / 15;
wigner3j_coeffs(4442) = sqrt(210) / 210;
wigner3j_coeffs(4450) = -sqrt(7) / 21;
wigner3j_coeffs(4458) = sqrt(14) / 21;
wigner3j_coeffs(4466) = -sqrt(21) / 21;
wigner3j_coeffs(4474) = sqrt(2) / 6;
wigner3j_coeffs(4482) = -sqrt(10) / 15;
wigner3j_coeffs(4704) = sqrt(70) / 210;
wigner3j_coeffs(4708) = -sqrt(14) / 42;
wigner3j_coeffs(4712) = sqrt(42) / 42;
wigner3j_coeffs(4716) = -sqrt(2) / 6;
wigner3j_coeffs(4720) = 1 / 3;
wigner3j_coeffs(4744) = -sqrt(14) / 42;
wigner3j_coeffs(4748) = 2 * sqrt(70) / 105;
wigner3j_coeffs(4752) = -sqrt(21) / 21;
wigner3j_coeffs(4756) = 2 * sqrt(7) / 21;
wigner3j_coeffs(4760) = -sqrt(2) / 6;
wigner3j_coeffs(4784) = sqrt(42) / 42;
wigner3j_coeffs(4788) = -sqrt(21) / 21;
wigner3j_coeffs(4792) = sqrt(70) / 35;
wigner3j_coeffs(4796) = -sqrt(21) / 21;
wigner3j_coeffs(4800) = sqrt(42) / 42;
wigner3j_coeffs(4824) = -sqrt(2) / 6;
wigner3j_coeffs(4828) = 2 * sqrt(7) / 21;
wigner3j_coeffs(4832) = -sqrt(21) / 21;
wigner3j_coeffs(4836) = 2 * sqrt(70) / 105;
wigner3j_coeffs(4840) = -sqrt(14) / 42;
wigner3j_coeffs(4864) = 1 / 3;
wigner3j_coeffs(4868) = -sqrt(2) / 6;
wigner3j_coeffs(4872) = sqrt(42) / 42;
wigner3j_coeffs(4876) = -sqrt(14) / 42;
wigner3j_coeffs(4880) = sqrt(70) / 210;
wigner3j_coeffs(4932) = sqrt(210) / 210;
wigner3j_coeffs(4938) = -sqrt(7) / 21;
wigner3j_coeffs(4944) = sqrt(14) / 21;
wigner3j_coeffs(4950) = -sqrt(21) / 21;
wigner3j_coeffs(4956) = sqrt(2) / 6;
wigner3j_coeffs(4962) = -sqrt(10) / 15;
wigner3j_coeffs(4988) = -sqrt(105) / 70;
wigner3j_coeffs(4994) = sqrt(35) / 30;
wigner3j_coeffs(5000) = -sqrt(70) / 42;
wigner3j_coeffs(5006) = sqrt(42) / 42;
wigner3j_coeffs(5012) = -sqrt(7) / 42;
wigner3j_coeffs(5018) = -sqrt(5) / 30;
wigner3j_coeffs(5024) = sqrt(15) / 15;
wigner3j_coeffs(5044) = sqrt(5) / 10;
wigner3j_coeffs(5050) = -2 * sqrt(105) / 105;
wigner3j_coeffs(5056) = sqrt(21) / 42;
wigner3j_coeffs(5068) = -sqrt(21) / 42;
wigner3j_coeffs(5074) = 2 * sqrt(105) / 105;
wigner3j_coeffs(5080) = -sqrt(5) / 10;
wigner3j_coeffs(5100) = -sqrt(15) / 15;
wigner3j_coeffs(5106) = sqrt(5) / 30;
wigner3j_coeffs(5112) = sqrt(7) / 42;
wigner3j_coeffs(5118) = -sqrt(42) / 42;
wigner3j_coeffs(5124) = sqrt(70) / 42;
wigner3j_coeffs(5130) = -sqrt(35) / 30;
wigner3j_coeffs(5136) = sqrt(105) / 70;
wigner3j_coeffs(5162) = sqrt(10) / 15;
wigner3j_coeffs(5168) = -sqrt(2) / 6;
wigner3j_coeffs(5174) = sqrt(21) / 21;
wigner3j_coeffs(5180) = -sqrt(14) / 21;
wigner3j_coeffs(5186) = sqrt(7) / 21;
wigner3j_coeffs(5192) = -sqrt(210) / 210;
wigner3j_coeffs(5246) = sqrt(330) / 165;
wigner3j_coeffs(5254) = -sqrt(330) / 110;
wigner3j_coeffs(5262) = sqrt(231) / 77;
wigner3j_coeffs(5270) = -sqrt(2310) / 231;
wigner3j_coeffs(5278) = sqrt(231) / 77;
wigner3j_coeffs(5286) = -sqrt(330) / 110;
wigner3j_coeffs(5294) = sqrt(330) / 165;
wigner3j_coeffs(5318) = -sqrt(1155) / 165;
wigner3j_coeffs(5326) = sqrt(165) / 66;
wigner3j_coeffs(5334) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(5342) = sqrt(462) / 462;
wigner3j_coeffs(5350) = sqrt(462) / 462;
wigner3j_coeffs(5358) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(5366) = sqrt(165) / 66;
wigner3j_coeffs(5374) = -sqrt(1155) / 165;
wigner3j_coeffs(5390) = 2 * sqrt(385) / 165;
wigner3j_coeffs(5398) = -sqrt(385) / 330;
wigner3j_coeffs(5406) = -4 * sqrt(385) / 1155;
wigner3j_coeffs(5414) = 17 * sqrt(385) / 2310;
wigner3j_coeffs(5422) = -2 * sqrt(385) / 231;
wigner3j_coeffs(5430) = 17 * sqrt(385) / 2310;
wigner3j_coeffs(5438) = -4 * sqrt(385) / 1155;
wigner3j_coeffs(5446) = -sqrt(385) / 330;
wigner3j_coeffs(5454) = 2 * sqrt(385) / 165;
wigner3j_coeffs(5470) = -sqrt(1155) / 165;
wigner3j_coeffs(5478) = sqrt(165) / 66;
wigner3j_coeffs(5486) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(5494) = sqrt(462) / 462;
wigner3j_coeffs(5502) = sqrt(462) / 462;
wigner3j_coeffs(5510) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(5518) = sqrt(165) / 66;
wigner3j_coeffs(5526) = -sqrt(1155) / 165;
wigner3j_coeffs(5550) = sqrt(330) / 165;
wigner3j_coeffs(5558) = -sqrt(330) / 110;
wigner3j_coeffs(5566) = sqrt(231) / 77;
wigner3j_coeffs(5574) = -sqrt(2310) / 231;
wigner3j_coeffs(5582) = sqrt(231) / 77;
wigner3j_coeffs(5590) = -sqrt(330) / 110;
wigner3j_coeffs(5598) = sqrt(330) / 165;
wigner3j_coeffs(5694) = sqrt(7) / 7;
wigner3j_coeffs(5700) = -sqrt(7) / 7;
wigner3j_coeffs(5706) = sqrt(7) / 7;
wigner3j_coeffs(5712) = -sqrt(7) / 7;
wigner3j_coeffs(5718) = sqrt(7) / 7;
wigner3j_coeffs(5724) = -sqrt(7) / 7;
wigner3j_coeffs(5730) = sqrt(7) / 7;
wigner3j_coeffs(5898) = sqrt(7) / 7;
wigner3j_coeffs(5908) = -sqrt(21) / 21;
wigner3j_coeffs(5912) = -sqrt(42) / 21;
wigner3j_coeffs(5918) = sqrt(105) / 105;
wigner3j_coeffs(5922) = 2 * sqrt(210) / 105;
wigner3j_coeffs(5926) = sqrt(70) / 35;
wigner3j_coeffs(5932) = -sqrt(35) / 35;
wigner3j_coeffs(5936) = -sqrt(105) / 35;
wigner3j_coeffs(5940) = -sqrt(35) / 35;
wigner3j_coeffs(5946) = sqrt(70) / 35;
wigner3j_coeffs(5950) = 2 * sqrt(210) / 105;
wigner3j_coeffs(5954) = sqrt(105) / 105;
wigner3j_coeffs(5960) = -sqrt(42) / 21;
wigner3j_coeffs(5964) = -sqrt(21) / 21;
wigner3j_coeffs(5974) = sqrt(7) / 7;
wigner3j_coeffs(6002) = sqrt(21) / 14;
wigner3j_coeffs(6008) = -sqrt(7) / 14;
wigner3j_coeffs(6016) = -sqrt(7) / 14;
wigner3j_coeffs(6022) = -sqrt(21) / 21;
wigner3j_coeffs(6028) = sqrt(105) / 42;
wigner3j_coeffs(6036) = sqrt(105) / 42;
wigner3j_coeffs(6042) = sqrt(21) / 42;
wigner3j_coeffs(6048) = -sqrt(14) / 14;
wigner3j_coeffs(6056) = -sqrt(14) / 14;
wigner3j_coeffs(6068) = sqrt(14) / 14;
wigner3j_coeffs(6076) = sqrt(14) / 14;
wigner3j_coeffs(6082) = -sqrt(21) / 42;
wigner3j_coeffs(6088) = -sqrt(105) / 42;
wigner3j_coeffs(6096) = -sqrt(105) / 42;
wigner3j_coeffs(6102) = sqrt(21) / 21;
wigner3j_coeffs(6108) = sqrt(7) / 14;
wigner3j_coeffs(6116) = sqrt(7) / 14;
wigner3j_coeffs(6122) = -sqrt(21) / 14;
wigner3j_coeffs(6144) = 1 / 3;
wigner3j_coeffs(6152) = -1 / 6;
wigner3j_coeffs(6160) = sqrt(7) / 42;
wigner3j_coeffs(6170) = -sqrt(3) / 6;
wigner3j_coeffs(6178) = sqrt(21) / 21;
wigner3j_coeffs(6186) = -sqrt(21) / 42;
wigner3j_coeffs(6196) = sqrt(105) / 42;
wigner3j_coeffs(6204) = -sqrt(105) / 42;
wigner3j_coeffs(6212) = sqrt(42) / 42;
wigner3j_coeffs(6222) = -sqrt(70) / 42;
wigner3j_coeffs(6230) = 2 * sqrt(7) / 21;
wigner3j_coeffs(6238) = -sqrt(70) / 42;
wigner3j_coeffs(6248) = sqrt(42) / 42;
wigner3j_coeffs(6256) = -sqrt(105) / 42;
wigner3j_coeffs(6264) = sqrt(105) / 42;
wigner3j_coeffs(6274) = -sqrt(21) / 42;
wigner3j_coeffs(6282) = sqrt(21) / 21;
wigner3j_coeffs(6290) = -sqrt(3) / 6;
wigner3j_coeffs(6300) = sqrt(7) / 42;
wigner3j_coeffs(6308) = -1 / 6;
wigner3j_coeffs(6316) = 1 / 3;
wigner3j_coeffs(6374) = sqrt(7) / 7;
wigner3j_coeffs(6386) = -sqrt(42) / 21;
wigner3j_coeffs(6388) = -sqrt(21) / 21;
wigner3j_coeffs(6398) = sqrt(70) / 35;
wigner3j_coeffs(6400) = 2 * sqrt(210) / 105;
wigner3j_coeffs(6402) = sqrt(105) / 105;
wigner3j_coeffs(6410) = -sqrt(35) / 35;
wigner3j_coeffs(6412) = -sqrt(105) / 35;
wigner3j_coeffs(6414) = -sqrt(35) / 35;
wigner3j_coeffs(6422) = sqrt(105) / 105;
wigner3j_coeffs(6424) = 2 * sqrt(210) / 105;
wigner3j_coeffs(6426) = sqrt(70) / 35;
wigner3j_coeffs(6436) = -sqrt(21) / 21;
wigner3j_coeffs(6438) = -sqrt(42) / 21;
wigner3j_coeffs(6450) = sqrt(7) / 7;
wigner3j_coeffs(6484) = sqrt(14) / 14;
wigner3j_coeffs(6488) = -sqrt(14) / 14;
wigner3j_coeffs(6504) = -sqrt(14) / 14;
wigner3j_coeffs(6512) = sqrt(14) / 14;
wigner3j_coeffs(6524) = sqrt(210) / 70;
wigner3j_coeffs(6528) = sqrt(35) / 35;
wigner3j_coeffs(6532) = -sqrt(35) / 35;
wigner3j_coeffs(6536) = -sqrt(210) / 70;
wigner3j_coeffs(6544) = -sqrt(70) / 70;
wigner3j_coeffs(6548) = -sqrt(70) / 35;
wigner3j_coeffs(6556) = sqrt(70) / 35;
wigner3j_coeffs(6560) = sqrt(70) / 70;
wigner3j_coeffs(6568) = sqrt(210) / 70;
wigner3j_coeffs(6572) = sqrt(35) / 35;
wigner3j_coeffs(6576) = -sqrt(35) / 35;
wigner3j_coeffs(6580) = -sqrt(210) / 70;
wigner3j_coeffs(6592) = -sqrt(14) / 14;
wigner3j_coeffs(6600) = sqrt(14) / 14;
wigner3j_coeffs(6616) = sqrt(14) / 14;
wigner3j_coeffs(6620) = -sqrt(14) / 14;
wigner3j_coeffs(6660) = sqrt(105) / 42;
wigner3j_coeffs(6666) = -sqrt(105) / 42;
wigner3j_coeffs(6672) = sqrt(42) / 42;
wigner3j_coeffs(6688) = -sqrt(105) / 42;
wigner3j_coeffs(6700) = sqrt(7) / 14;
wigner3j_coeffs(6706) = -sqrt(21) / 21;
wigner3j_coeffs(6716) = sqrt(42) / 42;
wigner3j_coeffs(6722) = sqrt(7) / 14;
wigner3j_coeffs(6728) = -sqrt(105) / 70;
wigner3j_coeffs(6734) = -sqrt(210) / 210;
wigner3j_coeffs(6740) = sqrt(70) / 35;
wigner3j_coeffs(6750) = -sqrt(21) / 21;
wigner3j_coeffs(6756) = -sqrt(210) / 210;
wigner3j_coeffs(6762) = 2 * sqrt(105) / 105;
wigner3j_coeffs(6768) = -sqrt(210) / 210;
wigner3j_coeffs(6774) = -sqrt(21) / 21;
wigner3j_coeffs(6784) = sqrt(70) / 35;
wigner3j_coeffs(6790) = -sqrt(210) / 210;
wigner3j_coeffs(6796) = -sqrt(105) / 70;
wigner3j_coeffs(6802) = sqrt(7) / 14;
wigner3j_coeffs(6808) = sqrt(42) / 42;
wigner3j_coeffs(6818) = -sqrt(21) / 21;
wigner3j_coeffs(6824) = sqrt(7) / 14;
wigner3j_coeffs(6836) = -sqrt(105) / 42;
wigner3j_coeffs(6852) = sqrt(42) / 42;
wigner3j_coeffs(6858) = -sqrt(105) / 42;
wigner3j_coeffs(6864) = sqrt(105) / 42;
wigner3j_coeffs(6902) = sqrt(15) / 15;
wigner3j_coeffs(6910) = -sqrt(5) / 10;
wigner3j_coeffs(6918) = sqrt(105) / 70;
wigner3j_coeffs(6926) = -sqrt(210) / 210;
wigner3j_coeffs(6938) = -sqrt(10) / 15;
wigner3j_coeffs(6946) = -sqrt(5) / 30;
wigner3j_coeffs(6954) = 2 * sqrt(105) / 105;
wigner3j_coeffs(6962) = -sqrt(35) / 30;
wigner3j_coeffs(6970) = sqrt(7) / 21;
wigner3j_coeffs(6982) = sqrt(2) / 6;
wigner3j_coeffs(6990) = -sqrt(7) / 42;
wigner3j_coeffs(6998) = -sqrt(21) / 42;
wigner3j_coeffs(7006) = sqrt(70) / 42;
wigner3j_coeffs(7014) = -sqrt(14) / 21;
wigner3j_coeffs(7026) = -sqrt(21) / 21;
wigner3j_coeffs(7034) = sqrt(42) / 42;
wigner3j_coeffs(7050) = -sqrt(42) / 42;
wigner3j_coeffs(7058) = sqrt(21) / 21;
wigner3j_coeffs(7070) = sqrt(14) / 21;
wigner3j_coeffs(7078) = -sqrt(70) / 42;
wigner3j_coeffs(7086) = sqrt(21) / 42;
wigner3j_coeffs(7094) = sqrt(7) / 42;
wigner3j_coeffs(7102) = -sqrt(2) / 6;
wigner3j_coeffs(7114) = -sqrt(7) / 21;
wigner3j_coeffs(7122) = sqrt(35) / 30;
wigner3j_coeffs(7130) = -2 * sqrt(105) / 105;
wigner3j_coeffs(7138) = sqrt(5) / 30;
wigner3j_coeffs(7146) = sqrt(10) / 15;
wigner3j_coeffs(7158) = sqrt(210) / 210;
wigner3j_coeffs(7166) = -sqrt(105) / 70;
wigner3j_coeffs(7174) = sqrt(5) / 10;
wigner3j_coeffs(7182) = -sqrt(15) / 15;
wigner3j_coeffs(7206) = sqrt(7) / 7;
wigner3j_coeffs(7212) = -sqrt(7) / 7;
wigner3j_coeffs(7218) = sqrt(7) / 7;
wigner3j_coeffs(7224) = -sqrt(7) / 7;
wigner3j_coeffs(7230) = sqrt(7) / 7;
wigner3j_coeffs(7236) = -sqrt(7) / 7;
wigner3j_coeffs(7242) = sqrt(7) / 7;
wigner3j_coeffs(7266) = sqrt(7) / 14;
wigner3j_coeffs(7268) = -sqrt(21) / 14;
wigner3j_coeffs(7284) = -sqrt(105) / 42;
wigner3j_coeffs(7286) = sqrt(21) / 21;
wigner3j_coeffs(7288) = sqrt(7) / 14;
wigner3j_coeffs(7302) = sqrt(14) / 14;
wigner3j_coeffs(7304) = -sqrt(21) / 42;
wigner3j_coeffs(7306) = -sqrt(105) / 42;
wigner3j_coeffs(7320) = -sqrt(14) / 14;
wigner3j_coeffs(7324) = sqrt(14) / 14;
wigner3j_coeffs(7338) = sqrt(105) / 42;
wigner3j_coeffs(7340) = sqrt(21) / 42;
wigner3j_coeffs(7342) = -sqrt(14) / 14;
wigner3j_coeffs(7356) = -sqrt(7) / 14;
wigner3j_coeffs(7358) = -sqrt(21) / 21;
wigner3j_coeffs(7360) = sqrt(105) / 42;
wigner3j_coeffs(7376) = sqrt(21) / 14;
wigner3j_coeffs(7378) = -sqrt(7) / 14;
wigner3j_coeffs(7420) = sqrt(42) / 42;
wigner3j_coeffs(7424) = -sqrt(105) / 42;
wigner3j_coeffs(7428) = sqrt(105) / 42;
wigner3j_coeffs(7450) = -sqrt(21) / 21;
wigner3j_coeffs(7454) = sqrt(7) / 14;
wigner3j_coeffs(7462) = -sqrt(105) / 42;
wigner3j_coeffs(7480) = sqrt(70) / 35;
wigner3j_coeffs(7484) = -sqrt(210) / 210;
wigner3j_coeffs(7488) = -sqrt(105) / 70;
wigner3j_coeffs(7492) = sqrt(7) / 14;
wigner3j_coeffs(7496) = sqrt(42) / 42;
wigner3j_coeffs(7510) = -sqrt(21) / 21;
wigner3j_coeffs(7514) = -sqrt(210) / 210;
wigner3j_coeffs(7518) = 2 * sqrt(105) / 105;
wigner3j_coeffs(7522) = -sqrt(210) / 210;
wigner3j_coeffs(7526) = -sqrt(21) / 21;
wigner3j_coeffs(7540) = sqrt(42) / 42;
wigner3j_coeffs(7544) = sqrt(7) / 14;
wigner3j_coeffs(7548) = -sqrt(105) / 70;
wigner3j_coeffs(7552) = -sqrt(210) / 210;
wigner3j_coeffs(7556) = sqrt(70) / 35;
wigner3j_coeffs(7574) = -sqrt(105) / 42;
wigner3j_coeffs(7582) = sqrt(7) / 14;
wigner3j_coeffs(7586) = -sqrt(21) / 21;
wigner3j_coeffs(7608) = sqrt(105) / 42;
wigner3j_coeffs(7612) = -sqrt(105) / 42;
wigner3j_coeffs(7616) = sqrt(42) / 42;
wigner3j_coeffs(7668) = sqrt(42) / 42;
wigner3j_coeffs(7674) = -sqrt(21) / 21;
wigner3j_coeffs(7680) = sqrt(21) / 21;
wigner3j_coeffs(7686) = -sqrt(42) / 42;
wigner3j_coeffs(7710) = -sqrt(21) / 21;
wigner3j_coeffs(7716) = sqrt(42) / 42;
wigner3j_coeffs(7728) = -sqrt(42) / 42;
wigner3j_coeffs(7734) = sqrt(21) / 21;
wigner3j_coeffs(7752) = sqrt(21) / 21;
wigner3j_coeffs(7764) = -sqrt(42) / 42;
wigner3j_coeffs(7770) = sqrt(42) / 42;
wigner3j_coeffs(7782) = -sqrt(21) / 21;
wigner3j_coeffs(7794) = -sqrt(42) / 42;
wigner3j_coeffs(7800) = -sqrt(42) / 42;
wigner3j_coeffs(7806) = sqrt(42) / 42;
wigner3j_coeffs(7818) = -sqrt(42) / 42;
wigner3j_coeffs(7824) = sqrt(42) / 42;
wigner3j_coeffs(7830) = sqrt(42) / 42;
wigner3j_coeffs(7842) = sqrt(21) / 21;
wigner3j_coeffs(7854) = -sqrt(42) / 42;
wigner3j_coeffs(7860) = sqrt(42) / 42;
wigner3j_coeffs(7872) = -sqrt(21) / 21;
wigner3j_coeffs(7890) = -sqrt(21) / 21;
wigner3j_coeffs(7896) = sqrt(42) / 42;
wigner3j_coeffs(7908) = -sqrt(42) / 42;
wigner3j_coeffs(7914) = sqrt(21) / 21;
wigner3j_coeffs(7938) = sqrt(42) / 42;
wigner3j_coeffs(7944) = -sqrt(21) / 21;
wigner3j_coeffs(7950) = sqrt(21) / 21;
wigner3j_coeffs(7956) = -sqrt(42) / 42;
wigner3j_coeffs(8010) = sqrt(33) / 33;
wigner3j_coeffs(8018) = -sqrt(22) / 22;
wigner3j_coeffs(8026) = sqrt(231) / 77;
wigner3j_coeffs(8034) = -sqrt(1155) / 231;
wigner3j_coeffs(8042) = sqrt(154) / 154;
wigner3j_coeffs(8064) = -sqrt(55) / 33;
wigner3j_coeffs(8072) = sqrt(11) / 33;
wigner3j_coeffs(8080) = sqrt(462) / 462;
wigner3j_coeffs(8088) = -4 * sqrt(77) / 231;
wigner3j_coeffs(8096) = sqrt(154) / 66;
wigner3j_coeffs(8104) = -sqrt(1155) / 231;
wigner3j_coeffs(8118) = sqrt(33) / 33;
wigner3j_coeffs(8126) = sqrt(11) / 33;
wigner3j_coeffs(8134) = -2 * sqrt(385) / 231;
wigner3j_coeffs(8142) = sqrt(2310) / 462;
wigner3j_coeffs(8150) = sqrt(154) / 462;
wigner3j_coeffs(8158) = -4 * sqrt(77) / 231;
wigner3j_coeffs(8166) = sqrt(231) / 77;
wigner3j_coeffs(8180) = -sqrt(22) / 22;
wigner3j_coeffs(8188) = sqrt(462) / 462;
wigner3j_coeffs(8196) = sqrt(2310) / 462;
wigner3j_coeffs(8204) = -sqrt(154) / 77;
wigner3j_coeffs(8212) = sqrt(2310) / 462;
wigner3j_coeffs(8220) = sqrt(462) / 462;
wigner3j_coeffs(8228) = -sqrt(22) / 22;
wigner3j_coeffs(8242) = sqrt(231) / 77;
wigner3j_coeffs(8250) = -4 * sqrt(77) / 231;
wigner3j_coeffs(8258) = sqrt(154) / 462;
wigner3j_coeffs(8266) = sqrt(2310) / 462;
wigner3j_coeffs(8274) = -2 * sqrt(385) / 231;
wigner3j_coeffs(8282) = sqrt(11) / 33;
wigner3j_coeffs(8290) = sqrt(33) / 33;
wigner3j_coeffs(8304) = -sqrt(1155) / 231;
wigner3j_coeffs(8312) = sqrt(154) / 66;
wigner3j_coeffs(8320) = -4 * sqrt(77) / 231;
wigner3j_coeffs(8328) = sqrt(462) / 462;
wigner3j_coeffs(8336) = sqrt(11) / 33;
wigner3j_coeffs(8344) = -sqrt(55) / 33;
wigner3j_coeffs(8366) = sqrt(154) / 154;
wigner3j_coeffs(8374) = -sqrt(1155) / 231;
wigner3j_coeffs(8382) = sqrt(231) / 77;
wigner3j_coeffs(8390) = -sqrt(22) / 22;
wigner3j_coeffs(8398) = sqrt(33) / 33;
wigner3j_coeffs(8508) = sqrt(7) / 42;
wigner3j_coeffs(8510) = -1 / 6;
wigner3j_coeffs(8512) = 1 / 3;
wigner3j_coeffs(8532) = -sqrt(21) / 42;
wigner3j_coeffs(8534) = sqrt(21) / 21;
wigner3j_coeffs(8536) = -sqrt(3) / 6;
wigner3j_coeffs(8556) = sqrt(42) / 42;
wigner3j_coeffs(8558) = -sqrt(105) / 42;
wigner3j_coeffs(8560) = sqrt(105) / 42;
wigner3j_coeffs(8580) = -sqrt(70) / 42;
wigner3j_coeffs(8582) = 2 * sqrt(7) / 21;
wigner3j_coeffs(8584) = -sqrt(70) / 42;
wigner3j_coeffs(8604) = sqrt(105) / 42;
wigner3j_coeffs(8606) = -sqrt(105) / 42;
wigner3j_coeffs(8608) = sqrt(42) / 42;
wigner3j_coeffs(8628) = -sqrt(3) / 6;
wigner3j_coeffs(8630) = sqrt(21) / 21;
wigner3j_coeffs(8632) = -sqrt(21) / 42;
wigner3j_coeffs(8652) = 1 / 3;
wigner3j_coeffs(8654) = -1 / 6;
wigner3j_coeffs(8656) = sqrt(7) / 42;
wigner3j_coeffs(8706) = sqrt(210) / 210;
wigner3j_coeffs(8710) = -sqrt(105) / 70;
wigner3j_coeffs(8714) = sqrt(5) / 10;
wigner3j_coeffs(8718) = -sqrt(15) / 15;
wigner3j_coeffs(8746) = -sqrt(7) / 21;
wigner3j_coeffs(8750) = sqrt(35) / 30;
wigner3j_coeffs(8754) = -2 * sqrt(105) / 105;
wigner3j_coeffs(8758) = sqrt(5) / 30;
wigner3j_coeffs(8762) = sqrt(10) / 15;
wigner3j_coeffs(8786) = sqrt(14) / 21;
wigner3j_coeffs(8790) = -sqrt(70) / 42;
wigner3j_coeffs(8794) = sqrt(21) / 42;
wigner3j_coeffs(8798) = sqrt(7) / 42;
wigner3j_coeffs(8802) = -sqrt(2) / 6;
wigner3j_coeffs(8826) = -sqrt(21) / 21;
wigner3j_coeffs(8830) = sqrt(42) / 42;
wigner3j_coeffs(8838) = -sqrt(42) / 42;
wigner3j_coeffs(8842) = sqrt(21) / 21;
wigner3j_coeffs(8866) = sqrt(2) / 6;
wigner3j_coeffs(8870) = -sqrt(7) / 42;
wigner3j_coeffs(8874) = -sqrt(21) / 42;
wigner3j_coeffs(8878) = sqrt(70) / 42;
wigner3j_coeffs(8882) = -sqrt(14) / 21;
wigner3j_coeffs(8906) = -sqrt(10) / 15;
wigner3j_coeffs(8910) = -sqrt(5) / 30;
wigner3j_coeffs(8914) = 2 * sqrt(105) / 105;
wigner3j_coeffs(8918) = -sqrt(35) / 30;
wigner3j_coeffs(8922) = sqrt(7) / 21;
wigner3j_coeffs(8950) = sqrt(15) / 15;
wigner3j_coeffs(8954) = -sqrt(5) / 10;
wigner3j_coeffs(8958) = sqrt(105) / 70;
wigner3j_coeffs(8962) = -sqrt(210) / 210;
wigner3j_coeffs(9026) = sqrt(154) / 154;
wigner3j_coeffs(9032) = -sqrt(1155) / 231;
wigner3j_coeffs(9038) = sqrt(231) / 77;
wigner3j_coeffs(9044) = -sqrt(22) / 22;
wigner3j_coeffs(9050) = sqrt(33) / 33;
wigner3j_coeffs(9082) = -sqrt(1155) / 231;
wigner3j_coeffs(9088) = sqrt(154) / 66;
wigner3j_coeffs(9094) = -4 * sqrt(77) / 231;
wigner3j_coeffs(9100) = sqrt(462) / 462;
wigner3j_coeffs(9106) = sqrt(11) / 33;
wigner3j_coeffs(9112) = -sqrt(55) / 33;
wigner3j_coeffs(9138) = sqrt(231) / 77;
wigner3j_coeffs(9144) = -4 * sqrt(77) / 231;
wigner3j_coeffs(9150) = sqrt(154) / 462;
wigner3j_coeffs(9156) = sqrt(2310) / 462;
wigner3j_coeffs(9162) = -2 * sqrt(385) / 231;
wigner3j_coeffs(9168) = sqrt(11) / 33;
wigner3j_coeffs(9174) = sqrt(33) / 33;
wigner3j_coeffs(9194) = -sqrt(22) / 22;
wigner3j_coeffs(9200) = sqrt(462) / 462;
wigner3j_coeffs(9206) = sqrt(2310) / 462;
wigner3j_coeffs(9212) = -sqrt(154) / 77;
wigner3j_coeffs(9218) = sqrt(2310) / 462;
wigner3j_coeffs(9224) = sqrt(462) / 462;
wigner3j_coeffs(9230) = -sqrt(22) / 22;
wigner3j_coeffs(9250) = sqrt(33) / 33;
wigner3j_coeffs(9256) = sqrt(11) / 33;
wigner3j_coeffs(9262) = -2 * sqrt(385) / 231;
wigner3j_coeffs(9268) = sqrt(2310) / 462;
wigner3j_coeffs(9274) = sqrt(154) / 462;
wigner3j_coeffs(9280) = -4 * sqrt(77) / 231;
wigner3j_coeffs(9286) = sqrt(231) / 77;
wigner3j_coeffs(9312) = -sqrt(55) / 33;
wigner3j_coeffs(9318) = sqrt(11) / 33;
wigner3j_coeffs(9324) = sqrt(462) / 462;
wigner3j_coeffs(9330) = -4 * sqrt(77) / 231;
wigner3j_coeffs(9336) = sqrt(154) / 66;
wigner3j_coeffs(9342) = -sqrt(1155) / 231;
wigner3j_coeffs(9374) = sqrt(33) / 33;
wigner3j_coeffs(9380) = -sqrt(22) / 22;
wigner3j_coeffs(9386) = sqrt(231) / 77;
wigner3j_coeffs(9392) = -sqrt(1155) / 231;
wigner3j_coeffs(9398) = sqrt(154) / 154;
wigner3j_coeffs(9468) = sqrt(11) / 33;
wigner3j_coeffs(9476) = -sqrt(110) / 66;
wigner3j_coeffs(9484) = 5 * sqrt(77) / 231;
wigner3j_coeffs(9492) = -5 * sqrt(77) / 231;
wigner3j_coeffs(9500) = sqrt(110) / 66;
wigner3j_coeffs(9508) = -sqrt(11) / 33;
wigner3j_coeffs(9540) = -sqrt(33) / 33;
wigner3j_coeffs(9548) = sqrt(33) / 33;
wigner3j_coeffs(9556) = -sqrt(2310) / 462;
wigner3j_coeffs(9572) = sqrt(2310) / 462;
wigner3j_coeffs(9580) = -sqrt(33) / 33;
wigner3j_coeffs(9588) = sqrt(33) / 33;
wigner3j_coeffs(9612) = sqrt(1155) / 165;
wigner3j_coeffs(9620) = -sqrt(165) / 165;
wigner3j_coeffs(9628) = -2 * sqrt(1155) / 1155;
wigner3j_coeffs(9636) = sqrt(462) / 154;
wigner3j_coeffs(9644) = -sqrt(462) / 154;
wigner3j_coeffs(9652) = 2 * sqrt(1155) / 1155;
wigner3j_coeffs(9660) = sqrt(165) / 165;
wigner3j_coeffs(9668) = -sqrt(1155) / 165;
wigner3j_coeffs(9684) = -sqrt(770) / 165;
wigner3j_coeffs(9692) = -sqrt(770) / 330;
wigner3j_coeffs(9700) = 13 * sqrt(770) / 2310;
wigner3j_coeffs(9708) = -3 * sqrt(770) / 770;
wigner3j_coeffs(9724) = 3 * sqrt(770) / 770;
wigner3j_coeffs(9732) = -13 * sqrt(770) / 2310;
wigner3j_coeffs(9740) = sqrt(770) / 330;
wigner3j_coeffs(9748) = sqrt(770) / 165;
wigner3j_coeffs(9764) = sqrt(1155) / 165;
wigner3j_coeffs(9772) = -sqrt(165) / 165;
wigner3j_coeffs(9780) = -2 * sqrt(1155) / 1155;
wigner3j_coeffs(9788) = sqrt(462) / 154;
wigner3j_coeffs(9796) = -sqrt(462) / 154;
wigner3j_coeffs(9804) = 2 * sqrt(1155) / 1155;
wigner3j_coeffs(9812) = sqrt(165) / 165;
wigner3j_coeffs(9820) = -sqrt(1155) / 165;
wigner3j_coeffs(9844) = -sqrt(33) / 33;
wigner3j_coeffs(9852) = sqrt(33) / 33;
wigner3j_coeffs(9860) = -sqrt(2310) / 462;
wigner3j_coeffs(9876) = sqrt(2310) / 462;
wigner3j_coeffs(9884) = -sqrt(33) / 33;
wigner3j_coeffs(9892) = sqrt(33) / 33;
wigner3j_coeffs(9924) = sqrt(11) / 33;
wigner3j_coeffs(9932) = -sqrt(110) / 66;
wigner3j_coeffs(9940) = 5 * sqrt(77) / 231;
wigner3j_coeffs(9948) = -5 * sqrt(77) / 231;
wigner3j_coeffs(9956) = sqrt(110) / 66;
wigner3j_coeffs(9964) = -sqrt(11) / 33;
wigner3j_coeffs(10152) = 1 / 3;
wigner3j_coeffs(10160) = -1 / 3;
wigner3j_coeffs(10168) = 1 / 3;
wigner3j_coeffs(10176) = -1 / 3;
wigner3j_coeffs(10184) = 1 / 3;
wigner3j_coeffs(10192) = -1 / 3;
wigner3j_coeffs(10200) = 1 / 3;
wigner3j_coeffs(10208) = -1 / 3;
wigner3j_coeffs(10216) = 1 / 3;
wigner3j_coeffs(10488) = 1 / 3;
wigner3j_coeffs(10502) = -1 / 6;
wigner3j_coeffs(10508) = -sqrt(3) / 6;
wigner3j_coeffs(10516) = sqrt(7) / 42;
wigner3j_coeffs(10522) = sqrt(21) / 21;
wigner3j_coeffs(10528) = sqrt(105) / 42;
wigner3j_coeffs(10536) = -sqrt(21) / 42;
wigner3j_coeffs(10542) = -sqrt(105) / 42;
wigner3j_coeffs(10548) = -sqrt(70) / 42;
wigner3j_coeffs(10556) = sqrt(42) / 42;
wigner3j_coeffs(10562) = 2 * sqrt(7) / 21;
wigner3j_coeffs(10568) = sqrt(42) / 42;
wigner3j_coeffs(10576) = -sqrt(70) / 42;
wigner3j_coeffs(10582) = -sqrt(105) / 42;
wigner3j_coeffs(10588) = -sqrt(21) / 42;
wigner3j_coeffs(10596) = sqrt(105) / 42;
wigner3j_coeffs(10602) = sqrt(21) / 21;
wigner3j_coeffs(10608) = sqrt(7) / 42;
wigner3j_coeffs(10616) = -sqrt(3) / 6;
wigner3j_coeffs(10622) = -1 / 6;
wigner3j_coeffs(10636) = 1 / 3;
wigner3j_coeffs(10674) = 2 * sqrt(5) / 15;
wigner3j_coeffs(10682) = -sqrt(5) / 15;
wigner3j_coeffs(10692) = -sqrt(5) / 15;
wigner3j_coeffs(10700) = -sqrt(5) / 10;
wigner3j_coeffs(10708) = sqrt(35) / 30;
wigner3j_coeffs(10718) = sqrt(35) / 30;
wigner3j_coeffs(10726) = sqrt(5) / 15;
wigner3j_coeffs(10734) = -sqrt(5) / 10;
wigner3j_coeffs(10744) = -sqrt(5) / 10;
wigner3j_coeffs(10752) = -sqrt(5) / 30;
wigner3j_coeffs(10760) = sqrt(2) / 6;
wigner3j_coeffs(10770) = sqrt(2) / 6;
wigner3j_coeffs(10786) = -sqrt(2) / 6;
wigner3j_coeffs(10796) = -sqrt(2) / 6;
wigner3j_coeffs(10804) = sqrt(5) / 30;
wigner3j_coeffs(10812) = sqrt(5) / 10;
wigner3j_coeffs(10822) = sqrt(5) / 10;
wigner3j_coeffs(10830) = -sqrt(5) / 15;
wigner3j_coeffs(10838) = -sqrt(35) / 30;
wigner3j_coeffs(10848) = -sqrt(35) / 30;
wigner3j_coeffs(10856) = sqrt(5) / 10;
wigner3j_coeffs(10864) = sqrt(5) / 15;
wigner3j_coeffs(10874) = sqrt(5) / 15;
wigner3j_coeffs(10882) = -2 * sqrt(5) / 15;
wigner3j_coeffs(11104) = 1 / 3;
wigner3j_coeffs(11124) = -sqrt(2) / 6;
wigner3j_coeffs(11128) = -sqrt(2) / 6;
wigner3j_coeffs(11144) = sqrt(42) / 42;
wigner3j_coeffs(11148) = 2 * sqrt(7) / 21;
wigner3j_coeffs(11152) = sqrt(42) / 42;
wigner3j_coeffs(11164) = -sqrt(14) / 42;
wigner3j_coeffs(11168) = -sqrt(21) / 21;
wigner3j_coeffs(11172) = -sqrt(21) / 21;
wigner3j_coeffs(11176) = -sqrt(14) / 42;
wigner3j_coeffs(11184) = sqrt(70) / 210;
wigner3j_coeffs(11188) = 2 * sqrt(70) / 105;
wigner3j_coeffs(11192) = sqrt(70) / 35;
wigner3j_coeffs(11196) = 2 * sqrt(70) / 105;
wigner3j_coeffs(11200) = sqrt(70) / 210;
wigner3j_coeffs(11208) = -sqrt(14) / 42;
wigner3j_coeffs(11212) = -sqrt(21) / 21;
wigner3j_coeffs(11216) = -sqrt(21) / 21;
wigner3j_coeffs(11220) = -sqrt(14) / 42;
wigner3j_coeffs(11232) = sqrt(42) / 42;
wigner3j_coeffs(11236) = 2 * sqrt(7) / 21;
wigner3j_coeffs(11240) = sqrt(42) / 42;
wigner3j_coeffs(11256) = -sqrt(2) / 6;
wigner3j_coeffs(11260) = -sqrt(2) / 6;
wigner3j_coeffs(11280) = 1 / 3;
wigner3j_coeffs(11332) = sqrt(15) / 15;
wigner3j_coeffs(11338) = -sqrt(10) / 15;
wigner3j_coeffs(11360) = -sqrt(5) / 10;
wigner3j_coeffs(11366) = -sqrt(5) / 30;
wigner3j_coeffs(11372) = sqrt(2) / 6;
wigner3j_coeffs(11388) = sqrt(105) / 70;
wigner3j_coeffs(11394) = 2 * sqrt(105) / 105;
wigner3j_coeffs(11400) = -sqrt(7) / 42;
wigner3j_coeffs(11406) = -sqrt(21) / 21;
wigner3j_coeffs(11416) = -sqrt(210) / 210;
wigner3j_coeffs(11422) = -sqrt(35) / 30;
wigner3j_coeffs(11428) = -sqrt(21) / 42;
wigner3j_coeffs(11434) = sqrt(42) / 42;
wigner3j_coeffs(11440) = sqrt(14) / 21;
wigner3j_coeffs(11450) = sqrt(7) / 21;
wigner3j_coeffs(11456) = sqrt(70) / 42;
wigner3j_coeffs(11468) = -sqrt(70) / 42;
wigner3j_coeffs(11474) = -sqrt(7) / 21;
wigner3j_coeffs(11484) = -sqrt(14) / 21;
wigner3j_coeffs(11490) = -sqrt(42) / 42;
wigner3j_coeffs(11496) = sqrt(21) / 42;
wigner3j_coeffs(11502) = sqrt(35) / 30;
wigner3j_coeffs(11508) = sqrt(210) / 210;
wigner3j_coeffs(11518) = sqrt(21) / 21;
wigner3j_coeffs(11524) = sqrt(7) / 42;
wigner3j_coeffs(11530) = -2 * sqrt(105) / 105;
wigner3j_coeffs(11536) = -sqrt(105) / 70;
wigner3j_coeffs(11552) = -sqrt(2) / 6;
wigner3j_coeffs(11558) = sqrt(5) / 30;
wigner3j_coeffs(11564) = sqrt(5) / 10;
wigner3j_coeffs(11586) = sqrt(10) / 15;
wigner3j_coeffs(11592) = -sqrt(15) / 15;
wigner3j_coeffs(11646) = 2 * sqrt(385) / 165;
wigner3j_coeffs(11654) = -sqrt(1155) / 165;
wigner3j_coeffs(11662) = sqrt(330) / 165;
wigner3j_coeffs(11682) = -sqrt(1155) / 165;
wigner3j_coeffs(11690) = -sqrt(385) / 330;
wigner3j_coeffs(11698) = sqrt(165) / 66;
wigner3j_coeffs(11706) = -sqrt(330) / 110;
wigner3j_coeffs(11718) = sqrt(330) / 165;
wigner3j_coeffs(11726) = sqrt(165) / 66;
wigner3j_coeffs(11734) = -4 * sqrt(385) / 1155;
wigner3j_coeffs(11742) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(11750) = sqrt(231) / 77;
wigner3j_coeffs(11762) = -sqrt(330) / 110;
wigner3j_coeffs(11770) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(11778) = 17 * sqrt(385) / 2310;
wigner3j_coeffs(11786) = sqrt(462) / 462;
wigner3j_coeffs(11794) = -sqrt(2310) / 231;
wigner3j_coeffs(11806) = sqrt(231) / 77;
wigner3j_coeffs(11814) = sqrt(462) / 462;
wigner3j_coeffs(11822) = -2 * sqrt(385) / 231;
wigner3j_coeffs(11830) = sqrt(462) / 462;
wigner3j_coeffs(11838) = sqrt(231) / 77;
wigner3j_coeffs(11850) = -sqrt(2310) / 231;
wigner3j_coeffs(11858) = sqrt(462) / 462;
wigner3j_coeffs(11866) = 17 * sqrt(385) / 2310;
wigner3j_coeffs(11874) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(11882) = -sqrt(330) / 110;
wigner3j_coeffs(11894) = sqrt(231) / 77;
wigner3j_coeffs(11902) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(11910) = -4 * sqrt(385) / 1155;
wigner3j_coeffs(11918) = sqrt(165) / 66;
wigner3j_coeffs(11926) = sqrt(330) / 165;
wigner3j_coeffs(11938) = -sqrt(330) / 110;
wigner3j_coeffs(11946) = sqrt(165) / 66;
wigner3j_coeffs(11954) = -sqrt(385) / 330;
wigner3j_coeffs(11962) = -sqrt(1155) / 165;
wigner3j_coeffs(11982) = sqrt(330) / 165;
wigner3j_coeffs(11990) = -sqrt(1155) / 165;
wigner3j_coeffs(11998) = 2 * sqrt(385) / 165;
wigner3j_coeffs(12108) = 1 / 3;
wigner3j_coeffs(12126) = -sqrt(3) / 6;
wigner3j_coeffs(12128) = -1 / 6;
wigner3j_coeffs(12144) = sqrt(105) / 42;
wigner3j_coeffs(12146) = sqrt(21) / 21;
wigner3j_coeffs(12148) = sqrt(7) / 42;
wigner3j_coeffs(12162) = -sqrt(70) / 42;
wigner3j_coeffs(12164) = -sqrt(105) / 42;
wigner3j_coeffs(12166) = -sqrt(21) / 42;
wigner3j_coeffs(12180) = sqrt(42) / 42;
wigner3j_coeffs(12182) = 2 * sqrt(7) / 21;
wigner3j_coeffs(12184) = sqrt(42) / 42;
wigner3j_coeffs(12198) = -sqrt(21) / 42;
wigner3j_coeffs(12200) = -sqrt(105) / 42;
wigner3j_coeffs(12202) = -sqrt(70) / 42;
wigner3j_coeffs(12216) = sqrt(7) / 42;
wigner3j_coeffs(12218) = sqrt(21) / 21;
wigner3j_coeffs(12220) = sqrt(105) / 42;
wigner3j_coeffs(12236) = -1 / 6;
wigner3j_coeffs(12238) = -sqrt(3) / 6;
wigner3j_coeffs(12256) = 1 / 3;
wigner3j_coeffs(12306) = sqrt(10) / 15;
wigner3j_coeffs(12310) = -sqrt(15) / 15;
wigner3j_coeffs(12336) = -sqrt(2) / 6;
wigner3j_coeffs(12340) = sqrt(5) / 30;
wigner3j_coeffs(12344) = sqrt(5) / 10;
wigner3j_coeffs(12366) = sqrt(21) / 21;
wigner3j_coeffs(12370) = sqrt(7) / 42;
wigner3j_coeffs(12374) = -2 * sqrt(105) / 105;
wigner3j_coeffs(12378) = -sqrt(105) / 70;
wigner3j_coeffs(12396) = -sqrt(14) / 21;
wigner3j_coeffs(12400) = -sqrt(42) / 42;
wigner3j_coeffs(12404) = sqrt(21) / 42;
wigner3j_coeffs(12408) = sqrt(35) / 30;
wigner3j_coeffs(12412) = sqrt(210) / 210;
wigner3j_coeffs(12426) = sqrt(7) / 21;
wigner3j_coeffs(12430) = sqrt(70) / 42;
wigner3j_coeffs(12438) = -sqrt(70) / 42;
wigner3j_coeffs(12442) = -sqrt(7) / 21;
wigner3j_coeffs(12456) = -sqrt(210) / 210;
wigner3j_coeffs(12460) = -sqrt(35) / 30;
wigner3j_coeffs(12464) = -sqrt(21) / 42;
wigner3j_coeffs(12468) = sqrt(42) / 42;
wigner3j_coeffs(12472) = sqrt(14) / 21;
wigner3j_coeffs(12490) = sqrt(105) / 70;
wigner3j_coeffs(12494) = 2 * sqrt(105) / 105;
wigner3j_coeffs(12498) = -sqrt(7) / 42;
wigner3j_coeffs(12502) = -sqrt(21) / 21;
wigner3j_coeffs(12524) = -sqrt(5) / 10;
wigner3j_coeffs(12528) = -sqrt(5) / 30;
wigner3j_coeffs(12532) = sqrt(2) / 6;
wigner3j_coeffs(12558) = sqrt(15) / 15;
wigner3j_coeffs(12562) = -sqrt(10) / 15;
wigner3j_coeffs(12626) = sqrt(33) / 33;
wigner3j_coeffs(12632) = -sqrt(55) / 33;
wigner3j_coeffs(12638) = sqrt(33) / 33;
wigner3j_coeffs(12668) = -sqrt(22) / 22;
wigner3j_coeffs(12674) = sqrt(11) / 33;
wigner3j_coeffs(12680) = sqrt(11) / 33;
wigner3j_coeffs(12686) = -sqrt(22) / 22;
wigner3j_coeffs(12710) = sqrt(231) / 77;
wigner3j_coeffs(12716) = sqrt(462) / 462;
wigner3j_coeffs(12722) = -2 * sqrt(385) / 231;
wigner3j_coeffs(12728) = sqrt(462) / 462;
wigner3j_coeffs(12734) = sqrt(231) / 77;
wigner3j_coeffs(12752) = -sqrt(1155) / 231;
wigner3j_coeffs(12758) = -4 * sqrt(77) / 231;
wigner3j_coeffs(12764) = sqrt(2310) / 462;
wigner3j_coeffs(12770) = sqrt(2310) / 462;
wigner3j_coeffs(12776) = -4 * sqrt(77) / 231;
wigner3j_coeffs(12782) = -sqrt(1155) / 231;
wigner3j_coeffs(12794) = sqrt(154) / 154;
wigner3j_coeffs(12800) = sqrt(154) / 66;
wigner3j_coeffs(12806) = sqrt(154) / 462;
wigner3j_coeffs(12812) = -sqrt(154) / 77;
wigner3j_coeffs(12818) = sqrt(154) / 462;
wigner3j_coeffs(12824) = sqrt(154) / 66;
wigner3j_coeffs(12830) = sqrt(154) / 154;
wigner3j_coeffs(12842) = -sqrt(1155) / 231;
wigner3j_coeffs(12848) = -4 * sqrt(77) / 231;
wigner3j_coeffs(12854) = sqrt(2310) / 462;
wigner3j_coeffs(12860) = sqrt(2310) / 462;
wigner3j_coeffs(12866) = -4 * sqrt(77) / 231;
wigner3j_coeffs(12872) = -sqrt(1155) / 231;
wigner3j_coeffs(12890) = sqrt(231) / 77;
wigner3j_coeffs(12896) = sqrt(462) / 462;
wigner3j_coeffs(12902) = -2 * sqrt(385) / 231;
wigner3j_coeffs(12908) = sqrt(462) / 462;
wigner3j_coeffs(12914) = sqrt(231) / 77;
wigner3j_coeffs(12938) = -sqrt(22) / 22;
wigner3j_coeffs(12944) = sqrt(11) / 33;
wigner3j_coeffs(12950) = sqrt(11) / 33;
wigner3j_coeffs(12956) = -sqrt(22) / 22;
wigner3j_coeffs(12986) = sqrt(33) / 33;
wigner3j_coeffs(12992) = -sqrt(55) / 33;
wigner3j_coeffs(12998) = sqrt(33) / 33;
wigner3j_coeffs(13068) = sqrt(770) / 165;
wigner3j_coeffs(13076) = -sqrt(1155) / 165;
wigner3j_coeffs(13084) = sqrt(33) / 33;
wigner3j_coeffs(13092) = -sqrt(11) / 33;
wigner3j_coeffs(13122) = -sqrt(1155) / 165;
wigner3j_coeffs(13130) = sqrt(770) / 330;
wigner3j_coeffs(13138) = sqrt(165) / 165;
wigner3j_coeffs(13146) = -sqrt(33) / 33;
wigner3j_coeffs(13154) = sqrt(110) / 66;
wigner3j_coeffs(13176) = sqrt(33) / 33;
wigner3j_coeffs(13184) = sqrt(165) / 165;
wigner3j_coeffs(13192) = -13 * sqrt(770) / 2310;
wigner3j_coeffs(13200) = 2 * sqrt(1155) / 1155;
wigner3j_coeffs(13208) = sqrt(2310) / 462;
wigner3j_coeffs(13216) = -5 * sqrt(77) / 231;
wigner3j_coeffs(13230) = -sqrt(11) / 33;
wigner3j_coeffs(13238) = -sqrt(33) / 33;
wigner3j_coeffs(13246) = 2 * sqrt(1155) / 1155;
wigner3j_coeffs(13254) = 3 * sqrt(770) / 770;
wigner3j_coeffs(13262) = -sqrt(462) / 154;
wigner3j_coeffs(13278) = 5 * sqrt(77) / 231;
wigner3j_coeffs(13292) = sqrt(110) / 66;
wigner3j_coeffs(13300) = sqrt(2310) / 462;
wigner3j_coeffs(13308) = -sqrt(462) / 154;
wigner3j_coeffs(13324) = sqrt(462) / 154;
wigner3j_coeffs(13332) = -sqrt(2310) / 462;
wigner3j_coeffs(13340) = -sqrt(110) / 66;
wigner3j_coeffs(13354) = -5 * sqrt(77) / 231;
wigner3j_coeffs(13370) = sqrt(462) / 154;
wigner3j_coeffs(13378) = -3 * sqrt(770) / 770;
wigner3j_coeffs(13386) = -2 * sqrt(1155) / 1155;
wigner3j_coeffs(13394) = sqrt(33) / 33;
wigner3j_coeffs(13402) = sqrt(11) / 33;
wigner3j_coeffs(13416) = 5 * sqrt(77) / 231;
wigner3j_coeffs(13424) = -sqrt(2310) / 462;
wigner3j_coeffs(13432) = -2 * sqrt(1155) / 1155;
wigner3j_coeffs(13440) = 13 * sqrt(770) / 2310;
wigner3j_coeffs(13448) = -sqrt(165) / 165;
wigner3j_coeffs(13456) = -sqrt(33) / 33;
wigner3j_coeffs(13478) = -sqrt(110) / 66;
wigner3j_coeffs(13486) = sqrt(33) / 33;
wigner3j_coeffs(13494) = -sqrt(165) / 165;
wigner3j_coeffs(13502) = -sqrt(770) / 330;
wigner3j_coeffs(13510) = sqrt(1155) / 165;
wigner3j_coeffs(13540) = sqrt(11) / 33;
wigner3j_coeffs(13548) = -sqrt(33) / 33;
wigner3j_coeffs(13556) = sqrt(1155) / 165;
wigner3j_coeffs(13564) = -sqrt(770) / 165;
wigner3j_coeffs(13608) = 1 / 3;
wigner3j_coeffs(13616) = -1 / 3;
wigner3j_coeffs(13624) = 1 / 3;
wigner3j_coeffs(13632) = -1 / 3;
wigner3j_coeffs(13640) = 1 / 3;
wigner3j_coeffs(13648) = -1 / 3;
wigner3j_coeffs(13656) = 1 / 3;
wigner3j_coeffs(13664) = -1 / 3;
wigner3j_coeffs(13672) = 1 / 3;
wigner3j_coeffs(13704) = sqrt(5) / 15;
wigner3j_coeffs(13706) = -2 * sqrt(5) / 15;
wigner3j_coeffs(13728) = -sqrt(35) / 30;
wigner3j_coeffs(13730) = sqrt(5) / 10;
wigner3j_coeffs(13732) = sqrt(5) / 15;
wigner3j_coeffs(13752) = sqrt(5) / 10;
wigner3j_coeffs(13754) = -sqrt(5) / 15;
wigner3j_coeffs(13756) = -sqrt(35) / 30;
wigner3j_coeffs(13776) = -sqrt(2) / 6;
wigner3j_coeffs(13778) = sqrt(5) / 30;
wigner3j_coeffs(13780) = sqrt(5) / 10;
wigner3j_coeffs(13800) = sqrt(2) / 6;
wigner3j_coeffs(13804) = -sqrt(2) / 6;
wigner3j_coeffs(13824) = -sqrt(5) / 10;
wigner3j_coeffs(13826) = -sqrt(5) / 30;
wigner3j_coeffs(13828) = sqrt(2) / 6;
wigner3j_coeffs(13848) = sqrt(35) / 30;
wigner3j_coeffs(13850) = sqrt(5) / 15;
wigner3j_coeffs(13852) = -sqrt(5) / 10;
wigner3j_coeffs(13872) = -sqrt(5) / 15;
wigner3j_coeffs(13874) = -sqrt(5) / 10;
wigner3j_coeffs(13876) = sqrt(35) / 30;
wigner3j_coeffs(13898) = 2 * sqrt(5) / 15;
wigner3j_coeffs(13900) = -sqrt(5) / 15;
wigner3j_coeffs(13958) = sqrt(330) / 165;
wigner3j_coeffs(13962) = -sqrt(1155) / 165;
wigner3j_coeffs(13966) = 2 * sqrt(385) / 165;
wigner3j_coeffs(13998) = -sqrt(330) / 110;
wigner3j_coeffs(14002) = sqrt(165) / 66;
wigner3j_coeffs(14006) = -sqrt(385) / 330;
wigner3j_coeffs(14010) = -sqrt(1155) / 165;
wigner3j_coeffs(14038) = sqrt(231) / 77;
wigner3j_coeffs(14042) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(14046) = -4 * sqrt(385) / 1155;
wigner3j_coeffs(14050) = sqrt(165) / 66;
wigner3j_coeffs(14054) = sqrt(330) / 165;
wigner3j_coeffs(14078) = -sqrt(2310) / 231;
wigner3j_coeffs(14082) = sqrt(462) / 462;
wigner3j_coeffs(14086) = 17 * sqrt(385) / 2310;
wigner3j_coeffs(14090) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(14094) = -sqrt(330) / 110;
wigner3j_coeffs(14118) = sqrt(231) / 77;
wigner3j_coeffs(14122) = sqrt(462) / 462;
wigner3j_coeffs(14126) = -2 * sqrt(385) / 231;
wigner3j_coeffs(14130) = sqrt(462) / 462;
wigner3j_coeffs(14134) = sqrt(231) / 77;
wigner3j_coeffs(14158) = -sqrt(330) / 110;
wigner3j_coeffs(14162) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(14166) = 17 * sqrt(385) / 2310;
wigner3j_coeffs(14170) = sqrt(462) / 462;
wigner3j_coeffs(14174) = -sqrt(2310) / 231;
wigner3j_coeffs(14198) = sqrt(330) / 165;
wigner3j_coeffs(14202) = sqrt(165) / 66;
wigner3j_coeffs(14206) = -4 * sqrt(385) / 1155;
wigner3j_coeffs(14210) = -3 * sqrt(1155) / 770;
wigner3j_coeffs(14214) = sqrt(231) / 77;
wigner3j_coeffs(14242) = -sqrt(1155) / 165;
wigner3j_coeffs(14246) = -sqrt(385) / 330;
wigner3j_coeffs(14250) = sqrt(165) / 66;
wigner3j_coeffs(14254) = -sqrt(330) / 110;
wigner3j_coeffs(14286) = 2 * sqrt(385) / 165;
wigner3j_coeffs(14290) = -sqrt(1155) / 165;
wigner3j_coeffs(14294) = sqrt(330) / 165;
wigner3j_coeffs(14370) = sqrt(11) / 33;
wigner3j_coeffs(14376) = -sqrt(33) / 33;
wigner3j_coeffs(14382) = sqrt(1155) / 165;
wigner3j_coeffs(14388) = -sqrt(770) / 165;
wigner3j_coeffs(14426) = -sqrt(110) / 66;
wigner3j_coeffs(14432) = sqrt(33) / 33;
wigner3j_coeffs(14438) = -sqrt(165) / 165;
wigner3j_coeffs(14444) = -sqrt(770) / 330;
wigner3j_coeffs(14450) = sqrt(1155) / 165;
wigner3j_coeffs(14482) = 5 * sqrt(77) / 231;
wigner3j_coeffs(14488) = -sqrt(2310) / 462;
wigner3j_coeffs(14494) = -2 * sqrt(1155) / 1155;
wigner3j_coeffs(14500) = 13 * sqrt(770) / 2310;
wigner3j_coeffs(14506) = -sqrt(165) / 165;
wigner3j_coeffs(14512) = -sqrt(33) / 33;
wigner3j_coeffs(14538) = -5 * sqrt(77) / 231;
wigner3j_coeffs(14550) = sqrt(462) / 154;
wigner3j_coeffs(14556) = -3 * sqrt(770) / 770;
wigner3j_coeffs(14562) = -2 * sqrt(1155) / 1155;
wigner3j_coeffs(14568) = sqrt(33) / 33;
wigner3j_coeffs(14574) = sqrt(11) / 33;
wigner3j_coeffs(14594) = sqrt(110) / 66;
wigner3j_coeffs(14600) = sqrt(2310) / 462;
wigner3j_coeffs(14606) = -sqrt(462) / 154;
wigner3j_coeffs(14618) = sqrt(462) / 154;
wigner3j_coeffs(14624) = -sqrt(2310) / 462;
wigner3j_coeffs(14630) = -sqrt(110) / 66;
wigner3j_coeffs(14650) = -sqrt(11) / 33;
wigner3j_coeffs(14656) = -sqrt(33) / 33;
wigner3j_coeffs(14662) = 2 * sqrt(1155) / 1155;
wigner3j_coeffs(14668) = 3 * sqrt(770) / 770;
wigner3j_coeffs(14674) = -sqrt(462) / 154;
wigner3j_coeffs(14686) = 5 * sqrt(77) / 231;
wigner3j_coeffs(14712) = sqrt(33) / 33;
wigner3j_coeffs(14718) = sqrt(165) / 165;
wigner3j_coeffs(14724) = -13 * sqrt(770) / 2310;
wigner3j_coeffs(14730) = 2 * sqrt(1155) / 1155;
wigner3j_coeffs(14736) = sqrt(2310) / 462;
wigner3j_coeffs(14742) = -5 * sqrt(77) / 231;
wigner3j_coeffs(14774) = -sqrt(1155) / 165;
wigner3j_coeffs(14780) = sqrt(770) / 330;
wigner3j_coeffs(14786) = sqrt(165) / 165;
wigner3j_coeffs(14792) = -sqrt(33) / 33;
wigner3j_coeffs(14798) = sqrt(110) / 66;
wigner3j_coeffs(14836) = sqrt(770) / 165;
wigner3j_coeffs(14842) = -sqrt(1155) / 165;
wigner3j_coeffs(14848) = sqrt(33) / 33;
wigner3j_coeffs(14854) = -sqrt(11) / 33;
wigner3j_coeffs(14940) = sqrt(2002) / 429;
wigner3j_coeffs(14948) = -sqrt(5005) / 429;
wigner3j_coeffs(14956) = sqrt(715) / 143;
wigner3j_coeffs(14964) = -sqrt(5005) / 429;
wigner3j_coeffs(14972) = sqrt(2002) / 429;
wigner3j_coeffs(15012) = -sqrt(5005) / 429;
wigner3j_coeffs(15020) = sqrt(2002) / 286;
wigner3j_coeffs(15028) = -sqrt(715) / 429;
wigner3j_coeffs(15036) = -sqrt(715) / 429;
wigner3j_coeffs(15044) = sqrt(2002) / 286;
wigner3j_coeffs(15052) = -sqrt(5005) / 429;
wigner3j_coeffs(15084) = sqrt(715) / 143;
wigner3j_coeffs(15092) = -sqrt(715) / 429;
wigner3j_coeffs(15100) = -sqrt(2002) / 546;
wigner3j_coeffs(15108) = 2 * sqrt(5005) / 1001;
wigner3j_coeffs(15116) = -sqrt(2002) / 546;
wigner3j_coeffs(15124) = -sqrt(715) / 429;
wigner3j_coeffs(15132) = sqrt(715) / 143;
wigner3j_coeffs(15156) = -sqrt(5005) / 429;
wigner3j_coeffs(15164) = -sqrt(715) / 429;
wigner3j_coeffs(15172) = 2 * sqrt(5005) / 1001;
wigner3j_coeffs(15180) = -3 * sqrt(2002) / 2002;
wigner3j_coeffs(15188) = -3 * sqrt(2002) / 2002;
wigner3j_coeffs(15196) = 2 * sqrt(5005) / 1001;
wigner3j_coeffs(15204) = -sqrt(715) / 429;
wigner3j_coeffs(15212) = -sqrt(5005) / 429;
wigner3j_coeffs(15228) = sqrt(2002) / 429;
wigner3j_coeffs(15236) = sqrt(2002) / 286;
wigner3j_coeffs(15244) = -sqrt(2002) / 546;
wigner3j_coeffs(15252) = -3 * sqrt(2002) / 2002;
wigner3j_coeffs(15260) = 3 * sqrt(2002) / 1001;
wigner3j_coeffs(15268) = -3 * sqrt(2002) / 2002;
wigner3j_coeffs(15276) = -sqrt(2002) / 546;
wigner3j_coeffs(15284) = sqrt(2002) / 286;
wigner3j_coeffs(15292) = sqrt(2002) / 429;
wigner3j_coeffs(15308) = -sqrt(5005) / 429;
wigner3j_coeffs(15316) = -sqrt(715) / 429;
wigner3j_coeffs(15324) = 2 * sqrt(5005) / 1001;
wigner3j_coeffs(15332) = -3 * sqrt(2002) / 2002;
wigner3j_coeffs(15340) = -3 * sqrt(2002) / 2002;
wigner3j_coeffs(15348) = 2 * sqrt(5005) / 1001;
wigner3j_coeffs(15356) = -sqrt(715) / 429;
wigner3j_coeffs(15364) = -sqrt(5005) / 429;
wigner3j_coeffs(15388) = sqrt(715) / 143;
wigner3j_coeffs(15396) = -sqrt(715) / 429;
wigner3j_coeffs(15404) = -sqrt(2002) / 546;
wigner3j_coeffs(15412) = 2 * sqrt(5005) / 1001;
wigner3j_coeffs(15420) = -sqrt(2002) / 546;
wigner3j_coeffs(15428) = -sqrt(715) / 429;
wigner3j_coeffs(15436) = sqrt(715) / 143;
wigner3j_coeffs(15468) = -sqrt(5005) / 429;
wigner3j_coeffs(15476) = sqrt(2002) / 286;
wigner3j_coeffs(15484) = -sqrt(715) / 429;
wigner3j_coeffs(15492) = -sqrt(715) / 429;
wigner3j_coeffs(15500) = sqrt(2002) / 286;
wigner3j_coeffs(15508) = -sqrt(5005) / 429;
wigner3j_coeffs(15548) = sqrt(2002) / 429;
wigner3j_coeffs(15556) = -sqrt(5005) / 429;
wigner3j_coeffs(15564) = sqrt(715) / 143;
wigner3j_coeffs(15572) = -sqrt(5005) / 429;
wigner3j_coeffs(15580) = sqrt(2002) / 429;
} else {
std::cout << "Not implemented." << std::endl;
}
return wigner3j_coeffs;
}
| true |
de85d86f6be38c674d2d76574d570a492c953754 | C++ | yuriyoung/xbattle | /src/actor/Actor.h | UTF-8 | 859 | 2.65625 | 3 | [] | no_license | /**
* @date 2017
* @filename Actor.h
* @class Actor
* @author Yuri Young<yuri.young@qq.com>
* @qq 12319597
* Copyright (c) 2017 Yuri Young, All rights reserved.
* @description Project created by QtCreator.
*/
#ifndef ACTOR_H
#define ACTOR_H
#include <cocos2d.h>
#include "ActorBreed.h"
class Actor : public cocos2d::Sprite
{
public:
Actor(ActorBreed *breed);
virtual ~Actor();
virtual bool initialize();
virtual void update(float delta) = 0;
virtual void startActions(float delta) = 0;
virtual void endLife();
virtual bool isLifeless();
virtual cocos2d::Vector<Actor *> &bullets();
ActorBreed *breed();
void setBreed(ActorBreed *breed);
protected:
virtual void installEvents();
private:
ActorBreed* m_breed;
cocos2d::Vector<Actor*> m_bullets;
};
#endif // ACTOR_H
| true |
2aa65a898e142484a3c2b01691fef2dbe5338300 | C++ | uchile-robotics-graveyard/code_graveyard | /bender_vision/src/nite/src/tracking/laser_tracker/PersonTracker.cpp | UTF-8 | 18,193 | 2.859375 | 3 | [] | no_license | #include "tracking/laser_tracker/PersonTracker.h"
#include <algorithm>ersonTracker::PersonTracker(int numData, float resolution) : numData(numData),resolution(resolution)
{
cycles = 0;
state = ST_CALIBRATING;
trackedIndex = -1;
//scheduled = false;
}
PersonTracker::~PersonTracker(void)
{
}
void PersonTracker::processNewReading(long* data, int data_max) {
segments.clear();
this->segment(data);
//if(segments.size() > 0) {
// printf("Length[0]=%f\n", segments[0].getExtent(), segments[0]);
//}
if(state == ST_CALIBRATING) {
// Obtener objeto a trackear
this->calibrate();
} else if(state == ST_TRACKING) {
// Trackear
this->track();
}
cycles++;
}
const std::vector<Segment>& PersonTracker::getSegments() {
return this->segments;
}
bool PersonTracker::isCalibrationOk() {
return this->calibrationOk;
}
int PersonTracker::getTrackedIndex() {
return this->trackedIndex;
}
void PersonTracker::startTracking() {
state = ST_TRACKING;
//calibrationOk = false;
calibrationOk = true;
doTransition(TRACK_OK); // Supposing that isCalibrationOk == true
}
void PersonTracker::startCalibration() {
state = ST_CALIBRATING;
calibrationOk = false;
}
void PersonTracker::segment(long *data) {
#if DEBUG_OUTPUT
// Abro archivo para escribir lecturas (para efectos de debugging)
char filename[256];
sprintf(filename, "debugdata\\%05d_laser.txt", cycles);
FILE* f = fopen(filename, "w+");
fprintf(f, "---------------------------------------------------------\n");
fprintf(f, "----------------------LASER SEGMENTS---------------------\n");
fprintf(f, "---------------------------------------------------------\n");
#endif
// Crear primer segmento
Segment s;
segments.push_back(s);
int segindex = 0; // Indice al ultimo segmento
// Variables que contienen ultimo angulo y radio validos
long lastR;
float lastA;
// Indice sobre los datos
int i=0;
// Angulo actual
float angle = -N135;
// Encontrar primer dato valido
for( ; i<numData; i++, angle+=resolution) {
if(data[i] == -1) {
#if DEBUG_OUTPUT
fprintf(f,"Data %f=>%d\n", angle, data[i]);
#endif
continue;
}
lastR = data[i];
lastA = angle;
break;
}
if(i == numData-1) {
segments.clear();
return;
}
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT START------------\n");
fprintf(f,"Data %f=>%d\n", angle, data[i]);
#endif
segments[segindex].addPoint(angle, data[i]);
i++; angle+=resolution;
for( ; i<numData; i++, angle+=resolution) {
// Saltarse datos invalidos
if(data[i] == -1) {
#if DEBUG_OUTPUT
fprintf(f,"Data %f=>%d\n", angle, data[i]);
#endif
continue;
}
// Ver a que distancia esta punto actual de ultimo punto
float x = (float)sqrt(data[i]*data[i] + lastR*lastR - 2*data[i]*lastR*cos(Deg2Rad(resolution)));
bool mustAddSegment = x > SEGMENT_DISTANCE_THRESHOLD;
if(mustAddSegment) {
// Poner en nuevo segmento
Segment snew;
snew.addPoint(angle,data[i]);
segments.push_back(snew);
segindex++;
} else {
// Poner en segmento actual
segments[segindex].addPoint(angle, data[i]);
}
// Ver si descartar ultimo segmento
if(mustAddSegment || i == numData-1) {
int segmentToCheck = 0;
// Si tuvo que agregar un segmento solo para el ultimo dato, descartamos este segmento
if(mustAddSegment && i == numData-1) {
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT DISCARDED (one reading only)------------\n");
#endif
segments.pop_back();
--segindex;
segmentToCheck = segindex;
} else if(mustAddSegment) {
segmentToCheck = segindex-1;
} else if(i == numData-1) {
segmentToCheck = segindex;
}
float segmentLength = (float)segments[segmentToCheck].getExtent();
long maxDistance;
if(segmentLength <= MIN_SEGMENT_LENGTH || segmentLength >= MAX_SEGMENT_LENGTH) {
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT DISCARDED (too short/long=%f)------------\n", segmentLength);
#endif
// Descartar segmento demasiado largo
segments.erase(segments.begin() + segmentToCheck);
segindex--;
} else if((maxDistance = segments[segmentToCheck].getMaxDistance()) >= MAX_SEGMENT_DISTANCE) {
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT DISCARDED (too far=%d)------------\n", maxDistance);
#endif
// Descartar segmento con puntos demasiado alejados
segments.erase(segments.begin() + segmentToCheck);
segindex--;
} else if(segments[segmentToCheck].distances.size() < MIN_SEGMENT_DATA_SIZE) {
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT DISCARDED (too few data=%d)------------\n", segments[segmentToCheck].distances.size());
#endif
// Descartar segmento con muy pocos datos
segments.erase(segments.begin() + segmentToCheck);
segindex--;
} else if(segments[segmentToCheck].getMaxAngle() <= MIN_ANGLE_RANGE || segments[segmentToCheck].getMinAngle() >= MAX_ANGLE_RANGE) {
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT DISCARDED (out of interest zone, angles[%f,%f])------------\n",
segments[segmentToCheck].getMinAngle(), segments[segmentToCheck].getMaxAngle());
#endif
// Descartar segmento fuera de angulos de interes
segments.erase(segments.begin() + segmentToCheck);
segindex--;
} else {
// Preservar segmento
#if DEBUG_OUTPUT
fprintf(f,"---------SEGMENT END (length=%f, maxDistance=%d)------------\n", segmentLength, maxDistance);
#endif
}
}
#if DEBUG_OUTPUT
fprintf(f,"Data %f=>%d distToLast=%f\n", angle, data[i], x);
#endif
lastR = data[i];
lastA = angle;
}
#if DEBUG_OUTPUT
fclose(f);
#endif
}
void PersonTracker::calibrate() {
#if DEBUG_OUTPUT
// Abro archivo para escribir lecturas (para efectos de debugging)
char filename[100];
sprintf(filename, "debugdata\\%05d_tracking.txt", cycles);
FILE* f = fopen(filename, "w+");
#endif
int n = segments.size();
for(int i=0;i<n;i++) {
if(segments[i].hasAngle(0)) {
//float minAngle = segments[i].getMinAngle();
//float maxAngle = segments[i].getMaxAngle();
//float minRadius = segments[i].getMinRadius();
//float maxRadius = segments[i].getMinRadius();
//
//float ma = (minAngle+maxAngle)/2;
//float mr = (minRadius+maxRadius)/2;
//float da = maxAngle-minAngle;
float ma, mr, da;
getFeatures(segments[i], &ma, &mr, &da);
trackedSegment.updateTo(ma, mr, da);
calibrationOk = true;
#if DEBUG_OUTPUT
fprintf(f, "Calibration with: ma=%f, mr=%f, da=%f\n", ma, mr, da);
fclose(f);
#endif
return;
}
}
calibrationOk = false;
#if DEBUG_OUTPUT
fprintf(f, "No object to calibrate with\n");
fclose(f);
#endif
}
void PersonTracker::trackFeatures(SegmentFeatures& sf, int& trackIndex, bool updateFeatures, int radius) {
#if DEBUG_OUTPUT
fprintf(log,"[trackFeatures] TrackedSegment (ma,mr,da)=(%f,%f,%f)\n", sf.getMeanAngle(), sf.getMeanRadius(), sf.getDeltaAngle());
#endif
int n = segments.size();
float minDist = std::numeric_limits<float>::infinity();
float newMeanA, newMeanR, newDeltaA;
float oldMeanA = sf.getMeanAngle(),
oldMeanR = sf.getMeanRadius(),
oldDeltaA = sf.getDeltaAngle();
float wOld = 0, wNew = 1-wOld;
for(int i=0;i<n;i++) {
// Get features for tracking
float meanA, meanR, deltaA;
getFeatures(segments[i], &meanA, &meanR, &deltaA);
// Get distance from candidate segment to tracked segment
float displacement = (float)PolarDistance(oldMeanR, oldMeanA, meanR, meanA);
if(displacement > radius) {
#if DEBUG_OUTPUT
fprintf(log,"[trackFeatures] candidate (ma,mr,da)=(%f,%f,%f) too physically far from segment (%f)\n", meanA, meanR, deltaA,displacement);
#endif
} else {
float dist = sf.distanceTo(meanA, meanR, deltaA);
#if DEBUG_OUTPUT
fprintf(log,"[trackFeatures] candidate (ma,mr,da)=(%f,%f,%f) phys-distance=%f tuple-distance=%f\n", meanA, meanR, deltaA, displacement, dist);
#endif
if(dist < minDist) {
minDist = dist;
newMeanA = meanA;
newMeanR = meanR;
newDeltaA = deltaA;
trackIndex = i;
}
}
}
// If we found a good candidate, update tracking
if(minDist < MAX_TRACKING_FEATURES_DISTANCE) {
#if DEBUG_OUTPUT
fprintf(log,"[trackFeatures] => Segment (%f,%f,%f) is the closest (tuple-dist=%f)\n", newMeanA, newMeanR, newDeltaA, minDist);
#endif
if(updateFeatures) {
sf.updateTo(
wNew*newMeanA+wOld*oldMeanA,
wNew*newMeanR+wOld*oldMeanR,
wNew*newDeltaA+wOld*oldDeltaA);
}
} else {
trackIndex = -1;
#if DEBUG_OUTPUT
fprintf(log,"[trackFeatures] => No matching object found (best tuple-dist=%f, threshold=%d)\n", minDist, MAX_TRACKING_FEATURES_DISTANCE);
#endif
}
}
void PersonTracker::doTransition(TrackingStatus s) {
trackingStatus = s;
cyclesInCurrentState = 0;
}
void PersonTracker::track() {
#if DEBUG_OUTPUT
// Abro archivo para escribir lecturas (para efectos de debugging)
char filename[128];
sprintf(filename, "debugdata\\%05d_tracking.txt", cycles);
log = fopen(filename, "w+");
#endif
switch(trackingStatus) {
case TRACK_OK: {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Tracking OK: (r,theta)=(%f,%f)\n",
trackedSegment.getMeanRadius(), trackedSegment.getMeanAngle());
fprintf(log, "[PersonTracker] track object\n");
#endif
trackFeatures(trackedSegment, trackedIndex, true, MAX_DISPLACEMENT_BETWEEN_READINGS);
if(trackedIndex >= 0) {
// Find element that could occlude tracked segment
float trA = trackedSegment.getMeanAngle(),
trR = trackedSegment.getMeanRadius();
int n = segments.size();
int leftIndex, rightIndex;
float leftA , rightA ;
float leftR , rightR ;
float leftDa , rightDa ;
bool leftOccl , rightOccl ;
// Left element
leftIndex = trackedIndex - 1;
if(leftIndex >= 0) {
getFeatures(segments[leftIndex], &leftA, &leftR, NULL);
} else {
leftA = MIN_ANGLE_RANGE;
leftR = 4000;
}
leftDa = trA - leftA;
leftOccl = leftR*sin(Deg2Rad(leftDa)) <= OCCLUSION_RISK_DISTANCE && leftR <= trR;
// Right element
rightIndex = trackedIndex + 1;
if(rightIndex <= n-1) {
getFeatures(segments[rightIndex], &rightA, &rightR, NULL);
} else {
rightA = MAX_ANGLE_RANGE;
rightR = 4000;
}
rightDa = rightA - trA;
rightOccl = rightR*sin(Deg2Rad(rightDa)) <= OCCLUSION_RISK_DISTANCE && rightR <= trR;
//printf("left : (r,t)=(%f,%f) da=%f, leftOccl =%d\n", leftR, leftA, leftDa, leftOccl?1:0);
//printf("right: (r,t)=(%f,%f) da=%f, rightOccl=%d\n", rightR, rightA, rightDa, rightOccl?1:0);
// Decide which occlusion is more serious, if any
bool hasOccl = leftOccl || rightOccl;
if(hasOccl) {
int occlIndex;
if(leftOccl && rightOccl) {
if(leftDa <= rightDa) {
occlIndex = leftIndex;
} else {
occlIndex = rightIndex;
}
} else if(leftOccl) {
occlIndex = leftIndex;
} else {
occlIndex = rightIndex;
}
float meanA, meanR, deltaA;
getFeatures(segments[occlIndex], &meanA, &meanR, &deltaA);
nearSegment.updateTo(meanA, meanR, deltaA);
nearIndex = occlIndex;
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to OCCLUSION_RISK: near object detected\n");
#endif
doTransition(TRACK_OCCLUSION_RISK);
} else {
// No occlusions, everything is ok
}
} else {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to LOST: no object detected\n");
#endif
doTransition(TRACK_LOST);
}
break;
}
case TRACK_OCCLUSION_RISK: {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Tracking OCCLUSION_RISK: (r,theta)=(%f,%f)\n",
trackedSegment.getMeanRadius(), trackedSegment.getMeanAngle());
fprintf(log, "[PersonTracker] track object\n");
#endif
trackFeatures(trackedSegment, trackedIndex, false, MAX_DISPLACEMENT_BETWEEN_READINGS);
#if DEBUG_OUTPUT
fprintf(log, "[PersonTracker] track occluder\n");
#endif
trackFeatures(nearSegment , nearIndex , true , MAX_DISPLACEMENT_BETWEEN_READINGS);
if(trackedIndex == nearIndex) {
if(trackedIndex != -1) {
if(cyclesInCurrentState >= MIN_CYCLES_OF_RISK_BEFORE_OCCLUSION) {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to OCCLUSION: object and occluder indistinguishable\n");
#endif
doTransition(TRACK_OCCLUSION);
} else {
// Some serious occlusions use this branch!!
numCyclesToRecover = 10;
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to RECOVER: not a serious risk of occlusion, wait %d frames\n", numCyclesToRecover);
#endif
doTransition(TRACK_RECOVER);
}
} else {
#if DEBUG_OUTPUT
//fprintf(log,"[PersonTracker] Transition to LOST: all objects lost\n");
#endif
//doTransition(TRACK_LOST);
}
} else {
if(trackedIndex == -1) {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to OCCLUSION: only occluder visible\n");
#endif
doTransition(TRACK_OCCLUSION);
} else if(nearIndex == -1) {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to OK: only main object visible\n");
#endif
doTransition(TRACK_OK);
} else {
// Si objetos estan muy lejos => pasar a ok
float trR, trA, nrR, nrA;
getFeatures(segments[trackedIndex], &trA, &trR, NULL);
getFeatures(segments[nearIndex] , &nrA, &nrR, NULL);
double dist = PolarDistance(trR, trA, nrR, nrA);
//fprintf(log,"[PersonTracker] Distance(%f,%f,%f,%f) %f\n", trR, trA, nrR, nrA, dist);
if(dist > 1.3*OCCLUSION_RISK_DISTANCE) {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to OK: object and occluder far from each other (%f)\n", dist);
#endif
doTransition(TRACK_OK);
} else {
}
}
}
break;
}
case TRACK_OCCLUSION: {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Tracking OCCLUSION: (r,theta)=(%f,%f)\n",
trackedSegment.getMeanRadius(), trackedSegment.getMeanAngle());
fprintf(log, "[PersonTracker] track object\n");
#endif
trackFeatures(trackedSegment, trackedIndex, false, MAX_DISPLACEMENT_BETWEEN_READINGS);
#if DEBUG_OUTPUT
fprintf(log, "[PersonTracker] track occluder\n");
#endif
trackFeatures(nearSegment , nearIndex , true , MAX_DISPLACEMENT_BETWEEN_READINGS);
if(trackedIndex == nearIndex) {
if(trackedIndex != -1) {
// If too many cycles in occlusion, just go to ok
if(cyclesInCurrentState >= MAX_CYCLES_IN_OCCLUSION) {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to OK: waited too much\n");
#endif
doTransition(TRACK_OK);
}
}
} else {
numCyclesToRecover = 20;
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to RECOVER: main object visible, wait %d frames\n", numCyclesToRecover);
#endif
doTransition(TRACK_RECOVER);
}
break;
}
case TRACK_LOST: {
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Tracking LOST\n");
fprintf(log, "[PersonTracker] track object\n");
#endif
trackFeatures(trackedSegment, trackedIndex, false, MAX_DISPLACEMENT_BETWEEN_READINGS);
if(trackedIndex != -1) {
numCyclesToRecover = std::min(cyclesInCurrentState, 15);
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Transition to RECOVER: main object visible, wait %d frames\n", numCyclesToRecover);
#endif
doTransition(TRACK_RECOVER);
}
// Idea: si lleva mucho tiempo en este estado, reiniciar con segmento al centro
break;
}
case TRACK_RECOVER: {
//trackFeatures(trackedSegment, trackedIndex, false);
#if DEBUG_OUTPUT
fprintf(log,"[PersonTracker] Tracking RECOVER: frame %d of %d\n", cyclesInCurrentState, numCyclesToRecover);
#endif
if(cyclesInCurrentState >= numCyclesToRecover) {
int excess = cyclesInCurrentState - numCyclesToRecover;
int radius = std::min(MAX_DISPLACEMENT_BETWEEN_READINGS + excess*RECOVERY_RADIUS_INCREMENT,MAX_RECOVERY_RADIUS);
#if DEBUG_OUTPUT
fprintf(log, "[PersonTracker] Looking for candidates in a radius of %d mm\n", radius);
#endif
trackFeatures(trackedSegment, trackedIndex, false, radius);
if(trackedIndex >= 0) {
float tr, ta;
getFeatures(segments[trackedIndex], &ta, &tr, NULL);
float dist = (float)PolarDistance(tr, ta, trackedSegment.getMeanRadius(), trackedSegment.getMeanAngle());
#if DEBUG_OUTPUT
fprintf(log, "[PersonTracker] Transition to OK: restarted tracking\n");
#endif
restartTrackingWithIndex(trackedIndex);
doTransition(TRACK_OK);
}
//float angle = trackedSegment.getMeanAngle();
//if(restartTrackingWithAngle(angle)) {
// fprintf("[PersonTracker] Transition to OK: restarted tracking\n", angle);
// doTransition(TRACK_OK);
//}
}
break;
}
}
cyclesInCurrentState++;
#if DEBUG_OUTPUT
fclose(log);
#endif
}
void PersonTracker::restartTrackingWithIndex(int index) {
float ma,mr,da;
getFeatures(segments[index],&ma,&mr,&da);
trackedSegment.updateTo(ma,mr,da);
}
int PersonTracker::restartTrackingWithAngle(float angle) {
int index = indexForAngle(angle);
if(index != -1) {
printf("[PersonTracker::restartTrackingWithAngle] Angle %f found in segment %d [%f,%f]\n", angle, index, segments[index].getMinAngle(), segments[index].getMaxAngle());
restartTrackingWithIndex(index);
return 1;
} else {
return 0;
}
}
int PersonTracker::indexForAngle(float angle) {
int n = segments.size();
for(int i=0;i<n;++i) {
if(segments[i].hasAngle(angle)) {
return i;
}
}
return -1;
}
void PersonTracker::getFeatures(Segment& s, float* meanA, float* meanR, float* deltaA) {
float minAngle = (float)s.getMinAngle();
float maxAngle = (float)s.getMaxAngle();
float minRadius = (float)s.getMinRadius();
float maxRadius = (float)s.getMinRadius();
if(meanA != NULL) {
*meanA = (minAngle+maxAngle)/2;
}
if(meanR != NULL) {
*meanR = (minRadius+maxRadius)/2;
}
if(deltaA != NULL) {
*deltaA = maxAngle-minAngle;
}
}
//void PersonTracker::scheduleRestartWithAngle(float angle) {
// scheduled = true;
// scheduledAngle = angle;
//}
//void PersonTracker::doScheduledRestarts() {
// if(scheduled) {
// if(indexForAngle(scheduledAngle) != -1) {
// scheduled = false;
// printf("[PersonTracker] Restart tracking with angle %f\n", scheduledAngle);
// restartTrackingWithAngle(scheduledAngle);
// }
// }
//}
| true |
9bfd4d83271836b39d2b033b0a970b5e84373538 | C++ | gky360/contests | /atcoder/past202012-open/e/Main.cpp | UTF-8 | 1,231 | 2.640625 | 3 | [] | no_license | /*
[past202012-open] E - Stamp
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double DD;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(c) (c).begin(), (c).end()
const int MAX_H = 10;
const int MAX_W = 10;
int H, W;
vector<string> S, T;
void rotate() {
int h = T.size(), w = T[0].size();
vector<string> t(w, string(h, '.'));
REP(i, h) REP(j, w) t[j][h - i - 1] = T[i][j];
T = t;
}
bool check(int p, int q) {
REP(i, T.size()) REP(j, T[0].size()) {
int a = i + p, b = j + q;
if (T[i][j] == '.') continue;
if (a < 0 || H <= a || b < 0 || W <= b || S[a][b] == '#') return false;
}
return true;
}
bool solve() {
REP(k, 4) {
for (int p = -MAX_H + 1; p < MAX_H - 1; p++) {
for (int q = -MAX_W + 1; q < MAX_W - 1; q++) {
if (check(p, q)) return true;
}
}
rotate();
}
return false;
}
int main() {
cin >> H >> W;
S.resize(H), T.resize(H);
REP(i, H) cin >> S[i];
REP(i, H) cin >> T[i];
cout << (solve() ? "Yes" : "No") << endl;
return 0;
}
| true |
c4ee11b06668fa80c07ff5d55ada9480d7f08257 | C++ | maedhros777/opengl-game | /source/Mesh.h | UTF-8 | 751 | 2.75 | 3 | [] | no_license | #ifndef MESH_H
#define MESH_H
#include "Animation.h"
const int MAX_INFLUENCES = 4;
const int SKEL_NAME_MAX_LEN = 32;
const float WEIGHT_OFFSET = 0.00001;
struct Vertex
{
float x, y, z, anim_x, anim_y, anim_z;
unsigned int boneIDs[MAX_INFLUENCES];
float weights[MAX_INFLUENCES];
};
struct Face
{
unsigned int v1, v2, v3;
};
class Mesh
{
private:
unsigned int num_verts, num_faces;
Vertex *vertices;
Face *faces;
Animation animation;
public:
Mesh() : num_verts(0), num_faces(0), vertices(0), faces(0)
{
}
ERR_RET animate(const std::string &anim_name, bool anim_loop = false)
{
return animation.animate(anim_name, anim_loop);
}
~Mesh();
void update();
void render() const;
ERR_RET load(const std::string &filename);
};
#endif
| true |
9605d74322f11037820764087adcaec8cfa9d685 | C++ | zhucebuliaopx/algorithm009-class02 | /Week_08/practice/190.颠倒二进制位.cpp | UTF-8 | 371 | 2.828125 | 3 | [] | no_license | /*
* @lc app=leetcode.cn id=190 lang=cpp
*
* [190] 颠倒二进制位
*/
// @lc code=start
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t ans = 0;
uint32_t MASK = 1;
for (int i=0;i<32;i++){
if (n & MASK) ans |= 1 << (31-i);
MASK <<= 1;
}
return ans;
}
};
// @lc code=end
| true |
715c8da5a87564746b5dd712e1042bff1e0d0b8c | C++ | t-highfill/cs430 | /geom.h | UTF-8 | 1,248 | 3.3125 | 3 | [] | no_license |
#ifndef __GEOM_H__
#define __GEOM_H__
#include <ostream>
#include <vector>
#include "linear.h"
template<class T>
class Point2D : public Matrix<T, 2, 1>
{
public:
Point2D() {
}
Point2D(const T x, const T y){
setX(x);
setY(y);
}
Point2D(const Point2D<T>& copy) : Point2D(){
setX(copy.getX());
setY(copy.getY());
}
Point2D<T>& operator=(Point2D<T> other){
setX(other.getX());
setY(other.getY());
return *this;
}
T getX() const{
return this->get(0,0);
}
void setX(const T val) {
this->get(0,0) = val;
}
T getY() const{
return this->get(1,0);
}
void setY(const T val) {
this->get(1,0) = val;
}
};
template<class T>
std::ostream& operator<<(std::ostream& out, Point2D<T> pt){
out << '(' << pt.getX() << ',' << pt.getY() << ')';
return out;
}
template<class T>
class Line2D {
private:
std::vector<Point2D<T> > _pts;
public:
Line2D(){}
Line2D(const Line2D<T>& copy){
_pts = copy._pts;
}
void add(Point2D<T> point){
_pts.push_back(point);
}
auto begin(){
return _pts.begin();
}
auto end(){
return _pts.end();
}
auto begin() const{
return _pts.begin();
}
auto end() const{
return _pts.end();
}
};
#endif // __GEOM_H__
| true |
8775d1fc802d278aae044f548370ce21dd41b44e | C++ | rwarnking/pointy | /source/instance_generator.cpp | UTF-8 | 3,207 | 3.265625 | 3 | [
"MIT"
] | permissive | #include "../header/instance_generator.h"
#include "../header/logger.h"
using namespace std;
using namespace logger;
int main(int argc, char **argv)
{
if (argc == 3)
{
try
{
int points = stoi(argv[2]);
GenerateInstance(argv[1], points);
}
catch(...)
{
Logger::PrintlnAbort(LEVEL::ERR, "ERROR: invalid point count argument");
}
}
else if (argc >= 5)
{
try
{
int points = stoi(argv[2]);
int min = stoi(argv[3]);
int max = stoi(argv[4]);
if (min > max)
{
Logger::Println(LEVEL::ERR, "ERROR: min value must be less or equal to max value: min = ", min, ", max = ", max);
PrintHelp();
return -1;
}
bool even = true;
if (argc == 6)
even = stoi(argv[5]) == 1;
GenerateInstance(argv[1], points, min, max, even);
}
catch(...)
{
Logger::PrintlnAbort(LEVEL::ERR, "ERROR: invalid point count argument");
}
}
else
{
PrintHelp();
}
return 0;
}
void PrintHelp()
{
Logger::Println(LEVEL::INFO, "This program generates a problem instance for the 4-corner labelling problem\n");
Logger::Println(LEVEL::INFO, "Usage: instance_generator <filename> <number of points> [min value] [max value] [uniform distribution{0=false,1=true}]");
Logger::Println(LEVEL::INFO, "Default values when none are given:");
Logger::Println(LEVEL::INFO, "\tmin value = -50");
Logger::Println(LEVEL::INFO, "\tmax value = 50");
Logger::Println(LEVEL::INFO, "\tuniform distribution = 1 (true)\n");
}
void GenerateInstance(const char *filename, int point_count, int min, int max, bool uniform)
{
vector<Point> points = vector<Point>(point_count);
// Generates points with even distribution across [min, max]
if (uniform)
{
default_random_engine gen;
uniform_int_distribution<int> pdis(min, max);
uniform_int_distribution<int> bdis((int) (1+abs(max-min)*0.05f), (int) (1+abs(max-min)*0.2f));
for (int i = 0; i < point_count; i++)
{
int x = pdis(gen);
int y = pdis(gen);
int w = bdis(gen);
int h = bdis(gen);
// Add new point to list
points[i] = Point(x, y, Box(w, h, string("box") + to_string(i+1)));
}
}
else
{
srand((unsigned int) time(0));
int rangeMax = (int) (abs(max-min) * 0.2f) + 1;
int rangeMin = (int) (abs(max-min) * 0.05f);
int range = abs(max-min) + 1;
for (int i = 0; i < point_count; i++)
{
int x = min + (rand() % range);
int y = min + (rand() % range);
int w = rangeMin + (rand() % rangeMax);
int h = rangeMin + (rand() % rangeMax);
// Add new point to list
points[i] = Point(x, y, Box(w, h, string("box") + to_string(i+1)));
}
}
Instance instance = Instance(&points);
instance.WriteFile((string(DATA_DIR) + filename).c_str());
} | true |
1d3700226a9690480a8f6145dd453051225541fd | C++ | kirtivr/leetcode | /Leetcode/1115.cc | UTF-8 | 1,948 | 3.5 | 4 | [] | no_license | #include <functional>
#include <chrono>
#include <thread>
#include <iostream>
#include <deque>
#include <mutex>
#include <vector>
class FooBar {
public:
FooBar(int n) {
this->n = n;
}
void foo(std::function<void()> printFoo) {
for (int i = 0; i < n; i++) {
{
std::unique_lock<std::mutex> lg(pm);
cv.wait(lg, [this] {
return !should_print;
});
// printFoo() outputs "foo". Do not change or remove this line.
printFoo();
should_print = true;
lg.unlock();
cv.notify_one();
}
}
}
void bar(std::function<void()> printBar) {
for (int i = 0; i < n; i++) {
{
std::unique_lock<std::mutex> lg(pm);
cv.wait(lg, [this] {
return should_print;
});
// printBar() outputs "bar". Do not change or remove this line.
printBar();
should_print = false;
lg.unlock();
cv.notify_one();
}
}
}
private:
int n;
std::mutex pm;
bool should_print = false;
std::condition_variable cv;
};
int main() {
auto start = std::chrono::high_resolution_clock::now();
FooBar fb(10);
std::thread t1([&fb] {
fb.foo([] (){
std::cout << "foo";
});
});
std::thread t2([&fb] {
fb.bar([] (){
std::cout << "bar";
});
});
t1.join();
t2.join();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
// To get the value of duration use the count()
// member function on the duration object
std::cout << std::endl << duration.count() << "ms" << std::endl;
} | true |
34be8c9611479ed2ddeb713a4456691c4d55c27e | C++ | GuessEver/ACMICPCSolutions | /UESTC/1077/B.cpp | UTF-8 | 1,215 | 2.734375 | 3 | [] | no_license | #include <cstdio>
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m;
char cap[100][100];
int sx, sy, sk;
bool found;
void dfs(int x, int y, int dir)
{
if(found) return;
if(cap[x][y] == 'x')
{
cap[x][y] = '&';
found = 1;
return;
}
int nx = x + dx[dir], ny = y + dy[dir], ndir = dir;
if(cap[nx][ny] == '/' && dir == 0) ndir = 1;
else if(cap[nx][ny] == '/' && dir == 1) ndir = 0;
else if(cap[nx][ny] == '/' && dir == 2) ndir = 3;
else if(cap[nx][ny] == '/' && dir == 3) ndir = 2;
else if(cap[nx][ny] == '\\' && dir == 0) ndir = 3;
else if(cap[nx][ny] == '\\' && dir == 1) ndir = 2;
else if(cap[nx][ny] == '\\' && dir == 2) ndir = 1;
else if(cap[nx][ny] == '\\' && dir == 3) ndir = 0;
dfs(nx, ny, ndir);
}
int main()
{
int cas = 0;
while(scanf("%d%d", &m, &n) == 2 && n && m)
{
for(int i = 1; i <= n; i++)
{
scanf("%s", cap[i] + 1);
for(int j = 1; j <= m; j++)
if(cap[i][j] == '*')
{
sx = i; sy = j;
if(i == 1) sk = 2;
else if(i == n) sk = 0;
else if(j == 1) sk = 1;
else if(j == m) sk = 3;
}
}
found = 0;
dfs(sx, sy, sk);
printf("HOUSE %d\n", ++cas);
for(int i = 1; i <= n; i++) puts(cap[i]+1);
}
return 0;
}
| true |
de5262a44400ad593a61379bd83d309597435ab4 | C++ | milkymay/algo_labs | /H.cpp | UTF-8 | 1,694 | 2.53125 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
int const inf = 1e9 + 7;
vector<int> used, used1, ord, comp;
int n, l, r, cnt, col;
vector<vector<pair<int, int>>> g, h;
int max_color;
void dfs1(int v, int d) {
used[v] = 1;
cnt++;
for (auto to : g[v]) {
int u = to.first;
int w = to.second;
if (!used[u] && w <= d) {
dfs1(u, d);
}
}
ord.push_back(v);
}
void dfs2(int v, int d) {
used[v] = 1;
comp[v] = col;
cnt++;
for (auto to : h[v]) {
int u = to.first;
int w = to.second;
if (!comp[u] && w <= d) {
dfs2(u, d);
}
}
}
bool ok(int d) {
dfs1(0, d);
if (cnt < n) {
return false;
}
cnt = 0;
used.assign(n, 0);
col = 1;
int v = ord[ord.size() - 1];
dfs2(v, d);
return cnt >= n;
}
int main() {
freopen ("avia.in", "r", stdin);
freopen ("avia.out", "w", stdout);
cin >> n;
g.resize(n, vector<pair<int, int>>());
h.resize(n, vector<pair<int, int>>());
used.resize(n, 0);
comp.resize(n, 0);
int a;
l = inf;
r = 0;
for (int u = 0; u < n; u++) {
for (int v = 0; v < n; v++) {
cin >> a;
if (u != v) {
g[u].emplace_back(v, a);
h[v].emplace_back(u, a);
l = min(l, a);
r = max(r, a);
}
}
}
l--;
while (r - l > 1) {
int m = (r + l)/2;
if (ok(m)) {
r = m;
} else {
l = m;
}
used.assign(n, 0);
comp.assign(n, 0);
ord.resize(0);
cnt = 0;
}
cout << r;
return 0;
}
| true |
d6d6a4a4f446afe0a4414f7e2b21f2aee66d3897 | C++ | davisking/dlib | /dlib/geometry/border_enumerator.h | UTF-8 | 5,032 | 2.8125 | 3 | [
"BSL-1.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BORDER_EnUMERATOR_H_
#define DLIB_BORDER_EnUMERATOR_H_
#include "border_enumerator_abstract.h"
#include "rectangle.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
class border_enumerator
{
public:
border_enumerator(
)
{
reset();
}
border_enumerator(
const rectangle& rect_,
unsigned long border_size
) :
rect(rect_),
inner_rect(shrink_rect(rect_, border_size))
{
reset();
}
border_enumerator(
const rectangle& rect_,
const rectangle& non_border_region
) :
rect(rect_),
inner_rect(non_border_region.intersect(rect))
{
reset();
}
void reset (
)
{
// make the four rectangles that surround inner_rect and intersect them
// with rect.
bleft = rect.intersect(rectangle(std::numeric_limits<long>::min(),
std::numeric_limits<long>::min(),
inner_rect.left()-1,
std::numeric_limits<long>::max()));
bright = rect.intersect(rectangle(inner_rect.right()+1,
std::numeric_limits<long>::min(),
std::numeric_limits<long>::max(),
std::numeric_limits<long>::max()));
btop = rect.intersect(rectangle(inner_rect.left(),
std::numeric_limits<long>::min(),
inner_rect.right(),
inner_rect.top()-1));
bbottom = rect.intersect(rectangle(inner_rect.left(),
inner_rect.bottom()+1,
inner_rect.right(),
std::numeric_limits<long>::max()));
p = bleft.tl_corner();
p.x() -= 1;
mode = atleft;
}
bool at_start (
) const
{
point temp = bleft.tl_corner();
temp.x() -=1;
return temp == p;
}
bool current_element_valid(
) const
{
return rect.contains(p);
}
bool move_next()
{
if (mode == atleft)
{
if (advance_point(bleft, p))
return true;
mode = attop;
p = btop.tl_corner();
p.x() -= 1;
}
if (mode == attop)
{
if (advance_point(btop, p))
return true;
mode = atright;
p = bright.tl_corner();
p.x() -= 1;
}
if (mode == atright)
{
if (advance_point(bright, p))
return true;
mode = atbottom;
p = bbottom.tl_corner();
p.x() -= 1;
}
if (advance_point(bbottom, p))
return true;
// put p outside rect since there are no more points to enumerate
p = rect.br_corner();
p.x() += 1;
return false;
}
size_t size (
) const
{
return rect.area() - inner_rect.area();
}
const point& element (
) const
{
// make sure requires clause is not broken
DLIB_ASSERT(current_element_valid(),
"\t point border_enumerator::element()"
<< "\n\t This function can't be called unless the element is valid."
<< "\n\t this: " << this
);
return p;
}
private:
bool advance_point (
const rectangle& r,
point& p
) const
{
p.x() += 1;
if (p.x() > r.right())
{
p.x() = r.left();
p.y() += 1;
}
return r.contains(p);
}
point p;
rectangle rect;
rectangle inner_rect; // the non-border regions of rect
enum emode
{
atleft,
atright,
atbottom,
attop
};
emode mode;
rectangle btop, bleft, bright, bbottom;
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_BORDER_EnUMERATOR_H_
| true |
2d1dfff9e4fb83185d808f69f08ae2d1b60217fd | C++ | ciscoruiz/dns_server | /include/dns.server.functions.h | UTF-8 | 10,145 | 3.203125 | 3 | [] | no_license | #ifndef _dns_server_functions_h
#define _dns_server_functions_h
#include <stdlib.h>
#include <string>
#include <dns.server.defines.h>
#include <dns.server.Exception.h>
#include <time.h>
#include <sys/time.h>
namespace dns {
namespace server {
class DataBlock;
/**
functions - Métodos básicos de conversión de datos.
@author francisco.antonio.ruiz.rayo@ericsson.com cisco.tierra@gmail.com.
*/
struct functions {
/**
Indica el número de bits de un entero.
*/
static const int intBitSize = sizeof (int) * 8;
/*
* Indica el número de bits de un entero largo.
*/
static const int int64BitSize = sizeof (Integer64) * 8;
/**
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asString (const int number) throw ();
/**
\param number Numero a convertir.
@return Un literal con el numero sin signo convertido a cadena decimal.
*/
static std::string asString (const unsigned int number) throw ();
/**
Devuelve un literal con tel numero convertido a cadena decimal
@return Un literal con el numero signo convertido a cadena decimal.
*/
static std::string asString (const Integer64 number) throw ();
/**
Devuelve un literal con tel numero convertido a cadena decimal
@return Un literal con el numero signo convertido a cadena decimal.
*/
static std::string asString (const Unsigned64 number) throw ();
/**
\param _bool Booleano a convertir.
\return Un literal con el boolean convertido a cadena.
*/
static const char* asString (const bool _bool) throw () { return (_bool == true) ? "true": "false"; }
/**
Devuelve una cadena con el bloque de datos decodificado en grupos de 16 bytes.
@param dataBlock Bloque de datos a interpretar.
\param characterByLine Número de caracteres en cada línea.
@return Devuelve una cadena con el bloque de datos decodificado en grupos de 16 bytes.
*/
static std::string asString (const DataBlock& dataBlock, const int characterByLine = 16) throw ();
/**
Devuelve una cadena con el numero en coma flotante.
\param v Numero a tratar.
\param format Formato aplicado para convertir el numero a cadena. Ver \em man printf.
\return una cadena con el numero en coma flotante.
*/
static std::string asString (const double v, const char* format="%e") throw ();
/**
Devuelve una cadena con el numero en coma flotante.
\param v Numero a tratar.
\param format Formato aplicado para convertir el numero a cadena. Ver \em man printf.
\return una cadena con el numero en coma flotante.
*/
static std::string asString (const float v, const char* format="%f") throw ();
/**
\param comment Comentario que precede al valor.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asText (const char* comment, const int number)
throw ()
{
std::string result (comment);
return result += asString (number);
}
/**
\param comment Comentario que precede al valor.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asText (const char* comment, const Integer64 number)
throw ()
{
std::string result (comment);
return result += asString (number);
}
/**
\param comment Comentario que precede al valor.
\param _bool Booleano a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asText (const char* comment, const bool _bool)
throw ()
{
std::string result (comment);
return result += asString (_bool);
}
/**
\param comment Comentario que precede al valor.
\param dataBlock Bloque de datos a interpretar.
\param characterByLine Número de caracteres en cada línea.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asText (const char* comment, const DataBlock& dataBlock, const int characterByLine = 16)
throw ()
{
std::string result (comment);
return result += asString (dataBlock, characterByLine);
}
/**
\param comment Comentario que precede al valor.
\param value Numero a tratar.
\param format Formato aplicado para convertir el numero a cadena. Ver \em man printf.
\return Un literal con el numero convertido a cadena.
*/
static std::string asText (const char* comment, const float value, const char* format="%f")
throw ()
{
std::string result (comment);
return result += asString (value, format);
}
/**
\param comment Comentario que precede al valor.
\param value Numero a tratar.
\param format Formato aplicado para convertir el numero a cadena. Ver \em man printf.
\return Un literal con el numero convertido a cadena.
*/
static std::string asText (const char* comment, const double value, const char* format="%e")
throw ()
{
std::string result (comment);
return result += asString (value, format);
}
/**
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena hexadecimal.
*/
static std::string asHexString (const int number) throw ();
/**
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena hexadecimal.
*/
static std::string asHexString (const Integer64 number) throw ();
/**
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena hexadecimal.
*/
static std::string asHexString (const Unsigned64 number) throw () { return asHexString ((Integer64) number); }
/**
\param comment Comentario que precede al valor.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asHexText (const char* comment, const int number)
throw ()
{
std::string result (comment);
return result += asHexString (number);
}
/**
\param comment Comentario que precede al valor.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
static std::string asHexText (const char* comment, const Integer64 number)
throw ()
{
std::string result (comment);
return result += asHexString (number);
}
/**
* Devuelve un cadena con el contenido del bloque de datos interpretado como BCD, pero pasa
* cada valor binario a su correspondiente carácter. Por ejemplo, el buffer aa210c quedará como una cadena "AA210C".
*
* \param dataBlock Bloque a codificar.
* \return La cadena que contiene el valor literal del buffer de datos.
*
*/
static std::string asHexString (const DataBlock& dataBlock) throw ();
/**
* Devuelve una cadena indicado las unidades de medida (bytes, KB - Kilobytes MB - Megabytes)
* en las que está expresada la cantidad.
*/
static std::string asByte (const int value) throw ();
/**
Devuelve la cadena que contiene el resultado de aplicar la especificacion \em format
sobre el resto de los parametros.
\param format especificacion de formato similiar al empleado en las funciones \em printf,
\em scanf, etc.
\return la cadena que contiene el resultado de aplicar la especificacion \em format
sobre el resto de los parametros.
*/
static std::string asString (const char* format, ...) throw ();
/**
Interpreta la cadena recibida como parametro como un dato de tipo boolean.
Si la cadena vale NULL, o contiene los literales "false" o "0" devolvera \em false,
si contiene los literales "true" o "1" devolvera \em true, en otro caso devolvera un excepcion.
\param str Cadena a interpretar.
\return El valor booleano correspondiente a la cadena recibida.
*/
static bool asBool (const char* str) throw (Exception);
/**
Interpreta la cadena recibida como parametro como un entero de 32 bits.
\return
*/
static int asInteger (const char* str) throw () { return atoi (str); }
/**
Interpreta la cadena recibida como parametro como un entero de 32 bits.
\return
*/
static Integer64 asInteger64 (const char* str) throw ();
/**
* Devuelve el número de bits necesarios para representar el valor recibido como parámetro.
* \param n Valor a estudiar.
* \return el número de bits necesarios para representar el valor recibido como parámetro.
*
*/
static int bitsize (const int n) throw () { return (n == 0) ? 1: functions::log2 (n) + 1; }
/**
* Devuelve el número de bits necesarios para representar el valor recibido como parámetro.
* \param n Valor a estudiar.
* \return el número de bits necesarios para representar el valor recibido como parámetro.
*
*/
static int bitsize (const Integer64 n) throw () {
register int aux = n >> intBitSize;
return (aux != 0) ? (bitsize (aux) + intBitSize): bitsize ((int) n);
}
/**
* Calcula el logaritmo en base 2 del número recibo como parámetro.
* \param v Valor a calcular.
* \return El algoritmo en base 2 del número recibido como parámetro o -1 si el parámetro recibido es 0.
*/
static int log2 (const unsigned int v) throw ();
/**
Calcula la funcion hash de la cadena recibida como parametro.
\param str Cadena a la que aplicar la funcion hash.
*/
static Integer64 hash (const char* str) throw ();
static const DataBlock& encodeShort (const Short value) throw (Exception);
static const DataBlock& encodeInteger (const int value) throw (Exception);
static const DataBlock& encode (const std::string& domain) throw (Exception);
static Short decodeShort (const char*& buffer) throw ();
// static int decodeInteger (const char*& buffer) throw ();
};
}
}
#endif
| true |
597643c2f5962d77ca9489ed5ccd69ff6e9d711f | C++ | ijh165/StreamlinedGradingSystem | /src/Model/CLASSES/account.cpp | UTF-8 | 8,685 | 2.71875 | 3 | [] | no_license | /************************************
*
* File Name: account.cpp
* Purpose : This class handles account model and account related action (when user is logged in)
*
* Authors:
* ihoo
* rca71
* cyrusc
* jhoi
* ftran
*
* Revision: 1.0
*
***********************************/
#include "account.h"
#include <QDebug>
Account::Account()
{
firstName='\0';
midName='\0';
lastName='\0';
userID='\0';
employeeID='\0';
password='\0';
isTA=false;
isInstructor=false;
isAdmin=false;
isAdminAssist=false;
isSysAdmin=false;
isNewAccount = false;
}
/* Constructor to initialize account object from database given user ID
* Note: caller need to verify that user exist */
Account::Account(QString _userID)
{
dbManager db;
QSqlQueryModel* AccountModel = db.getAllUserInfo(_userID);
accountID = AccountModel->record(0).value("accountID").toInt();
firstName = AccountModel->record(0).value("firstName").toString();
midName = AccountModel->record(0).value("middleName").toString();;
lastName = AccountModel->record(0).value("lastName").toString();;
userID = _userID;
employeeID = AccountModel->record(0).value("employeeID").toString();
password = AccountModel->record(0).value("password").toString();
isTA = AccountModel->record(0).value("isTA").toBool();
isInstructor = AccountModel->record(0).value("isInstructor").toBool();
isAdmin = AccountModel->record(0).value("isAdmin").toBool();
isAdminAssist = AccountModel->record(0).value("isAdminAssist").toBool();
isSysAdmin = AccountModel->record(0).value("isSystemAdmin").toBool();
isNewAccount = AccountModel->record(0).value("isPasswordTemp").toBool();
delete AccountModel;
}
Account::Account(QString _employeeID, int stub) //stub is useless variable reason why I add this is so that I can overload the constructor
{
(void)stub;
dbManager db;
QSqlQueryModel* AccountModel = db.getAllUserInfo_EID(_employeeID);
accountID = AccountModel->record(0).value("accountID").toInt();
firstName = AccountModel->record(0).value("firstName").toString();
midName = AccountModel->record(0).value("middleName").toString();
lastName = AccountModel->record(0).value("lastName").toString();
userID = AccountModel->record(0).value("userName").toString();
employeeID = _employeeID;
password = AccountModel->record(0).value("password").toString();
isTA = AccountModel->record(0).value("isTA").toBool();
isInstructor = AccountModel->record(0).value("isInstructor").toBool();
isAdmin = AccountModel->record(0).value("isAdmin").toBool();
isAdminAssist = AccountModel->record(0).value("isAdminAssist").toBool();
isSysAdmin = AccountModel->record(0).value("isSystemAdmin").toBool();
isNewAccount = AccountModel->record(0).value("isPasswordTemp").toBool();
stub=-999; //this is useless variable reason why I add this is so that I can overload the constructor
delete AccountModel;
}
Account::Account(QString _firstName,
QString _midName,
QString _lastName,
QString _userID,
QString _employeeID,
QString _password,
bool _isTA,
bool _isInstructor,
bool _isAdmin,
bool _isAdminAssist,
bool _isSysAdmin)
{
firstName=_firstName;
midName=_midName;
lastName=_lastName;
userID=_userID;
employeeID=_employeeID;
password=_password;
isTA=_isTA;
isInstructor=_isInstructor;
isAdmin=_isAdmin;
isAdminAssist=_isAdminAssist;
isSysAdmin=_isSysAdmin;
}
Account::~Account()
{
}
//setters
void Account::setFirstName(QString _firstName)
{
firstName=_firstName;
}
void Account::setMidName(QString _midName)
{
midName=_midName;
}
void Account::setLastName(QString _lastName)
{
lastName=_lastName;
}
void Account::setUserID(QString _userID)
{
userID=_userID;
}
void Account::setEmployeeID(QString _employeeID)
{
employeeID=_employeeID;
}
void Account::setPassword(QString _password)
{
password=_password;
}
void Account::setIsNewAccount(bool bVal)
{
isNewAccount = bVal;
}
void Account::setIsBlocked(bool bVal)
{
isBlocked = bVal;
}
//getters
QString Account::getFirstName()
{
return firstName;
}
QString Account::getMidName()
{
return midName;
}
QString Account::getLastName()
{
return lastName;
}
QString Account::getUserID()
{
return userID;
}
QString Account::getEmployeeID()
{
return employeeID;
}
QString Account::getPassword()
{
return password;
}
bool Account::isAccountSysAdmin()
{
return isSysAdmin;
}
bool Account::isAccountAdminAssist()
{
return isAdminAssist;
}
bool Account::isAccountAdmin()
{
return isAdmin;
}
bool Account::isAccountInstructor()
{
return isInstructor;
}
bool Account::isAccountTA()
{
return isTA;
}
bool Account::isAccountBlocked()
{
return isBlocked;
}
bool Account::isAccountFirstLogin()
{
qDebug() << "current account isNewAccount? " << isNewAccount;
return isNewAccount;
}
int Account::getAccountID()
{
return accountID;
}
/*=====================================MISC_FUNCTIONS==========================================*/
//retrieve course ID
int Account::retrieveCourseID(QString courseName, QString courseNumber, QString startDate, QString endDate)
{
dbManager db;
int CourseID = db.retrieveCourseID(courseName,courseNumber,startDate,endDate);
return CourseID;
}
int Account::getcourseNumCount(){
dbManager db;
int courseNumCount = db.getNumberOfAssignedCourses(employeeID);
return courseNumCount;
}
int Account::getactivityNumCount(){
dbManager db;
int courseNumCount = db.getNumberOfAssignedActivity(employeeID);
return courseNumCount;
}
//......................................
QString Account::searchmyCourse(int recordNumber)
{
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
QString Course = /*CourseModel->record(recordNumber).value("courseName").toString() +*/
" " + CourseModel->record(recordNumber).value("courseNumber").toString() +
" From "+CourseModel->record(recordNumber).value("startDate").toString() +
" to "+CourseModel->record(recordNumber).value("endDate").toString();
return Course;
}
void Account::searchmyActivity(int rowNumber, int recordNumber,QString &ActivityName,QString &ActivityType)
{
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
QString courseID = CourseModel->record(rowNumber).value("courseID").toString();
QSqlQueryModel* ActivityModel = db.getListActivity(courseID);
ActivityName = ActivityModel->record(recordNumber).value("activityName").toString();
ActivityType = ActivityModel->record(recordNumber).value("activityType").toString();
}
//.......................
QString Account::getCourseName(int recordNumber){
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
QString Name = CourseModel->record(recordNumber).value("courseName").toString();
return Name;
}
QString Account::getCourseNumber(int recordNumber){
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
QString Number = CourseModel->record(recordNumber).value("courseNumber").toString();
return Number;
}
QString Account::getStartDate(int recordNumber){
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
QString StartDate = CourseModel->record(recordNumber).value("startDate").toString();
return StartDate;
}
QString Account::getEndDate(int recordNumber){
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
QString EndDate = CourseModel->record(recordNumber).value("endDate").toString();
return EndDate;
}
void Account::getownActivityInfo_Data(int rowNumberofCourseList,QString activityName,
QString &dueDateTime, QString &pathToSolution ,QString &pathToSubmissions,QString &language, QString &ActivityID,QString &courseID){
dbManager db;
QSqlQueryModel* CourseModel = db.getAssignedCourses(employeeID);
courseID = CourseModel->record(rowNumberofCourseList).value("courseID").toString();
QSqlQueryModel* ActivityModel= db.getActivityInfo(courseID, activityName);
dueDateTime = ActivityModel->record(0).value("dueDateTime").toString();
pathToSolution = ActivityModel->record(0).value("pathToSolution").toString();
pathToSubmissions = ActivityModel->record(0).value("pathToSubmissions").toString();
language = ActivityModel->record(0).value("language").toString();
ActivityID = ActivityModel->record(0).value("activityID").toString();
}
| true |
71a5c979a0c2efaef591fffe85e6ddfbcf169e44 | C++ | rajibkumardas/vor | /vor-arduino/vor_led.cpp | UTF-8 | 357 | 2.796875 | 3 | [
"MIT"
] | permissive | /*
Arduino on-board LED actuator for testing.
*/
#include "vor_led.h"
VorLed::VorLed() :
VorActuator(LED_PIN, DIGITAL_OUTPUT) {
turnOff();
}
void VorLed::turnOn() {
VorActuator::write(HIGH);
_on = true;
}
void VorLed::turnOff() {
VorActuator::write(LOW);
_on = false;
}
void VorLed::toggle() {
_on ? turnOff() : turnOn();
}
| true |
a973f5704f45ab4ef44fd336213ba73948ceb86f | C++ | kaiwang19/Data_Structures_and_Algorithms | /arrays/array.cpp | UTF-8 | 487 | 3.46875 | 3 | [] | no_license | #include <iostream>
#include <string>
using namespace std;
using std::string;
int main()
{
int myNum[3] = {10, 20, 30};
string myArray[4];
string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
for (int i = 0; i < 4; i++)
{
cout << cars[i] << "\n";
}
string myCars[] = {"Volvo", "BMW", "Ford"}; // size of array is always 3
string hisCars[5] = {"Volvo", "BMW", "Ford"}; // size of array is 5, even though it's only three elements inside it
}
| true |
2aaa606a403859edbdb69001874318d8cba2fa46 | C++ | seleznevaksenia/algorithms | /lab_05.cpp | WINDOWS-1251 | 596 | 2.625 | 3 | [] | no_license | /*6. n: */
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
void main()
{
int i, m, n;
cout << "i=";
cin >> i;
cout << "\n";
for (n = 1; n <= i; n++) {
for (m = 1; m <= i; m++) {
if (m >= 10 && n >= 10 || n<10)
cout << "1/" << m << "!^" << n << " ";
if (m < 10 && n >= 10)
cout << "1/" << m << "!^" << n << " ";
}
cout << "\n";
}
cout << "\n";
cout << "Press any key";
_getch();//
}
| true |
b0894de9cf31184144e86e4339c598f71b6a3bf8 | C++ | 0xflotus/Acid | /Sources/Scenes/ISpatialStructure.hpp | UTF-8 | 3,419 | 3.03125 | 3 | [
"MIT"
] | permissive | #pragma once
#include <memory>
#include <vector>
#include "Physics/Frustum.hpp"
namespace acid
{
class GameObject;
class IComponent;
class Collider;
/// <summary>
/// A data structure that stores objects with a notion of space.
/// </summary>
class ACID_EXPORT ISpatialStructure
{
public:
/// <summary>
/// Adds a new object to the spatial structure.
/// </summary>
/// <param name="object"> The object to add. </param>
virtual void Add(GameObject *object) = 0;
/// <summary>
/// Adds a new object to the spatial structure.
/// </summary>
/// <param name="object"> The object to add. </param>
virtual void Add(std::unique_ptr<GameObject> object) = 0;
/// <summary>
/// Removes an object from the spatial structure.
/// </summary>
/// <param name="object"> The object to remove. </param>
/// <returns> If the object was removed. </returns>
virtual bool Remove(GameObject *object) = 0;
/// <summary>
/// Moves an object to another spatial structure.
/// </summary>
/// <param name="object"> The object to remove. </param>
/// <param name="structure"> The structure to move to. </param>
/// <returns> If the object was moved. </returns>
virtual bool Move(GameObject *object, ISpatialStructure *structure) = 0;
/// <summary>
/// Removes all objects from the spatial structure..
/// </summary>
virtual void Clear() = 0;
/// <summary>
/// Updates all of the game object.
/// </summary>
virtual void Update() = 0;
/// <summary>
/// Gets the size of this structure.
/// </summary>
/// <returns> The structures size. </returns>
virtual uint32_t GetSize() = 0;
/// <summary>
/// Returns a set of all objects in the spatial structure.
/// </summary>
/// </param>
/// <returns> The list specified by of all objects. </returns>
virtual std::vector<GameObject *> QueryAll() = 0;
/// <summary>
/// Returns a set of all objects in a spatial objects contained in a frustum.
/// </summary>
/// <param name="range"> The frustum range of space being queried. </param>
/// </param>
/// <returns> The list of all object in range. </returns>
virtual std::vector<GameObject *> QueryFrustum(const Frustum &range) = 0;
/// <summary>
/// Returns a set of all objects in a spatial objects contained in a sphere.
/// </summary>
/// <param name="centre"> The centre of the sphere. </param>
/// <param name="radius"> The spheres radius. </param>
/// <param name="result"> The list to store the data into.
/// </param>
/// <returns> The list of all object in range. </returns>
// virtual std::vector<GameObject *> QuerySphere(const Vector3 ¢re, const Vector3 &radius) = 0;
/// <summary>
/// Returns a set of all objects in a spatial objects contained in a cube.
/// </summary>
/// <param name="min"> The minimum point of the cube. </param>
/// <param name="max"> The maximum point of the cube. </param>
/// <param name="result"> The list to store the data into.
/// </param>
/// <returns> The list of all object in range. </returns>
// virtual std::vector<GameObject *> QueryCube(const Vector3 &min, const Vector3 &max) = 0;
/// <summary>
/// If the structure contains the object.
/// </summary>
/// <param name="object"> The object to check for.
/// </param>
/// <returns> If the structure contains the object. </returns>
virtual bool Contains(GameObject *object) = 0;
};
}
| true |
1350e9d45e393894918da18a36f0083aa79b858a | C++ | octavianpetru/rfio | /rfio.cpp | UTF-8 | 3,705 | 2.828125 | 3 | [] | no_license | #include "rfio.h"
#include <cstdio>
#include "RCSwitch.h"
#include "wiringPi.h"
unsigned long before;
unsigned int indexReceive = 0;
RCSwitch mySwitch = RCSwitch();
int main(int argc, char **argv) {
// setup wiringPi
if (wiringPiSetup() == -1) {
return -1;
}
// TX_POWER_PIN
pinMode(TX_POWER_PIN, OUTPUT);
digitalWrite(TX_POWER_PIN, LOW);
// enable transmit
mySwitch.enableTransmit(TX_PIN);
mySwitch.setProtocol(1);
mySwitch.setRepeatTransmit(8);
// enable receive
mySwitch.enableReceive(RX_PIN); // Receiver on interrupt 0 => that is pin #2
printf("RCSWITCH_MAX_CHANGES: %d\n\n", RCSWITCH_MAX_CHANGES);
before = millis();
indexReceive = 0;
for (;;) {
if (mySwitch.available()) {
unsigned long receivedValue = mySwitch.getReceivedValue();
char receivedValueStr[33] = { '\0' };
toBinStr(receivedValue, receivedValueStr, 32);
printf("%s\n", receivedValueStr);
mySwitch.resetAvailable();
TemperatureMessage *temperatureMessage = readReceivedValue(
receivedValue);
char outputString[160];
sprintf(outputString,
"indexReceive %3d / startLabel: %s / id: %3d / canal: %1d / temperature: %4d / temperatureStr: %s / endLabel: %s / time: %lu\n\n",
(*temperatureMessage).indexReceive,
(*temperatureMessage).startLabel, (*temperatureMessage).id,
(*temperatureMessage).canal, (*temperatureMessage).temperature,
(*temperatureMessage).temperatureStr,
(*temperatureMessage).endLabel, (*temperatureMessage).time);
printf(outputString);
// enable TX
digitalWrite(TX_POWER_PIN, HIGH);
delay(1000);
char s[13] = { '\0' };
toBinStr((*temperatureMessage).temperature, s, 12);
char str[38] = { '\0' };
sprintf(str, "1001001000110010%s110011000", s);
mySwitch.sendString(str);
// disable TX
digitalWrite(TX_POWER_PIN, LOW);
char outputStringSend[160];
sprintf(outputStringSend,"%3d sent %3d\n\n", (*temperatureMessage).indexReceive, (*temperatureMessage).temperature);
printf(outputStringSend);
free(temperatureMessage);
}
}
return 0;
}
void toBinStr(long value, char* output, int i) {
output[i] = '\0';
for (i = i - 1; i >= 0; --i, value >>= 1) {
output[i] = (value & 1) + '0';
}
}
/*
* 10010111010100000000111010111100
* missing the last 5 bits (37 in total)
*/
TemperatureMessage *readReceivedValue(unsigned long receivedValue) {
// allocate struct
TemperatureMessage *temperatureMessage;
temperatureMessage = (TemperatureMessage*) malloc(
sizeof(TemperatureMessage));
// start label
short startLabelLong = (receivedValue >> 28) & 15;
toBinStr(startLabelLong, (*temperatureMessage).startLabel, 4);
// id
(*temperatureMessage).id = (receivedValue >> 20) & 255;
// canal
(*temperatureMessage).canal = (receivedValue >> 16) & 15;
(*temperatureMessage).canal += 1;
// temperature
(*temperatureMessage).temperature = (receivedValue >> 4) & 4095;
// 2^12 = 4096
if ((*temperatureMessage).temperature > 2047) {
(*temperatureMessage).temperature = -(4096
- (*temperatureMessage).temperature);
}
// temperature as string
short upperValue = (*temperatureMessage).temperature / 10 * 10;
short lowerValue = abs((*temperatureMessage).temperature - upperValue);
upperValue /= 10;
sprintf((*temperatureMessage).temperatureStr, "%3d%s%1d", int(upperValue),
".", lowerValue);
(*temperatureMessage).temperatureStr[5] = '\0';
// end label
short endLabelLong = receivedValue & 15;
toBinStr(endLabelLong, (*temperatureMessage).endLabel, 4);
// index of receive
(*temperatureMessage).indexReceive = ++indexReceive;
// time since last
(*temperatureMessage).time = millis() - before;
before = millis();
return temperatureMessage;
}
| true |
5195580d62ad788e979a5d0c31cd80639b1ffdc0 | C++ | HOSHICHEN7267/1092CP2 | /homework/bus.cpp | UTF-8 | 1,715 | 2.84375 | 3 | [] | no_license | #include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std;
int main(){
int start = 0, target = 0;
int busnum = 0;
int stopnum = 0;
unordered_map< int, vector<int> > stops;
vector< vector<int> > route;
queue<int> bfs;
int ans = 0;
cin >> start >> target >> busnum;
if(start == target){
cout << 0 << '\n';
return 0;
}
for(int i = 0 ; i < busnum ; ++i){
cin >> stopnum;
vector<int> tmp;
for(int j = 0 ; j < stopnum ; ++j){
//cout << "j: " << j << '\n';
int a;
cin >> a;
tmp.push_back(a);
}
route.push_back(tmp);
}
for(int i = 0 ; i < route.size() ; ++i){
//cout << "i: " << i << '\n';
for(int j : route[i]){
stops[j].push_back(i);
}
}
vector<int> visited(route.size(), 0);
bfs.push(start);
while(!bfs.empty()){
int num = bfs.size();
++ans;
while(num--){
//cout << "num: " << num << '\n';
int now = bfs.front();
bfs.pop();
for(int i : stops[now]){
//cout << "i: " << i << '\n';
if(visited[i]){
continue;
}
visited[i] = 1;
for(int j : route[i]){
//cout << "j: " << j << '\n';
if(j == target){
cout << ans << '\n';
return 0;
}
bfs.push(j);
}
//cout << '\n';
}
}
}
cout << -1 << '\n';
return 0;
}
| true |
d877c0a2bdc3ab5d4275f8672a797146b255e4f1 | C++ | PraiseHelix/PocketAnimals | /LevelOpenWorldPocketAnimals.hpp | UTF-8 | 742 | 2.5625 | 3 | [
"MIT"
] | permissive | #pragma once
#include "..\SGPE\Level.hpp"
#include "GraphicsSFMLGrid.hpp"
class LevelOpenWorldPocketAnimals : public Level
{
private:
std::vector<GameObject*> gameObjects;
std::shared_ptr<GraphicsSFMLGrid> graphics;
public:
LevelOpenWorldPocketAnimals(std::vector<GameObject*> gameObjects, std::shared_ptr<GraphicsSFMLGrid> graphics) :Level(gameObjects, graphics), gameObjects(gameObjects), graphics(graphics) {};
/// \brief
/// Calls the update function of all it's gameobject
void Update() {
for (auto gb : gameObjects) {
gb->onUpdate();
}
};
void Start() {
// should have an init function if required
};
/// \brief
/// Calls the graphics render mode
void Render() {
graphics->Render();
};
void Close() {}
};
| true |
0772fd78926580822157ed358be8bd6d1d2ed302 | C++ | meteorsnows/QuickCut | /src/QuickCutShared/Action.h | UTF-8 | 1,608 | 2.828125 | 3 | [
"MIT"
] | permissive |
#pragma once
#include <string>
enum eActionType { ActionKeyMap = 0x00, ActionAppStart = 0x01, ActionUnknown = 0xFF };
class Action
{
public:
Action();
Action(std::string name, const eActionType & type,
std::string srcKey, std::string dstKey,
std::string appPath, std::string appArgs);
Action(std::string id, std::string name, const eActionType & type,
std::string srcKey, std::string dstKey,
std::string appPath, std::string appArgs,
std::string createdDate);
static std::string getType(eActionType type);
static eActionType getType(const std::string & type);
static std::string getKey(int key);
const std::string & getId() const;
const std::string & getName() const;
void setName(const std::string & name);
eActionType getType() const;
void setType(eActionType type);
std::string getSrcKey() const;
void setSrcKey(const std::string & key);
std::string getDstKey() const;
void setDstKey(const std::string & key);
const std::string & getAppPath() const;
void setAppPath(const std::string & path);
const std::string & getAppArgs() const;
void setAppArgs(const std::string & path);
const std::string & getCreatedDate() const;
void reset();
private:
std::string m_szUuid;
std::string m_szName;
eActionType m_eType;
std::string m_szSrcKey; // string with delimited ',' char. Could have multiple keys.
std::string m_szDstKey;
std::string m_szAppPath;
std::string m_szAppArgs;
std::string m_szCreatedDate;
}; | true |
4f0e22f481aca922dad8fc23dbabe6277d0dea26 | C++ | csheare/2D | /bb/lists.cpp | UTF-8 | 399 | 2.75 | 3 | [] | no_license | #include<iostream>
#include<cstring>
#include<list>
#include<map>
#include<vector>
int main(){
std::map<std::string,int> map;
std::list<int> list;
map["A"] = 1;
std::vector<int> vec;
vec.reserve(2);
std::vector<int> vec2(2);
std::cout<< vec.capacity() <<std::endl;
std::cout<< vec2.capacity() <<std::endl;
std::cout<< map["A"] <<std::endl;
//map["B"] = 2;
//std::cout<< map <<std::endl;
}
| true |
a03cecc3be708ab09aaf95df59ff4deef62d6e4e | C++ | fanfeilong/dcel | /src/stlpache.string.h | UTF-8 | 3,331 | 3.21875 | 3 | [
"MIT"
] | permissive | #ifndef DCEL_STLPACHE_STRING_H
#define DCEL_STLPACHE_STRING_H
#include <string>
#include <iterator>
#include <sstream>
using namespace std;
namespace stlpache
{
inline string& left_trim(string &ss)
{
string::iterator p=find_if(ss.begin(),ss.end(),not1(ptr_fun(isspace)));
ss.erase(ss.begin(),p);
return ss;
}
inline string& right_trim(string &ss)
{
string::reverse_iterator p=find_if(ss.rbegin(),ss.rend(),not1(ptr_fun(isspace)));
ss.erase(p.base(),ss.end());
return ss;
}
inline string& trim(string &st)
{
left_trim(right_trim(st));
return st;
}
inline std::string itos(int i)
{
std::stringstream ss;
std::string s;
ss << i;
s = ss.str();
return s;
}
inline std::string ws2s(const std::wstring& ws)
{
std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest,0,_Dsize);
wcstombs(_Dest,_Source,_Dsize);
std::string result = _Dest;
delete []_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
inline std::wstring s2ws(const std::string& s)
{
setlocale(LC_ALL, "chs");
const char* _Source = s.c_str();
size_t _Dsize = s.size() + 1;
wchar_t *_Dest = new wchar_t[_Dsize];
wmemset(_Dest, 0, _Dsize);
mbstowcs(_Dest,_Source,_Dsize);
std::wstring result = _Dest;
delete []_Dest;
setlocale(LC_ALL, "C");
return result;
}
struct string_token_iterator : public std::iterator<std::input_iterator_tag, std::string>
{
public:
string_token_iterator() : str(0), start(0), end(0) {}
string_token_iterator(const std::string & str_, const char * separator_ = " ")
:separator(separator_),str(&str_),end(0)
{
find_next();
}
string_token_iterator(const string_token_iterator & rhs)
:separator(rhs.separator),str(rhs.str),start(rhs.start),end(rhs.end)
{
}
string_token_iterator & operator++()
{
find_next();
return *this;
}
string_token_iterator operator++(int)
{
string_token_iterator temp(*this);
++(*this);
return temp;
}
std::string operator*() const
{
return std::string(*str, start, end - start);
}
bool operator==(const string_token_iterator & rhs) const
{
return (rhs.str == str && rhs.start == start && rhs.end == end);
}
bool operator!=(const string_token_iterator & rhs) const
{
return !(rhs == *this);
}
private:
void find_next(void)
{
start = str->find_first_not_of(separator, end);
if(start == std::string::npos)
{
start = end = 0;
str = 0;
return;
}
end = str->find_first_of(separator, start);
}
const char * separator;
const std::string * str;
std::string::size_type start;
std::string::size_type end;
};
struct line
{
std::string data;
operator std::string() const
{
return data;
}
friend std::istream& operator>>(std::istream& in,line& linestr)
{
std::getline(in,linestr.data);
return in;
}
friend std::ostream& operator<<(std::ostream& out,line const& linestr)
{
out<<linestr.data;
return out;
}
};
typedef std::istream_iterator<line> istream_line_iterator;
typedef std::ostream_iterator<line> ostream_line_iterator;
}
#endif | true |
f8d14aa143994f6efa385ea70ff227bd9235d683 | C++ | qfu/LeetCode_1 | /M_3_Longest_Substring_Without_Repeating_Characters.cpp | UTF-8 | 1,509 | 3.203125 | 3 | [] | no_license | #include <unordered_map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int size = s.size();
if(!size) return 0;
vector<int> dp(size,0);
unordered_map<char,int> map;
int p = 1;
int m = 0;
dp[0] = 1;
map[s[0]] = 1;
for (int i = 1; i < size; ++i){
if(s[i] != s[i-1] && !map[s[i]]) dp[i] = max(dp[i],dp[i-1]+1);
else if(s[i] != s[i-1] && map[s[i]]){
p = max(dp[i-1],p);
//because I cannot include the previous occurance
// what is fucked up is the first value
//not necessary start from the top
if(map[s[i]] == 1 && s.find_first_of(s[i]) == 0){
m = max(1,m);
dp[i] = dp[i-1];
}
else{
m = max(map[s[i]],m);
dp[i] = dp[i-1]- dp[m]+1;
}
}
//if(i == 4) cout << dp[i] << " 1";
p = max(dp[i],p);
map[s[i]] = i;
}
return p;
}
};
int main(int argc, char const *argv[])
{
/* code */
string t1 = "abcabcbb";
string t2 = "bbbbb";
string t3 = "pwwkew";
string t4 = "ckilbkd";
string t5 = "dcdf";
Solution s;
cout << s.lengthOfLongestSubstring(t1);
cout << s.lengthOfLongestSubstring(t2);
cout << s.lengthOfLongestSubstring(t3);
cout << s.lengthOfLongestSubstring(t4);
cout << s.lengthOfLongestSubstring(t5);
return 0;
} | true |
0e2f3fb044c9dd0b52d3700ab527a3a8c86c28be | C++ | youkuxiaobin/algorithm | /quick/main.cpp | UTF-8 | 1,499 | 3.328125 | 3 | [] | no_license | /*
* =====================================================================================
*
* Filename: main.cpp
*
* Description: 快排函数
*
* Version: 1.0
* Created: 2015年03月01日 19时37分06秒
* Revision: none
* Compiler: gcc
*
* Author: liyankun (), liyankun@baidu.com
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <iostream>
using namespace std;
void swap(int& a, int& b)
{
int c = a;
a = b;
b = c;
}
/*
* * 快速排序的分区函数
* */
int partition(int a[], int start, int end)
{
int partion = a[end];
int i = start - 1;
for (int j = start; j <= end-1; j++)
{
if (a[j] < partion)
{
i++;
swap(a[i], a[j]);
}
}
swap(a[i+1], a[end]);
return i+1;
}
void quicksort(int a[], int start, int end)
{
if (start < end)
{
int q = partition(a, start, end);
quicksort(a, start, q-1);
quicksort(a, q+1, end);
}
}
void output(int a[], int count)
{
for (int i = 0; i< count; i++)
{
cout<<"array["<<i<<"] = "<<a[i]<<endl;
}
}
int main(int argc, char** argv)
{
int a[] = {2, 8, 7, 1, 3, 5, 6, 4};
int count = sizeof(a)/sizeof(a[0]);
cout<<"sort before"<<endl;
output(a, count);
quicksort(a, 0, count -1);
cout<<"sort after"<<endl;
output(a, count);
return 0;
}
| true |
e342fc32433068e70abbdcd0ce0c59871d8c6c87 | C++ | Yoriyakd/SnowFight | /就職作品/UI/TimePenaltyUI.cpp | SHIFT_JIS | 2,383 | 2.734375 | 3 | [] | no_license | #include "TimePenaltyUI.h"
#include"../DirectX/Sprite.h"
TimePenaltyUI::TimePenaltyUI(int _MinusTime) : effectDisplayFlag(-1), flashIntervalCnt(0) , penaltyTime_s(_MinusTime), displayTime_frame(90)
{
minusTex = GetResource.GetTexture(TimePenalty_Tex);
numberTex = GetResource.GetTexture(TimeNumber_Tex);
effectTex = GetResource.GetTexture(TimePenaltyEffect_Tex);
D3DXMatrixTranslation(&numberOffsetMat, 56, 0, 0);
D3DXMatrixTranslation(&mat, 100, 60, 0);
D3DXMatrixTranslation(&effectMat, -60, -30, 0);
}
TimePenaltyUI::~TimePenaltyUI()
{
}
void TimePenaltyUI::Draw()
{
if (effectDisplayFlag == 1)
{
RECT RcEffect = { 0, 0, 256, 256 };
Sprite::GetInstance().GetSprite()->SetTransform(&effectMat);
Sprite::GetInstance().GetSprite()->Draw(effectTex, &RcEffect, &D3DXVECTOR3(0, 0, 0), NULL, D3DCOLOR_ARGB(255, 255, 255, 255));
}
RECT RcMinus = { 0, 0, 46, 46 };
Sprite::GetInstance().GetSprite()->SetTransform(&mat);
Sprite::GetInstance().GetSprite()->Draw(minusTex, &RcMinus, &D3DXVECTOR3(0, 0, 0), NULL, D3DCOLOR_ARGB(alpha, 255, 255, 255));
int DisplayNum;
const int NUM_DIGITS = 4; //\0}邽3\4
char cTime[NUM_DIGITS];
D3DXMATRIX NumberMat, NumberDisMat;
D3DXMatrixTranslation(&NumberDisMat, 40, 0, 0); //̊Ԋu
NumberMat = mat * numberOffsetMat;
sprintf_s(cTime, sizeof(cTime), "%d", penaltyTime_s); //1o悤ɕɕϊ
for (int i = 0; i < NUM_DIGITS; i++)
{
if (cTime[i] == '\0')break; //vf̏I[Ȃbreak
DisplayNum = cTime[i] - '0'; //ɕϊ
RECT RcNumber = { 46 * DisplayNum, 0, 46 * (DisplayNum + 1), 46 };
Sprite::GetInstance().GetSprite()->SetTransform(&NumberMat);
Sprite::GetInstance().GetSprite()->Draw(numberTex, &RcNumber, &D3DXVECTOR3(0, 0, 0), NULL, D3DCOLOR_ARGB(alpha, 255, 255, 255));
NumberMat = NumberDisMat * NumberMat; //Eɂ炷
}
}
bool TimePenaltyUI::Update()
{
displayTime_frame--;
if (displayTime_frame > 0)
{
flashIntervalCnt--;
if (flashIntervalCnt < 0)
{
effectDisplayFlag *= -1;
flashIntervalCnt = EFFECT_FLASH_INTERVAL;
}
return true; //\ԂIĂ甖Ȃn߂
}
D3DXMATRIX Tmp;
D3DXMatrixTranslation(&Tmp, 0, -0.3f, 0);
mat = Tmp * mat;
alpha -= 2;
if (alpha < 0)
{
return false;
}
return true;
}
| true |
2019ff9f95a0223e49c0cc6d55872fafaf67c973 | C++ | AJaySi/Arduino-HCSR04 | /multi_hcrs04.ino | UTF-8 | 3,680 | 2.8125 | 3 | [] | no_license | #include <NewPing.h>
/*
The NewPing library written by Tim Eckel provides :
1. Works with many ultrasonic sensor models: SR04, SRF05, SRF06, DYP-ME007 & Parallax PING
2. Doesn't lag for a full second if no ping echo is received like all other ultrasonic libraries
3. Ping sensors consistently and reliably at up to 30 times per second
4. Timer interrupt method for event-driven sketches
5. Doesn't use pulseIn, which is slow and gives incorrect results with some ultrasonic sensor models
...
*/
// Include the NewPing library. Instructions at https://playground.arduino.cc/Code/NewPing/
#define triggerPinFront 9
#define echoPinFront 10
#define triggerPinBack 11
#define echoPinBack 12
#define MAX_DISTANCE_BACK 250
#define MAX_DISTANCE_FRONT 350
// Constructor: NewPing sonar(trigger_pin, echo_pin [, max_cm_distance]);
// Initializes NewPing to use pin 12(trigger output) and pin 11 for echo input, with max_ping_distance to 350cm
NewPing sonarFront(triggerPinFront, echoPinFront, MAX_DISTANCE_FRONT);
NewPing sonarBack(triggerPinBack, echoPinBack, MAX_DISTANCE_BACK);
float duration, distance;
void setup()
{
// Start the serial monitor, at 9600 baudrate.
Serial.begin(9600);
}
void loop()
{
float backDistance = back_distance();
Serial.println(F("Back Object distance is: "));
Serial.print(backDistance);
Serial.println(" cms");
float frontDistance = front_distance();
Serial.println(F("Front object distance is: "));
Serial.print(frontDistance);
Serial.println(" cms");
}
// Common function to get the distance to nearest object at the back.
float back_distance()
{
// Wait 50ms between pings (about 20 pings/sec).
// 29ms should be the shortest delay between pings.
delay(500);
Serial.println(F("#####################################"));
Serial.println(F("Starting NewPing HC-SR04 measurements"));
Serial.print("Using sonar.ping_cm: ");
Serial.print(sonarBack.ping_cm());
Serial.println("cm");
duration = sonarBack.ping();
distance = (duration / 2) * 0.0343;
Serial.print("Self Calculated: ");
// Distance will be 0 when out of set max range.
Serial.print(distance);
Serial.println(" cms");
// The ping_median() function takes 'n' duration measurements in a row,
// throws away the out of range readings and then averages the remaining ones.
int iterations = 5;
duration = sonarBack.ping_median(iterations);
distance = (duration / 2) * 0.0343;
Serial.print("Median Calculated: ");
Serial.print(distance);
Serial.println(" cms");
// return the median calculated distance from duration.
return distance;
}
// Common function to get distance to nearest object, in front.
float front_distance()
{
// Wait 50ms between pings (about 20 pings/sec).
// 29ms should be the shortest delay between pings.
delay(500);
Serial.println(F("#####################################"));
Serial.println(F("Starting NewPing HC-SR04 measurements"));
Serial.print("Using sonar.ping_cm: ");
Serial.print(sonarFront.ping_cm());
Serial.println("cm");
duration = sonarFront.ping();
distance = (duration / 2) * 0.0343;
Serial.print("Self Calculated: ");
// Distance will be 0 when out of set max range.
Serial.print(distance);
Serial.println(" cms");
// The ping_median() function takes 'n' duration measurements in a row,
// throws away the out of range readings and then averages the remaining ones.
int iterations = 5;
duration = sonarFront.ping_median(iterations);
distance = (duration / 2) * 0.0343;
Serial.print("Median Calculated: ");
Serial.print(distance);
Serial.println(" cms");
//return calculated distance from median duration
return distance;
}
| true |
20f6f1bae24fd20090cc5d4fafe0b6b0178de6bb | C++ | colinporth/gpio | /sharp/sharpLcdTest.cpp | UTF-8 | 5,042 | 2.859375 | 3 | [] | no_license | #include "cSharpLcd.h"
#include <unistd.h>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
bool toggle = true;
int numRepetitions = 4;
cSharpLcd sharpLcd;
int lcdWidth = sharpLcd.getDisplayWidth();
int lcdHeight = sharpLcd.getDisplayHeight();
sharpLcd.clearDisplay();
while(1) {
printf ("sinewave\n");
//{{{ print sinewave
float increment = 6.2831f / lcdWidth;
for (float theta = 0; theta < 10.f; theta += 0.1256f) {
for (int y = 0; y < lcdHeight; y++) {
sharpLcd.clearLine();
for (int x = 1; x <= lcdWidth; x++) {
int sinValue = (sin(theta + (x * increment)) * lcdHeight/2) + lcdHeight/2;
if (sinValue >= y && y > lcdHeight/2)
sharpLcd.writePixelToLine (x, 0);
if (sinValue <= y && y <= lcdHeight/2)
sharpLcd.writePixelToLine (x, 0);
}
sharpLcd.lineToFrame (y);
}
sharpLcd.displayFrame();
usleep (10000);
}
//}}}
printf ("circles\n");
//{{{ print expanding and contracting circles
unsigned int originX = lcdWidth/2;
unsigned int originY = lcdHeight/2;
unsigned int expandingCircleRadius = (lcdHeight/2) * 0.9;
for (unsigned int repeat = 0; repeat < 2; repeat++) {
for (unsigned int radius = 5; radius < expandingCircleRadius; radius++) {
sharpLcd.clearDisplay();
for (unsigned int y = originY - radius; y <= originY; y++) {
sharpLcd.clearLine();
// need to calculate left and right limits of the circle
float theta = acos (float(abs (originY - (float)y))/float(radius));
theta -= 1.5708;
unsigned int xLength = cos (theta) * float(radius);
for(unsigned int x = originX - xLength; x <= originX; x++) {
sharpLcd.writePixelToLine (x, 0);
sharpLcd.writePixelToLine (originX + (originX - x), 0);
}
sharpLcd.lineToFrame (y);
sharpLcd.lineToFrame (originY + (originY - y));
}
sharpLcd.displayFrame();
usleep (20000);
}
for (unsigned int radius = expandingCircleRadius; radius > 2; radius--) {
sharpLcd.clearDisplay();
for (unsigned int y = originY - radius; y <= originY; y++) {
sharpLcd.clearLine();
// need to calculate left and right limits of the circle
float theta = acos (float(abs (originY-(float)y))/float(radius)) - 1.5708f;
unsigned int xLength = cos (theta) * float(radius);
for (unsigned int x = originX - xLength; x <= originX ; x++) {
sharpLcd.writePixelToLine (x, 0);
sharpLcd.writePixelToLine (originX + (originX - x), 0);
}
sharpLcd.lineToFrame (y);
sharpLcd.lineToFrame (originY + (originY - y));
}
sharpLcd.clearLine();
sharpLcd.lineToFrame (originY + radius);
sharpLcd.lineToFrame (originY - radius);
sharpLcd.displayFrame();
usleep (20000);
}
}
//}}}
printf ("circling circles\n");
//{{{ print circling circle
numRepetitions = 4;
unsigned int sweepRadius = (lcdHeight/2) * 0.8;
unsigned int sweepOriginX = lcdWidth/2;
unsigned int sweepOriginY = lcdHeight/2;
unsigned int circleRadius = 0.7 * ((lcdHeight/2) - sweepRadius);
for (float rads = 0; rads < 6.2824 * numRepetitions; rads += 0.04) {
sharpLcd.clearDisplay();
// calculate circle centre
unsigned int circleOriginX = sweepOriginX + cos(rads)*sweepRadius;
unsigned int circleOriginY = sweepOriginY + sin(rads)*sweepRadius;
// draw circle about the centre
for(unsigned int y = circleOriginY - circleRadius; y <= circleOriginY; y++) {
sharpLcd.clearLine();
// need to calculate left and right limits of the circle
float theta = acos (float(std::abs (circleOriginY - (float)y)) / float(circleRadius));
theta -= 1.5708;
unsigned int xLength = cos (theta) * float(circleRadius);
for(unsigned int x = circleOriginX - xLength; x <= circleOriginX; x++) {
sharpLcd.writePixelToLine (x, 0);
sharpLcd.writePixelToLine (circleOriginX + (circleOriginX - x), 0);
}
sharpLcd.lineToFrame (y);
sharpLcd.lineToFrame (circleOriginY + circleOriginY - y);
}
sharpLcd.displayFrame();
usleep (10000);
}
//}}}
printf ("chequerboard\n");
//{{{ print chequerboard patterns
numRepetitions = 8;
for (int i = 0; i < numRepetitions; i++) {
sharpLcd.clearDisplay();
for (int y = 0; y < lcdHeight; y++) {
for (int x = 0; x < lcdWidth/8; x++) {
sharpLcd.writeByteToLine (x, toggle ? 0xFF : 0x00);
toggle = !toggle;
}
sharpLcd.lineToFrame (y);
if ((y % 8) == 0)
toggle = !toggle;
}
sharpLcd.displayFrame();
usleep (250000);
toggle = !toggle;
}
//}}}
}
sleep(1);
return 0;
}
| true |
abd9ab954231a6a7aad11782e04e9ceae586e04a | C++ | XI-E/LHospital | /UI/test.cpp | UTF-8 | 5,815 | 3 | 3 | [] | no_license | //No need to use ui::init() explicitly
#include "ui/ui.hpp"
#include "ui/test.hpp"
void test_weird_error()
{
int shit = 14;
box menu2(coord(2, 4), 40, 10 );
menu2 << "Enter your shit: ";
menu2 >> shit;
menu2.setexit_button("Submit my shit");
menu2.loop();
menu2.clear();
menu2 << "Your shit's coming up!" << ui::endl; getch();
menu2 << "Here's your shit: ";
menu2 << shit;
menu2 << ". Deal with it!" << ui::endl;
getch();
}
int exit_func()
{
char c = getch();
int x = wherex(), y = wherey();
gotoxy(1, ui::scr_height - 1);
if(c != '1')
{
cprintf("Returning 0"); getch();
gotoxy(x, y);
return 0;
}
else
{
cprintf("Returning 1"); getch();
gotoxy(x, y);
return 1;
}
}
void test_back()
{
box window;
int a, b;
window << "Here's some sample text" << ui::endl;
window << "Enter some fake data I don't care about" << ui::endl;
window << "Fake #1: "; window >> a;
window << "Fake #2: "; window >> b;
window.setexit_button("A fake button");
window.setback_func(exit_func);
window.loop();
}
void test_all()
{
ui::clrscr();
box menu2(coord(2, 4), 40, 10 );
menu2.settcolor(GREEN);
menu2 << ui::centeralign << "Employee Management" << ui::endl << ui::endl;
menu2.settcolor(WHITE);
int menu2_height;
menu2_height = 10;
// menu2.setheight(menu2_height);
menu2 << "View employee data" << ui::endl;
menu2.settcolor(ui::tcolor);
// menu2 << "Enter employee's id: ";
unsigned long id;
menu2 >> id;
menu2 << ui::endl;
menu2.setexit_button("Submit");
menu2.loop();
menu2.clear();
menu2.setheight(15);
menu2.settcolor(GREEN);
menu2 << ui::centeralign << "Employee Management" << ui::endl << ui::endl;
menu2.settcolor(WHITE);
menu2 << "Employee Details: " << ui::endl;
menu2.settcolor(ui::tcolor);
getch();
menu2.hide();
getch();
menu2.display();
getch();
menu2 << "ID: " << 1 << ui::endl;
getch();
menu2.hide();
getch();
menu2.display();
getch();
char name[40], pwd[40];
int age;
long phn;
float amt;
char date[30];
box window;
window.settcolor(CYAN);
window << ui::centeralign << "LHOSPITAL";
window << ui::endl << ui::endl;
window.settcolor(ui::tcolor);
window.setfooter_tcolor(GREEN);
window << box::setheader << "28/10/2017"
<< box::setheader << ui::rightalign << "11:45 PM"
<< box::setfooter << ui::centeralign
<< "Everything looks OK";
window << "Fill the following form: " << ui::endl;
coord c(ui::scr_width/4, ui::scr_height/3);
box b(c, ui::scr_width / 3, 10);
b.settcolor_input(YELLOW);
b << "Enter details: " << ui::endl
<< "Name: "; b >> name;
b << "Age: "; b >> age;
b << "Phone num: "; b >> phn;
b << "Date: ";
b.setdefault("27/10/2017");
b >> date;
b << "Amount: "; b >> amt;
b << "Password: "; b >> box::setpassword >> pwd;
b.f.setvisibility_mode(frame::nosides);
b.f.display();
b.setexit_button("Submit");
b.loop();
b.hide();
window << "You entered the following data: " << ui::endl
<< "Name: " << name << ui::endl
<< "Age: " << age << ui::endl
<< "Phone num: " << phn << ui::endl
<< "Date: " << date << ui::endl
<< "Amount: " << amt << ui::endl
<< "Password: " << pwd << ui::endl;
}
void test_listlayout()
{
list_layout l;
l.setpos(coord(2,1));
l.setheight(6);
interactive *list[10];
//Setting the text boxes
for(int i = 0; i < 9; i++)
{
char s[] = {'A'+i, ':', ' ', '\0'};
l.settcolor(LIGHTGRAY);
l << coord(2, i + 1) << s;
l.settcolor(RED);
list[i] = l.settext_box(coord(5, i + 1));
}
l.settcolor(LIGHTGRAY);
list[9] = l.setbutton(coord(3, i + 1), "Submit");
//Rudimentary scrolling
i = 100;
int j = 0;
int lines_scrolled = l.getlines_scrolled(),
height = l.getheight();
coord pos_topleft(2,1);
int y = pos_topleft.y;
while(i--)
{
coord c = list[j]->getpos();
if(c.y - lines_scrolled > height)
{
lines_scrolled = c.y - height;
}
else if(c.y - lines_scrolled < y)
{
lines_scrolled = c.y - y;
}
l.setlines_scrolled(lines_scrolled);
int response = list[j]->input(-lines_scrolled);
if(response == interactive::GOTONEXT)
{
if(j < 9) j++; else j = 0;
}
else if(response == interactive::GOTOPREV)
{
if(j > 0) j--; else j = 9;
}
else if(response == interactive::CLICKED)
{
coord init_pos(wherex(), wherey());
gotoxy(1, ui::scr_height-1);
cprintf("%s%d", "Clicked ", i);
gotoxy(init_pos.x, init_pos.y);
}
}
}
void test_textbox()
{
text_box t;
t.setpos(coord(1,1));
for(int i = 0; i < 5; i++)
{
int a = t.input();
int x = wherex(), y = wherey();
gotoxy(1, ui::scr_height-1);
if(a == interactive::GOTONEXT)
{
cout << "GOTONEXT";
}
else if(a == interactive::GOTOPREV)
{
cout << "GOTOPREV";
}
else
{
cout << "UNDEFINED";
}
gotoxy(x, y);
}
}
void test_frame()
{
frame f;
f.display();
getch();
f << ui::top << 't'
<< ui::left << 'l'
<< ui::bottom << 'b'
<< ui::right << 'r';
f.settcolor(LIGHTBLUE);
f.display();
getch();
f << (ui::top | ui::left) << (char) 201
<< (ui::bottom | ui::left) << (char) 200
<< (ui::top | ui::right) << (char) 187
<< (ui::bottom | ui::right) << (char) 188
<< ui::top << (char) 205
<< ui::bottom << (char) 205
<< ui::left << (char) 186
<< ui::right << (char) 186;
f.settcolor(ui::tcolor);
f.display();
getch();
f.setheight(ui::scr_height/2);
getch();
f.setwidth(ui::scr_width/3);
getch();
f.setcorner_top_left(coord( (ui::scr_width-f.getwidth()) / 2, (ui::scr_height-f.getheight()) / 2));
getch();
f.setvisibility_mode(frame::nosides);
}
| true |
054b08f334a65ba3e2c8bd60dcb9ab40c4b89e11 | C++ | roshanajicherian/Coding-Challenges | /CodeChef/January Long 2019/Breaking Bricks.cpp | UTF-8 | 1,110 | 2.65625 | 3 | [] | no_license | #include <iostream>
using namespace std;
int countnot(int A[])
{ int zer=0;
for(int i=0;i<3;i++)
{
if(A[i]!=0)
zer++;
}
return zer;
}
int main()
{
int t=0;
cin>>t;
while(t--)
{
int s=0,inisum=0;
cin>>s;
int A[3];
for(int i=0;i<3;i++)
{
cin>>A[i];
inisum+=A[i];
}
int fsum=0,bsum=0,locf=0,locb=2,cou=0;
if(s<A[0] || s<A[2])
cout<<cou<<'\n';
else if (A[0]==A[1] && A[0]==A[2] && A[0]==s)
cout<<3<<'\n';
else if (inisum<=s)
cout<<1<<'\n';
else
{
while(inisum!=0)
{
fsum=0;
for(int i=0;fsum+A[i]<=s && i<3;i++)
{
if(A[i]!=0)
{
fsum+=A[i];
locf=i;
}
}
inisum=0;
for(int i=0;i<=locf;i++)
A[i]=0;
cou++;
if(countnot(A)==1)
{
cou++;
break;
}
for(int i=0;i<3;i++)
{
inisum+=A[i];
}
}
cout<<cou<<'\n';
}
}
return 0;
}
| true |
0384f746c425c8caa617ff691178ee9f12e2ac2c | C++ | Yeeunbb/Lecture_Algorithm | /algo3/main3.cpp | UHC | 3,019 | 3.671875 | 4 | [] | no_license | #include <iostream>
#include <iomanip>
using namespace std;
struct People{ //մ ü
int Arrive_time; // ð
int Consult_time; //˻ ð
int Real_Arrive; // ð
int End_Time; //˻簡 ð
};
void arrayToHeap(People arr[], int n); //迭 Լ
void rebuildHeap(People arr[], int root, int n); //ּ Լ
int main(){
int k, n; //ɻ :k, ° :n
float result = 0;
int waiting_time=0; // ٸ ð
cin >> k >> n;
People* Airport = new People[k]; //ɻ ŭ ü 迭
People* customer = new People[n]; // ŭ ü 迭
for(int i=0; i<n; i++){ //մ
cin >> customer[i].Arrive_time >> customer[i].Consult_time;
customer[i].Real_Arrive = 0;
customer[i].End_Time = 0;
if(i!=0){ //¥ ð ջ ¥ ð + ð
customer[i].Real_Arrive = customer[i-1].Real_Arrive + customer[i].Arrive_time;
}
}
for(int i=0; i<k; i++){ //ɻ ŭ ֱ.
Airport[i] = customer[i];
Airport[i].End_Time = Airport[i].Real_Arrive + Airport[i].Consult_time;
}//ɻ簡 ð ¥ ð + ˻ϴ ð
arrayToHeap(Airport, k); //ɻ 迭
for(int i=k; i<n; i++){ //Airport root մԵ ֱ
if(Airport[0].End_Time - customer[i].Real_Arrive>=0){
waiting_time += Airport[0].End_Time - customer[i].Real_Arrive;
customer[i].End_Time += Airport[0].End_Time + customer[i].Consult_time;
}
else{ //ٸ ð
customer[i].End_Time = customer[i].Real_Arrive + customer[i].Consult_time;
}
Airport[0] = customer[i]; //root ü
arrayToHeap(Airport, k); //ּڰ root ٽ
}
result = (float)waiting_time / n;
cout << fixed << setprecision(1) << result << endl;
return 0;
}
void arrayToHeap(People arr[], int n){ //迭 Լ
for(int root = n/2 -1; root >= 0; root--){
rebuildHeap(arr, root, n);
}
/* ٽ 迭 ڵ
int heap_size = n;
for(int last = n-1; last > 0; last--){
int temp = arr[0];
arr[0] = arr[last];
arr[last] = temp;
heap_size--;
rebuildHeap(arr, 0, heap_size);
} */
}
void rebuildHeap(People arr[], int root, int n){ //root ּڰ ǵ rebuildHeap
int smallChild;
People x = arr[root];
int current = root;
while(2*current + 1 < n){
int leftChild = 2*current + 1;
int rightChild = leftChild + 1;
if(rightChild < n && (arr[rightChild].End_Time < arr[leftChild].End_Time))
smallChild = rightChild;
else
smallChild = leftChild;
if(x.End_Time > arr[smallChild].End_Time){
arr[current] = arr[smallChild];
current = smallChild;
}
else
break;
}
arr[current] = x;
}
| true |
4ca32ab8dd4509260163a2ec60945dc449e09bfc | C++ | oykukapcak/oykukapcak_termproject_3 | /Source.cpp | UTF-8 | 6,683 | 2.71875 | 3 | [] | no_license | #include <iostream>
#include <string>
#include <pthread.h>
#include <semaphore.h>
#include <Windows.h>
#include <fstream>
#include "Memory.h"
#include "CPU.h"
#include "Assembler.cpp"
#include "ProcessImage.h"
#include "ProcessInfo.h"
#include "BoundedBuffer.h"
#include "LinkedList.h"
using namespace std;
const int quantumConstant = 5;
Memory * mainMemory;
CPU * myCPU;
BoundedBuffer<ProcessInfo> * fileInputQueue;
BoundedBuffer<unsigned int> * consoleInputQueue;
LinkedList * readyQueue;
LinkedList * blockedQueue;
void * producerFileInputFunction(void *)
{
ifstream input;
input.open("inputSequence.txt");
string filePath, binaryFile;
int time, size;
while(!input.eof())
{
input >> filePath >> time;
printf("File path read: %s \n", filePath.c_str());
size = createBinaryFile(filePath);
binaryFile = filePath.substr(0, filePath.find(".")) + ".bin";
ProcessInfo proInfo(binaryFile, size);
printf("Assembly file opened, converted it to binary and written it to the binary file: %s \n", binaryFile.c_str());
fileInputQueue->insert_item(proInfo);
printf("Process info created and stored in file input queue. \n");
printf("Now thread will sleep for %i ms. \n", time);
Sleep(time);
}
return NULL;
}
void * consumerFileInputFunction(void *)
{
char* buffer;
int size;
string fileName;
while(true)
{
ProcessInfo proInfo = fileInputQueue->remove_item();
size = proInfo.getInstructionSize();
fileName = proInfo.getFileName();
printf("File %s removed from the file input queue. \n", fileName.c_str());
printf("Check for available space in memory for %i \n", size);
while(mainMemory->hasFreeSpace(size) == -1)
{
Sleep(2000);
}
int BR = mainMemory->hasFreeSpace(size);
printf("Available space found, binary file %s is opened. \n", fileName.c_str());
buffer = readBinaryFile(size, fileName);
mainMemory->addInstructions(buffer, size, BR);
printf("Binary version of instructions is sloaded into the memory. \n");
ProcessImage proImage(BR, BR+size);
readyQueue->insertItemToEnd(proImage);
printf("New process instance is created and added to the end of ready queue. \n");
}
return NULL;
}
void * osThreadFunction(void *)
{
int usedQuantum;
bool isBlocked;
while(true)
{
if(readyQueue->isEmpty())
{
Sleep(2000);
}
else
{
Node nodeToBeExec = readyQueue->removeFirstItem();
printf("First process of the ready queue is removed.\n");
ProcessImage processToBeExec = nodeToBeExec.item;
int size = processToBeExec.LR - processToBeExec.BR +1;
myCPU->transferFromImage(processToBeExec);
printf("Process image is transferred to CPU. Fetch-Decode-Execute cycle will begin. \n");
usedQuantum = 0;
isBlocked = false;
while(usedQuantum < quantumConstant && myCPU->getPC() != (myCPU->getLR() - myCPU->getBR()) && !isBlocked)
{
myCPU->fetch();
printf("Fetch is done \n");
printf("IR: %i \n", myCPU->getIR());
printf("BR: %i \n", myCPU->getBR());
printf("PC: %i \n", myCPU->getPC()+myCPU->getBR());
printf("LR: %i \n", myCPU->getLR());
myCPU->decodeExecute();
printf("Decoded and executed \n");
if(myCPU->getIR() == 0) //I/O operation
{
if(myCPU->getV() == 0) //read
{
printf("I/O operation. Process should receive input. So it is sent to the end of Blocked Queue.\n");
myCPU->transferToImage(processToBeExec);
blockedQueue->insertItemToEnd(processToBeExec);
isBlocked = true;
}
else if(myCPU->getV() != 0) //write
{
printf("I/O operatioon. Process is giving output: ");
printf("%i \n", myCPU->getV());
}
}
usedQuantum++;
printf("Used quantum is: %i \n", usedQuantum);
}
if(!isBlocked)
{
if(usedQuantum < quantumConstant) //If a process finishes executing before its quantum if over,
//then the thread should empty the memory allocated by the process.
{
printf("Process finished executing before its quantum is over, the thread will empty the memory allocated by the process. \n");
myCPU->transferToImage(processToBeExec);
mainMemory->removeInstructions(size, processToBeExec.BR);
}
else if(usedQuantum == quantumConstant) //process bitmedi ama quantum bitti VE block'a da girmedi
{
printf("Process finished its quantum time and it is not finished or blocked, it is sent back to the end of the Ready Queue. \n");
myCPU->transferToImage(processToBeExec);
readyQueue->insertItemToEnd(processToBeExec);
}
}
processToBeExec.dumpToDisk();
}
}
return NULL;
}
void * producerConsoleInputFunction(void *)
{
unsigned int input_int;
while(true)
{
cin >> input_int;
printf("Input '%i' is received and added to Console Input Queue. \n", input_int);
consoleInputQueue->insert_item(input_int);
}
return NULL;
}
void * consumerConsoleInputFunction(void *)
{
unsigned int input_int;
Node process_node;
while(true)
{
input_int = consoleInputQueue->remove_item();
printf("Removed '%i' from the Console Input Queue. \n", input_int);
while(blockedQueue->isEmpty()) //there are no processes in Blocked Queue
{
Sleep(2000);
}
process_node = blockedQueue->removeFirstItem();
printf("First process of the Blocked Queue removed. \n");
process_node.item.V = input_int;
printf("Value of the register V is set to '%i'. \n", input_int);
readyQueue->insertItemToEnd(process_node.item);
printf("Process is put to the end of the Ready Queue. \n");
}
return NULL;
}
int main()
{
pthread_t producerFileInput, consumerFileInput, osThread, producerConsoleInput, consumerConsoleInput;
mainMemory = new Memory(80);
myCPU = new CPU(mainMemory);
fileInputQueue = new BoundedBuffer<ProcessInfo>(5);
consoleInputQueue = new BoundedBuffer<unsigned int>(5);
readyQueue = new LinkedList();
blockedQueue = new LinkedList();
pthread_create(&producerFileInput, NULL, producerFileInputFunction, NULL);
pthread_create(&consumerFileInput, NULL, consumerFileInputFunction, NULL);
pthread_create(&osThread, NULL, osThreadFunction, NULL);
pthread_create(&producerConsoleInput, NULL, producerConsoleInputFunction, NULL);
pthread_create(&consumerConsoleInput, NULL, consumerConsoleInputFunction, NULL);
pthread_join(producerFileInput, NULL);
pthread_join(consumerFileInput, NULL);
pthread_join(osThread, NULL);
pthread_join(producerConsoleInput, NULL);
pthread_join(consumerConsoleInput, NULL);
return 0;
} | true |
547189e272bbdfdbcce57738dbe9954cc8302ed5 | C++ | twentylemon/euchre | /euchre/Hybrid2Player.h | UTF-8 | 729 | 2.609375 | 3 | [] | no_license |
#pragma once
#include "HybridPlayer.h"
class Hybrid2Player : public HybridPlayer
{
public:
Hybrid2Player();
Hybrid2Player(double threshold);
Hybrid2Player(std::string name);
Hybrid2Player(std::string name, double threshold);
const static double DEFAULT_THRESHOLD;
/*
virtual std::pair<int,bool> orderUp(const Card& top, bool yourTeam) const override;
virtual std::pair<int,bool> pickItUp(const Card& top) const override;
virtual void replaceCard(const Card& top) override;
virtual std::pair<int,bool> callTrump(int badSuit) const override;
virtual std::pair<int,bool> stickTrump(int badSuit) const override;
*/
virtual Card playCard(const Trick& trick) override;
};
| true |
a06edd4ded77018c369eb576185c6b2b4098a3a2 | C++ | jakewandro/WandroJake_SummerClass | /HW/Assignment 4/Gaddis_7thEd_Chap5_Prob5_MembershipFee/main.cpp | UTF-8 | 834 | 3.375 | 3 | [] | no_license | /*
* File: main.cpp
* Author: Jake T Wandro
* Created on July 7, 2016, 9:37 PM
* Purpose: Membership Fees Increase
*/
//System Libraries
#include <iostream> //Input/Output Stream Library
using namespace std; //iostream uses the strand namespace
//user libraries
//Global Constants
//Function Prototypes
//Execution Begins Here!
int main(int argc, char** argv) {
//Declare Variables Here, no doubles
//Input Data
cout<<"The membership fee is increasing at 4% a year"<<endl<<endl;
cout<<"Year Membership Fee Cost"<<endl;
cout<<"------------------------------"<<endl;
//Process data
for(float times=1,year=2016,fee=2500;times<=6;times++,year++){
cout<<year<<" $"<<fee<<endl;
fee+=fee*.04;
}
//Output data
//Exit Stage Right!
return 0;
}
| true |
8a0c2b5e7c1bef51c4a2ff7aafa72cbf84770ce3 | C++ | indkumar8999/DSAlgo-Preparation | /disjoint-sets.cpp | UTF-8 | 1,188 | 3.234375 | 3 | [
"MIT"
] | permissive |
#include <bits/stdc++.h>
using namespace std;
int root(int parent[], int x){
while(x != parent[x]){
parent[x] = parent[parent[x]];
x = parent[x];
}
return x;
}
void union_1(int parent[], int rank[], int x, int y){
int r_x = root(parent, x);
int r_y = root(parent, y);
if(r_x == r_y){
return;
}
if(rank[r_x] >= rank[r_y]){
parent[r_y] = r_x;
rank[r_x] += rank[r_y];
}else{
parent[r_x] = r_y;
rank[r_y] += rank[r_x];
}
}
bool find(int parent[], int x, int y){
int r_x = root(parent, x);
int r_y = root(parent, y);
return r_x == r_y;
}
int main(){
int n;
cin>>n;
int parent[n];
int rank[n];
for(int i=0;i<n;i++){
parent[i] = i;
rank[i] = 1;
}
int e;
cin>>e;
for(int i=0;i<e;i++){
int x,y;
cin>>x>>y;
union_1(parent, rank, x, y);
}
cout<<find(parent,0,2)<<"\n";
cout<<find(parent,1,2)<<"\n";
cout<<find(parent,3,4)<<"\n";
cout<<find(parent,3,6)<<"\n";
cout<<find(parent,6,4)<<"\n";
cout<<find(parent,0,4)<<"\n";
return 0;
}
/*
7
6
0 1
1 2
3 4
4 5
5 6
3 6
*/
| true |
b4b525a3fbd9eece5f58bc47e01a2ebf21d8da8e | C++ | tomhrr/dale | /src/dale/TypeMap/TypeMap.cpp | UTF-8 | 666 | 2.765625 | 3 | [
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #include "TypeMap.h"
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <utility>
#include "../STL/STL.h"
#include "../Utils/Utils.h"
namespace dale {
std::map<std::string, std::string> dale_typemap;
bool addTypeMapEntry(const char *from, const char *to) {
dale_typemap.insert(std::pair<std::string, std::string>(from, to));
return true;
}
bool getTypeMapEntry(const char *from, std::string *to) {
std::map<std::string, std::string>::iterator iter =
dale_typemap.find(from);
if (iter != dale_typemap.end()) {
to->append(iter->second);
return true;
} else {
return false;
}
}
}
| true |
9beea40d801fff081fc05092c4f5ccc37c26d60d | C++ | bigplik/Arduino_mac | /ESP8266/Blynk/sensor_read_float_value/sensor_read_float_value.ino | UTF-8 | 2,596 | 2.703125 | 3 | [] | no_license | /**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example shows how value can be pushed from Arduino to
* the Blynk App.
*
* WARNING :
* For this example you'll need SimpleTimer library:
* https://github.com/jfturcot/SimpleTimer
* Visit this page for more information:
* http://playground.arduino.cc/Code/SimpleTimer
*
* App project setup:
* Value Display widget attached to V5
*
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
//#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "e2e5a06027dd402294ea9806d58d5418";
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendUptime()
{
int sensorValue = analogRead(A0);
float volt = (sensorValue/1024.0) * 3.3;
int tempC = ((volt + 0.05) * 20);
volt = (tempC / 20.0);
String nowy = "zero";
//Blynk.virtualWrite(0, tempC);
// You can send any value at any time.
// Please don't send more that 10 values per second.
float volt2 = analogRead(A0) * (3.3/1023.0);
volt = volt - 0.05;
Blynk.virtualWrite(V5, volt);
Blynk.virtualWrite(V6, nowy);
Blynk.virtualWrite(V7, "%2.f", volt);
}
// BLYNK_READ(V0)
//{
//float vbat = (float)analogRead(A0)/75;
//Blynk.virtualWrite(0, vbat);
//}
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "HTC_one", "12345678");
// Setup a function to be called every second
timer.setInterval(1000L, sendUptime);
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
| true |
98cc279640f3f2781a7df28a939dad0f1bea6a31 | C++ | levuoj/arcade | /includes/State.hpp | UTF-8 | 1,394 | 2.734375 | 3 | [] | no_license | //
// State.hpp for arcade in /home/zawadi_p/rendu/CPP/cpp_arcade/header
//
// Made by Pierre Zawadil
// Login <pierre.zawadil@epitech.eu>
//
// Started on Thu Mar 23 15:35:22 2017 Pierre Zawadil
// Last update Sun Apr 9 13:15:45 2017 thomas vigier
//
#ifndef STATE_HPP
# define STATE_HPP
#include <unordered_map>
#include <utility>
#include "Element.hpp"
#include "Coords.hpp"
struct pairHash
{
template <typename T, typename U>
std::size_t operator() (const std::pair<T, U> &p) const
{
auto hash1 = std::hash<T>{}(p.first);
auto hash2 = std::hash<U>{}(p.second);
return (hash1 ^ hash2);
}
};
class State
{
private:
std::unordered_map<std::pair<int, int>, Element, pairHash> _map;
int _time;
int _score;
int _life;
Coords _mapSize;
std::string _name;
public:
std::unordered_map<std::pair<int, int>, Element, pairHash> const& getMap() const;
int getTime() const;
int getScore() const;
int getLife() const;
Coords const& getMapSize() const;
std::string const& getName() const;
void setMap(std::unordered_map<std::pair<int, int>, Element, pairHash>);
void setTime(int);
void setScore(int);
void setLife(int);
void setMapSize(Coords const&);
void setName(std::string const&);
State();
State(int, int, int, Coords const&, std::string const&);
~State();
};
#endif /* !STATE_HPP */
| true |
70473b1d6b7e38edce87f82269cdb00631d81c6c | C++ | IndieLightAndMagic/sorter-hexa-bassoon | /merge/merge.h | UTF-8 | 2,341 | 3.28125 | 3 | [] | no_license | #ifndef __MERGE_H__
#define __MERGE_H__
#include <iostream>
#include <vector>
#include <sort/sort.h>
template <typename T>
class MergeSorter : public Sorter<T> {
unsigned int m_pivotalIndex = 0;
void PrintPartitions(const std::vector<T>& u, unsigned int pivotIndex, unsigned int depth = 0) {
while (depth--) std::cout << " ";
auto uSize = u.size();
for(auto index = 0; index < uSize ; ++index) std::cout << (index == pivotIndex ? " [" : " ") << u[index] << (index == pivotIndex ? "] " : "");
std::cout << "\n";
}
void MergePartitions(std::vector<T>& u, unsigned int startIndex, unsigned int pivotIndex, unsigned int endIndex) {
auto indexLeft = startIndex;
auto indexRight = pivotIndex + 1;
std::vector<T> temp;
while (indexLeft <= pivotIndex && indexRight <= endIndex) {
if (u[indexLeft] <= u[indexRight]) temp.push_back(u[indexLeft++]);
else temp.push_back(u[indexRight++]);
if (indexLeft > pivotIndex) while (indexRight <= endIndex) temp.push_back(u[indexRight++]);
else if (indexRight > endIndex) while (indexLeft <= pivotIndex) temp.push_back(u[indexLeft++]);
}
auto tempSz = temp.size();
for (unsigned int index = 0; index < tempSz; ++index) u[startIndex + index] = temp[index];
}
void Partitionate(std::vector<T>& u, unsigned int startIndex, unsigned int endIndex, unsigned int depth = 0) {
this->Print(u,startIndex, endIndex);
if (endIndex - startIndex == 1)
{
if (u[startIndex] > u[endIndex]) std::swap(u[startIndex], u[endIndex]);
return;
}
unsigned int pivotIndex = startIndex + endIndex;
pivotIndex >>= 1;
Partitionate(u, startIndex, pivotIndex, depth + 1);
Partitionate(u, pivotIndex + 1, endIndex, depth + 1);
this->PrintPartitions(u, pivotIndex, depth);
MergePartitions(u, startIndex, pivotIndex, endIndex);
}
public:
MergeSorter():m_pivotalIndex(0){}
void Sort(std::vector<T>& u)
{
Partitionate(u, 0, u.size() - 1);
}
void setPivotalIndex(unsigned int pivotalIndex)
{
m_pivotalIndex = pivotalIndex;
}
};
#endif /*__MERGE_H__*/
| true |
98ca4b073f35beea654080283a84ce91e84572bb | C++ | RuslanShugaipov/Lab_2-4-term | /Shannon-Fano/Shannon-Fano/Encode_N_Decode.h | UTF-8 | 5,718 | 3.234375 | 3 | [] | no_license | #pragma once
#include <iostream>
#include "LinkedList.h"
#include "RB-TREE(DEF).h"
#include <string>
#include <iomanip>
using namespace std;
//a template function that sorts two arrays at once
template<class ARRAY_TYPE_1, class ARRAY_TYPE_2>
void Bubble_Sort(ARRAY_TYPE_1* array_1, ARRAY_TYPE_2* array_2, int Array_Size)
{
ARRAY_TYPE_1 temp_1;
ARRAY_TYPE_2 temp_2;
for (int i = 0; i < Array_Size; ++i)
{
for (int j = i + 1; j < Array_Size; ++j)
{
if (array_1[i] < array_1[j])
{
//data
temp_1 = array_1[i];
array_1[i] = array_1[j];
array_1[j] = temp_1;
//key
temp_2 = array_2[i];
array_2[i] = array_2[j];
array_2[j] = temp_2;
}
}
}
}
//a template function that looks for a boundary that divides an array into two equal or nearly equal parts
template<class ARRAY_TYPE>
unsigned Search_Border(ARRAY_TYPE* array, int start, int end)
{
unsigned from_begin = 0, from_end = 0;
int j = end - 1;
for (int i = start; ; i++)
{
if (i == j)
{
return i;
}
from_begin += array[i];
while (true)
{
if (from_end < from_begin)
from_end += array[j--];
else
break;
if (i == j)
{
return i;
}
}
if (i == j)
{
return i;
}
}
}
//a function that implements the Shannon-Fano algorithm using the Search_Border function
void Shannon_Fano(unsigned* freq, char* sym, string& Branch, string& Full_Branch, int start, int end, RB_TREE_Node<char, string>* Symbols_Code, unsigned& Memory_Size_After)
{
unsigned m;
string T_Branch = "";
T_Branch = Full_Branch + Branch;
if (start == end)
{
Memory_Size_After += T_Branch.length() * freq[start];
Symbols_Code->Insert(sym[start], T_Branch);
cout << sym[start] << "\t" << freq[start] << "\t\t" << T_Branch << endl;
return;
}
m = Search_Border(freq, start, end);
string zero = "0", one = "1";
Shannon_Fano(freq, sym, one, T_Branch, start, m, Symbols_Code, Memory_Size_After);
Shannon_Fano(freq, sym, zero, T_Branch, m + 1, end, Symbols_Code, Memory_Size_After);
}
//a function that calls within itself a function that implements the Shannon-Fano algorithm, and also outputs the following data:
//the amount of memory that the source and encoded strings occupy, the table of frequencies and character codes, the result of en-
//coding and decoding, the compression ratio
void Encoding_N_Decoding(string& str)
{
//output the input string/text
cout << "Input string/text: " << str << "\n\n";
//variables that contain the size of the string before encoding and after encoding the string
unsigned Memory_Size_Before = str.length() * 8, Memory_Size_After = 0;
//creating the Frequency variable to create a map, and then filling it with characters and the frequency of their occurrence
RB_TREE_Node<char, unsigned> Frequency;
Frequency.NIL_N_Root();
//filling the associative array with values from the string/text
for (int i = 0; i < str.length(); ++i)
{
try
{
Frequency.Insert(str[i], 1);
}
catch (int ex)
{
if (ex == -1)
Frequency[str[i]]++;
}
}
//creating a variable that stores the number of encoded characters for easy use
unsigned Array_Size = Frequency.Get_Size();
//creating 2 arrays that will store characters and their frequencies
unsigned* A = new unsigned[Array_Size];
char* B = new char[Array_Size];
//using the added RB_TREE_Node.h of the method, we fill the arrays created earlier with the values of the keys and data of the associative array
Frequency.Fill_Array(Frequency.Get_Root(), A, "data");
Frequency.Fill_Array(Frequency.Get_Root(), B, "key");
//two arrays of characters and their frequencies are sorted at once
Bubble_Sort(A, B, Array_Size);
string zero = "";
RB_TREE_Node<char, string> Symbols_Code;
Symbols_Code.NIL_N_Root();
//output the table, size, and coefficient
cout << "Symbol:\tFrequency:\tCode:\n";
Shannon_Fano(A, B, zero, zero, 0, Array_Size - 1, &Symbols_Code, Memory_Size_After);
cout << "\nSize in bits before encoding: " << Memory_Size_Before << "\n\nSize in bits after encoding: " << Memory_Size_After << endl;
//the coefficient is calculated as follows: from one, we subtract the quotient of the line size after and before encoding,
//then multiply by 100 and get the result as a percentage
cout << "\nCompression ratio: " << round((1 - ((double)Memory_Size_After / (double)Memory_Size_Before)) * 100) << "%\n";
//we output the result of encoding the string, for further convenience, we put a space between the bits of individual characters
string Encoding_Result = "";
//concatenate the strings to get the final string
for (int i = 0; i < str.length(); i++)
{
Encoding_Result += Symbols_Code[str[i]] + " ";
}
cout << "\nResult of encoding: " << Encoding_Result << endl;
//we create an associative array for convenience, since operator overloads were created
//for the task, spaces were placed between the bits of individual characters
//in advance, so it is easy to decode a string using overload operators
RB_TREE_Node<string, char> Codes_Symbol;
Codes_Symbol.NIL_N_Root();
for (int i = 0; i < Array_Size; ++i)
{
Codes_Symbol.Insert(Symbols_Code[B[i]], B[i]);
}
string Decoding_Result = "", Code;
//concatenate the strings to get the final string
for (int i = 0; i < Encoding_Result.length(); i++)
{
Code = "";
while (true)
{
if (Encoding_Result[i] != ' ')
Code += Encoding_Result[i++];
else
break;
}
Decoding_Result += Codes_Symbol[Code];
}
cout << "\nResult of decoding: " << Decoding_Result << endl;
delete[] A;
delete[] B;
}
| true |
af15fd7305fc9a587836997f9821744236c7fb66 | C++ | AThilenius/thilenius | /base/regex.cc | UTF-8 | 1,231 | 2.53125 | 3 | [] | no_license | // Copyright 2015 Alec Thilenius
// All rights reserved.
#include "base/regex.h"
#include <boost/regex.hpp>
namespace thilenius {
namespace base {
ValueOf<std::string> Regex::FindFirstMatch(const std::string& content,
const std::string& regex) {
std::vector<std::string> matches = Regex::FindAllMatches(content, regex);
if (matches.size() == 0) {
return {"", "Failed to find " + regex + " in " + content};
}
return {static_cast<std::string>(matches[0])};
}
std::vector<std::string> Regex::FindAllMatches(const std::string& content,
const std::string& regex) {
::boost::regex regex_obj(regex);
std::vector<std::string> matches;
::boost::smatch smatch;
std::string::const_iterator start = content.begin();
std::string::const_iterator end = content.end();
while (boost::regex_search(start, end, smatch, regex_obj)) {
std::string match_string(smatch[1].first, smatch[1].second);
matches.push_back(match_string);
// Update the beginning of the range to the character
// following the whole match
start = smatch[0].second;
}
return std::move(matches);
}
} // namespace base
} // namespace thilenius
| true |
2ca6ea38296e42394f1054caf86063c72eb6931c | C++ | PedchenkoL/Cpp_OOP | /Однорукий бандит.cpp | UTF-8 | 2,587 | 3.015625 | 3 | [] | no_license | #include <cstdlib>
#include <Time.h>
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <queue>
#include <windows.h>
using namespace std;
class Line {
public:
int val_1;
int val_2;
int val_3;
int changeValue, changeValue_2, changeValue_3, changeValue_4;
void Roll() {
val_1 = rand() % 20 + 1;
val_2 = rand() % 20 + 1;
val_3 = rand() % 20 + 1;
cout << val_1 << endl;
cout << val_2 << endl;
cout << val_3 << endl;
}
void Drum_1() {
cout << " # " << endl;
cout << "# #" << endl;
cout << " # " << endl;
}
void Drum_2() {
cout << " & " << endl;
cout << "& &" << endl;
cout << " & " << endl;
}
void Drum_3() {
cout << " $ " << endl;
cout << "$ $" << endl;
cout << " $ " << endl;
}
void Drum_4() {
cout << " * " << endl;
cout << "* *" << endl;
cout << " * " << endl;
}
void Vall_1_DrumRolling() {
val_1 += val_1 % 4;
while (val_1 >= 0) {
if (val_1 >= changeValue) {
val_1 -= changeValue;
for (int k = 1; k < 5; k++) {
if (k == changeValue_4) {
Drum_1();
Sleep(500);
system("cls");
}
else if (k == changeValue_3) {
Drum_2();
Sleep(500);
system("cls");
}
else if (k == changeValue_2) {
Drum_3();
Sleep(500);
system("cls");
}
else if (k == changeValue) {
Drum_4();
Sleep(500);
system("cls");
}
}
}
else if (val_1 = changeValue) {
Drum_4();
Sleep(500);
system("cls");
break;
}
else if (val_1 = changeValue_2) {
Drum_3();
Sleep(500);
system("cls");
break;
}
else if (val_1 = changeValue_3) {
Drum_2();
Sleep(500);
system("cls");
break;
}
else if (val_1 = changeValue_4) {
Drum_1();
Sleep(500);
break;
system("cls");
}
}
}
void Win() {
if (val_1 == val_2 && val_2 == val_3 && val_3 == val_1) {
cout << endl << "Winner, winner, chicken dinner!" << endl;
}
else if (val_2 == val_3) {
cout << endl << "U are won a few... " << endl;
}
else if (val_3 == val_1) {
cout << endl << "U are won a few... " << endl;
}
else if (val_1 == val_2) {
cout << endl << "U are won a few... " << endl;
}
}
};
int main() {
srand((unsigned)time(NULL));
srand((unsigned)rand());
Line line;
line.changeValue = 4;
line.changeValue_2 = 3;
line.changeValue_3 = 2;
line.changeValue_4 = 1;
line.Roll();
line.Win();
line.Vall_1_DrumRolling();
}
| true |
97309f791e215f5ecf859907dcd0ca0aac31d419 | C++ | Saurav-Paul/Codeforces-Problem-Solution-By-Saurav-Paul | /C - Labs .cpp | UTF-8 | 672 | 2.90625 | 3 | [] | no_license | /*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n ; scanf("%d",&n) ;
vector< vector<int > > grid(n,vector<int> (n));
int temp = n ;
bool ok = true ;
int x = 1;
int y = 0 ;
while(temp --){
if(ok)
for(int i = 0 ; i < n ; i++){
grid[i][y] = x ++;
}
else{
for(int i = n-1 ; i >= 0 ; i--){
grid[i][y] = x ++;
}
}
y++ ;
ok ^= 1 ;
}
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n; j++){
printf("%d ",grid[i][j] );
}
puts("");
}
return 0;
}
| true |
d5d02cbcb90943ba40422826a735c0e0fc20b9a3 | C++ | nowhh01/designPatterns | /structural/adapter.cpp | UTF-8 | 2,348 | 3.15625 | 3 | [
"Apache-2.0"
] | permissive | #include <iostream>
#include <memory>
#include <string>
class LightningPhone
{
public:
virtual void Recharge() = 0;
virtual void UseLightning() = 0;
virtual void Display() = 0;
};
class MicroUsbPhone
{
public:
virtual void Recharge() = 0;
virtual void UseMicroUsb() = 0;
virtual void Display() = 0;
};
class Iphone : public LightningPhone
{
public:
void Recharge() override
{
if(mHasConnector)
{
std::cout << "Recharge started" << std::endl;
std::cout << "Recharge finished" << std::endl;
}
else
{
std::cout << "Connect Lightning first" << std::endl;
}
}
void UseLightning() override
{
mHasConnector = true;
std::cout << "Lightning connected" << std::endl;
}
void Display() override
{
UseLightning();
Recharge();
}
private:
bool mHasConnector;
};
class Android : public MicroUsbPhone
{
public:
void Recharge() override
{
if(mHasConnector)
{
std::cout << "Recharge started" << std::endl;
std::cout << "Recharge finished" << std::endl;
}
else
{
std::cout << "Connect MicroUsb first" << std::endl;
}
}
void UseMicroUsb() override
{
mHasConnector = true;
std::cout << "MicroUsb connected" << std::endl;
}
void Display() override
{
UseMicroUsb();
Recharge();
}
private:
bool mHasConnector;
};
class LightningToMicroUsbAdapter : public MicroUsbPhone
{
public:
LightningToMicroUsbAdapter(std::unique_ptr<LightningPhone> lightningPhone) : mLightningPhone{ std::move(lightningPhone) }
{
}
void Recharge() override
{
mLightningPhone->Recharge();
}
void UseMicroUsb() override
{
std::cout << "MicroUsb connected" << std::endl;
mLightningPhone->UseLightning();
}
void Display() override
{
UseMicroUsb();
Recharge();
}
private:
std::unique_ptr<LightningPhone> mLightningPhone;
};
int main()
{
std::unique_ptr<Android> android = std::make_unique<Android>();
std::unique_ptr<Iphone> iPhone = std::make_unique<Iphone>();
std::cout << "Recharging android with MicroUsb" << std::endl;
android->Display();
std::cout << '\n';
std::cout << "Recharging iPhone with Lightning" << std::endl;
android->Display();
std::cout << '\n';
std::unique_ptr<LightningToMicroUsbAdapter> adapter = std::make_unique<LightningToMicroUsbAdapter>(std::move(iPhone));
std::cout << "Recharging iPhone with MicroUsb" << std::endl;
adapter->Display();
}
| true |
03352c0227e4391fa439b1f5317df9a16c15f1dc | C++ | jtlai0921/PG20048_example | /ch03/to_number.cpp | GB18030 | 427 | 2.84375 | 3 | [] | no_license | //To_Number.cpp
#include <iostream.h>
#include <conio.h>
void main()
{ int i,number,n;
char ch;
cout <<"J5ӼƦrr('0'..'9'):";
for (i=0,number=0;i<5;i++)
{ cin >> ch; //Ūr
n = ch - '0'; //ରƦr'1'=>1
number = number * 10 + n; //ରƭ
}
cout <<"ƭȬ:"
<< number << endl;
cout <<"ƼƭȬ:"
<< (number*2) << endl;
getch();
} | true |
9570eee31e8662048865355ba67e07463e806cbe | C++ | kmjp/procon | /leetcode/251-300/270/2096.cpp | UTF-8 | 1,501 | 2.640625 | 3 | [] | no_license | typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
string A,B;
class Solution {
public:
int s,d;
string S;
void traverse(TreeNode* root) {
if(root->val==s) A=S;
if(root->val==d) B=S;
if(root->left) {
S+="L";
traverse(root->left);
}
if(root->right) {
S+="R";
traverse(root->right);
}
S.pop_back();
}
string getDirections(TreeNode* root, int startValue, int destValue) {
s=startValue;
d=destValue;
S="L";
traverse(root);
reverse(ALL(A));
reverse(ALL(B));
while(A.size()&&B.size()&&A.back()==B.back()) {
A.pop_back();
B.pop_back();
}
FORR(c,A) c='U';
reverse(ALL(B));
return A+B;
}
};
| true |
479fbda203f76704c8552433eb99b4ed24d7b846 | C++ | sid1980/ChessGame_OSG | /ZGK_OSG/Board.cpp | UTF-8 | 6,048 | 2.75 | 3 | [] | no_license | #include "Board.h"
#include <iostream>
#include "Figures.h"
#include <iomanip>
#include "Colours.h"
#include <osg/Group>
#include <osg/ShapeDrawable>
#include <osg/MatrixTransform>
#include <osg/Geode>
#include <osg/ref_ptr>
using namespace std;
using namespace osg;
Board::BoardField::BoardField(Colours colour) {
this->colour = colour;
this->figure = nullptr;
this->figure_OBJ = nullptr;
this->createOBJ();
}
void Board::BoardField::setFigureOBJ(Colours colour) {
if (this->figure != nullptr) {
this->figure_OBJ = this->figure->getOBJ(colour);
}
}
void Board::BoardField::createOBJ() {
Vec4* black = new Vec4(0.0, 0.0, 0.0, 1.0);
Vec4* white = new Vec4(1.0, 1.0, 1.0, 1.0);
this->field_OBJ = new ShapeDrawable;
Vec3* center = new Vec3(0.0, 0.0, 0.0);
this->field_OBJ.get()->setShape(new Box(*center, 12.5, 12.5, 0.05));
if (this->colour == Colours::BLACK) {
this->field_OBJ.get()->setColor(*black);
}
else {
this->field_OBJ.get()->setColor(*white);
}
}
void Board::BoardField::setFigure(Figure* figure) {
this->figure = figure;
this->setFigureOBJ(this->colour);
}
void Board::fillBoard() {
// wypelniamy od lewego gornego rogu
// gora to czarni, dol to biali
// zaczynamy od bialego pola (lewy gorny)
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (i % 2 == 0) {
if (j % 2 == 0) {
this->fields[i][j] = new BoardField(Colours::WHITE);
}
else {
this->fields[i][j] = new BoardField(Colours::BLACK);
}
}
else {
if (j % 2 == 0) {
this->fields[i][j] = new BoardField(Colours::BLACK);
}
else {
this->fields[i][j] = new BoardField(Colours::WHITE);
}
}
}
}
// BLACK - TOP
this->fields[0][0]->setFigure(new Rook(Colours::BLACK));
this->fields[0][1]->setFigure(new Knight(Colours::BLACK));
this->fields[0][2]->setFigure(new Bishop(Colours::BLACK));
this->fields[0][3]->setFigure(new Queen(Colours::BLACK));
this->fields[0][4]->setFigure(new King(Colours::BLACK));
this->fields[0][5]->setFigure(new Bishop(Colours::BLACK));
this->fields[0][6]->setFigure(new Knight(Colours::BLACK));
this->fields[0][7]->setFigure(new Rook(Colours::BLACK));
for (int i = 0; i < 8; i++) {
this->fields[1][i]->setFigure(new Pawn(Colours::BLACK));
}
// WHITE - BOTTOM
this->fields[7][0]->setFigure(new Rook(Colours::WHITE));
this->fields[7][1]->setFigure(new Knight(Colours::WHITE));
this->fields[7][2]->setFigure(new Bishop(Colours::WHITE));
this->fields[7][3]->setFigure(new Queen(Colours::WHITE));
this->fields[7][4]->setFigure(new King(Colours::WHITE));
this->fields[7][5]->setFigure(new Bishop(Colours::WHITE));
this->fields[7][6]->setFigure(new Knight(Colours::WHITE));
this->fields[7][7]->setFigure(new Rook(Colours::WHITE));
for (int i = 0; i < 8; i++) {
this->fields[6][i]->setFigure(new Pawn(Colours::WHITE));
}
}
void Board::createOBJ() {
Vec4* dark = new Vec4(0.05, 0.05, 0.05, 1.0);
Vec4* black = new Vec4(0.0, 0.0, 0.0, 1.0);
Vec4* white = new Vec4(1.0, 1.0, 1.0, 1.0);
Vec4* red = new Vec4(1.0, 0.0, 0.0, 1.0);
this->board_OBJ = new Group;
ref_ptr<Geode> geom_node = new Geode;
ref_ptr<ShapeDrawable> drw = new ShapeDrawable;
drw->setShape(new Box(Vec3(0.0, 0.0, 0.0), this->width_OBJ + this->frame_OBJ * 2, this->height_OBJ + this->frame_OBJ * 2, this->size_OBJ));
drw->setColor(*dark);
geom_node->addDrawable(drw);
drw = new ShapeDrawable();
drw->setShape(new Box(Vec3(0.0, 0.0, this->size_OBJ / 2.0), this->width_OBJ + 2.0, this->height_OBJ + 2.0, 0.04));
drw->setColor(*white);
geom_node->addDrawable(drw);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
ref_ptr<Geode> g = new Geode;
drw = this->fields[i][j]->field_OBJ;
g.get()->addDrawable(drw);
ref_ptr<MatrixTransform> t = new MatrixTransform;
t.get()->setMatrix(Matrix::translate(-this->width_OBJ / 2.0 + j * 12.5 + 12.5 / 2.0, -this->height_OBJ / 2.0 + i * 12.5 + 12.5 / 2.0, this->size_OBJ / 2.0));
t.get()->addChild(g);
geom_node.get()->addChild(t);
}
}
this->board_OBJ.get()->addChild(geom_node);
}
Board::Board() {
this->width_OBJ = 100.0;
this->height_OBJ = 100.0;
this->size_OBJ = 10.0;
this->frame_OBJ = 20.0;
this->fillBoard();
this->createOBJ();
this->renderFiguresOBJ();
}
void Board::renderFiguresOBJ() {
Vec4* black = new Vec4(0.0, 0.0, 0.0, 1.0);
Vec4* white = new Vec4(1.0, 1.0, 1.0, 1.0);
this->figures_OBJ = new Group;
ref_ptr<Geode> geom_node = new Geode;
ref_ptr<Group> gr = new Group;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
ref_ptr<Geode> g = new Geode;
gr = this->fields[i][j]->figure_OBJ;
g.get()->addChild(gr);
ref_ptr<MatrixTransform> t = new MatrixTransform;
t.get()->setMatrix(Matrix::translate(-this->width_OBJ / 2.0 + j * 12.5 + 12.5 / 2.0, -this->height_OBJ / 2.0 + i * 12.5 + 12.5 / 2.0, this->size_OBJ / 2.0));
t.get()->addChild(g);
geom_node.get()->addChild(t);
}
}
this->figures_OBJ.get()->addChild(geom_node);
cout << endl;
}
void Board::printColours() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
switch (this->fields[i][j]->colour) {
case Colours::BLACK:
cout << "[B] ";
break;
case Colours::WHITE:
cout << "[W] ";
break;
}
}
cout << endl;
}
}
void Board::printFigures() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (this->fields[i][j]->figure == nullptr) {
cout << setw(11) << " ";
}
else {
string color;
switch (this->fields[i][j]->colour) {
case Colours::BLACK:
color = "[B]";
break;
case Colours::WHITE:
color = "[W]";
break;
}
cout << color << " " << setw(7) << left << this->fields[i][j]->figure->toString();
}
}
cout << endl;
}
cout << endl;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (this->fields[i][j]->figure_OBJ == nullptr) {
cout << setw(11) << " ";
}
else {
cout << setw(11) << "3D";
}
}
cout << endl;
}
cout << endl;
cout << endl;
}
| true |
32ceb9ed832c237d7535fb43a07ddae143f29c68 | C++ | Lcoderfit/Introduction-to-algotithms | /Chapter 4-FindMaximumSubarray/4-1.FindMaximumSubarry.cpp | UTF-8 | 2,302 | 3.25 | 3 | [
"MIT"
] | permissive | #include<iostream>
#include<vector>
#include<tuple>
#include<iomanip>
using namespace std;
class Solution{
public:
const int MIN_INT=-0x7ffffffe;
typedef tuple<int,int,int> TupleType;
//求跨分隔点的最大子数组
TupleType findMaxCrossingSubarray(vector<int>&a, int low, int mid, int high)
{
int leftsum=MIN_INT;
int leftmark=0;
int sum=0;
for(int i=mid;i>=low;i--){
sum+=a[i];
if(sum>leftsum){
leftsum=sum;
leftmark=i;
}
}
int rightsum=MIN_INT;
int rightmark=0;
sum=0;
for(int j=mid+1;j<=high;j++){
sum+=a[j];
if(sum>rightsum){
rightsum=sum;
rightmark=j;
}
}
int res=leftsum+rightsum;
return make_tuple(leftmark,rightmark,res);
}
//求整个数组的最大子数组,先求分隔点左边的最大子数组,然后求分隔点右边的,最后跨分隔点的
TupleType findMaximumSubarray(vector<int>&a, int low, int high)
{
if(low==high){
return make_tuple(low,high,a[low]);
}
else{
int mid=(low+high)/2;
int leftlow,lefthigh,leftsum;
tie(leftlow,lefthigh,leftsum)=findMaximumSubarray(a,low,mid);
int rightlow,righthigh,rightsum;
tie(rightlow,righthigh,rightsum)=findMaximumSubarray(a,mid+1,high);
int crosslow,crosshigh,crosssum;
tie(crosslow,crosshigh,crosssum)=findMaxCrossingSubarray(a,low,mid,high);
if(leftsum>=rightsum && leftsum>=crosssum){
return make_tuple(leftlow,lefthigh,leftsum);
}
else if(rightsum>=leftsum && rightsum>=crosssum){
return make_tuple(rightlow,righthigh,rightsum);
}
else{
return make_tuple(crosslow,crosshigh,crosssum);
}
}
}
};
int main()
{
vector<int>a{13,-3,-25,20,-3,-16,-23,
18,20,-7,12,-5,-22,15,-4,7};
int i,j,sum;
Solution solution;
tie(i,j,sum)=solution.findMaximumSubarray(a,0,a.size()-1);
cout<<setiosflags(ios::left);
cout<<setw(4)<<i<<setw(4)<<j<<setw(4)<<sum<<endl;
return 0;
}
| true |
5b3ebcef8e9a28e24ef221dde6ddf780a9527961 | C++ | ahmedsalemas/Problem-solving | /A. Vitya in the Countryside/main.cpp | UTF-8 | 616 | 2.84375 | 3 | [] | no_license | #include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x;
cin>>n;
vector<int>v1;
for(int i=0;i<n;i++){
cin>>x;
v1.push_back(x);
}
if(v1.back()==15){
cout<<"DOWN"<<endl;
}
else if(v1.back()==0){
cout<<"UP"<<endl;
}
else if(v1.size()==1 && v1.front()==0){
cout<<"UP"<<endl;
}
else if(v1.size()==1 && v1.front()==15){
cout<<"DOWN"<<endl;
}
else if(v1.size()==1){
cout<<"-1"<<endl;
}
else if(v1.back()>v1[v1.size()-2]){
cout<<"UP"<<endl;
}
else if(v1.back()<v1[v1.size()-2]){
cout<<"DOWN"<<endl;
}
}
| true |
b66adbcb97a30f326999b32495d05738860c69a8 | C++ | andry-dervy/less_03 | /src/less_03.cpp | UTF-8 | 1,123 | 3.5625 | 4 | [] | no_license | //============================================================================
// Name : less_03.cpp
// Author : andry antonenko
// IDE : Eclipse IDE
// Copyright : Your copyright notice
// Description : Simple Numbers in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cmath>
using namespace std;
bool numberIsSimple(int nD);
int main() {
cout << "Введите целое число:" << endl; // prints
uint32_t d;
cin >> d;
if(numberIsSimple(d))
{
cout << "Число " << d << " простое." << endl; // prints
}
else
{
cout << "Число " << d << " не является простым." << endl; // prints
}
return 0;
}
bool numberIsSimple(int nD)
{
int nSqrt = (int)sqrt(nD);
int nDivider;
int nIter = 0;
if (nD > 3)
{
do
{
nDivider = 2 + nIter;
if (nIter < 1) nIter++;
else nIter += 2;
if ((nD % nDivider) == 0)
return false;
else if (nDivider > nSqrt)
return true;
} while (true);
}
else
return true;
}
| true |
d6df55343d6ed88d7c7461643b4a585bc5ab6924 | C++ | ZdravkoHvarlingov/binary-huffman-codding | /HuffmanCoding.h | UTF-8 | 876 | 2.8125 | 3 | [] | no_license | #pragma once
#include <string>
#include <map>
#define TABLE_SIZE 256
class HuffmanCoding
{
public:
HuffmanCoding();
void Encode(const char*, const char*, const char*);
void Decode(const char*, const char*, const char*);
struct TreeNode
{
unsigned long long weight;
char symbol;
TreeNode *left, *right;
TreeNode(long long weight, char symbol, TreeNode *left = nullptr, TreeNode *right = nullptr)
: weight(weight), symbol(symbol), left(left), right(right)
{}
};
private:
void BuildFrequencyTable(const char*);
void BuildTree(const char*);
void BuildCodesTable(TreeNode*, std::map<char, std::string>&);
void DeleteTree(TreeNode *);
void SerializeTree(TreeNode *, std::ofstream&);
TreeNode* DeserializeTree(std::ifstream&);
TreeNode *root;
unsigned long long asciiTable[TABLE_SIZE];
std::string code;
};
| true |
72a54fedabd71883c6ba0a7bfc196c4a47a4a0ff | C++ | sak9188/SoftRendering | /Softrendering/Base/Canvas.h | GB18030 | 1,420 | 2.53125 | 3 | [
"MIT"
] | permissive | #pragma once
#include "SFRSetting.h"
#include <glm\glm.hpp>
#include <graphics.h>
namespace SFR
{
class Canvas
{
SINGLETON(Canvas)
public:
void Init(glm::vec2 size);
void Init(int width, int height);
void Init(float width, float height);
// Ⱦ
// void SetRenderFunc(func*);
// void RenderLoop();
// void RenderOnce(func*=nullptr);
void SetBrushColor(glm::vec4 color);
// Bresenham
void SetDrawLineMode(/* ö */);
void DrawLine(int x, int y);
void DrawLine(float x, float y);
// ѿ
void DrawLineDescartes(int x1, int y1, int x2, int y2);
void DrawLineDescartes(float x1, float y1, float x2, float y2);
void DrawLineDescartes(glm::vec2 p1, glm::vec2 p2);
// DDA
void DrawLineDDA(int x1, int y1, int x2, int y2);
void DrawLineDDA(float x1, float y1, float x2, float y2);
void DrawLineDDA(glm::vec2 p1, glm::vec2 p2);
// Bresenham
void DrawLineBresenham(int x1, int y1, int x2, int y2);
void DrawLineBresenham(float x1, float y1, float x2, float y2);
void DrawLineBresenham(glm::vec2 p1, glm::vec2 p2);
// Բ
void DrawOrbicular(int r, int x, int y);
void DrawOrbicular(float r, float x, float y);
void DrawOrbicular(float r, glm::vec2 p);
void DrawOrbicular(glm::vec3 com);
private:
bool _is_init;
glm::uint _brush_color;
glm::vec2 _size;
// func* _render_fun;
~Canvas();
};
} | true |