Skip to content

Instantly share code, notes, and snippets.

@08vivek08
Created July 22, 2019 15:16
Show Gist options
  • Save 08vivek08/a5f6a24ad73e436724301dea548b8141 to your computer and use it in GitHub Desktop.
Save 08vivek08/a5f6a24ad73e436724301dea548b8141 to your computer and use it in GitHub Desktop.
/* 2. Randomly generate all code of four digit no with
unit as a fibboniccai no & prime no
tenth & hundred place difference as 2
*/
#include <bits/stdc++.h>
using namespace std;
int arr[]={2,3,5};
void code_gen(){
for(int i=1000;i<9999;i++){
int d1,d2,d3,d4;
d1=i%10;
d2=(i/10)%10;
d3=(i/100)%10;
d4=(i/1000)%10;
set<int>s;
s.insert(d1);
s.insert(d2);
s.insert(d3);
s.insert(d4);
// check all digit are distinct
if(s.size()!=4){
continue;
}
// check original condition
if(d1==2 || d1==3 || d1==5){
if(d3-d2==2 && d4-d3==2){
cout<<i<<"\n";
}
}
}
}
int main(){
code_gen();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment